2 * Copyright (c) 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 * Initial contribution from John Hawkinson (jhawk@mit.edu).
24 /* \summary: Kerberos printer */
30 #include "netdissect-stdinc.h"
32 #include "netdissect.h"
38 * Athena Technical Plan
40 * Kerberos Authentication and Authorization System
41 * by S. P. Miller, B. C. Neuman, J. I. Schiller, and J. H. Saltzer
43 * http://web.mit.edu/Saltzer/www/publications/athenaplan/e.2.1.pdf
45 * 7. Appendix I Design Specifications
49 * RFC 1510, RFC 2630, etc.
52 static const char tstr
[] = " [|kerberos]";
54 static const u_char
*c_print(netdissect_options
*, const u_char
*, const u_char
*);
55 static const u_char
*krb4_print_hdr(netdissect_options
*, const u_char
*);
56 static void krb4_print(netdissect_options
*, const u_char
*);
58 #define AUTH_MSG_KDC_REQUEST 1<<1
59 #define AUTH_MSG_KDC_REPLY 2<<1
60 #define AUTH_MSG_APPL_REQUEST 3<<1
61 #define AUTH_MSG_APPL_REQUEST_MUTUAL 4<<1
62 #define AUTH_MSG_ERR_REPLY 5<<1
63 #define AUTH_MSG_PRIVATE 6<<1
64 #define AUTH_MSG_SAFE 7<<1
65 #define AUTH_MSG_APPL_ERR 8<<1
66 #define AUTH_MSG_DIE 63<<1
69 #define KERB_ERR_NAME_EXP 1
70 #define KERB_ERR_SERVICE_EXP 2
71 #define KERB_ERR_AUTH_EXP 3
72 #define KERB_ERR_PKT_VER 4
73 #define KERB_ERR_NAME_MAST_KEY_VER 5
74 #define KERB_ERR_SERV_MAST_KEY_VER 6
75 #define KERB_ERR_BYTE_ORDER 7
76 #define KERB_ERR_PRINCIPAL_UNKNOWN 8
77 #define KERB_ERR_PRINCIPAL_NOT_UNIQUE 9
78 #define KERB_ERR_NULL_KEY 10
81 nd_uint8_t pvno
; /* Protocol Version */
82 nd_uint8_t type
; /* Type+B */
85 static const struct tok type2str
[] = {
86 { AUTH_MSG_KDC_REQUEST
, "KDC_REQUEST" },
87 { AUTH_MSG_KDC_REPLY
, "KDC_REPLY" },
88 { AUTH_MSG_APPL_REQUEST
, "APPL_REQUEST" },
89 { AUTH_MSG_APPL_REQUEST_MUTUAL
, "APPL_REQUEST_MUTUAL" },
90 { AUTH_MSG_ERR_REPLY
, "ERR_REPLY" },
91 { AUTH_MSG_PRIVATE
, "PRIVATE" },
92 { AUTH_MSG_SAFE
, "SAFE" },
93 { AUTH_MSG_APPL_ERR
, "APPL_ERR" },
94 { AUTH_MSG_DIE
, "DIE" },
98 static const struct tok kerr2str
[] = {
99 { KERB_ERR_OK
, "OK" },
100 { KERB_ERR_NAME_EXP
, "NAME_EXP" },
101 { KERB_ERR_SERVICE_EXP
, "SERVICE_EXP" },
102 { KERB_ERR_AUTH_EXP
, "AUTH_EXP" },
103 { KERB_ERR_PKT_VER
, "PKT_VER" },
104 { KERB_ERR_NAME_MAST_KEY_VER
, "NAME_MAST_KEY_VER" },
105 { KERB_ERR_SERV_MAST_KEY_VER
, "SERV_MAST_KEY_VER" },
106 { KERB_ERR_BYTE_ORDER
, "BYTE_ORDER" },
107 { KERB_ERR_PRINCIPAL_UNKNOWN
, "PRINCIPAL_UNKNOWN" },
108 { KERB_ERR_PRINCIPAL_NOT_UNIQUE
,"PRINCIPAL_NOT_UNIQUE" },
109 { KERB_ERR_NULL_KEY
, "NULL_KEY"},
113 static const u_char
*
114 c_print(netdissect_options
*ndo
,
115 const u_char
*s
, const u_char
*ep
)
128 fn_print_char(ndo
, c
);
135 static const u_char
*
136 krb4_print_hdr(netdissect_options
*ndo
,
141 #define PRINT if ((cp = c_print(ndo, cp, ndo->ndo_snapend)) == NULL) goto trunc
151 ND_PRINT("%s", tstr
);
158 krb4_print(netdissect_options
*ndo
,
161 const struct krb
*kp
;
165 #define PRINT if ((cp = c_print(ndo, cp, ndo->ndo_snapend)) == NULL) goto trunc
166 /* True if struct krb is little endian */
167 #define IS_LENDIAN(kp) ((EXTRACT_U_1((kp)->type) & 0x01) != 0)
168 #define KTOHSP(kp, cp) (IS_LENDIAN(kp) ? EXTRACT_LE_U_2(cp) : EXTRACT_BE_U_2(cp))
170 kp
= (const struct krb
*)cp
;
172 if (!ND_TTEST_1(kp
->type
)) {
173 ND_PRINT("%s", tstr
);
177 type
= EXTRACT_U_1(kp
->type
) & (0xFF << 1);
180 IS_LENDIAN(kp
) ? "le" : "be", tok2str(type2str
, NULL
, type
));
184 case AUTH_MSG_KDC_REQUEST
:
185 if ((cp
= krb4_print_hdr(ndo
, cp
)) == NULL
)
189 ND_PRINT(" %umin ", EXTRACT_U_1(cp
) * 5);
196 case AUTH_MSG_APPL_REQUEST
:
199 ND_PRINT("v%u ", EXTRACT_U_1(cp
));
203 ND_PRINT(" (%u)", EXTRACT_U_1(cp
));
206 ND_PRINT(" (%u)", EXTRACT_U_1(cp
));
209 case AUTH_MSG_KDC_REPLY
:
210 if ((cp
= krb4_print_hdr(ndo
, cp
)) == NULL
)
212 cp
+= 10; /* timestamp + n + exp + kvno */
213 ND_TCHECK_LEN(cp
, sizeof(short));
214 len
= KTOHSP(kp
, cp
);
215 ND_PRINT(" (%u)", len
);
218 case AUTH_MSG_ERR_REPLY
:
219 if ((cp
= krb4_print_hdr(ndo
, cp
)) == NULL
)
221 cp
+= 4; /* timestamp */
222 ND_TCHECK_LEN(cp
, sizeof(short));
223 ND_PRINT(" %s ", tok2str(kerr2str
, NULL
, KTOHSP(kp
, cp
)));
229 ND_PRINT("(unknown)");
235 ND_PRINT("%s", tstr
);
239 krb_print(netdissect_options
*ndo
,
242 const struct krb
*kp
;
244 kp
= (const struct krb
*)dat
;
246 if (dat
>= ndo
->ndo_snapend
) {
247 ND_PRINT("%s", tstr
);
251 switch (EXTRACT_U_1(kp
->pvno
)) {
256 ND_PRINT(" v%u", EXTRACT_U_1(kp
->pvno
));
260 ND_PRINT(" v%u", EXTRACT_U_1(kp
->pvno
));
261 krb4_print(ndo
, (const u_char
*)kp
);
267 /* Decode ASN.1 here "someday" */