2 * Routines for Kerberos
3 * Wes Hardaker (c) 2000
4 * wjhardaker@ucdavis.edu
5 * Richard Sharpe (C) 2002, rsharpe@samba.org, modularized a bit more and
6 * added AP-REQ and AP-REP dissection
8 * See RFC 1510, and various I-Ds and other documents showing additions,
9 * e.g. ones listed under
11 * http://www.isi.edu/people/bcn/krb-revisions/
15 * http://www.ietf.org/internet-drafts/draft-ietf-krb-wg-kerberos-clarifications-03.txt
17 * $Id: packet-kerberos.c,v 1.38 2003/04/25 21:30:42 guy Exp $
19 * Ethereal - Network traffic analyzer
20 * By Gerald Combs <gerald@ethereal.com>
21 * Copyright 1998 Gerald Combs
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * as published by the Free Software Foundation; either version 2
26 * of the License, or (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
48 #include <epan/packet.h>
50 #include <epan/strutil.h>
53 #include "packet-netbios.h"
54 #include "packet-gssapi.h"
55 #include "packet-tcp.h"
58 #define UDP_PORT_KERBEROS 88
59 #define TCP_PORT_KERBEROS 88
61 /* Desegment Kerberos over TCP messages */
62 static gboolean krb_desegment = TRUE;
64 static gint proto_kerberos = -1;
65 static gint hf_krb_rm_reserved = -1;
66 static gint hf_krb_rm_reclen = -1;
68 static gint ett_kerberos = -1;
69 static gint ett_preauth = -1;
70 static gint ett_addresses = -1;
71 static gint ett_request = -1;
72 static gint ett_princ = -1;
73 static gint ett_ticket = -1;
74 static gint ett_encrypted = -1;
75 static gint ett_etype = -1;
76 static gint ett_additional_tickets = -1;
77 static gint ett_recordmark = -1;
80 #define KRB_RM_RESERVED 0x80000000L
81 #define KRB_RM_RECLEN 0x7fffffffL
83 #define KRB5_MSG_AS_REQ 10 /* AS-REQ type */
84 #define KRB5_MSG_AS_REP 11 /* AS-REP type */
85 #define KRB5_MSG_TGS_REQ 12 /* TGS-REQ type */
86 #define KRB5_MSG_TGS_REP 13 /* TGS-REP type */
87 #define KRB5_MSG_AP_REQ 14 /* AP-REQ type */
88 #define KRB5_MSG_AP_REP 15 /* AP-REP type */
90 #define KRB5_MSG_SAFE 20 /* KRB-SAFE type */
91 #define KRB5_MSG_PRIV 21 /* KRB-PRIV type */
92 #define KRB5_MSG_CRED 22 /* KRB-CRED type */
93 #define KRB5_MSG_ERROR 30 /* KRB-ERROR type */
95 /* Type tags within KDC-REQ */
96 #define KRB5_KDC_REQ_PVNO 1
97 #define KRB5_KDC_REQ_MSG_TYPE 2
98 #define KRB5_KDC_REQ_PADATA 3
99 #define KRB5_KDC_REQ_REQBODY 4
101 /* Type tags within KDC-REP */
102 #define KRB5_KDC_REP_PVNO 0
103 #define KRB5_KDC_REP_MSG_TYPE 1
104 #define KRB5_KDC_REP_PADATA 2
105 #define KRB5_KDC_REP_CREALM 3
106 #define KRB5_KDC_REP_CNAME 4
107 #define KRB5_KDC_REP_TICKET 5
108 #define KRB5_KDC_REP_ENC_PART 6
110 /* Type tags within KDC-REQ-BODY */
111 #define KRB5_BODY_KDC_OPTIONS 0
112 #define KRB5_BODY_CNAME 1
113 #define KRB5_BODY_REALM 2
114 #define KRB5_BODY_SNAME 3
115 #define KRB5_BODY_FROM 4
116 #define KRB5_BODY_TILL 5
117 #define KRB5_BODY_RTIME 6
118 #define KRB5_BODY_NONCE 7
119 #define KRB5_BODY_ENCTYPE 8
120 #define KRB5_BODY_ADDRESSES 9
121 #define KRB5_BODY_ENC_AUTHORIZATION_DATA 10
122 #define KRB5_BODY_ADDITIONAL_TICKETS 11
124 /* TAGs within AP-REQ */
125 #define KRB5_AP_REQ_APOPTIONS 2
126 #define KRB5_AP_REQ_TICKET 3
127 #define KRB5_AP_REQ_ENC_DATA 4
129 /* TAGs within AP-REP */
130 #define KRB5_AP_REP_ENC_DATA 2
132 /* Type tags within KRB-ERROR */
133 #define KRB5_ERROR_PVNO 0
134 #define KRB5_ERROR_MSG_TYPE 1
135 #define KRB5_ERROR_CTIME 2
136 #define KRB5_ERROR_CUSEC 3
137 #define KRB5_ERROR_STIME 4
138 #define KRB5_ERROR_SUSEC 5
139 #define KRB5_ERROR_ERROR_CODE 6
140 #define KRB5_ERROR_CREALM 7
141 #define KRB5_ERROR_CNAME 8
142 #define KRB5_ERROR_REALM 9
143 #define KRB5_ERROR_SNAME 10
144 #define KRB5_ERROR_ETEXT 11
145 #define KRB5_ERROR_EDATA 12
147 /* address type constants */
148 #define KRB5_ADDR_IPv4 0x02
149 #define KRB5_ADDR_CHAOS 0x05
150 #define KRB5_ADDR_XEROX 0x06
151 #define KRB5_ADDR_ISO 0x07
152 #define KRB5_ADDR_DECNET 0x0c
153 #define KRB5_ADDR_APPLETALK 0x10
154 #define KRB5_ADDR_NETBIOS 0x14
155 #define KRB5_ADDR_IPv6 0x18
157 /* encryption type constants */
158 #define KRB5_ENCTYPE_NULL 0
159 #define KRB5_ENCTYPE_DES_CBC_CRC 1
160 #define KRB5_ENCTYPE_DES_CBC_MD4 2
161 #define KRB5_ENCTYPE_DES_CBC_MD5 3
162 #define KRB5_ENCTYPE_DES_CBC_RAW 4
163 #define KRB5_ENCTYPE_DES3_CBC_SHA 5
164 #define KRB5_ENCTYPE_DES3_CBC_RAW 6
165 #define KRB5_ENCTYPE_DES_HMAC_SHA1 8
166 #define KRB5_ENCTYPE_DES3_CBC_SHA1 16
167 #define KERB_ENCTYPE_RC4_HMAC 23
168 #define KERB_ENCTYPE_RC4_HMAC_EXP 24
169 #define KRB5_ENCTYPE_UNKNOWN 0x1ff
170 #define KRB5_ENCTYPE_LOCAL_DES3_HMAC_SHA1 0x7007
173 * For KERB_ENCTYPE_RC4_HMAC and KERB_ENCTYPE_RC4_HMAC_EXP, see
175 * http://www.ietf.org/internet-drafts/draft-brezak-win2k-krb-rc4-hmac-04.txt
177 * unless it's expired.
180 /* pre-authentication type constants */
181 #define KRB5_PA_TGS_REQ 1
182 #define KRB5_PA_ENC_TIMESTAMP 2
183 #define KRB5_PA_PW_SALT 3
184 #define KRB5_PA_ENC_ENCKEY 4
185 #define KRB5_PA_ENC_UNIX_TIME 5
186 #define KRB5_PA_ENC_SANDIA_SECURID 6
187 #define KRB5_PA_SESAME 7
188 #define KRB5_PA_OSF_DCE 8
189 #define KRB5_PA_CYBERSAFE_SECUREID 9
190 #define KRB5_PA_AFS3_SALT 10
191 #define KRB5_PA_ENCTYPE_INFO 11
192 #define KRB5_PA_SAM_CHALLENGE 12
193 #define KRB5_PA_SAM_RESPONSE 13
194 #define KRB5_PA_DASS 16
195 #define KRB5_PA_USE_SPECIFIED_KVNO 20
196 #define KRB5_PA_SAM_REDIRECT 21
197 #define KRB5_PA_GET_FROM_TYPED_DATA 22
198 #define KRB5_PA_SAM_ETYPE_INFO 23
199 #define KRB5_PA_ALT_PRINC 24
200 #define KRB5_PA_SAM_CHALLENGE2 30
201 #define KRB5_PA_SAM_RESPONSE2 31
202 #define KRB5_PA_PAC_REQUEST 128
204 /* Type tags within Ticket */
205 #define KRB5_TKT_TKT_VNO 0
206 #define KRB5_TKT_REALM 1
207 #define KRB5_TKT_SNAME 2
208 #define KRB5_TKT_ENC_PART 3
210 /* Principal name-type */
211 #define KRB5_NT_UNKNOWN 0
212 #define KRB5_NT_PRINCIPAL 1
213 #define KRB5_NT_SRV_INST 2
214 #define KRB5_NT_SRV_HST 3
215 #define KRB5_NT_SRV_XHST 4
216 #define KRB5_NT_UID 5
218 /* error table constants */
219 /* I prefixed the krb5_err.et constant names with KRB5_ET_ for these */
220 #define KRB5_ET_KRB5KDC_ERR_NONE 0
221 #define KRB5_ET_KRB5KDC_ERR_NAME_EXP 1
222 #define KRB5_ET_KRB5KDC_ERR_SERVICE_EXP 2
223 #define KRB5_ET_KRB5KDC_ERR_BAD_PVNO 3
224 #define KRB5_ET_KRB5KDC_ERR_C_OLD_MAST_KVNO 4
225 #define KRB5_ET_KRB5KDC_ERR_S_OLD_MAST_KVNO 5
226 #define KRB5_ET_KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN 6
227 #define KRB5_ET_KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN 7
228 #define KRB5_ET_KRB5KDC_ERR_PRINCIPAL_NOT_UNIQUE 8
229 #define KRB5_ET_KRB5KDC_ERR_NULL_KEY 9
230 #define KRB5_ET_KRB5KDC_ERR_CANNOT_POSTDATE 10
231 #define KRB5_ET_KRB5KDC_ERR_NEVER_VALID 11
232 #define KRB5_ET_KRB5KDC_ERR_POLICY 12
233 #define KRB5_ET_KRB5KDC_ERR_BADOPTION 13
234 #define KRB5_ET_KRB5KDC_ERR_ETYPE_NOSUPP 14
235 #define KRB5_ET_KRB5KDC_ERR_SUMTYPE_NOSUPP 15
236 #define KRB5_ET_KRB5KDC_ERR_PADATA_TYPE_NOSUPP 16
237 #define KRB5_ET_KRB5KDC_ERR_TRTYPE_NOSUPP 17
238 #define KRB5_ET_KRB5KDC_ERR_CLIENT_REVOKED 18
239 #define KRB5_ET_KRB5KDC_ERR_SERVICE_REVOKED 19
240 #define KRB5_ET_KRB5KDC_ERR_TGT_REVOKED 20
241 #define KRB5_ET_KRB5KDC_ERR_CLIENT_NOTYET 21
242 #define KRB5_ET_KRB5KDC_ERR_SERVICE_NOTYET 22
243 #define KRB5_ET_KRB5KDC_ERR_KEY_EXP 23
244 #define KRB5_ET_KRB5KDC_ERR_PREAUTH_FAILED 24
245 #define KRB5_ET_KRB5KDC_ERR_PREAUTH_REQUIRED 25
246 #define KRB5_ET_KRB5KDC_ERR_SERVER_NOMATCH 26
247 #define KRB5_ET_KRB5KRB_AP_ERR_BAD_INTEGRITY 31
248 #define KRB5_ET_KRB5KRB_AP_ERR_TKT_EXPIRED 32
249 #define KRB5_ET_KRB5KRB_AP_ERR_TKT_NYV 33
250 #define KRB5_ET_KRB5KRB_AP_ERR_REPEAT 34
251 #define KRB5_ET_KRB5KRB_AP_ERR_NOT_US 35
252 #define KRB5_ET_KRB5KRB_AP_ERR_BADMATCH 36
253 #define KRB5_ET_KRB5KRB_AP_ERR_SKEW 37
254 #define KRB5_ET_KRB5KRB_AP_ERR_BADADDR 38
255 #define KRB5_ET_KRB5KRB_AP_ERR_BADVERSION 39
256 #define KRB5_ET_KRB5KRB_AP_ERR_MSG_TYPE 40
257 #define KRB5_ET_KRB5KRB_AP_ERR_MODIFIED 41
258 #define KRB5_ET_KRB5KRB_AP_ERR_BADORDER 42
259 #define KRB5_ET_KRB5KRB_AP_ERR_ILL_CR_TKT 43
260 #define KRB5_ET_KRB5KRB_AP_ERR_BADKEYVER 44
261 #define KRB5_ET_KRB5KRB_AP_ERR_NOKEY 45
262 #define KRB5_ET_KRB5KRB_AP_ERR_MUT_FAIL 46
263 #define KRB5_ET_KRB5KRB_AP_ERR_BADDIRECTION 47
264 #define KRB5_ET_KRB5KRB_AP_ERR_METHOD 48
265 #define KRB5_ET_KRB5KRB_AP_ERR_BADSEQ 49
266 #define KRB5_ET_KRB5KRB_AP_ERR_INAPP_CKSUM 50
267 #define KRB5_ET_KRB5KRB_ERR_RESPONSE_TOO_BIG 52
268 #define KRB5_ET_KRB5KRB_ERR_GENERIC 60
269 #define KRB5_ET_KRB5KRB_ERR_FIELD_TOOLONG 61
271 static const value_string krb5_error_codes[] = {
272 { KRB5_ET_KRB5KDC_ERR_NONE, "KRB5KDC_ERR_NONE" },
273 { KRB5_ET_KRB5KDC_ERR_NAME_EXP, "KRB5KDC_ERR_NAME_EXP" },
274 { KRB5_ET_KRB5KDC_ERR_SERVICE_EXP, "KRB5KDC_ERR_SERVICE_EXP" },
275 { KRB5_ET_KRB5KDC_ERR_BAD_PVNO, "KRB5KDC_ERR_BAD_PVNO" },
276 { KRB5_ET_KRB5KDC_ERR_C_OLD_MAST_KVNO, "KRB5KDC_ERR_C_OLD_MAST_KVNO" },
277 { KRB5_ET_KRB5KDC_ERR_S_OLD_MAST_KVNO, "KRB5KDC_ERR_S_OLD_MAST_KVNO" },
278 { KRB5_ET_KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN, "KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN" },
279 { KRB5_ET_KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN, "KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN" },
280 { KRB5_ET_KRB5KDC_ERR_PRINCIPAL_NOT_UNIQUE, "KRB5KDC_ERR_PRINCIPAL_NOT_UNIQUE" },
281 { KRB5_ET_KRB5KDC_ERR_NULL_KEY, "KRB5KDC_ERR_NULL_KEY" },
282 { KRB5_ET_KRB5KDC_ERR_CANNOT_POSTDATE, "KRB5KDC_ERR_CANNOT_POSTDATE" },
283 { KRB5_ET_KRB5KDC_ERR_NEVER_VALID, "KRB5KDC_ERR_NEVER_VALID" },
284 { KRB5_ET_KRB5KDC_ERR_POLICY, "KRB5KDC_ERR_POLICY" },
285 { KRB5_ET_KRB5KDC_ERR_BADOPTION, "KRB5KDC_ERR_BADOPTION" },
286 { KRB5_ET_KRB5KDC_ERR_ETYPE_NOSUPP, "KRB5KDC_ERR_ETYPE_NOSUPP" },
287 { KRB5_ET_KRB5KDC_ERR_SUMTYPE_NOSUPP, "KRB5KDC_ERR_SUMTYPE_NOSUPP" },
288 { KRB5_ET_KRB5KDC_ERR_PADATA_TYPE_NOSUPP, "KRB5KDC_ERR_PADATA_TYPE_NOSUPP" },
289 { KRB5_ET_KRB5KDC_ERR_TRTYPE_NOSUPP, "KRB5KDC_ERR_TRTYPE_NOSUPP" },
290 { KRB5_ET_KRB5KDC_ERR_CLIENT_REVOKED, "KRB5KDC_ERR_CLIENT_REVOKED" },
291 { KRB5_ET_KRB5KDC_ERR_SERVICE_REVOKED, "KRB5KDC_ERR_SERVICE_REVOKED" },
292 { KRB5_ET_KRB5KDC_ERR_TGT_REVOKED, "KRB5KDC_ERR_TGT_REVOKED" },
293 { KRB5_ET_KRB5KDC_ERR_CLIENT_NOTYET, "KRB5KDC_ERR_CLIENT_NOTYET" },
294 { KRB5_ET_KRB5KDC_ERR_SERVICE_NOTYET, "KRB5KDC_ERR_SERVICE_NOTYET" },
295 { KRB5_ET_KRB5KDC_ERR_KEY_EXP, "KRB5KDC_ERR_KEY_EXP" },
296 { KRB5_ET_KRB5KDC_ERR_PREAUTH_FAILED, "KRB5KDC_ERR_PREAUTH_FAILED" },
297 { KRB5_ET_KRB5KDC_ERR_PREAUTH_REQUIRED, "KRB5KDC_ERR_PREAUTH_REQUIRED" },
298 { KRB5_ET_KRB5KDC_ERR_SERVER_NOMATCH, "KRB5KDC_ERR_SERVER_NOMATCH" },
299 { KRB5_ET_KRB5KRB_AP_ERR_BAD_INTEGRITY, "KRB5KRB_AP_ERR_BAD_INTEGRITY" },
300 { KRB5_ET_KRB5KRB_AP_ERR_TKT_EXPIRED, "KRB5KRB_AP_ERR_TKT_EXPIRED" },
301 { KRB5_ET_KRB5KRB_AP_ERR_TKT_NYV, "KRB5KRB_AP_ERR_TKT_NYV" },
302 { KRB5_ET_KRB5KRB_AP_ERR_REPEAT, "KRB5KRB_AP_ERR_REPEAT" },
303 { KRB5_ET_KRB5KRB_AP_ERR_NOT_US, "KRB5KRB_AP_ERR_NOT_US" },
304 { KRB5_ET_KRB5KRB_AP_ERR_BADMATCH, "KRB5KRB_AP_ERR_BADMATCH" },
305 { KRB5_ET_KRB5KRB_AP_ERR_SKEW, "KRB5KRB_AP_ERR_SKEW" },
306 { KRB5_ET_KRB5KRB_AP_ERR_BADADDR, "KRB5KRB_AP_ERR_BADADDR" },
307 { KRB5_ET_KRB5KRB_AP_ERR_BADVERSION, "KRB5KRB_AP_ERR_BADVERSION" },
308 { KRB5_ET_KRB5KRB_AP_ERR_MSG_TYPE, "KRB5KRB_AP_ERR_MSG_TYPE" },
309 { KRB5_ET_KRB5KRB_AP_ERR_MODIFIED, "KRB5KRB_AP_ERR_MODIFIED" },
310 { KRB5_ET_KRB5KRB_AP_ERR_BADORDER, "KRB5KRB_AP_ERR_BADORDER" },
311 { KRB5_ET_KRB5KRB_AP_ERR_ILL_CR_TKT, "KRB5KRB_AP_ERR_ILL_CR_TKT" },
312 { KRB5_ET_KRB5KRB_AP_ERR_BADKEYVER, "KRB5KRB_AP_ERR_BADKEYVER" },
313 { KRB5_ET_KRB5KRB_AP_ERR_NOKEY, "KRB5KRB_AP_ERR_NOKEY" },
314 { KRB5_ET_KRB5KRB_AP_ERR_MUT_FAIL, "KRB5KRB_AP_ERR_MUT_FAIL" },
315 { KRB5_ET_KRB5KRB_AP_ERR_BADDIRECTION, "KRB5KRB_AP_ERR_BADDIRECTION" },
316 { KRB5_ET_KRB5KRB_AP_ERR_METHOD, "KRB5KRB_AP_ERR_METHOD" },
317 { KRB5_ET_KRB5KRB_AP_ERR_BADSEQ, "KRB5KRB_AP_ERR_BADSEQ" },
318 { KRB5_ET_KRB5KRB_AP_ERR_INAPP_CKSUM, "KRB5KRB_AP_ERR_INAPP_CKSUM" },
319 { KRB5_ET_KRB5KRB_ERR_RESPONSE_TOO_BIG, "KRB5KRB_ERR_RESPONSE_TOO_BIG"},
320 { KRB5_ET_KRB5KRB_ERR_GENERIC, "KRB5KRB_ERR_GENERIC" },
321 { KRB5_ET_KRB5KRB_ERR_FIELD_TOOLONG, "KRB5KRB_ERR_FIELD_TOOLONG" },
326 static const value_string krb5_princ_types[] = {
327 { KRB5_NT_UNKNOWN , "Unknown" },
328 { KRB5_NT_PRINCIPAL , "Principal" },
329 { KRB5_NT_SRV_INST , "Service and Instance" },
330 { KRB5_NT_SRV_HST , "Service and Host" },
331 { KRB5_NT_SRV_XHST , "Service and Host Components" },
332 { KRB5_NT_UID , "Unique ID" },
336 static const value_string krb5_preauthentication_types[] = {
337 { KRB5_PA_TGS_REQ , "PA-TGS-REQ" },
338 { KRB5_PA_ENC_TIMESTAMP , "PA-ENC-TIMESTAMP" },
339 { KRB5_PA_PW_SALT , "PA-PW-SALT" },
340 { KRB5_PA_ENC_ENCKEY , "PA-ENC-ENCKEY" },
341 { KRB5_PA_ENC_UNIX_TIME , "PA-ENC-UNIX-TIME" },
342 { KRB5_PA_ENC_SANDIA_SECURID , "PA-PW-SALT" },
343 { KRB5_PA_SESAME , "PA-SESAME" },
344 { KRB5_PA_OSF_DCE , "PA-OSF-DCE" },
345 { KRB5_PA_CYBERSAFE_SECUREID , "PA-CYBERSAFE-SECURID" },
346 { KRB5_PA_AFS3_SALT , "PA-AFS3-SALT" },
347 { KRB5_PA_ENCTYPE_INFO , "PA-ENCTYPE-INFO" },
348 { KRB5_PA_SAM_CHALLENGE , "PA-SAM-CHALLENGE" },
349 { KRB5_PA_SAM_RESPONSE , "PA-SAM-RESPONSE" },
350 { KRB5_PA_DASS , "PA-DASS" },
351 { KRB5_PA_USE_SPECIFIED_KVNO , "PA-USE-SPECIFIED-KVNO" },
352 { KRB5_PA_SAM_REDIRECT , "PA-SAM-REDIRECT" },
353 { KRB5_PA_GET_FROM_TYPED_DATA , "PA-GET-FROM-TYPED-DATA" },
354 { KRB5_PA_SAM_ETYPE_INFO , "PA-SAM-ETYPE-INFO" },
355 { KRB5_PA_ALT_PRINC , "PA-ALT-PRINC" },
356 { KRB5_PA_SAM_CHALLENGE2 , "PA-SAM-CHALLENGE2" },
357 { KRB5_PA_SAM_RESPONSE2 , "PA-SAM-RESPONSE2" },
358 { KRB5_PA_PAC_REQUEST , "PA-PAC-REQUEST" },
362 static const value_string krb5_encryption_types[] = {
363 { KRB5_ENCTYPE_NULL , "NULL" },
364 { KRB5_ENCTYPE_DES_CBC_CRC , "des-cbc-crc" },
365 { KRB5_ENCTYPE_DES_CBC_MD4 , "des-cbc-md4" },
366 { KRB5_ENCTYPE_DES_CBC_MD5 , "des-cbc-md5" },
367 { KRB5_ENCTYPE_DES_CBC_RAW , "des-cbc-raw" },
368 { KRB5_ENCTYPE_DES3_CBC_SHA , "des3-cbc-sha" },
369 { KRB5_ENCTYPE_DES3_CBC_RAW , "des3-cbc-raw" },
370 { KRB5_ENCTYPE_DES_HMAC_SHA1 , "des-hmac-sha1" },
371 { KRB5_ENCTYPE_DES3_CBC_SHA1 , "des3-cbc-sha1" },
372 { KERB_ENCTYPE_RC4_HMAC , "rc4-hmac" },
373 { KERB_ENCTYPE_RC4_HMAC_EXP , "rc4-hmac-exp" },
374 { KRB5_ENCTYPE_UNKNOWN , "unknown" },
375 { KRB5_ENCTYPE_LOCAL_DES3_HMAC_SHA1 , "local-des3-hmac-sha1" },
379 static const value_string krb5_address_types[] = {
380 { KRB5_ADDR_IPv4, "IPv4"},
381 { KRB5_ADDR_CHAOS, "CHAOS"},
382 { KRB5_ADDR_XEROX, "XEROX"},
383 { KRB5_ADDR_ISO, "ISO"},
384 { KRB5_ADDR_DECNET, "DECNET"},
385 { KRB5_ADDR_APPLETALK, "APPLETALK"},
386 { KRB5_ADDR_NETBIOS, "NETBIOS"},
387 { KRB5_ADDR_IPv6, "IPv6"},
391 static const value_string krb5_msg_types[] = {
392 { KRB5_MSG_TGS_REQ, "TGS-REQ" },
393 { KRB5_MSG_TGS_REP, "TGS-REP" },
394 { KRB5_MSG_AS_REQ, "AS-REQ" },
395 { KRB5_MSG_AS_REP, "AS-REP" },
396 { KRB5_MSG_AP_REQ, "AP-REQ" },
397 { KRB5_MSG_AP_REP, "AP-REP" },
398 { KRB5_MSG_SAFE, "KRB-SAFE" },
399 { KRB5_MSG_PRIV, "KRB-PRIV" },
400 { KRB5_MSG_CRED, "KRB-CRED" },
401 { KRB5_MSG_ERROR, "KRB-ERROR" },
405 static struct { char *set; char *unset; } bitval = { "Set", "Not set" };
407 static int dissect_PrincipalName(char *title, ASN1_SCK *asn1p,
408 packet_info *pinfo, proto_tree *tree,
410 static int dissect_Ticket(ASN1_SCK *asn1p, packet_info *pinfo,
411 proto_tree *tree, int start_offset);
412 static int dissect_EncryptedData(char *title, ASN1_SCK *asn1p,
413 packet_info *pinfo, proto_tree *tree,
415 static int dissect_Addresses(ASN1_SCK *asn1p, packet_info *pinfo,
416 proto_tree *tree, int start_offset);
417 static void dissect_kerberos_udp(tvbuff_t *tvb, packet_info *pinfo,
419 static void dissect_kerberos_tcp(tvbuff_t *tvb, packet_info *pinfo,
421 static gint dissect_kerberos_common(tvbuff_t *tvb, packet_info *pinfo,
422 proto_tree *tree, int do_col_info,
424 static void show_krb_recordmark(proto_tree *kerberos_tree, tvbuff_t *tvb,
425 gint start, guint32 krb_rm);
426 static gint kerberos_rm_to_reclen(guint krb_rm);
427 static void dissect_kerberos_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo,
429 static guint get_krb_pdu_len(tvbuff_t *tvb, int offset);
432 to_error_str(int ret) {
435 case ASN1_ERR_EOC_MISMATCH:
436 return("EOC mismatch");
438 case ASN1_ERR_WRONG_TYPE:
439 return("Wrong type for that item");
441 case ASN1_ERR_LENGTH_NOT_DEFINITE:
442 return("Length was indefinite");
444 case ASN1_ERR_LENGTH_MISMATCH:
445 return("Length mismatch");
447 case ASN1_ERR_WRONG_LENGTH_FOR_TYPE:
448 return("Wrong length for that item's type");
451 return("Unknown error");
455 krb_proto_tree_add_time(proto_tree *tree, tvbuff_t *tvb, int offset,
456 int str_len, char *name, guchar *str)
459 proto_tree_add_text(tree, tvb, offset, str_len,
460 "%s: %.4s-%.2s-%.2s %.2s:%.2s:%.2s (%.1s)",
461 name, str, str+4, str+6,
462 str+8, str+10, str+12,
468 * You must be kidding. I'm going to actually use a macro to do something?
472 #define KRB_HEAD_DECODE_OR_DIE(token) \
473 start = asn1p->offset; \
474 ret = asn1_header_decode (asn1p, &cls, &con, &tag, &def, &item_len); \
475 if (ret != ASN1_ERR_NOERROR) {\
476 if (check_col(pinfo->cinfo, COL_INFO)) \
477 col_add_fstr(pinfo->cinfo, COL_INFO, "ERROR: Problem at %s: %s, offset: %d", \
478 token, to_error_str(ret), start); \
482 if (check_col(pinfo->cinfo, COL_INFO)) \
483 col_add_fstr(pinfo->cinfo, COL_INFO, "not definite: %s", token); \
484 fprintf(stderr,"not definite: %s\n", token); \
487 offset += (asn1p->offset - start);
489 #define CHECK_APPLICATION_TYPE(expected_tag) \
490 (cls == ASN1_APL && con == ASN1_CON && tag == expected_tag)
492 #define DIE_IF_NOT_APPLICATION_TYPE(token, expected_tag) \
493 if (!CHECK_APPLICATION_TYPE(expected_tag)) \
494 DIE_WITH_BAD_TYPE(token, expected_tag);
496 #define CHECK_CONTEXT_TYPE(expected_tag) \
497 (cls == ASN1_CTX && con == ASN1_CON && tag == expected_tag)
499 #define DIE_IF_NOT_CONTEXT_TYPE(token, expected_tag) \
500 if (!CHECK_CONTEXT_TYPE(expected_tag)) \
501 DIE_WITH_BAD_TYPE(token, expected_tag);
503 #define DIE_WITH_BAD_TYPE(token, expected_tag) \
505 if (check_col(pinfo->cinfo, COL_INFO)) \
506 col_add_fstr(pinfo->cinfo, COL_INFO, "ERROR: Problem at %s: %s (tag=%d exp=%d, con=%d, cls=%d, offset=%0x)", \
507 token, to_error_str(ASN1_ERR_WRONG_TYPE), tag, expected_tag, con, cls, start); \
511 #define KRB_DECODE_APPLICATION_TAGGED_HEAD_OR_DIE(token, expected_tag) \
512 KRB_HEAD_DECODE_OR_DIE(token); \
513 DIE_IF_NOT_APPLICATION_TYPE(token, expected_tag);
515 #define KRB_DECODE_CONTEXT_HEAD_OR_DIE(token, expected_tag) \
516 KRB_HEAD_DECODE_OR_DIE(token); \
517 DIE_IF_NOT_CONTEXT_TYPE(token, expected_tag);
519 #define KRB_SEQ_HEAD_DECODE_OR_DIE(token) \
520 ret = asn1_sequence_decode (asn1p, &item_len, &header_len); \
521 if (ret != ASN1_ERR_NOERROR) {\
522 if (check_col(pinfo->cinfo, COL_INFO)) \
523 col_add_fstr(pinfo->cinfo, COL_INFO, "ERROR: Problem at %s: %s", \
524 token, to_error_str(ret)); \
527 offset += header_len;
529 #define KRB_DECODE_OR_DIE(token, fn, val) \
530 ret = fn (asn1p, &val, &length); \
531 if (ret != ASN1_ERR_NOERROR) { \
532 if (check_col(pinfo->cinfo, COL_INFO)) \
533 col_add_fstr(pinfo->cinfo, COL_INFO, "ERROR: Problem at %s: %s", \
534 token, to_error_str(ret)); \
538 #define KRB_DECODE_UINT32_OR_DIE(token, val) \
539 KRB_DECODE_OR_DIE(token, asn1_uint32_decode, val);
541 #define KRB_DECODE_STRING_OR_DIE(token, expected_tag, val, val_len, item_len) \
542 ret = asn1_string_decode (asn1p, &val, &val_len, &item_len, expected_tag); \
543 if (ret != ASN1_ERR_NOERROR) { \
544 if (check_col(pinfo->cinfo, COL_INFO)) \
545 col_add_fstr(pinfo->cinfo, COL_INFO, "ERROR: Problem at %s: %s", \
546 token, to_error_str(ret)); \
550 #define KRB_DECODE_OCTET_STRING_OR_DIE(token, val, val_len, item_len) \
551 KRB_DECODE_STRING_OR_DIE(token, ASN1_OTS, val, val_len, item_len)
553 #define KRB_DECODE_GENERAL_STRING_OR_DIE(token, val, val_len, item_len) \
554 KRB_DECODE_STRING_OR_DIE(token, ASN1_GENSTR, val, val_len, item_len)
556 #define KRB_DECODE_GENERAL_TIME_OR_DIE(token, val, val_len, item_len) \
557 KRB_DECODE_STRING_OR_DIE(token, ASN1_GENTIM, val, val_len, item_len)
559 /* dissect_type_value_pair decodes (roughly) this:
566 which is all over the place in krb5 */
569 dissect_type_value_pair(ASN1_SCK *asn1p, int *inoff,
570 guint32 *type, int *type_len, int *type_off,
571 guchar **val, int *val_len, int *val_off) {
580 start = asn1p->offset;
581 asn1_header_decode (asn1p, &cls, &con, &tag, &def, &tmp_len);
582 offset += (asn1p->offset - start);
586 start = asn1p->offset;
587 asn1_header_decode (asn1p, &cls, &con, &tag, &def, &tmp_len);
588 offset += (asn1p->offset - start);
594 ret = asn1_uint32_decode(asn1p, type, type_len);
595 if (ret != ASN1_ERR_NOERROR) {
596 fprintf(stderr,"die: type_value_pair: type, %s\n", to_error_str(ret));
601 /* OCTET STRING (or generic data) */
603 start = asn1p->offset;
604 asn1_header_decode (asn1p, &cls, &con, &tag, &def, val_len);
605 asn1_header_decode (asn1p, &cls, &con, &tag, &def, val_len);
606 offset += asn1p->offset - start;
612 asn1_string_value_decode (asn1p, *val_len, val);
614 *inoff = offset + *val_len;
618 dissect_kerberos_main(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int do_col_info)
620 return (dissect_kerberos_common(tvb, pinfo, tree, do_col_info, FALSE));
624 dissect_kerberos_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
626 if (check_col(pinfo->cinfo, COL_PROTOCOL))
627 col_set_str(pinfo->cinfo, COL_PROTOCOL, "KRB5");
629 (void)dissect_kerberos_common(tvb, pinfo, tree, TRUE, FALSE);
633 kerberos_rm_to_reclen(guint krb_rm)
635 return (krb_rm & KRB_RM_RECLEN);
639 get_krb_pdu_len(tvbuff_t *tvb, int offset)
644 krb_rm = tvb_get_ntohl(tvb, offset);
645 pdulen = kerberos_rm_to_reclen(krb_rm);
650 dissect_kerberos_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
652 pinfo->fragmented = TRUE;
653 if (dissect_kerberos_common(tvb, pinfo, tree, TRUE, TRUE) < 0) {
655 * The dissector failed to recognize this as a valid
656 * Kerberos message. Mark it as a continuation packet.
658 if (check_col(pinfo->cinfo, COL_INFO)) {
659 col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
665 dissect_kerberos_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
667 if (check_col(pinfo->cinfo, COL_PROTOCOL))
668 col_set_str(pinfo->cinfo, COL_PROTOCOL, "KRB5");
670 tcp_dissect_pdus(tvb, pinfo, tree, krb_desegment, 4, get_krb_pdu_len,
671 dissect_kerberos_tcp_pdu);
675 * Display the TCP record mark.
678 show_krb_recordmark(proto_tree *tree, tvbuff_t *tvb, gint start, guint32 krb_rm)
687 rec_len = kerberos_rm_to_reclen(krb_rm);
688 rm_item = proto_tree_add_text(tree, tvb, start, 4,
689 "Record Mark: %u %s", rec_len, plurality(rec_len, "byte", "bytes"));
690 rm_tree = proto_item_add_subtree(rm_item, ett_recordmark);
691 proto_tree_add_boolean(rm_tree, hf_krb_rm_reserved, tvb, start, 4, krb_rm);
692 proto_tree_add_uint(rm_tree, hf_krb_rm_reclen, tvb, start, 4, krb_rm);
696 dissect_kerberos_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
697 int do_col_info, gboolean have_rm)
700 proto_tree *kerberos_tree = NULL;
701 proto_tree *etype_tree = NULL;
702 proto_tree *preauth_tree = NULL;
703 proto_tree *request_tree = NULL;
704 proto_tree *additional_tickets_tree = NULL;
705 ASN1_SCK asn1, *asn1p = &asn1;
706 proto_item *item = NULL;
713 int start, end, message_end, sequence_end;
717 guint protocol_message_type;
721 guint32 preauth_type;
727 int tmp_pos1, tmp_pos2;
729 /* TCP record mark and length */
734 krb_rm = tvb_get_ntohl(tvb, offset);
735 krb_reclen = kerberos_rm_to_reclen(krb_rm);
738 * What is a reasonable size limit?
740 if (krb_reclen > 10 * 1024 * 1024) {
746 asn1_open(&asn1, tvb, offset);
749 KRB_HEAD_DECODE_OR_DIE("top");
750 protocol_message_type = tag;
752 item = proto_tree_add_item(tree, proto_kerberos, tvb, 0, -1, FALSE);
753 kerberos_tree = proto_item_add_subtree(item, ett_kerberos);
756 * If item_len and krb_reclen disagree, which should we trust? Stick
757 * with item_len for now.
759 message_end = asn1p->offset + item_len;
762 KRB_HEAD_DECODE_OR_DIE("top2");
765 KRB_HEAD_DECODE_OR_DIE("version-wrap");
766 KRB_DECODE_UINT32_OR_DIE("version", version);
770 show_krb_recordmark(kerberos_tree, tvb, 0, krb_rm);
772 proto_tree_add_text(kerberos_tree, tvb, offset, length,
779 KRB_HEAD_DECODE_OR_DIE("message-type-wrap");
780 KRB_DECODE_UINT32_OR_DIE("message-type", msg_type);
783 proto_tree_add_text(kerberos_tree, tvb, offset, length,
785 val_to_str(msg_type, krb5_msg_types,
786 "Unknown msg type %#x"));
790 if (do_col_info & check_col(pinfo->cinfo, COL_INFO))
791 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(msg_type, krb5_msg_types,
792 "Unknown msg type %#x"));
794 /* is preauthentication present? */
795 KRB_HEAD_DECODE_OR_DIE("padata-or-body");
796 if (((protocol_message_type == KRB5_MSG_AS_REQ ||
797 protocol_message_type == KRB5_MSG_TGS_REQ) &&
798 tag == KRB5_KDC_REQ_PADATA) ||
799 ((protocol_message_type == KRB5_MSG_AS_REP ||
800 protocol_message_type == KRB5_MSG_TGS_REP) &&
801 tag == KRB5_KDC_REP_PADATA)) {
802 /* pre-authentication supplied */
805 item = proto_tree_add_text(kerberos_tree, tvb, offset,
806 item_len, "Pre-Authentication");
807 preauth_tree = proto_item_add_subtree(item, ett_preauth);
810 KRB_HEAD_DECODE_OR_DIE("sequence of pa-data");
811 end = asn1p->offset + item_len;
813 while(asn1p->offset < end) {
814 dissect_type_value_pair(asn1p, &offset,
815 &preauth_type, &item_len, &tmp_pos1,
816 &str, &str_len, &tmp_pos2);
819 proto_tree_add_text(preauth_tree, tvb, tmp_pos1,
820 item_len, "Type: %s",
821 val_to_str(preauth_type,
822 krb5_preauthentication_types,
823 "Unknown preauth type %#x"));
824 proto_tree_add_text(preauth_tree, tvb, tmp_pos2,
825 str_len, "Value: %s",
826 bytes_to_str(str, str_len));
829 KRB_HEAD_DECODE_OR_DIE("message-body");
832 switch (protocol_message_type) {
834 case KRB5_MSG_AS_REQ:
835 case KRB5_MSG_TGS_REQ:
837 AS-REQ ::= [APPLICATION 10] KDC-REQ
838 TGS-REQ ::= [APPLICATION 12] KDC-REQ
840 KDC-REQ ::= SEQUENCE {
843 padata[3] SEQUENCE OF PA-DATA OPTIONAL,
844 req-body[4] KDC-REQ-BODY
847 KDC-REQ-BODY ::= SEQUENCE {
848 kdc-options[0] KDCOptions,
849 cname[1] PrincipalName OPTIONAL,
850 -- Used only in AS-REQ
851 realm[2] Realm, -- Server's realm
852 -- Also client's in AS-REQ
853 sname[3] PrincipalName OPTIONAL,
854 from[4] KerberosTime OPTIONAL,
855 till[5] KerberosTime,
856 rtime[6] KerberosTime OPTIONAL,
858 etype[8] SEQUENCE OF INTEGER, -- EncryptionType,
859 -- in preference order
860 addresses[9] HostAddresses OPTIONAL,
861 enc-authorization-data[10] EncryptedData OPTIONAL,
862 -- Encrypted AuthorizationData encoding
863 additional-tickets[11] SEQUENCE OF Ticket OPTIONAL
868 KRB_HEAD_DECODE_OR_DIE("body-sequence");
870 item = proto_tree_add_text(kerberos_tree, tvb, offset,
871 item_len, "Request");
872 request_tree = proto_item_add_subtree(item, ett_request);
874 sequence_end = asn1p->offset + item_len;
877 KRB_HEAD_DECODE_OR_DIE("kdc options");
879 KRB_HEAD_DECODE_OR_DIE("kdc options:bits");
882 proto_tree_add_text(request_tree, tvb, offset, item_len,
884 tvb_bytes_to_str(asn1p->tvb, asn1p->offset,
888 asn1p->offset += item_len;
890 KRB_HEAD_DECODE_OR_DIE("Client Name or Realm");
892 if (CHECK_CONTEXT_TYPE(KRB5_BODY_CNAME)) {
893 item_len = dissect_PrincipalName("Client Name", asn1p, pinfo,
894 request_tree, offset);
898 KRB_HEAD_DECODE_OR_DIE("Realm");
901 DIE_IF_NOT_CONTEXT_TYPE("Realm", KRB5_BODY_REALM);
902 KRB_DECODE_GENERAL_STRING_OR_DIE("Realm", str, str_len, item_len);
904 proto_tree_add_text(request_tree, tvb, offset, item_len,
905 "Realm: %.*s", str_len, str);
909 KRB_HEAD_DECODE_OR_DIE("Server Name");
910 if (CHECK_CONTEXT_TYPE(KRB5_BODY_SNAME)) {
911 item_len = dissect_PrincipalName("Server Name", asn1p, pinfo,
912 request_tree, offset);
916 KRB_HEAD_DECODE_OR_DIE("From or Till");
919 if (CHECK_CONTEXT_TYPE(KRB5_BODY_FROM)) {
920 KRB_DECODE_GENERAL_TIME_OR_DIE("From", str, str_len, item_len);
921 krb_proto_tree_add_time(request_tree, asn1p->tvb, offset, item_len,
924 KRB_HEAD_DECODE_OR_DIE("Till");
927 DIE_IF_NOT_CONTEXT_TYPE("Till", KRB5_BODY_TILL);
928 KRB_DECODE_GENERAL_TIME_OR_DIE("Till", str, str_len, item_len);
929 krb_proto_tree_add_time(request_tree, asn1p->tvb, offset, item_len,
933 KRB_HEAD_DECODE_OR_DIE("Renewable Until or Nonce");
934 if (CHECK_CONTEXT_TYPE(KRB5_BODY_RTIME)) {
935 KRB_DECODE_GENERAL_TIME_OR_DIE("Renewable Until", str, str_len, item_len);
936 krb_proto_tree_add_time(request_tree, asn1p->tvb, offset, item_len,
937 "Renewable Until", str);
939 KRB_HEAD_DECODE_OR_DIE("Nonce");
942 DIE_IF_NOT_CONTEXT_TYPE("Nonce", KRB5_BODY_NONCE);
943 KRB_DECODE_UINT32_OR_DIE("Nonce", tmp_int);
945 proto_tree_add_text(request_tree, tvb, offset, length,
951 KRB_DECODE_CONTEXT_HEAD_OR_DIE("encryption type spot",
953 KRB_HEAD_DECODE_OR_DIE("encryption type list");
955 item = proto_tree_add_text(request_tree, tvb, offset,
956 item_len, "Encryption Types");
957 etype_tree = proto_item_add_subtree(item, ett_etype);
959 total_len = item_len;
960 while(total_len > 0) {
961 KRB_DECODE_UINT32_OR_DIE("encryption type", tmp_int);
963 proto_tree_add_text(etype_tree, tvb, offset, length,
966 krb5_encryption_types,
967 "Unknown encryption type %#x"));
973 if (asn1p->offset >= sequence_end)
975 KRB_HEAD_DECODE_OR_DIE("addresses or enc-authorization-data");
976 if (CHECK_CONTEXT_TYPE(KRB5_BODY_ADDRESSES)) {
977 /* addresses supplied */
979 length = dissect_Addresses(asn1p, pinfo, kerberos_tree,
984 if (asn1p->offset >= sequence_end)
986 KRB_HEAD_DECODE_OR_DIE("enc-authorization-data or additional-tickets");
989 if (CHECK_CONTEXT_TYPE(KRB5_BODY_ENC_AUTHORIZATION_DATA)) {
990 /* enc-authorization-data supplied */
991 length = dissect_EncryptedData("Encrypted Payload", asn1p, pinfo,
992 kerberos_tree, offset);
996 if (asn1p->offset >= sequence_end)
998 KRB_HEAD_DECODE_OR_DIE("additional-tickets");
1001 /* additional-tickets supplied */
1002 if (kerberos_tree) {
1003 item = proto_tree_add_text(kerberos_tree, tvb, offset,
1004 item_len, "Additional Tickets");
1005 additional_tickets_tree = proto_item_add_subtree(item, ett_additional_tickets);
1007 end = asn1p->offset + item_len;
1008 while(asn1p->offset < end) {
1009 KRB_DECODE_CONTEXT_HEAD_OR_DIE("ticket", KRB5_KDC_REP_TICKET);
1010 length = dissect_Ticket(asn1p, pinfo, additional_tickets_tree,
1019 case KRB5_MSG_AS_REP:
1020 case KRB5_MSG_TGS_REP:
1022 AS-REP ::= [APPLICATION 11] KDC-REP
1023 TGS-REP ::= [APPLICATION 13] KDC-REP
1025 KDC-REP ::= SEQUENCE {
1027 msg-type[1] INTEGER,
1028 padata[2] SEQUENCE OF PA-DATA OPTIONAL,
1030 cname[4] PrincipalName,
1032 enc-part[6] EncryptedData
1036 DIE_IF_NOT_CONTEXT_TYPE("crealm", KRB5_KDC_REP_CREALM);
1037 KRB_DECODE_GENERAL_STRING_OR_DIE("realm name", str, str_len, item_len);
1038 if (kerberos_tree) {
1039 proto_tree_add_text(kerberos_tree, tvb, offset, item_len,
1040 "Realm: %.*s", str_len, str);
1044 KRB_DECODE_CONTEXT_HEAD_OR_DIE("cname", KRB5_KDC_REP_CNAME);
1045 item_len = dissect_PrincipalName("Client Name", asn1p, pinfo,
1046 kerberos_tree, offset);
1051 KRB_DECODE_CONTEXT_HEAD_OR_DIE("ticket", KRB5_KDC_REP_TICKET);
1052 length = dissect_Ticket(asn1p, pinfo, kerberos_tree, offset);
1057 KRB_DECODE_CONTEXT_HEAD_OR_DIE("enc-msg-part",
1058 KRB5_KDC_REP_ENC_PART);
1059 length = dissect_EncryptedData("Encrypted Payload", asn1p, pinfo,
1060 kerberos_tree, offset);
1066 case KRB5_MSG_AP_REQ:
1069 /* We pulled the header above */
1071 KRB_HEAD_DECODE_OR_DIE("ap options:bits");
1073 if (kerberos_tree) {
1074 proto_tree_add_text(kerberos_tree, tvb, offset, item_len,
1076 tvb_bytes_to_str(asn1p->tvb, asn1p->offset,
1080 asn1p->offset += item_len;
1082 KRB_DECODE_CONTEXT_HEAD_OR_DIE("ticket", KRB5_AP_REQ_TICKET);
1083 length = dissect_Ticket(asn1p, pinfo, kerberos_tree, offset);
1088 KRB_DECODE_CONTEXT_HEAD_OR_DIE("authenticator",
1089 KRB5_AP_REQ_ENC_DATA);
1090 length = dissect_EncryptedData("Authenticator", asn1p, pinfo,
1091 kerberos_tree, offset);
1097 case KRB5_MSG_AP_REP:
1098 length = dissect_EncryptedData("EncPart", asn1p, pinfo,
1099 kerberos_tree, offset);
1105 case KRB5_MSG_ERROR:
1107 KRB-ERROR ::= [APPLICATION 30] SEQUENCE {
1109 msg-type[1] INTEGER,
1110 ctime[2] KerberosTime OPTIONAL,
1111 cusec[3] INTEGER OPTIONAL,
1112 stime[4] KerberosTime,
1114 error-code[6] INTEGER,
1115 crealm[7] Realm OPTIONAL,
1116 cname[8] PrincipalName OPTIONAL,
1117 realm[9] Realm, -- Correct realm
1118 sname[10] PrincipalName, -- Correct name
1119 e-text[11] GeneralString OPTIONAL,
1120 e-data[12] OCTET STRING OPTIONAL
1127 if (CHECK_CONTEXT_TYPE(KRB5_ERROR_CTIME)) {
1128 KRB_DECODE_GENERAL_TIME_OR_DIE("ctime", str, str_len, item_len);
1129 krb_proto_tree_add_time(kerberos_tree, asn1p->tvb, offset, item_len,
1132 KRB_HEAD_DECODE_OR_DIE("cusec");
1136 if (CHECK_CONTEXT_TYPE(KRB5_ERROR_CUSEC)) {
1137 KRB_DECODE_UINT32_OR_DIE("cusec", tmp_int);
1138 if (kerberos_tree) {
1139 proto_tree_add_text(kerberos_tree, tvb, offset, length,
1145 KRB_HEAD_DECODE_OR_DIE("sutime");
1148 DIE_IF_NOT_CONTEXT_TYPE("sutime", KRB5_ERROR_STIME);
1149 KRB_DECODE_GENERAL_TIME_OR_DIE("stime", str, str_len, item_len);
1150 krb_proto_tree_add_time(kerberos_tree, asn1p->tvb, offset, item_len,
1154 KRB_HEAD_DECODE_OR_DIE("susec");
1155 DIE_IF_NOT_CONTEXT_TYPE("susec", KRB5_ERROR_SUSEC);
1156 KRB_DECODE_UINT32_OR_DIE("susec", tmp_int);
1157 if (kerberos_tree) {
1158 proto_tree_add_text(kerberos_tree, tvb, offset, length,
1164 KRB_HEAD_DECODE_OR_DIE("errcode");
1165 DIE_IF_NOT_CONTEXT_TYPE("errcode", KRB5_ERROR_ERROR_CODE);
1166 KRB_DECODE_UINT32_OR_DIE("errcode", tmp_int);
1167 if (kerberos_tree) {
1168 proto_tree_add_text(kerberos_tree, tvb, offset, length,
1170 val_to_str(tmp_int, krb5_error_codes,
1171 "Unknown error code %#x"));
1174 KRB_HEAD_DECODE_OR_DIE("crealm");
1176 if (CHECK_CONTEXT_TYPE(KRB5_ERROR_CREALM)) {
1177 KRB_DECODE_GENERAL_STRING_OR_DIE("crealm", str, str_len, item_len);
1178 if (kerberos_tree) {
1179 proto_tree_add_text(kerberos_tree, tvb, offset, item_len,
1180 "crealm: %.*s", str_len, str);
1183 KRB_HEAD_DECODE_OR_DIE("cname");
1186 if (CHECK_CONTEXT_TYPE(KRB5_ERROR_CNAME)) {
1187 item_len = dissect_PrincipalName("cname", asn1p, pinfo,
1188 kerberos_tree, offset);
1192 KRB_HEAD_DECODE_OR_DIE("realm");
1195 DIE_IF_NOT_CONTEXT_TYPE("realm", KRB5_ERROR_REALM);
1196 KRB_DECODE_GENERAL_STRING_OR_DIE("realm", str, str_len, item_len);
1197 if (kerberos_tree) {
1198 proto_tree_add_text(kerberos_tree, tvb, offset, item_len,
1199 "realm: %.*s", str_len, str);
1202 KRB_HEAD_DECODE_OR_DIE("sname");
1204 DIE_IF_NOT_CONTEXT_TYPE("sname", KRB5_ERROR_SNAME);
1205 item_len = dissect_PrincipalName("sname", asn1p, pinfo,
1206 kerberos_tree, offset);
1211 if (asn1p->offset >= message_end)
1213 KRB_HEAD_DECODE_OR_DIE("e-text");
1214 if ( CHECK_CONTEXT_TYPE(KRB5_ERROR_ETEXT) ) {
1215 KRB_DECODE_GENERAL_STRING_OR_DIE("etext", str, str_len, item_len);
1216 if (kerberos_tree) {
1217 proto_tree_add_text(kerberos_tree, tvb, offset, item_len,
1218 "etext: %.*s", str_len, str);
1221 if (asn1p->offset >= message_end)
1223 KRB_HEAD_DECODE_OR_DIE("e-data");
1226 if ( CHECK_CONTEXT_TYPE(KRB5_ERROR_EDATA) ) {
1230 KRB_DECODE_OCTET_STRING_OR_DIE("e-data", data, data_len, item_len);
1232 if (kerberos_tree) {
1233 proto_tree_add_text(kerberos_tree, tvb, offset, item_len,
1234 "Error Data: %s", bytes_to_str(data, data_len));
1245 dissect_PrincipalName(char *title, ASN1_SCK *asn1p, packet_info *pinfo,
1246 proto_tree *tree, int start_offset)
1249 PrincipalName ::= SEQUENCE {
1250 name-type[0] INTEGER,
1251 name-string[1] SEQUENCE OF GeneralString
1254 proto_tree *princ_tree = NULL;
1255 int offset = start_offset;
1260 guint cls, con, tag;
1261 guint header_len, item_len, total_len, type_len;
1264 proto_item *item = NULL;
1273 /* principal name */
1274 KRB_SEQ_HEAD_DECODE_OR_DIE("principal section");
1277 item = proto_tree_add_text(tree, asn1p->tvb, start_offset,
1278 (offset - start_offset) + item_len, "%s",
1280 princ_tree = proto_item_add_subtree(item, ett_princ);
1286 KRB_DECODE_CONTEXT_HEAD_OR_DIE("principal type", 0);
1287 KRB_DECODE_UINT32_OR_DIE("princ-type", princ_type);
1288 type_offset = offset;
1289 type_len = item_len;
1293 proto_tree_add_text(princ_tree, asn1p->tvb, type_offset, type_len,
1295 val_to_str(princ_type, krb5_princ_types,
1296 "Unknown name type %#x"));
1299 KRB_DECODE_CONTEXT_HEAD_OR_DIE("principal name-string", 1);
1300 KRB_SEQ_HEAD_DECODE_OR_DIE("principal name-string sequence-of");
1301 total_len = item_len;
1302 if (total_len == 0) {
1303 /* There are no name strings in this PrincipalName, so we can't
1304 put any in the top-level item. */
1305 return offset - start_offset;
1308 /* Put the first name string in the top-level item. */
1309 KRB_DECODE_GENERAL_STRING_OR_DIE("principal name", name, name_len, item_len);
1311 proto_item_set_text(item, "%s: %.*s", title, (int) name_len, name);
1312 proto_tree_add_text(princ_tree, asn1p->tvb, offset, item_len,
1313 "Name: %.*s", (int) name_len, name);
1315 total_len -= item_len;
1318 /* Now process the rest of the strings.
1319 XXX - put them in the item as well? */
1320 while (total_len > 0) {
1321 KRB_DECODE_GENERAL_STRING_OR_DIE("principal name", name, name_len, item_len);
1323 proto_tree_add_text(princ_tree, asn1p->tvb, offset, item_len,
1324 "Name: %.*s", (int) name_len, name);
1326 total_len -= item_len;
1329 return offset - start_offset;
1333 dissect_Addresses(ASN1_SCK *asn1p, packet_info *pinfo,
1334 proto_tree *tree, int start_offset) {
1335 proto_tree *address_tree = NULL;
1336 int offset = start_offset;
1339 guint cls, con, tag;
1343 proto_item *item = NULL;
1346 int tmp_pos1, tmp_pos2;
1347 guint32 address_type;
1352 char netbios_name[(NETBIOS_NAME_LEN - 1)*4 + 1];
1353 int netbios_name_type;
1355 KRB_HEAD_DECODE_OR_DIE("sequence of addresses");
1357 item = proto_tree_add_text(tree, asn1p->tvb, offset,
1358 item_len, "Addresses");
1359 address_tree = proto_item_add_subtree(item, ett_addresses);
1363 end = asn1p->offset + item_len;
1365 while(asn1p->offset < end) {
1366 dissect_type_value_pair(asn1p, &offset,
1367 &address_type, &item_len, &tmp_pos1,
1368 &str, &str_len, &tmp_pos2);
1371 proto_tree_add_text(address_tree, asn1p->tvb, tmp_pos1,
1372 item_len, "Type: %s",
1373 val_to_str(address_type, krb5_address_types,
1374 "Unknown address type %#x"));
1375 switch(address_type) {
1376 case KRB5_ADDR_IPv4:
1377 proto_tree_add_text(address_tree, asn1p->tvb, tmp_pos2,
1378 str_len, "Value: %d.%d.%d.%d",
1379 str[0], str[1], str[2], str[3]);
1382 case KRB5_ADDR_NETBIOS:
1383 if (str_len == NETBIOS_NAME_LEN) {
1384 netbios_name_type = process_netbios_name(str,
1386 proto_tree_add_text(address_tree, asn1p->tvb, tmp_pos2,
1388 "Value: %s<%02x> (%s)",
1389 netbios_name, netbios_name_type,
1390 netbios_name_type_descr(netbios_name_type));
1392 proto_tree_add_text(address_tree, asn1p->tvb, tmp_pos2,
1394 "Value (Invalid length %d, should be 16): \"%s\"",
1395 str_len, format_text(str, str_len));
1399 /* XXX - do KRB5_ADDR_IPv6 */
1402 proto_tree_add_text(address_tree, asn1p->tvb, tmp_pos2,
1403 str_len, "Value: %s",
1404 bytes_to_str(str, str_len));
1409 return offset - start_offset;
1413 dissect_EncryptedData(char *title, ASN1_SCK *asn1p, packet_info *pinfo,
1414 proto_tree *tree, int start_offset)
1417 EncryptedData ::= SEQUENCE {
1418 etype[0] INTEGER, -- EncryptionType
1419 kvno[1] INTEGER OPTIONAL,
1420 cipher[2] OCTET STRING -- ciphertext
1423 proto_tree *encr_tree = NULL;
1424 int offset = start_offset;
1427 guint cls, con, tag;
1428 guint header_len, item_len, data_len;
1431 proto_item *item = NULL;
1438 KRB_SEQ_HEAD_DECODE_OR_DIE("encrypted data section");
1441 item = proto_tree_add_text(tree, asn1p->tvb, start_offset,
1442 (offset - start_offset) + item_len,
1443 "Encrypted Data: %s", title);
1444 encr_tree = proto_item_add_subtree(item, ett_princ);
1448 KRB_DECODE_CONTEXT_HEAD_OR_DIE("encryption type", 0);
1449 KRB_DECODE_UINT32_OR_DIE("encr-type", val);
1451 proto_tree_add_text(encr_tree, asn1p->tvb, offset, length,
1453 val_to_str(val, krb5_encryption_types,
1454 "Unknown encryption type %#x"));
1459 KRB_HEAD_DECODE_OR_DIE("kvno-wrap or cipher-wrap");
1460 if (CHECK_CONTEXT_TYPE(1)) {
1461 KRB_DECODE_UINT32_OR_DIE("kvno", val);
1463 proto_tree_add_text(encr_tree, asn1p->tvb, offset, length,
1467 KRB_HEAD_DECODE_OR_DIE("cipher-wrap");
1470 DIE_IF_NOT_CONTEXT_TYPE("cipher-wrap", 2);
1471 KRB_DECODE_OCTET_STRING_OR_DIE("cipher", data, data_len, item_len);
1474 proto_tree_add_text(encr_tree, asn1p->tvb, offset, item_len,
1475 "CipherText: %s", bytes_to_str(data, data_len));
1479 return offset - start_offset;
1483 dissect_Ticket(ASN1_SCK *asn1p, packet_info *pinfo,
1484 proto_tree *tree, int start_offset)
1487 Ticket ::= [APPLICATION 1] SEQUENCE {
1490 sname[2] PrincipalName,
1491 enc-part[3] EncryptedData
1494 proto_tree *ticket_tree = NULL;
1495 int offset = start_offset;
1498 guint cls, con, tag;
1499 guint header_len, total_len;
1503 proto_item *item = NULL;
1511 KRB_DECODE_APPLICATION_TAGGED_HEAD_OR_DIE("Ticket section", 1);
1512 KRB_SEQ_HEAD_DECODE_OR_DIE("Ticket sequence");
1513 total_len = item_len;
1516 item = proto_tree_add_text(tree, asn1p->tvb, start_offset,
1517 (offset - start_offset) + item_len,
1519 ticket_tree = proto_item_add_subtree(item, ett_ticket);
1523 KRB_DECODE_CONTEXT_HEAD_OR_DIE("Ticket tkt-vno", KRB5_TKT_TKT_VNO);
1524 KRB_DECODE_UINT32_OR_DIE("Ticket tkt-vno", val);
1526 proto_tree_add_text(ticket_tree, asn1p->tvb, offset, length,
1527 "Version: %u", val);
1530 total_len -= length;
1533 KRB_DECODE_CONTEXT_HEAD_OR_DIE("Ticket realm", KRB5_TKT_REALM);
1534 KRB_DECODE_GENERAL_STRING_OR_DIE("Ticket realm string", str, str_len, item_len);
1536 proto_tree_add_text(ticket_tree, asn1p->tvb, offset, item_len,
1537 "Realm: %.*s", str_len, str);
1540 total_len -= item_len;
1542 /* server name (sname) */
1543 KRB_DECODE_CONTEXT_HEAD_OR_DIE("Ticket sname", KRB5_TKT_SNAME);
1544 item_len = dissect_PrincipalName("Service Name", asn1p, pinfo, ticket_tree,
1550 /* encrypted part */
1551 KRB_DECODE_CONTEXT_HEAD_OR_DIE("enc-part", KRB5_TKT_ENC_PART);
1552 length = dissect_EncryptedData("Ticket data", asn1p, pinfo, ticket_tree,
1558 return offset - start_offset;
1563 proto_register_kerberos(void)
1565 static hf_register_info hf[] = {
1566 { &hf_krb_rm_reserved, {
1567 "Reserved", "kerberos.rm.reserved", FT_BOOLEAN, 32,
1568 &bitval, KRB_RM_RESERVED, "Record mark reserved bit", HFILL }},
1569 { &hf_krb_rm_reclen, {
1570 "Record Length", "kerberos.rm.length", FT_UINT32, BASE_DEC,
1571 NULL, KRB_RM_RECLEN, "Record length", HFILL }},
1574 static gint *ett[] = {
1583 &ett_additional_tickets,
1586 module_t *krb_module;
1588 proto_kerberos = proto_register_protocol("Kerberos", "KRB5", "kerberos");
1589 proto_register_field_array(proto_kerberos, hf, array_length(hf));
1590 proto_register_subtree_array(ett, array_length(ett));
1592 /* Register preferences */
1593 krb_module = prefs_register_protocol(proto_kerberos, NULL);
1594 prefs_register_bool_preference(krb_module, "desegment",
1595 "Desegment Kerberos over TCP messages",
1596 "Whether the dissector should desegment "
1597 "multi-segment Kerberos messages", &krb_desegment);
1601 proto_reg_handoff_kerberos(void)
1603 dissector_handle_t kerberos_handle_udp;
1604 dissector_handle_t kerberos_handle_tcp;
1606 kerberos_handle_udp = create_dissector_handle(dissect_kerberos_udp,
1608 kerberos_handle_tcp = create_dissector_handle(dissect_kerberos_tcp,
1610 dissector_add("udp.port", UDP_PORT_KERBEROS, kerberos_handle_udp);
1611 dissector_add("tcp.port", TCP_PORT_KERBEROS, kerberos_handle_tcp);
1617 MISC definitions from RFC1510:
1619 Realm ::= GeneralString
1621 KerberosTime ::= GeneralizedTime
1623 HostAddress ::= SEQUENCE {
1624 addr-type[0] INTEGER,
1625 address[1] OCTET STRING
1628 HostAddresses ::= SEQUENCE OF SEQUENCE {
1629 addr-type[0] INTEGER,
1630 address[1] OCTET STRING
1633 AuthorizationData ::= SEQUENCE OF SEQUENCE {
1635 ad-data[1] OCTET STRING
1637 APOptions ::= BIT STRING {
1644 TicketFlags ::= BIT STRING {
1659 KDCOptions ::= BIT STRING {
1673 enc-tkt-in-skey(28),
1679 LastReq ::= SEQUENCE OF SEQUENCE {
1681 lr-value[1] KerberosTime
1684 Ticket ::= [APPLICATION 1] SEQUENCE {
1687 sname[2] PrincipalName,
1688 enc-part[3] EncryptedData
1691 -- Encrypted part of ticket
1692 EncTicketPart ::= [APPLICATION 3] SEQUENCE {
1693 flags[0] TicketFlags,
1694 key[1] EncryptionKey,
1696 cname[3] PrincipalName,
1697 transited[4] TransitedEncoding,
1698 authtime[5] KerberosTime,
1699 starttime[6] KerberosTime OPTIONAL,
1700 endtime[7] KerberosTime,
1701 renew-till[8] KerberosTime OPTIONAL,
1702 caddr[9] HostAddresses OPTIONAL,
1703 authorization-data[10] AuthorizationData OPTIONAL
1706 -- encoded Transited field
1707 TransitedEncoding ::= SEQUENCE {
1708 tr-type[0] INTEGER, -- must be registered
1709 contents[1] OCTET STRING
1712 -- Unencrypted authenticator
1713 Authenticator ::= [APPLICATION 2] SEQUENCE {
1714 authenticator-vno[0] INTEGER,
1716 cname[2] PrincipalName,
1717 cksum[3] Checksum OPTIONAL,
1719 ctime[5] KerberosTime,
1720 subkey[6] EncryptionKey OPTIONAL,
1721 seq-number[7] INTEGER OPTIONAL,
1722 authorization-data[8] AuthorizationData OPTIONAL
1725 PA-DATA ::= SEQUENCE {
1726 padata-type[1] INTEGER,
1727 padata-value[2] OCTET STRING,
1728 -- might be encoded AP-REQ
1731 padata-type ::= PA-ENC-TIMESTAMP
1732 padata-value ::= EncryptedData -- PA-ENC-TS-ENC
1734 PA-ENC-TS-ENC ::= SEQUENCE {
1735 patimestamp[0] KerberosTime, -- client's time
1736 pausec[1] INTEGER OPTIONAL
1739 EncASRepPart ::= [APPLICATION 25[25]] EncKDCRepPart
1740 EncTGSRepPart ::= [APPLICATION 26] EncKDCRepPart
1742 EncKDCRepPart ::= SEQUENCE {
1743 key[0] EncryptionKey,
1744 last-req[1] LastReq,
1746 key-expiration[3] KerberosTime OPTIONAL,
1747 flags[4] TicketFlags,
1748 authtime[5] KerberosTime,
1749 starttime[6] KerberosTime OPTIONAL,
1750 endtime[7] KerberosTime,
1751 renew-till[8] KerberosTime OPTIONAL,
1753 sname[10] PrincipalName,
1754 caddr[11] HostAddresses OPTIONAL
1757 AP-REQ ::= [APPLICATION 14] SEQUENCE {
1759 msg-type[1] INTEGER,
1760 ap-options[2] APOptions,
1762 authenticator[4] EncryptedData
1765 APOptions ::= BIT STRING {
1771 AP-REP ::= [APPLICATION 15] SEQUENCE {
1773 msg-type[1] INTEGER,
1774 enc-part[2] EncryptedData
1777 EncAPRepPart ::= [APPLICATION 27] SEQUENCE {
1778 ctime[0] KerberosTime,
1780 subkey[2] EncryptionKey OPTIONAL,
1781 seq-number[3] INTEGER OPTIONAL
1784 KRB-SAFE ::= [APPLICATION 20] SEQUENCE {
1786 msg-type[1] INTEGER,
1787 safe-body[2] KRB-SAFE-BODY,
1791 KRB-SAFE-BODY ::= SEQUENCE {
1792 user-data[0] OCTET STRING,
1793 timestamp[1] KerberosTime OPTIONAL,
1794 usec[2] INTEGER OPTIONAL,
1795 seq-number[3] INTEGER OPTIONAL,
1796 s-address[4] HostAddress,
1797 r-address[5] HostAddress OPTIONAL
1800 KRB-PRIV ::= [APPLICATION 21] SEQUENCE {
1802 msg-type[1] INTEGER,
1803 enc-part[3] EncryptedData
1806 EncKrbPrivPart ::= [APPLICATION 28] SEQUENCE {
1807 user-data[0] OCTET STRING,
1808 timestamp[1] KerberosTime OPTIONAL,
1809 usec[2] INTEGER OPTIONAL,
1810 seq-number[3] INTEGER OPTIONAL,
1811 s-address[4] HostAddress, -- sender's addr
1812 r-address[5] HostAddress OPTIONAL
1816 KRB-CRED ::= [APPLICATION 22] SEQUENCE {
1818 msg-type[1] INTEGER, -- KRB_CRED
1819 tickets[2] SEQUENCE OF Ticket,
1820 enc-part[3] EncryptedData
1823 EncKrbCredPart ::= [APPLICATION 29] SEQUENCE {
1824 ticket-info[0] SEQUENCE OF KrbCredInfo,
1825 nonce[1] INTEGER OPTIONAL,
1826 timestamp[2] KerberosTime OPTIONAL,
1827 usec[3] INTEGER OPTIONAL,
1828 s-address[4] HostAddress OPTIONAL,
1829 r-address[5] HostAddress OPTIONAL
1832 KrbCredInfo ::= SEQUENCE {
1833 key[0] EncryptionKey,
1834 prealm[1] Realm OPTIONAL,
1835 pname[2] PrincipalName OPTIONAL,
1836 flags[3] TicketFlags OPTIONAL,
1837 authtime[4] KerberosTime OPTIONAL,
1838 starttime[5] KerberosTime OPTIONAL,
1839 endtime[6] KerberosTime OPTIONAL
1840 renew-till[7] KerberosTime OPTIONAL,
1841 srealm[8] Realm OPTIONAL,
1842 sname[9] PrincipalName OPTIONAL,
1843 caddr[10] HostAddresses OPTIONAL
1846 KRB-ERROR ::= [APPLICATION 30] SEQUENCE {
1848 msg-type[1] INTEGER,
1849 ctime[2] KerberosTime OPTIONAL,
1850 cusec[3] INTEGER OPTIONAL,
1851 stime[4] KerberosTime,
1853 error-code[6] INTEGER,
1854 crealm[7] Realm OPTIONAL,
1855 cname[8] PrincipalName OPTIONAL,
1856 realm[9] Realm, -- Correct realm
1857 sname[10] PrincipalName, -- Correct name
1858 e-text[11] GeneralString OPTIONAL,
1859 e-data[12] OCTET STRING OPTIONAL
1862 e-data This field contains additional data about the error for use
1863 by the application to help it recover from or handle the
1864 error. If the errorcode is KDC_ERR_PREAUTH_REQUIRED, then
1865 the e-data field will contain an encoding of a sequence of
1866 padata fields, each corresponding to an acceptable pre-
1867 authentication method and optionally containing data for
1870 METHOD-DATA ::= SEQUENCE of PA-DATA
1872 If the error-code is KRB_AP_ERR_METHOD, then the e-data field will
1873 contain an encoding of the following sequence:
1875 METHOD-DATA ::= SEQUENCE {
1876 method-type[0] INTEGER,
1877 method-data[1] OCTET STRING OPTIONAL
1880 EncryptionKey ::= SEQUENCE {
1882 keyvalue[1] OCTET STRING
1885 Checksum ::= SEQUENCE {
1886 cksumtype[0] INTEGER,
1887 checksum[1] OCTET STRING