2 * Routines for Kerberos
3 * Wes Hardaker (c) 2000
4 * wjhardaker@ucdavis.edu
6 * $Id: packet-kerberos.c,v 1.14 2001/01/09 06:31:37 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 1998 Didier Jorand
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #ifdef HAVE_SYS_TYPES_H
36 # include <sys/types.h>
47 #define UDP_PORT_KERBEROS 88
48 #define TCP_PORT_KERBEROS 88
50 static gint ett_kerberos = -1;
51 static gint ett_preauth = -1;
52 static gint ett_addresses = -1;
53 static gint ett_request = -1;
54 static gint ett_princ = -1;
55 static gint ett_ticket = -1;
56 static gint ett_encrypted = -1;
57 static gint ett_etype = -1;
58 static gint proto_kerberos = -1;
60 #define KRB5_MSG_AS_REQ 10 /* AS-REQ type */
61 #define KRB5_MSG_AS_REP 11 /* AS-REP type */
62 #define KRB5_MSG_TGS_REQ 12 /* TGS-REQ type */
63 #define KRB5_MSG_TGS_REP 13 /* TGS-REP type */
64 #define KRB5_MSG_AP_REQ 14 /* AP-REQ type */
65 #define KRB5_MSG_AP_REP 15 /* AP-REP type */
67 #define KRB5_MSG_SAFE 20 /* KRB-SAFE type */
68 #define KRB5_MSG_PRIV 21 /* KRB-PRIV type */
69 #define KRB5_MSG_CRED 22 /* KRB-CRED type */
70 #define KRB5_MSG_ERROR 30 /* KRB-ERROR type */
72 /* Type tags within KDC-REQ */
73 #define KRB5_KDC_REQ_PVNO 1
74 #define KRB5_KDC_REQ_MSG_TYPE 2
75 #define KRB5_KDC_REQ_PADATA 3
76 #define KRB5_KDC_REQ_REQBODY 4
78 /* Type tags within KDC-REP */
79 #define KRB5_KDC_REP_PVNO 0
80 #define KRB5_KDC_REP_MSG_TYPE 1
81 #define KRB5_KDC_REP_PADATA 2
82 #define KRB5_KDC_REP_CREALM 3
83 #define KRB5_KDC_REP_CNAME 4
84 #define KRB5_KDC_REP_TICKET 5
85 #define KRB5_KDC_REP_ENC_PART 6
87 /* Type tags within KDC-REQ-BODY */
88 #define KRB5_BODY_KDC_OPTIONS 0
89 #define KRB5_BODY_CNAME 1
90 #define KRB5_BODY_REALM 2
91 #define KRB5_BODY_SNAME 3
92 #define KRB5_BODY_FROM 4
93 #define KRB5_BODY_TILL 5
94 #define KRB5_BODY_RTIME 6
95 #define KRB5_BODY_NONCE 7
96 #define KRB5_BODY_ENCTYPE 8
97 #define KRB5_BODY_ADDRESSES 9
98 #define KRB5_BODY_ENC_AUTHORIZATION_DATA 10
99 #define KRB5_BODY_ADDITIONAL_TICKETS 11
101 /* Type tags within KRB-ERROR */
102 #define KRB5_ERROR_PVNO 0
103 #define KRB5_ERROR_MSG_TYPE 1
104 #define KRB5_ERROR_CTIME 2
105 #define KRB5_ERROR_CUSEC 3
106 #define KRB5_ERROR_STIME 4
107 #define KRB5_ERROR_SUSEC 5
108 #define KRB5_ERROR_ERROR_CODE 6
109 #define KRB5_ERROR_CREALM 7
110 #define KRB5_ERROR_CNAME 8
111 #define KRB5_ERROR_REALM 9
112 #define KRB5_ERROR_SNAME 10
113 #define KRB5_ERROR_ETEXT 11
114 #define KRB5_ERROR_EDATA 12
116 /* address type constants */
117 #define KRB5_ADDR_IPv4 0x02
118 #define KRB5_ADDR_CHAOS 0x05
119 #define KRB5_ADDR_XEROX 0x06
120 #define KRB5_ADDR_ISO 0x07
121 #define KRB5_ADDR_DECNET 0x0c
122 #define KRB5_ADDR_APPLETALK 0x10
124 /* encryption type constants */
125 #define KRB5_ENCTYPE_NULL 0
126 #define KRB5_ENCTYPE_DES_CBC_CRC 1
127 #define KRB5_ENCTYPE_DES_CBC_MD4 2
128 #define KRB5_ENCTYPE_DES_CBC_MD5 3
129 #define KRB5_ENCTYPE_DES_CBC_RAW 4
130 #define KRB5_ENCTYPE_DES3_CBC_SHA 5
131 #define KRB5_ENCTYPE_DES3_CBC_RAW 6
132 #define KRB5_ENCTYPE_DES_HMAC_SHA1 8
133 #define KRB5_ENCTYPE_DES3_CBC_SHA1 0x10
134 #define KRB5_ENCTYPE_UNKNOWN 0x1ff
135 #define KRB5_ENCTYPE_LOCAL_DES3_HMAC_SHA1 0x7007
137 /* pre-authentication type constants */
138 #define KRB5_PA_TGS_REQ 1
139 #define KRB5_PA_ENC_TIMESTAMP 2
140 #define KRB5_PA_PW_SALT 3
141 #define KRB5_PA_ENC_ENCKEY 4
142 #define KRB5_PA_ENC_UNIX_TIME 5
143 #define KRB5_PA_ENC_SANDIA_SECURID 6
144 #define KRB5_PA_SESAME 7
145 #define KRB5_PA_OSF_DCE 8
146 #define KRB5_PA_CYBERSAFE_SECUREID 9
147 #define KRB5_PA_AFS3_SALT 10
148 #define KRB5_PA_ENCTYPE_INFO 11
149 #define KRB5_PA_SAM_CHALLENGE 12
150 #define KRB5_PA_SAM_RESPONSE 13
151 #define KRB5_PA_DASS 16
153 /* Type tags within Ticket */
154 #define KRB5_TKT_TKT_VNO 0
155 #define KRB5_TKT_REALM 1
156 #define KRB5_TKT_SNAME 2
157 #define KRB5_TKT_ENC_PART 3
159 /* Principal name-type */
160 #define KRB5_NT_UNKNOWN 0
161 #define KRB5_NT_PRINCIPAL 1
162 #define KRB5_NT_SRV_INST 2
163 #define KRB5_NT_SRV_HST 3
164 #define KRB5_NT_SRV_XHST 4
165 #define KRB5_NT_UID 5
167 /* error table constants */
168 /* I prefixed the krb5_err.et constant names with KRB5_ET_ for these */
169 #define KRB5_ET_KRB5KDC_ERR_NONE 0
170 #define KRB5_ET_KRB5KDC_ERR_NAME_EXP 1
171 #define KRB5_ET_KRB5KDC_ERR_SERVICE_EXP 2
172 #define KRB5_ET_KRB5KDC_ERR_BAD_PVNO 3
173 #define KRB5_ET_KRB5KDC_ERR_C_OLD_MAST_KVNO 4
174 #define KRB5_ET_KRB5KDC_ERR_S_OLD_MAST_KVNO 5
175 #define KRB5_ET_KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN 6
176 #define KRB5_ET_KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN 7
177 #define KRB5_ET_KRB5KDC_ERR_PRINCIPAL_NOT_UNIQUE 8
178 #define KRB5_ET_KRB5KDC_ERR_NULL_KEY 9
179 #define KRB5_ET_KRB5KDC_ERR_CANNOT_POSTDATE 10
180 #define KRB5_ET_KRB5KDC_ERR_NEVER_VALID 11
181 #define KRB5_ET_KRB5KDC_ERR_POLICY 12
182 #define KRB5_ET_KRB5KDC_ERR_BADOPTION 13
183 #define KRB5_ET_KRB5KDC_ERR_ETYPE_NOSUPP 14
184 #define KRB5_ET_KRB5KDC_ERR_SUMTYPE_NOSUPP 15
185 #define KRB5_ET_KRB5KDC_ERR_PADATA_TYPE_NOSUPP 16
186 #define KRB5_ET_KRB5KDC_ERR_TRTYPE_NOSUPP 17
187 #define KRB5_ET_KRB5KDC_ERR_CLIENT_REVOKED 18
188 #define KRB5_ET_KRB5KDC_ERR_SERVICE_REVOKED 19
189 #define KRB5_ET_KRB5KDC_ERR_TGT_REVOKED 20
190 #define KRB5_ET_KRB5KDC_ERR_CLIENT_NOTYET 21
191 #define KRB5_ET_KRB5KDC_ERR_SERVICE_NOTYET 22
192 #define KRB5_ET_KRB5KDC_ERR_KEY_EXP 23
193 #define KRB5_ET_KRB5KDC_ERR_PREAUTH_FAILED 24
194 #define KRB5_ET_KRB5KDC_ERR_PREAUTH_REQUIRED 25
195 #define KRB5_ET_KRB5KDC_ERR_SERVER_NOMATCH 26
196 #define KRB5_ET_KRB5KRB_AP_ERR_BAD_INTEGRITY 31
197 #define KRB5_ET_KRB5KRB_AP_ERR_TKT_EXPIRED 32
198 #define KRB5_ET_KRB5KRB_AP_ERR_TKT_NYV 33
199 #define KRB5_ET_KRB5KRB_AP_ERR_REPEAT 34
200 #define KRB5_ET_KRB5KRB_AP_ERR_NOT_US 35
201 #define KRB5_ET_KRB5KRB_AP_ERR_BADMATCH 36
202 #define KRB5_ET_KRB5KRB_AP_ERR_SKEW 37
203 #define KRB5_ET_KRB5KRB_AP_ERR_BADADDR 38
204 #define KRB5_ET_KRB5KRB_AP_ERR_BADVERSION 39
205 #define KRB5_ET_KRB5KRB_AP_ERR_MSG_TYPE 40
206 #define KRB5_ET_KRB5KRB_AP_ERR_MODIFIED 41
207 #define KRB5_ET_KRB5KRB_AP_ERR_BADORDER 42
208 #define KRB5_ET_KRB5KRB_AP_ERR_ILL_CR_TKT 43
209 #define KRB5_ET_KRB5KRB_AP_ERR_BADKEYVER 44
210 #define KRB5_ET_KRB5KRB_AP_ERR_NOKEY 45
211 #define KRB5_ET_KRB5KRB_AP_ERR_MUT_FAIL 46
212 #define KRB5_ET_KRB5KRB_AP_ERR_BADDIRECTION 47
213 #define KRB5_ET_KRB5KRB_AP_ERR_METHOD 48
214 #define KRB5_ET_KRB5KRB_AP_ERR_BADSEQ 49
215 #define KRB5_ET_KRB5KRB_AP_ERR_INAPP_CKSUM 50
216 #define KRB5_ET_KRB5KRB_ERR_GENERIC 60
217 #define KRB5_ET_KRB5KRB_ERR_FIELD_TOOLONG 61
219 static const value_string krb5_error_codes[] = {
220 { KRB5_ET_KRB5KDC_ERR_NONE, "KRB5KDC_ERR_NONE" },
221 { KRB5_ET_KRB5KDC_ERR_NAME_EXP, "KRB5KDC_ERR_NAME_EXP" },
222 { KRB5_ET_KRB5KDC_ERR_SERVICE_EXP, "KRB5KDC_ERR_SERVICE_EXP" },
223 { KRB5_ET_KRB5KDC_ERR_BAD_PVNO, "KRB5KDC_ERR_BAD_PVNO" },
224 { KRB5_ET_KRB5KDC_ERR_C_OLD_MAST_KVNO, "KRB5KDC_ERR_C_OLD_MAST_KVNO" },
225 { KRB5_ET_KRB5KDC_ERR_S_OLD_MAST_KVNO, "KRB5KDC_ERR_S_OLD_MAST_KVNO" },
226 { KRB5_ET_KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN, "KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN" },
227 { KRB5_ET_KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN, "KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN" },
228 { KRB5_ET_KRB5KDC_ERR_PRINCIPAL_NOT_UNIQUE, "KRB5KDC_ERR_PRINCIPAL_NOT_UNIQUE" },
229 { KRB5_ET_KRB5KDC_ERR_NULL_KEY, "KRB5KDC_ERR_NULL_KEY" },
230 { KRB5_ET_KRB5KDC_ERR_CANNOT_POSTDATE, "KRB5KDC_ERR_CANNOT_POSTDATE" },
231 { KRB5_ET_KRB5KDC_ERR_NEVER_VALID, "KRB5KDC_ERR_NEVER_VALID" },
232 { KRB5_ET_KRB5KDC_ERR_POLICY, "KRB5KDC_ERR_POLICY" },
233 { KRB5_ET_KRB5KDC_ERR_BADOPTION, "KRB5KDC_ERR_BADOPTION" },
234 { KRB5_ET_KRB5KDC_ERR_ETYPE_NOSUPP, "KRB5KDC_ERR_ETYPE_NOSUPP" },
235 { KRB5_ET_KRB5KDC_ERR_SUMTYPE_NOSUPP, "KRB5KDC_ERR_SUMTYPE_NOSUPP" },
236 { KRB5_ET_KRB5KDC_ERR_PADATA_TYPE_NOSUPP, "KRB5KDC_ERR_PADATA_TYPE_NOSUPP" },
237 { KRB5_ET_KRB5KDC_ERR_TRTYPE_NOSUPP, "KRB5KDC_ERR_TRTYPE_NOSUPP" },
238 { KRB5_ET_KRB5KDC_ERR_CLIENT_REVOKED, "KRB5KDC_ERR_CLIENT_REVOKED" },
239 { KRB5_ET_KRB5KDC_ERR_SERVICE_REVOKED, "KRB5KDC_ERR_SERVICE_REVOKED" },
240 { KRB5_ET_KRB5KDC_ERR_TGT_REVOKED, "KRB5KDC_ERR_TGT_REVOKED" },
241 { KRB5_ET_KRB5KDC_ERR_CLIENT_NOTYET, "KRB5KDC_ERR_CLIENT_NOTYET" },
242 { KRB5_ET_KRB5KDC_ERR_SERVICE_NOTYET, "KRB5KDC_ERR_SERVICE_NOTYET" },
243 { KRB5_ET_KRB5KDC_ERR_KEY_EXP, "KRB5KDC_ERR_KEY_EXP" },
244 { KRB5_ET_KRB5KDC_ERR_PREAUTH_FAILED, "KRB5KDC_ERR_PREAUTH_FAILED" },
245 { KRB5_ET_KRB5KDC_ERR_PREAUTH_REQUIRED, "KRB5KDC_ERR_PREAUTH_REQUIRED" },
246 { KRB5_ET_KRB5KDC_ERR_SERVER_NOMATCH, "KRB5KDC_ERR_SERVER_NOMATCH" },
247 { KRB5_ET_KRB5KRB_AP_ERR_BAD_INTEGRITY, "KRB5KRB_AP_ERR_BAD_INTEGRITY" },
248 { KRB5_ET_KRB5KRB_AP_ERR_TKT_EXPIRED, "KRB5KRB_AP_ERR_TKT_EXPIRED" },
249 { KRB5_ET_KRB5KRB_AP_ERR_TKT_NYV, "KRB5KRB_AP_ERR_TKT_NYV" },
250 { KRB5_ET_KRB5KRB_AP_ERR_REPEAT, "KRB5KRB_AP_ERR_REPEAT" },
251 { KRB5_ET_KRB5KRB_AP_ERR_NOT_US, "KRB5KRB_AP_ERR_NOT_US" },
252 { KRB5_ET_KRB5KRB_AP_ERR_BADMATCH, "KRB5KRB_AP_ERR_BADMATCH" },
253 { KRB5_ET_KRB5KRB_AP_ERR_SKEW, "KRB5KRB_AP_ERR_SKEW" },
254 { KRB5_ET_KRB5KRB_AP_ERR_BADADDR, "KRB5KRB_AP_ERR_BADADDR" },
255 { KRB5_ET_KRB5KRB_AP_ERR_BADVERSION, "KRB5KRB_AP_ERR_BADVERSION" },
256 { KRB5_ET_KRB5KRB_AP_ERR_MSG_TYPE, "KRB5KRB_AP_ERR_MSG_TYPE" },
257 { KRB5_ET_KRB5KRB_AP_ERR_MODIFIED, "KRB5KRB_AP_ERR_MODIFIED" },
258 { KRB5_ET_KRB5KRB_AP_ERR_BADORDER, "KRB5KRB_AP_ERR_BADORDER" },
259 { KRB5_ET_KRB5KRB_AP_ERR_ILL_CR_TKT, "KRB5KRB_AP_ERR_ILL_CR_TKT" },
260 { KRB5_ET_KRB5KRB_AP_ERR_BADKEYVER, "KRB5KRB_AP_ERR_BADKEYVER" },
261 { KRB5_ET_KRB5KRB_AP_ERR_NOKEY, "KRB5KRB_AP_ERR_NOKEY" },
262 { KRB5_ET_KRB5KRB_AP_ERR_MUT_FAIL, "KRB5KRB_AP_ERR_MUT_FAIL" },
263 { KRB5_ET_KRB5KRB_AP_ERR_BADDIRECTION, "KRB5KRB_AP_ERR_BADDIRECTION" },
264 { KRB5_ET_KRB5KRB_AP_ERR_METHOD, "KRB5KRB_AP_ERR_METHOD" },
265 { KRB5_ET_KRB5KRB_AP_ERR_BADSEQ, "KRB5KRB_AP_ERR_BADSEQ" },
266 { KRB5_ET_KRB5KRB_AP_ERR_INAPP_CKSUM, "KRB5KRB_AP_ERR_INAPP_CKSUM" },
267 { KRB5_ET_KRB5KRB_ERR_GENERIC, "KRB5KRB_ERR_GENERIC" },
268 { KRB5_ET_KRB5KRB_ERR_FIELD_TOOLONG, "KRB5KRB_ERR_FIELD_TOOLONG" },
273 static const value_string krb5_princ_types[] = {
274 { KRB5_NT_UNKNOWN , "Unknown" },
275 { KRB5_NT_PRINCIPAL , "Principal" },
276 { KRB5_NT_SRV_INST , "Service and Instance" },
277 { KRB5_NT_SRV_HST , "Service and Host" },
278 { KRB5_NT_SRV_XHST , "Service and Host Components" },
279 { KRB5_NT_UID , "Unique ID" },
283 static const value_string krb5_preauthentication_types[] = {
284 { KRB5_PA_TGS_REQ , "PA-TGS-REQ" },
285 { KRB5_PA_ENC_TIMESTAMP , "PA-ENC-TIMESTAMP" },
286 { KRB5_PA_PW_SALT , "PA-PW-SALT" },
287 { KRB5_PA_ENC_ENCKEY , "PA-ENC-ENCKEY" },
288 { KRB5_PA_ENC_UNIX_TIME , "PA-ENC-UNIX-TIME" },
289 { KRB5_PA_ENC_SANDIA_SECURID , "PA-PW-SALT" },
290 { KRB5_PA_SESAME , "PA-SESAME" },
291 { KRB5_PA_OSF_DCE , "PA-OSF-DCE" },
292 { KRB5_PA_CYBERSAFE_SECUREID , "PA-CYBERSAFE-SECURID" },
293 { KRB5_PA_AFS3_SALT , "PA-AFS3-SALT" },
294 { KRB5_PA_ENCTYPE_INFO , "PA-ENCTYPE-INFO" },
295 { KRB5_PA_SAM_CHALLENGE , "PA-SAM-CHALLENGE" },
296 { KRB5_PA_SAM_RESPONSE , "PA-SAM-RESPONSE" },
297 { KRB5_PA_DASS , "PA-DASS" },
301 static const value_string krb5_encryption_types[] = {
302 { KRB5_ENCTYPE_NULL , "NULL" },
303 { KRB5_ENCTYPE_DES_CBC_CRC , "des-cbc-crc" },
304 { KRB5_ENCTYPE_DES_CBC_MD4 , "des-cbc-md4" },
305 { KRB5_ENCTYPE_DES_CBC_MD5 , "des-cbc-md5" },
306 { KRB5_ENCTYPE_DES_CBC_RAW , "des-cbc-raw" },
307 { KRB5_ENCTYPE_DES3_CBC_SHA , "des3-cbc-sha" },
308 { KRB5_ENCTYPE_DES3_CBC_RAW , "des3-cbc-raw" },
309 { KRB5_ENCTYPE_DES_HMAC_SHA1 , "des-hmac-sha1" },
310 { KRB5_ENCTYPE_DES3_CBC_SHA1 , "des3-cbc-sha1" },
311 { KRB5_ENCTYPE_UNKNOWN , "unknown" },
312 { KRB5_ENCTYPE_LOCAL_DES3_HMAC_SHA1 , "local-des3-hmac-sha1" },
316 static const value_string krb5_address_types[] = {
317 { KRB5_ADDR_IPv4, "IPv4"},
318 { KRB5_ADDR_CHAOS, "CHAOS"},
319 { KRB5_ADDR_XEROX, "XEROX"},
320 { KRB5_ADDR_ISO, "ISO"},
321 { KRB5_ADDR_DECNET, "DECNET"},
322 { KRB5_ADDR_APPLETALK, "APPLETALK"},
326 static const value_string krb5_msg_types[] = {
327 { KRB5_MSG_TGS_REQ, "TGS-REQ" },
328 { KRB5_MSG_TGS_REP, "TGS-REP" },
329 { KRB5_MSG_AS_REQ, "AS-REQ" },
330 { KRB5_MSG_AS_REP, "AS-REP" },
331 { KRB5_MSG_AP_REQ, "AP-REQ" },
332 { KRB5_MSG_AP_REP, "AP-REP" },
333 { KRB5_MSG_SAFE, "KRB-SAFE" },
334 { KRB5_MSG_PRIV, "KRB-PRIV" },
335 { KRB5_MSG_CRED, "KRB-CRED" },
336 { KRB5_MSG_ERROR, "KRB-ERROR" },
340 static int dissect_PrincipalName(char *title, ASN1_SCK *asn1p,
341 frame_data *fd, proto_tree *tree,
343 static int dissect_Ticket(char *title, ASN1_SCK *asn1p, frame_data *fd,
344 proto_tree *tree, int start_offset);
345 static int dissect_EncryptedData(char *title, ASN1_SCK *asn1p, frame_data *fd,
346 proto_tree *tree, int start_offset);
347 static int dissect_Addresses(char *title, ASN1_SCK *asn1p, frame_data *fd,
348 proto_tree *tree, int start_offset);
351 to_error_str(int ret) {
355 return("Ran out of data");
357 case ASN1_ERR_EOC_MISMATCH:
358 return("EOC mismatch");
360 case ASN1_ERR_WRONG_TYPE:
361 return("Wrong type for that item");
363 case ASN1_ERR_LENGTH_NOT_DEFINITE:
364 return("Length was indefinite");
366 case ASN1_ERR_LENGTH_MISMATCH:
367 return("Length mismatch");
369 case ASN1_ERR_WRONG_LENGTH_FOR_TYPE:
370 return("Wrong length for that item's type");
373 return("Unknown error");
377 krb_proto_tree_add_time(proto_tree *tree, int offset, int str_len,
378 char *name, guchar *str) {
380 proto_tree_add_text(tree, NullTVB, offset, str_len,
381 "%s: %.4s-%.2s-%.2s %.2s:%.2s:%.2s (%.1s)",
382 name, str, str+4, str+6,
383 str+8, str+10, str+12,
389 * You must be kidding. I'm going to actually use a macro to do something?
393 #define KRB_HEAD_DECODE_OR_DIE(token) \
394 start = asn1p->pointer; \
395 ret = asn1_header_decode (asn1p, &cls, &con, &tag, &def, &item_len); \
396 if (ret != ASN1_ERR_NOERROR && ret != ASN1_ERR_EMPTY) {\
397 if (check_col(fd, COL_INFO)) \
398 col_add_fstr(fd, COL_INFO, "ERROR: Problem at %s: %s", \
399 token, to_error_str(ret)); \
403 if (check_col(fd, COL_INFO)) \
404 col_add_fstr(fd, COL_INFO, "not definite: %s", token); \
405 fprintf(stderr,"not definite: %s\n", token); \
408 offset += (asn1p->pointer - start);
410 #define CHECK_APPLICATION_TYPE(expected_tag) \
411 (cls == ASN1_APL && con == ASN1_CON && tag == expected_tag)
413 #define DIE_IF_NOT_APPLICATION_TYPE(token, expected_tag) \
414 if (!CHECK_APPLICATION_TYPE(expected_tag)) \
415 DIE_WITH_BAD_TYPE(token, expected_tag);
417 #define CHECK_CONTEXT_TYPE(expected_tag) \
418 (cls == ASN1_CTX && con == ASN1_CON && tag == expected_tag)
420 #define DIE_IF_NOT_CONTEXT_TYPE(token, expected_tag) \
421 if (!CHECK_CONTEXT_TYPE(expected_tag)) \
422 DIE_WITH_BAD_TYPE(token, expected_tag);
424 #define DIE_WITH_BAD_TYPE(token, expected_tag) \
426 if (check_col(fd, COL_INFO)) \
427 col_add_fstr(fd, COL_INFO, "ERROR: Problem at %s: %s (tag=%d exp=%d)", \
428 token, to_error_str(ASN1_ERR_WRONG_TYPE), tag, expected_tag); \
432 #define KRB_DECODE_APPLICATION_TAGGED_HEAD_OR_DIE(token, expected_tag) \
433 KRB_HEAD_DECODE_OR_DIE(token); \
434 DIE_IF_NOT_APPLICATION_TYPE(token, expected_tag);
436 #define KRB_DECODE_CONTEXT_HEAD_OR_DIE(token, expected_tag) \
437 KRB_HEAD_DECODE_OR_DIE(token); \
438 DIE_IF_NOT_CONTEXT_TYPE(token, expected_tag);
440 #define KRB_SEQ_HEAD_DECODE_OR_DIE(token) \
441 ret = asn1_sequence_decode (asn1p, &item_len, &header_len); \
442 if (ret != ASN1_ERR_NOERROR && ret != ASN1_ERR_EMPTY) {\
443 if (check_col(fd, COL_INFO)) \
444 col_add_fstr(fd, COL_INFO, "ERROR: Problem at %s: %s", \
445 token, to_error_str(ret)); \
448 offset += header_len;
450 #define KRB_DECODE_OR_DIE(token, fn, val) \
451 ret = fn (asn1p, &val, &length); \
452 if (ret != ASN1_ERR_NOERROR) { \
453 if (check_col(fd, COL_INFO)) \
454 col_add_fstr(fd, COL_INFO, "ERROR: Problem at %s: %s", \
455 token, to_error_str(ret)); \
459 #define KRB_DECODE_UINT32_OR_DIE(token, val) \
460 KRB_DECODE_OR_DIE(token, asn1_uint32_decode, val);
462 #define KRB_DECODE_STRING_OR_DIE(token, expected_tag, val, val_len, item_len) \
463 ret = asn1_string_decode (asn1p, &val, &val_len, &item_len, expected_tag); \
464 if (ret != ASN1_ERR_NOERROR) { \
465 if (check_col(fd, COL_INFO)) \
466 col_add_fstr(fd, COL_INFO, "ERROR: Problem at %s: %s", \
467 token, to_error_str(ret)); \
471 #define KRB_DECODE_OCTET_STRING_OR_DIE(token, val, val_len, item_len) \
472 KRB_DECODE_STRING_OR_DIE(token, ASN1_OTS, val, val_len, item_len)
474 #define KRB_DECODE_GENERAL_STRING_OR_DIE(token, val, val_len, item_len) \
475 KRB_DECODE_STRING_OR_DIE(token, ASN1_GENSTR, val, val_len, item_len)
477 #define KRB_DECODE_GENERAL_TIME_OR_DIE(token, val, val_len, item_len) \
478 KRB_DECODE_STRING_OR_DIE(token, ASN1_GENTIM, val, val_len, item_len)
480 /* dissect_type_value_pair decodes (roughly) this:
487 which is all over the place in krb5 */
490 dissect_type_value_pair(ASN1_SCK *asn1p, int *inoff,
491 guint32 *type, int *type_len, int *type_off,
492 guchar **val, int *val_len, int *val_off) {
501 start = asn1p->pointer;
502 asn1_header_decode (asn1p, &cls, &con, &tag, &def, &tmp_len);
503 offset += (asn1p->pointer - start);
507 start = asn1p->pointer;
508 asn1_header_decode (asn1p, &cls, &con, &tag, &def, &tmp_len);
509 offset += (asn1p->pointer - start);
515 ret = asn1_uint32_decode(asn1p, type, type_len);
516 if (ret != ASN1_ERR_NOERROR) {
517 fprintf(stderr,"die: type_value_pair: type, %s\n", to_error_str(ret));
522 /* OCTET STRING (or generic data) */
524 start = asn1p->pointer;
525 asn1_header_decode (asn1p, &cls, &con, &tag, &def, val_len);
526 asn1_header_decode (asn1p, &cls, &con, &tag, &def, val_len);
527 offset += asn1p->pointer - start;
533 asn1_string_value_decode (asn1p, *val_len, val);
535 *inoff = offset + *val_len;
539 dissect_kerberos_main(const u_char *pd, int offset, frame_data *fd,
542 proto_tree *kerberos_tree = NULL;
543 proto_tree *etype_tree = NULL;
544 proto_tree *preauth_tree = NULL;
545 proto_tree *request_tree = NULL;
546 ASN1_SCK asn1, *asn1p = &asn1;
547 proto_item *item = NULL;
552 guint item_len, total_len;
557 guint protocol_message_type;
561 guint32 preauth_type;
567 int tmp_pos1, tmp_pos2;
570 item = proto_tree_add_item(tree, proto_kerberos, NullTVB, offset,
571 END_OF_FRAME, FALSE);
572 kerberos_tree = proto_item_add_subtree(item, ett_kerberos);
575 asn1_open(&asn1, &pd[offset], END_OF_FRAME);
578 KRB_HEAD_DECODE_OR_DIE("top");
579 protocol_message_type = tag;
582 KRB_HEAD_DECODE_OR_DIE("top2");
585 KRB_HEAD_DECODE_OR_DIE("version-wrap");
586 KRB_DECODE_UINT32_OR_DIE("version", version);
589 proto_tree_add_text(kerberos_tree, NullTVB, offset, length,
596 KRB_HEAD_DECODE_OR_DIE("message-type-wrap");
597 KRB_DECODE_UINT32_OR_DIE("message-type", msg_type);
600 proto_tree_add_text(kerberos_tree, NullTVB, offset, length,
602 val_to_str(msg_type, krb5_msg_types,
603 "Unknown msg type %#x"));
607 if (check_col(fd, COL_INFO))
608 col_add_str(fd, COL_INFO, val_to_str(msg_type, krb5_msg_types,
609 "Unknown msg type %#x"));
611 /* is preauthentication present? */
612 KRB_HEAD_DECODE_OR_DIE("padata-or-body");
613 if (((protocol_message_type == KRB5_MSG_AS_REQ ||
614 protocol_message_type == KRB5_MSG_TGS_REQ) &&
615 tag == KRB5_KDC_REQ_PADATA) ||
616 ((protocol_message_type == KRB5_MSG_AS_REP ||
617 protocol_message_type == KRB5_MSG_TGS_REP) &&
618 tag == KRB5_KDC_REP_PADATA)) {
619 /* pre-authentication supplied */
622 item = proto_tree_add_text(kerberos_tree, NullTVB, offset,
623 item_len, "Pre-Authentication");
624 preauth_tree = proto_item_add_subtree(item, ett_preauth);
627 KRB_HEAD_DECODE_OR_DIE("sequence of pa-data");
628 start = asn1p->pointer + item_len;
630 while(start > asn1p->pointer) {
631 dissect_type_value_pair(asn1p, &offset,
632 &preauth_type, &item_len, &tmp_pos1,
633 &str, &str_len, &tmp_pos2);
636 proto_tree_add_text(preauth_tree, NullTVB, tmp_pos1,
637 item_len, "Type: %s",
638 val_to_str(preauth_type,
639 krb5_preauthentication_types,
640 "Unknown preauth type %#x"));
641 proto_tree_add_text(preauth_tree, NullTVB, tmp_pos2,
642 str_len, "Value: %s",
643 bytes_to_str(str, str_len));
646 KRB_HEAD_DECODE_OR_DIE("message-body");
649 switch (protocol_message_type) {
651 case KRB5_MSG_AS_REQ:
652 case KRB5_MSG_TGS_REQ:
654 AS-REQ ::= [APPLICATION 10] KDC-REQ
655 TGS-REQ ::= [APPLICATION 12] KDC-REQ
657 KDC-REQ ::= SEQUENCE {
660 padata[3] SEQUENCE OF PA-DATA OPTIONAL,
661 req-body[4] KDC-REQ-BODY
664 KDC-REQ-BODY ::= SEQUENCE {
665 kdc-options[0] KDCOptions,
666 cname[1] PrincipalName OPTIONAL,
667 -- Used only in AS-REQ
668 realm[2] Realm, -- Server's realm
669 -- Also client's in AS-REQ
670 sname[3] PrincipalName OPTIONAL,
671 from[4] KerberosTime OPTIONAL,
672 till[5] KerberosTime,
673 rtime[6] KerberosTime OPTIONAL,
675 etype[8] SEQUENCE OF INTEGER, -- EncryptionType,
676 -- in preference order
677 addresses[9] HostAddresses OPTIONAL,
678 enc-authorization-data[10] EncryptedData OPTIONAL,
679 -- Encrypted AuthorizationData encoding
680 additional-tickets[11] SEQUENCE OF Ticket OPTIONAL
685 KRB_HEAD_DECODE_OR_DIE("body-sequence");
687 item = proto_tree_add_text(kerberos_tree, NullTVB, offset,
688 item_len, "Request");
689 request_tree = proto_item_add_subtree(item, ett_request);
693 KRB_HEAD_DECODE_OR_DIE("kdc options");
695 KRB_HEAD_DECODE_OR_DIE("kdc options:bits");
698 proto_tree_add_text(request_tree, NullTVB, offset, item_len,
700 bytes_to_str(asn1.pointer, item_len));
703 asn1.pointer += item_len;
705 KRB_HEAD_DECODE_OR_DIE("Client Name or Realm");
707 if (CHECK_CONTEXT_TYPE(KRB5_BODY_CNAME)) {
708 item_len = dissect_PrincipalName("Client Name", asn1p, fd,
709 request_tree, offset);
713 KRB_HEAD_DECODE_OR_DIE("Realm");
716 DIE_IF_NOT_CONTEXT_TYPE("Realm", KRB5_BODY_REALM);
717 KRB_DECODE_GENERAL_STRING_OR_DIE("Realm", str, str_len, item_len);
719 proto_tree_add_text(request_tree, NullTVB, offset, item_len,
720 "Realm: %.*s", str_len, str);
724 KRB_HEAD_DECODE_OR_DIE("Server Name");
725 if (CHECK_CONTEXT_TYPE(KRB5_BODY_SNAME)) {
726 item_len = dissect_PrincipalName("Server Name", asn1p, fd,
727 request_tree, offset);
731 KRB_HEAD_DECODE_OR_DIE("From or Till");
734 if (CHECK_CONTEXT_TYPE(KRB5_BODY_FROM)) {
735 KRB_DECODE_GENERAL_TIME_OR_DIE("From", str, str_len, item_len);
736 krb_proto_tree_add_time(request_tree, offset, item_len,
739 KRB_HEAD_DECODE_OR_DIE("Till");
742 DIE_IF_NOT_CONTEXT_TYPE("Till", KRB5_BODY_TILL);
743 KRB_DECODE_GENERAL_TIME_OR_DIE("Till", str, str_len, item_len);
744 krb_proto_tree_add_time(request_tree, offset, item_len,
748 KRB_HEAD_DECODE_OR_DIE("Renewable Until or Nonce");
749 if (CHECK_CONTEXT_TYPE(KRB5_BODY_RTIME)) {
750 KRB_DECODE_GENERAL_TIME_OR_DIE("Renewable Until", str, str_len, item_len);
751 krb_proto_tree_add_time(request_tree, offset, item_len,
752 "Renewable Until", str);
754 KRB_HEAD_DECODE_OR_DIE("Nonce");
757 DIE_IF_NOT_CONTEXT_TYPE("Nonce", KRB5_BODY_NONCE);
758 KRB_DECODE_UINT32_OR_DIE("Nonce", tmp_int);
760 proto_tree_add_text(request_tree, NullTVB, offset, length,
766 KRB_DECODE_CONTEXT_HEAD_OR_DIE("encryption type spot",
768 KRB_HEAD_DECODE_OR_DIE("encryption type list");
770 item = proto_tree_add_text(request_tree, NullTVB, offset,
771 item_len, "Encryption Types");
772 etype_tree = proto_item_add_subtree(item, ett_etype);
774 total_len = item_len;
775 while(total_len > 0) {
776 KRB_DECODE_UINT32_OR_DIE("encryption type", tmp_int);
778 proto_tree_add_text(etype_tree, NullTVB, offset, length,
781 krb5_encryption_types,
782 "Unknown encryption type %#x"));
788 KRB_HEAD_DECODE_OR_DIE("addresses");
789 if (CHECK_CONTEXT_TYPE(KRB5_BODY_ADDRESSES)) {
790 /* pre-authentication supplied */
792 offset = dissect_Addresses("Addresses", asn1p, fd, kerberos_tree,
796 KRB_HEAD_DECODE_OR_DIE("auth-data");
800 case KRB5_MSG_AS_REP:
801 case KRB5_MSG_TGS_REP:
803 AS-REP ::= [APPLICATION 11] KDC-REP
804 TGS-REP ::= [APPLICATION 13] KDC-REP
806 KDC-REP ::= SEQUENCE {
809 padata[2] SEQUENCE OF PA-DATA OPTIONAL,
811 cname[4] PrincipalName,
813 enc-part[6] EncryptedData
817 DIE_IF_NOT_CONTEXT_TYPE("crealm", KRB5_KDC_REP_CREALM);
818 KRB_DECODE_GENERAL_STRING_OR_DIE("realm name", str, str_len, item_len);
820 proto_tree_add_text(kerberos_tree, NullTVB, offset, item_len,
821 "Realm: %.*s", str_len, str);
825 KRB_DECODE_CONTEXT_HEAD_OR_DIE("cname", KRB5_KDC_REP_CNAME);
826 item_len = dissect_PrincipalName("Client Name", asn1p, fd,
827 kerberos_tree, offset);
832 KRB_DECODE_CONTEXT_HEAD_OR_DIE("ticket", KRB5_KDC_REP_TICKET);
833 offset = dissect_Ticket("ticket", asn1p, fd, kerberos_tree, offset);
837 KRB_DECODE_CONTEXT_HEAD_OR_DIE("enc-msg-part",
838 KRB5_KDC_REP_ENC_PART);
839 offset = dissect_EncryptedData("Encrypted Payload", asn1p, fd,
840 kerberos_tree, offset);
847 KRB-ERROR ::= [APPLICATION 30] SEQUENCE {
850 ctime[2] KerberosTime OPTIONAL,
851 cusec[3] INTEGER OPTIONAL,
852 stime[4] KerberosTime,
854 error-code[6] INTEGER,
855 crealm[7] Realm OPTIONAL,
856 cname[8] PrincipalName OPTIONAL,
857 realm[9] Realm, -- Correct realm
858 sname[10] PrincipalName, -- Correct name
859 e-text[11] GeneralString OPTIONAL,
860 e-data[12] OCTET STRING OPTIONAL
867 if (CHECK_CONTEXT_TYPE(KRB5_ERROR_CTIME)) {
868 KRB_DECODE_GENERAL_TIME_OR_DIE("ctime", str, str_len, item_len);
869 krb_proto_tree_add_time(kerberos_tree, offset, item_len,
872 KRB_HEAD_DECODE_OR_DIE("cusec");
876 if (CHECK_CONTEXT_TYPE(KRB5_ERROR_CUSEC)) {
877 KRB_DECODE_UINT32_OR_DIE("cusec", tmp_int);
879 proto_tree_add_text(kerberos_tree, NullTVB, offset, length,
885 KRB_HEAD_DECODE_OR_DIE("sutime");
888 DIE_IF_NOT_CONTEXT_TYPE("sutime", KRB5_ERROR_STIME);
889 KRB_DECODE_GENERAL_TIME_OR_DIE("stime", str, str_len, item_len);
890 krb_proto_tree_add_time(kerberos_tree, offset, item_len,
894 KRB_HEAD_DECODE_OR_DIE("susec");
895 DIE_IF_NOT_CONTEXT_TYPE("susec", KRB5_ERROR_SUSEC);
896 KRB_DECODE_UINT32_OR_DIE("susec", tmp_int);
898 proto_tree_add_text(kerberos_tree, NullTVB, offset, length,
904 KRB_HEAD_DECODE_OR_DIE("errcode");
905 DIE_IF_NOT_CONTEXT_TYPE("errcode", KRB5_ERROR_ERROR_CODE);
906 KRB_DECODE_UINT32_OR_DIE("errcode", tmp_int);
908 proto_tree_add_text(kerberos_tree, NullTVB, offset, length,
912 "Unknown error code %#x"));
915 KRB_HEAD_DECODE_OR_DIE("crealm");
917 if (CHECK_CONTEXT_TYPE(KRB5_ERROR_CREALM)) {
918 KRB_DECODE_GENERAL_STRING_OR_DIE("crealm", str, str_len, item_len);
920 proto_tree_add_text(kerberos_tree, NullTVB, offset, item_len,
921 "crealm: %.*s", str_len, str);
924 KRB_HEAD_DECODE_OR_DIE("cname");
927 if (CHECK_CONTEXT_TYPE(KRB5_ERROR_CNAME)) {
928 item_len = dissect_PrincipalName("cname", asn1p, fd,
929 kerberos_tree, offset);
933 KRB_HEAD_DECODE_OR_DIE("realm");
936 DIE_IF_NOT_CONTEXT_TYPE("realm", KRB5_ERROR_REALM);
937 KRB_DECODE_GENERAL_STRING_OR_DIE("realm", str, str_len, item_len);
939 proto_tree_add_text(kerberos_tree, NullTVB, offset, item_len,
940 "realm: %.*s", str_len, str);
943 KRB_HEAD_DECODE_OR_DIE("sname");
945 DIE_IF_NOT_CONTEXT_TYPE("sname", KRB5_ERROR_SNAME);
946 item_len = dissect_PrincipalName("sname", asn1p, fd,
947 kerberos_tree, offset);
951 KRB_HEAD_DECODE_OR_DIE("e-text");
953 if ( CHECK_CONTEXT_TYPE(KRB5_ERROR_ETEXT) ) {
954 KRB_DECODE_GENERAL_STRING_OR_DIE("etext", str, str_len, item_len);
956 proto_tree_add_text(kerberos_tree, NullTVB, offset, item_len,
957 "etext: %.*s", str_len, str);
960 KRB_HEAD_DECODE_OR_DIE("e-data");
963 if ( CHECK_CONTEXT_TYPE(KRB5_ERROR_EDATA) ) {
967 KRB_DECODE_OCTET_STRING_OR_DIE("e-data", data, data_len, item_len);
970 proto_tree_add_text(kerberos_tree, NullTVB, offset, data_len,
971 "Error Data: %s", bytes_to_str(data, item_len));
982 dissect_kerberos(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
984 OLD_CHECK_DISPLAY_AS_DATA(proto_kerberos, pd, offset, fd, tree);
986 if (check_col(fd, COL_PROTOCOL))
987 col_set_str(fd, COL_PROTOCOL, "KRB5");
989 dissect_kerberos_main(pd, offset, fd, tree);
993 dissect_PrincipalName(char *title, ASN1_SCK *asn1p, frame_data *fd,
994 proto_tree *tree, int start_offset)
997 PrincipalName ::= SEQUENCE {
998 name-type[0] INTEGER,
999 name-string[1] SEQUENCE OF GeneralString
1002 proto_tree *princ_tree = NULL;
1003 int offset = start_offset;
1007 const guchar *start;
1008 guint cls, con, tag;
1009 guint header_len, item_len, total_len, type_len;
1012 proto_item *item = NULL;
1021 /* principal name */
1022 KRB_SEQ_HEAD_DECODE_OR_DIE("principal section");
1025 item = proto_tree_add_text(tree, NullTVB, start_offset,
1026 (offset - start_offset) + item_len, "%s",
1028 princ_tree = proto_item_add_subtree(item, ett_princ);
1034 KRB_DECODE_CONTEXT_HEAD_OR_DIE("principal type", 0);
1035 KRB_DECODE_UINT32_OR_DIE("princ-type", princ_type);
1036 type_offset = offset;
1037 type_len = item_len;
1041 proto_tree_add_text(princ_tree, NullTVB, type_offset, type_len,
1043 val_to_str(princ_type, krb5_princ_types,
1044 "Unknown name type %#x"));
1047 KRB_DECODE_CONTEXT_HEAD_OR_DIE("principal name-string", 1);
1048 KRB_SEQ_HEAD_DECODE_OR_DIE("principal name-string sequence-of");
1049 total_len = item_len;
1050 if (total_len == 0) {
1051 /* There are no name strings in this PrincipalName, so we can't
1052 put any in the top-level item. */
1053 return offset - start_offset;
1056 /* Put the first name string in the top-level item. */
1057 KRB_DECODE_GENERAL_STRING_OR_DIE("principal name", name, name_len, item_len);
1059 proto_item_set_text(item, "%s: %.*s", title, (int) name_len, name);
1060 proto_tree_add_text(princ_tree, NullTVB, offset, item_len,
1061 "Name: %.*s", (int) name_len, name);
1063 total_len -= item_len;
1066 /* Now process the rest of the strings.
1067 XXX - put them in the item as well? */
1068 while (total_len > 0) {
1069 KRB_DECODE_GENERAL_STRING_OR_DIE("principal name", name, name_len, item_len);
1071 proto_tree_add_text(princ_tree, NullTVB, offset, item_len,
1072 "Name: %.*s", (int) name_len, name);
1074 total_len -= item_len;
1077 return offset - start_offset;
1081 dissect_Addresses(char *title, ASN1_SCK *asn1p, frame_data *fd,
1082 proto_tree *tree, int start_offset) {
1083 proto_tree *address_tree = NULL;
1084 int offset = start_offset;
1086 const guchar *start;
1087 guint cls, con, tag;
1091 proto_item *item = NULL;
1094 int tmp_pos1, tmp_pos2;
1095 guint32 address_type;
1100 KRB_HEAD_DECODE_OR_DIE("sequence of addresses");
1102 item = proto_tree_add_text(tree, NullTVB, offset,
1103 item_len, "Addresses");
1104 address_tree = proto_item_add_subtree(item, ett_addresses);
1107 start = asn1p->pointer + item_len;
1109 while(start > asn1p->pointer) {
1110 dissect_type_value_pair(asn1p, &offset,
1111 &address_type, &item_len, &tmp_pos1,
1112 &str, &str_len, &tmp_pos2);
1115 proto_tree_add_text(address_tree, NullTVB, tmp_pos1,
1116 item_len, "Type: %s",
1117 val_to_str(address_type, krb5_address_types,
1118 "Unknown address type %#x"));
1119 switch(address_type) {
1120 case KRB5_ADDR_IPv4:
1121 proto_tree_add_text(address_tree, NullTVB, tmp_pos2,
1122 str_len, "Value: %d.%d.%d.%d",
1123 str[0], str[1], str[2], str[3]);
1127 proto_tree_add_text(address_tree, NullTVB, tmp_pos2,
1128 str_len, "Value: %s",
1129 bytes_to_str(str, str_len));
1138 dissect_EncryptedData(char *title, ASN1_SCK *asn1p, frame_data *fd,
1139 proto_tree *tree, int start_offset)
1142 EncryptedData ::= SEQUENCE {
1143 etype[0] INTEGER, -- EncryptionType
1144 kvno[1] INTEGER OPTIONAL,
1145 cipher[2] OCTET STRING -- ciphertext
1148 proto_tree *encr_tree = NULL;
1149 int offset = start_offset;
1151 const guchar *start;
1152 guint cls, con, tag;
1153 guint header_len, item_len, data_len;
1156 proto_item *item = NULL;
1163 KRB_SEQ_HEAD_DECODE_OR_DIE("encrypted data section");
1166 item = proto_tree_add_text(tree, NullTVB, start_offset,
1167 (offset - start_offset) + item_len,
1168 "Encrypted Data: %s", title);
1169 encr_tree = proto_item_add_subtree(item, ett_princ);
1173 KRB_DECODE_CONTEXT_HEAD_OR_DIE("encryption type", 0);
1174 KRB_DECODE_UINT32_OR_DIE("encr-type", val);
1176 proto_tree_add_text(encr_tree, NullTVB, offset, length,
1178 val_to_str(val, krb5_encryption_types,
1179 "Unknown encryption type %#x"));
1184 KRB_HEAD_DECODE_OR_DIE("kvno-wrap or cipher-wrap");
1185 if (CHECK_CONTEXT_TYPE(1)) {
1186 KRB_DECODE_UINT32_OR_DIE("kvno", val);
1188 proto_tree_add_text(encr_tree, NullTVB, offset, length,
1192 KRB_HEAD_DECODE_OR_DIE("cipher-wrap");
1195 DIE_IF_NOT_CONTEXT_TYPE("cipher-wrap", 2);
1196 KRB_DECODE_OCTET_STRING_OR_DIE("cipher", data, data_len, item_len);
1199 proto_tree_add_text(encr_tree, NullTVB, offset, data_len,
1200 "CipherText: %s", bytes_to_str(data, item_len));
1208 dissect_Ticket(char *title, ASN1_SCK *asn1p, frame_data *fd, proto_tree *tree,
1212 Ticket ::= [APPLICATION 1] SEQUENCE {
1215 sname[2] PrincipalName,
1216 enc-part[3] EncryptedData
1219 proto_tree *ticket_tree = NULL;
1220 int offset = start_offset;
1222 const guchar *start;
1223 guint cls, con, tag;
1224 guint header_len, item_len, total_len;
1227 proto_item *item = NULL;
1235 KRB_DECODE_APPLICATION_TAGGED_HEAD_OR_DIE("Ticket section", 1);
1236 KRB_SEQ_HEAD_DECODE_OR_DIE("Ticket sequence");
1237 total_len = item_len;
1240 item = proto_tree_add_text(tree, NullTVB, start_offset,
1241 (offset - start_offset) + item_len,
1243 ticket_tree = proto_item_add_subtree(item, ett_ticket);
1247 KRB_DECODE_CONTEXT_HEAD_OR_DIE("Ticket tkt-vno", KRB5_TKT_TKT_VNO);
1248 KRB_DECODE_UINT32_OR_DIE("Ticket tkt-vno", val);
1250 proto_tree_add_text(ticket_tree, NullTVB, offset, length,
1251 "Version: %u", val);
1254 total_len -= length;
1257 KRB_DECODE_CONTEXT_HEAD_OR_DIE("Ticket realm", KRB5_TKT_REALM);
1258 KRB_DECODE_GENERAL_STRING_OR_DIE("Ticket realm string", str, str_len, item_len);
1260 proto_tree_add_text(ticket_tree, NullTVB, offset, item_len,
1261 "Realm: %.*s", str_len, str);
1264 total_len -= item_len;
1266 /* server name (sname) */
1267 KRB_DECODE_CONTEXT_HEAD_OR_DIE("Ticket sname", KRB5_TKT_SNAME);
1268 item_len = dissect_PrincipalName("Service Name", asn1p, fd, ticket_tree,
1274 /* encrypted part */
1275 KRB_DECODE_CONTEXT_HEAD_OR_DIE("enc-part", KRB5_TKT_ENC_PART);
1276 offset = dissect_EncryptedData("Ticket data", asn1p, fd, ticket_tree,
1286 proto_register_kerberos(void) {
1288 static hf_register_info hf[] = {
1291 static gint *ett[] = {
1301 proto_kerberos = proto_register_protocol("Kerberos", "KRB5", "kerberos");
1303 proto_register_field_array(proto_kerberos, hf, array_length(hf));
1305 proto_register_subtree_array(ett, array_length(ett));
1309 proto_reg_handoff_kerberos(void)
1311 old_dissector_add("udp.port", UDP_PORT_KERBEROS, dissect_kerberos,
1313 old_dissector_add("tcp.port", TCP_PORT_KERBEROS, dissect_kerberos,
1319 MISC definitions from RFC1510:
1321 Realm ::= GeneralString
1323 KerberosTime ::= GeneralizedTime
1325 HostAddress ::= SEQUENCE {
1326 addr-type[0] INTEGER,
1327 address[1] OCTET STRING
1330 HostAddresses ::= SEQUENCE OF SEQUENCE {
1331 addr-type[0] INTEGER,
1332 address[1] OCTET STRING
1335 AuthorizationData ::= SEQUENCE OF SEQUENCE {
1337 ad-data[1] OCTET STRING
1339 APOptions ::= BIT STRING {
1346 TicketFlags ::= BIT STRING {
1361 KDCOptions ::= BIT STRING {
1375 enc-tkt-in-skey(28),
1381 LastReq ::= SEQUENCE OF SEQUENCE {
1383 lr-value[1] KerberosTime
1386 Ticket ::= [APPLICATION 1] SEQUENCE {
1389 sname[2] PrincipalName,
1390 enc-part[3] EncryptedData
1393 -- Encrypted part of ticket
1394 EncTicketPart ::= [APPLICATION 3] SEQUENCE {
1395 flags[0] TicketFlags,
1396 key[1] EncryptionKey,
1398 cname[3] PrincipalName,
1399 transited[4] TransitedEncoding,
1400 authtime[5] KerberosTime,
1401 starttime[6] KerberosTime OPTIONAL,
1402 endtime[7] KerberosTime,
1403 renew-till[8] KerberosTime OPTIONAL,
1404 caddr[9] HostAddresses OPTIONAL,
1405 authorization-data[10] AuthorizationData OPTIONAL
1408 -- encoded Transited field
1409 TransitedEncoding ::= SEQUENCE {
1410 tr-type[0] INTEGER, -- must be registered
1411 contents[1] OCTET STRING
1414 -- Unencrypted authenticator
1415 Authenticator ::= [APPLICATION 2] SEQUENCE {
1416 authenticator-vno[0] INTEGER,
1418 cname[2] PrincipalName,
1419 cksum[3] Checksum OPTIONAL,
1421 ctime[5] KerberosTime,
1422 subkey[6] EncryptionKey OPTIONAL,
1423 seq-number[7] INTEGER OPTIONAL,
1424 authorization-data[8] AuthorizationData OPTIONAL
1427 PA-DATA ::= SEQUENCE {
1428 padata-type[1] INTEGER,
1429 padata-value[2] OCTET STRING,
1430 -- might be encoded AP-REQ
1433 padata-type ::= PA-ENC-TIMESTAMP
1434 padata-value ::= EncryptedData -- PA-ENC-TS-ENC
1436 PA-ENC-TS-ENC ::= SEQUENCE {
1437 patimestamp[0] KerberosTime, -- client's time
1438 pausec[1] INTEGER OPTIONAL
1441 EncASRepPart ::= [APPLICATION 25[25]] EncKDCRepPart
1442 EncTGSRepPart ::= [APPLICATION 26] EncKDCRepPart
1444 EncKDCRepPart ::= SEQUENCE {
1445 key[0] EncryptionKey,
1446 last-req[1] LastReq,
1448 key-expiration[3] KerberosTime OPTIONAL,
1449 flags[4] TicketFlags,
1450 authtime[5] KerberosTime,
1451 starttime[6] KerberosTime OPTIONAL,
1452 endtime[7] KerberosTime,
1453 renew-till[8] KerberosTime OPTIONAL,
1455 sname[10] PrincipalName,
1456 caddr[11] HostAddresses OPTIONAL
1459 AP-REQ ::= [APPLICATION 14] SEQUENCE {
1461 msg-type[1] INTEGER,
1462 ap-options[2] APOptions,
1464 authenticator[4] EncryptedData
1467 APOptions ::= BIT STRING {
1473 AP-REP ::= [APPLICATION 15] SEQUENCE {
1475 msg-type[1] INTEGER,
1476 enc-part[2] EncryptedData
1479 EncAPRepPart ::= [APPLICATION 27] SEQUENCE {
1480 ctime[0] KerberosTime,
1482 subkey[2] EncryptionKey OPTIONAL,
1483 seq-number[3] INTEGER OPTIONAL
1486 KRB-SAFE ::= [APPLICATION 20] SEQUENCE {
1488 msg-type[1] INTEGER,
1489 safe-body[2] KRB-SAFE-BODY,
1493 KRB-SAFE-BODY ::= SEQUENCE {
1494 user-data[0] OCTET STRING,
1495 timestamp[1] KerberosTime OPTIONAL,
1496 usec[2] INTEGER OPTIONAL,
1497 seq-number[3] INTEGER OPTIONAL,
1498 s-address[4] HostAddress,
1499 r-address[5] HostAddress OPTIONAL
1502 KRB-PRIV ::= [APPLICATION 21] SEQUENCE {
1504 msg-type[1] INTEGER,
1505 enc-part[3] EncryptedData
1508 EncKrbPrivPart ::= [APPLICATION 28] SEQUENCE {
1509 user-data[0] OCTET STRING,
1510 timestamp[1] KerberosTime OPTIONAL,
1511 usec[2] INTEGER OPTIONAL,
1512 seq-number[3] INTEGER OPTIONAL,
1513 s-address[4] HostAddress, -- sender's addr
1514 r-address[5] HostAddress OPTIONAL
1518 KRB-CRED ::= [APPLICATION 22] SEQUENCE {
1520 msg-type[1] INTEGER, -- KRB_CRED
1521 tickets[2] SEQUENCE OF Ticket,
1522 enc-part[3] EncryptedData
1525 EncKrbCredPart ::= [APPLICATION 29] SEQUENCE {
1526 ticket-info[0] SEQUENCE OF KrbCredInfo,
1527 nonce[1] INTEGER OPTIONAL,
1528 timestamp[2] KerberosTime OPTIONAL,
1529 usec[3] INTEGER OPTIONAL,
1530 s-address[4] HostAddress OPTIONAL,
1531 r-address[5] HostAddress OPTIONAL
1534 KrbCredInfo ::= SEQUENCE {
1535 key[0] EncryptionKey,
1536 prealm[1] Realm OPTIONAL,
1537 pname[2] PrincipalName OPTIONAL,
1538 flags[3] TicketFlags OPTIONAL,
1539 authtime[4] KerberosTime OPTIONAL,
1540 starttime[5] KerberosTime OPTIONAL,
1541 endtime[6] KerberosTime OPTIONAL
1542 renew-till[7] KerberosTime OPTIONAL,
1543 srealm[8] Realm OPTIONAL,
1544 sname[9] PrincipalName OPTIONAL,
1545 caddr[10] HostAddresses OPTIONAL
1548 KRB-ERROR ::= [APPLICATION 30] SEQUENCE {
1550 msg-type[1] INTEGER,
1551 ctime[2] KerberosTime OPTIONAL,
1552 cusec[3] INTEGER OPTIONAL,
1553 stime[4] KerberosTime,
1555 error-code[6] INTEGER,
1556 crealm[7] Realm OPTIONAL,
1557 cname[8] PrincipalName OPTIONAL,
1558 realm[9] Realm, -- Correct realm
1559 sname[10] PrincipalName, -- Correct name
1560 e-text[11] GeneralString OPTIONAL,
1561 e-data[12] OCTET STRING OPTIONAL
1564 e-data This field contains additional data about the error for use
1565 by the application to help it recover from or handle the
1566 error. If the errorcode is KDC_ERR_PREAUTH_REQUIRED, then
1567 the e-data field will contain an encoding of a sequence of
1568 padata fields, each corresponding to an acceptable pre-
1569 authentication method and optionally containing data for
1572 METHOD-DATA ::= SEQUENCE of PA-DATA
1574 If the error-code is KRB_AP_ERR_METHOD, then the e-data field will
1575 contain an encoding of the following sequence:
1577 METHOD-DATA ::= SEQUENCE {
1578 method-type[0] INTEGER,
1579 method-data[1] OCTET STRING OPTIONAL
1582 EncryptionKey ::= SEQUENCE {
1584 keyvalue[1] OCTET STRING
1587 Checksum ::= SEQUENCE {
1588 cksumtype[0] INTEGER,
1589 checksum[1] OCTET STRING