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).
25 static const char rcsid[] =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-krb.c,v 1.15 2000/09/29 04:58:42 guy Exp $";
33 #include <sys/param.h>
35 #include <sys/socket.h>
37 #include <netinet/in.h>
43 #include "interface.h"
44 #include "addrtoname.h"
46 const u_char *c_print(register const u_char *, register const u_char *);
47 const u_char *krb4_print_hdr(const u_char *);
48 void krb4_print(const u_char *);
49 void krb_print(const u_char *, u_int);
52 #define AUTH_MSG_KDC_REQUEST 1<<1
53 #define AUTH_MSG_KDC_REPLY 2<<1
54 #define AUTH_MSG_APPL_REQUEST 3<<1
55 #define AUTH_MSG_APPL_REQUEST_MUTUAL 4<<1
56 #define AUTH_MSG_ERR_REPLY 5<<1
57 #define AUTH_MSG_PRIVATE 6<<1
58 #define AUTH_MSG_SAFE 7<<1
59 #define AUTH_MSG_APPL_ERR 8<<1
60 #define AUTH_MSG_DIE 63<<1
63 #define KERB_ERR_NAME_EXP 1
64 #define KERB_ERR_SERVICE_EXP 2
65 #define KERB_ERR_AUTH_EXP 3
66 #define KERB_ERR_PKT_VER 4
67 #define KERB_ERR_NAME_MAST_KEY_VER 5
68 #define KERB_ERR_SERV_MAST_KEY_VER 6
69 #define KERB_ERR_BYTE_ORDER 7
70 #define KERB_ERR_PRINCIPAL_UNKNOWN 8
71 #define KERB_ERR_PRINCIPAL_NOT_UNIQUE 9
72 #define KERB_ERR_NULL_KEY 10
75 u_char pvno; /* Protocol Version */
76 u_char type; /* Type+B */
79 static char tstr[] = " [|kerberos]";
81 static struct tok type2str[] = {
82 { AUTH_MSG_KDC_REQUEST, "KDC_REQUEST" },
83 { AUTH_MSG_KDC_REPLY, "KDC_REPLY" },
84 { AUTH_MSG_APPL_REQUEST, "APPL_REQUEST" },
85 { AUTH_MSG_APPL_REQUEST_MUTUAL, "APPL_REQUEST_MUTUAL" },
86 { AUTH_MSG_ERR_REPLY, "ERR_REPLY" },
87 { AUTH_MSG_PRIVATE, "PRIVATE" },
88 { AUTH_MSG_SAFE, "SAFE" },
89 { AUTH_MSG_APPL_ERR, "APPL_ERR" },
90 { AUTH_MSG_DIE, "DIE" },
94 static struct tok kerr2str[] = {
95 { KERB_ERR_OK, "OK" },
96 { KERB_ERR_NAME_EXP, "NAME_EXP" },
97 { KERB_ERR_SERVICE_EXP, "SERVICE_EXP" },
98 { KERB_ERR_AUTH_EXP, "AUTH_EXP" },
99 { KERB_ERR_PKT_VER, "PKT_VER" },
100 { KERB_ERR_NAME_MAST_KEY_VER, "NAME_MAST_KEY_VER" },
101 { KERB_ERR_SERV_MAST_KEY_VER, "SERV_MAST_KEY_VER" },
102 { KERB_ERR_BYTE_ORDER, "BYTE_ORDER" },
103 { KERB_ERR_PRINCIPAL_UNKNOWN, "PRINCIPAL_UNKNOWN" },
104 { KERB_ERR_PRINCIPAL_NOT_UNIQUE,"PRINCIPAL_NOT_UNIQUE" },
105 { KERB_ERR_NULL_KEY, "NULL_KEY"},
110 /* little endian (unaligned) to host byte order */
111 /* XXX need to look at this... */
112 #define vtohlp(x) ((( ((char *)(x))[0] ) ) | \
113 (( ((char *)(x))[1] ) << 8) | \
114 (( ((char *)(x))[2] ) << 16) | \
115 (( ((char *)(x))[3] ) << 24))
116 #define vtohsp(x) ((( ((char *)(x))[0] ) ) | \
117 (( ((char *)(x))[1] ) << 8))
118 /* network (big endian) (unaligned) to host byte order */
119 #define ntohlp(x) ((( ((char *)(x))[3] ) ) | \
120 (( ((char *)(x))[2] ) << 8) | \
121 (( ((char *)(x))[1] ) << 16) | \
122 (( ((char *)(x))[0] ) << 24))
123 #define ntohsp(x) ((( ((char *)(x))[1] ) ) | \
124 (( ((char *)(x))[0] ) << 8))
129 c_print(register const u_char *s, register const u_char *ep)
147 c ^= 0x40; /* DEL to ?, others to alpha */
158 krb4_print_hdr(const u_char *cp)
162 #define PRINT if ((cp = c_print(cp, snapend)) == NULL) goto trunc
179 krb4_print(const u_char *cp)
181 register const struct krb *kp;
185 #define PRINT if ((cp = c_print(cp, snapend)) == NULL) goto trunc
186 /* True if struct krb is little endian */
187 #define IS_LENDIAN(kp) (((kp)->type & 0x01) != 0)
188 #define KTOHSP(kp, cp) (IS_LENDIAN(kp) ? vtohsp(cp) : ntohsp(cp))
190 kp = (struct krb *)cp;
192 if ((&kp->type) >= snapend) {
197 type = kp->type & (0xFF << 1);
200 IS_LENDIAN(kp) ? "le" : "be", tok2str(type2str, NULL, type));
204 case AUTH_MSG_KDC_REQUEST:
205 if ((cp = krb4_print_hdr(cp)) == NULL)
209 printf(" %dmin ", *cp++ * 5);
215 case AUTH_MSG_APPL_REQUEST:
218 printf("v%d ", *cp++);
221 printf(" (%d)", *cp++);
223 printf(" (%d)", *cp);
226 case AUTH_MSG_KDC_REPLY:
227 if ((cp = krb4_print_hdr(cp)) == NULL)
229 cp += 10; /* timestamp + n + exp + kvno */
230 TCHECK2(*cp, sizeof(short));
231 len = KTOHSP(kp, cp);
232 printf(" (%d)", len);
235 case AUTH_MSG_ERR_REPLY:
236 if ((cp = krb4_print_hdr(cp)) == NULL)
238 cp += 4; /* timestamp */
239 TCHECK2(*cp, sizeof(short));
240 printf(" %s ", tok2str(kerr2str, NULL, KTOHSP(kp, cp)));
246 fputs("(unknown)", stdout);
256 krb_print(const u_char *dat, u_int length)
258 register const struct krb *kp;
260 kp = (struct krb *)dat;
262 if (dat >= snapend) {
272 printf(" v%d", kp->pvno);
276 printf(" v%d", kp->pvno);
277 krb4_print((const u_char *)kp);
282 fputs(" v5", stdout);
283 /* Decode ASN.1 here "someday" */