xref: /dflybsd-src/contrib/tcpdump/print-krb.c (revision 59c07fbdf8168fa08c76c515186d561b5a92690c)
141c99275SPeter Avalos /*
241c99275SPeter Avalos  * Copyright (c) 1995, 1996, 1997
341c99275SPeter Avalos  *	The Regents of the University of California.  All rights reserved.
441c99275SPeter Avalos  *
541c99275SPeter Avalos  * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos  * modification, are permitted provided that: (1) source code distributions
741c99275SPeter Avalos  * retain the above copyright notice and this paragraph in its entirety, (2)
841c99275SPeter Avalos  * distributions including binary code include the above copyright notice and
941c99275SPeter Avalos  * this paragraph in its entirety in the documentation or other materials
1041c99275SPeter Avalos  * provided with the distribution, and (3) all advertising materials mentioning
1141c99275SPeter Avalos  * features or use of this software display the following acknowledgement:
1241c99275SPeter Avalos  * ``This product includes software developed by the University of California,
1341c99275SPeter Avalos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1441c99275SPeter Avalos  * the University nor the names of its contributors may be used to endorse
1541c99275SPeter Avalos  * or promote products derived from this software without specific prior
1641c99275SPeter Avalos  * written permission.
1741c99275SPeter Avalos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1841c99275SPeter Avalos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1941c99275SPeter Avalos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2041c99275SPeter Avalos  *
2141c99275SPeter Avalos  * Initial contribution from John Hawkinson (jhawk@mit.edu).
2241c99275SPeter Avalos  */
2341c99275SPeter Avalos 
24411677aeSAaron LI /* \summary: Kerberos printer */
2541c99275SPeter Avalos 
2641c99275SPeter Avalos #ifdef HAVE_CONFIG_H
27*ed775ee7SAntonio Huete Jimenez #include <config.h>
2841c99275SPeter Avalos #endif
2941c99275SPeter Avalos 
30*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
3141c99275SPeter Avalos 
32411677aeSAaron LI #include "netdissect.h"
3341c99275SPeter Avalos #include "extract.h"
3441c99275SPeter Avalos 
35*ed775ee7SAntonio Huete Jimenez /*
36*ed775ee7SAntonio Huete Jimenez  * Kerberos 4:
37*ed775ee7SAntonio Huete Jimenez  *
38*ed775ee7SAntonio Huete Jimenez  * Athena Technical Plan
39*ed775ee7SAntonio Huete Jimenez  * Section E.2.1
40*ed775ee7SAntonio Huete Jimenez  * Kerberos Authentication and Authorization System
41*ed775ee7SAntonio Huete Jimenez  * by S. P. Miller, B. C. Neuman, J. I. Schiller, and J. H. Saltzer
42*ed775ee7SAntonio Huete Jimenez  *
43*ed775ee7SAntonio Huete Jimenez  * https://web.mit.edu/Saltzer/www/publications/athenaplan/e.2.1.pdf
44*ed775ee7SAntonio Huete Jimenez  *
45*ed775ee7SAntonio Huete Jimenez  * 7. Appendix I Design Specifications
46*ed775ee7SAntonio Huete Jimenez  *
47*ed775ee7SAntonio Huete Jimenez  * Kerberos 5:
48*ed775ee7SAntonio Huete Jimenez  *
49*ed775ee7SAntonio Huete Jimenez  * RFC 1510, RFC 2630, etc.
50*ed775ee7SAntonio Huete Jimenez  */
51411677aeSAaron LI 
52*ed775ee7SAntonio Huete Jimenez 
53*ed775ee7SAntonio Huete Jimenez static const u_char *c_print(netdissect_options *, const u_char *, const u_char *);
54411677aeSAaron LI static const u_char *krb4_print_hdr(netdissect_options *, const u_char *);
55411677aeSAaron LI static void krb4_print(netdissect_options *, const u_char *);
5641c99275SPeter Avalos 
5741c99275SPeter Avalos #define AUTH_MSG_KDC_REQUEST			1<<1
5841c99275SPeter Avalos #define AUTH_MSG_KDC_REPLY			2<<1
5941c99275SPeter Avalos #define AUTH_MSG_APPL_REQUEST			3<<1
6041c99275SPeter Avalos #define AUTH_MSG_APPL_REQUEST_MUTUAL		4<<1
6141c99275SPeter Avalos #define AUTH_MSG_ERR_REPLY			5<<1
6241c99275SPeter Avalos #define AUTH_MSG_PRIVATE			6<<1
6341c99275SPeter Avalos #define AUTH_MSG_SAFE				7<<1
6441c99275SPeter Avalos #define AUTH_MSG_APPL_ERR			8<<1
6541c99275SPeter Avalos #define AUTH_MSG_DIE				63<<1
6641c99275SPeter Avalos 
6741c99275SPeter Avalos #define KERB_ERR_OK				0
6841c99275SPeter Avalos #define KERB_ERR_NAME_EXP			1
6941c99275SPeter Avalos #define KERB_ERR_SERVICE_EXP			2
7041c99275SPeter Avalos #define KERB_ERR_AUTH_EXP			3
7141c99275SPeter Avalos #define KERB_ERR_PKT_VER			4
7241c99275SPeter Avalos #define KERB_ERR_NAME_MAST_KEY_VER		5
7341c99275SPeter Avalos #define KERB_ERR_SERV_MAST_KEY_VER		6
7441c99275SPeter Avalos #define KERB_ERR_BYTE_ORDER			7
7541c99275SPeter Avalos #define KERB_ERR_PRINCIPAL_UNKNOWN		8
7641c99275SPeter Avalos #define KERB_ERR_PRINCIPAL_NOT_UNIQUE		9
7741c99275SPeter Avalos #define KERB_ERR_NULL_KEY			10
7841c99275SPeter Avalos 
7941c99275SPeter Avalos struct krb {
80*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t pvno;	/* Protocol Version */
81*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t type;	/* Type+B */
8241c99275SPeter Avalos };
8341c99275SPeter Avalos 
84411677aeSAaron LI static const struct tok type2str[] = {
8541c99275SPeter Avalos 	{ AUTH_MSG_KDC_REQUEST,		"KDC_REQUEST" },
8641c99275SPeter Avalos 	{ AUTH_MSG_KDC_REPLY,		"KDC_REPLY" },
8741c99275SPeter Avalos 	{ AUTH_MSG_APPL_REQUEST,	"APPL_REQUEST" },
8841c99275SPeter Avalos 	{ AUTH_MSG_APPL_REQUEST_MUTUAL,	"APPL_REQUEST_MUTUAL" },
8941c99275SPeter Avalos 	{ AUTH_MSG_ERR_REPLY,		"ERR_REPLY" },
9041c99275SPeter Avalos 	{ AUTH_MSG_PRIVATE,		"PRIVATE" },
9141c99275SPeter Avalos 	{ AUTH_MSG_SAFE,		"SAFE" },
9241c99275SPeter Avalos 	{ AUTH_MSG_APPL_ERR,		"APPL_ERR" },
9341c99275SPeter Avalos 	{ AUTH_MSG_DIE,			"DIE" },
9441c99275SPeter Avalos 	{ 0,				NULL }
9541c99275SPeter Avalos };
9641c99275SPeter Avalos 
97411677aeSAaron LI static const struct tok kerr2str[] = {
9841c99275SPeter Avalos 	{ KERB_ERR_OK,			"OK" },
9941c99275SPeter Avalos 	{ KERB_ERR_NAME_EXP,		"NAME_EXP" },
10041c99275SPeter Avalos 	{ KERB_ERR_SERVICE_EXP,		"SERVICE_EXP" },
10141c99275SPeter Avalos 	{ KERB_ERR_AUTH_EXP,		"AUTH_EXP" },
10241c99275SPeter Avalos 	{ KERB_ERR_PKT_VER,		"PKT_VER" },
10341c99275SPeter Avalos 	{ KERB_ERR_NAME_MAST_KEY_VER,	"NAME_MAST_KEY_VER" },
10441c99275SPeter Avalos 	{ KERB_ERR_SERV_MAST_KEY_VER,	"SERV_MAST_KEY_VER" },
10541c99275SPeter Avalos 	{ KERB_ERR_BYTE_ORDER,		"BYTE_ORDER" },
10641c99275SPeter Avalos 	{ KERB_ERR_PRINCIPAL_UNKNOWN,	"PRINCIPAL_UNKNOWN" },
10741c99275SPeter Avalos 	{ KERB_ERR_PRINCIPAL_NOT_UNIQUE,"PRINCIPAL_NOT_UNIQUE" },
10841c99275SPeter Avalos 	{ KERB_ERR_NULL_KEY,		"NULL_KEY"},
10941c99275SPeter Avalos 	{ 0,				NULL}
11041c99275SPeter Avalos };
11141c99275SPeter Avalos 
11241c99275SPeter Avalos static const u_char *
c_print(netdissect_options * ndo,const u_char * s,const u_char * ep)113411677aeSAaron LI c_print(netdissect_options *ndo,
114*ed775ee7SAntonio Huete Jimenez         const u_char *s, const u_char *ep)
11541c99275SPeter Avalos {
116*ed775ee7SAntonio Huete Jimenez 	u_char c;
117*ed775ee7SAntonio Huete Jimenez 	int flag;
11841c99275SPeter Avalos 
11941c99275SPeter Avalos 	flag = 1;
12041c99275SPeter Avalos 	while (s < ep) {
121*ed775ee7SAntonio Huete Jimenez 		c = GET_U_1(s);
122*ed775ee7SAntonio Huete Jimenez 		s++;
12341c99275SPeter Avalos 		if (c == '\0') {
12441c99275SPeter Avalos 			flag = 0;
12541c99275SPeter Avalos 			break;
12641c99275SPeter Avalos 		}
127*ed775ee7SAntonio Huete Jimenez 		fn_print_char(ndo, c);
12841c99275SPeter Avalos 	}
12941c99275SPeter Avalos 	if (flag)
13041c99275SPeter Avalos 		return NULL;
13141c99275SPeter Avalos 	return (s);
13241c99275SPeter Avalos }
13341c99275SPeter Avalos 
13441c99275SPeter Avalos static const u_char *
krb4_print_hdr(netdissect_options * ndo,const u_char * cp)135411677aeSAaron LI krb4_print_hdr(netdissect_options *ndo,
136411677aeSAaron LI                const u_char *cp)
13741c99275SPeter Avalos {
13841c99275SPeter Avalos 	cp += 2;
13941c99275SPeter Avalos 
140411677aeSAaron LI #define PRINT		if ((cp = c_print(ndo, cp, ndo->ndo_snapend)) == NULL) goto trunc
14141c99275SPeter Avalos 
14241c99275SPeter Avalos 	PRINT;
143*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(".");
14441c99275SPeter Avalos 	PRINT;
145*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("@");
14641c99275SPeter Avalos 	PRINT;
14741c99275SPeter Avalos 	return (cp);
14841c99275SPeter Avalos 
14941c99275SPeter Avalos trunc:
150*ed775ee7SAntonio Huete Jimenez 	nd_print_trunc(ndo);
15141c99275SPeter Avalos 	return (NULL);
15241c99275SPeter Avalos 
15341c99275SPeter Avalos #undef PRINT
15441c99275SPeter Avalos }
15541c99275SPeter Avalos 
15641c99275SPeter Avalos static void
krb4_print(netdissect_options * ndo,const u_char * cp)157411677aeSAaron LI krb4_print(netdissect_options *ndo,
158411677aeSAaron LI            const u_char *cp)
15941c99275SPeter Avalos {
160*ed775ee7SAntonio Huete Jimenez 	const struct krb *kp;
16141c99275SPeter Avalos 	u_char type;
16241c99275SPeter Avalos 	u_short len;
16341c99275SPeter Avalos 
164411677aeSAaron LI #define PRINT		if ((cp = c_print(ndo, cp, ndo->ndo_snapend)) == NULL) goto trunc
16541c99275SPeter Avalos /*  True if struct krb is little endian */
166*ed775ee7SAntonio Huete Jimenez #define IS_LENDIAN(kp)	((GET_U_1((kp)->type) & 0x01) != 0)
167*ed775ee7SAntonio Huete Jimenez #define KTOHSP(kp, cp)	(IS_LENDIAN(kp) ? GET_LE_U_2(cp) : GET_BE_U_2(cp))
16841c99275SPeter Avalos 
169411677aeSAaron LI 	kp = (const struct krb *)cp;
17041c99275SPeter Avalos 
171*ed775ee7SAntonio Huete Jimenez 	type = GET_U_1(kp->type) & (0xFF << 1);
17241c99275SPeter Avalos 
173*ed775ee7SAntonio Huete Jimenez 	ND_PRINT(" %s %s: ",
174*ed775ee7SAntonio Huete Jimenez 	    IS_LENDIAN(kp) ? "le" : "be", tok2str(type2str, NULL, type));
17541c99275SPeter Avalos 
17641c99275SPeter Avalos 	switch (type) {
17741c99275SPeter Avalos 
17841c99275SPeter Avalos 	case AUTH_MSG_KDC_REQUEST:
179411677aeSAaron LI 		if ((cp = krb4_print_hdr(ndo, cp)) == NULL)
18041c99275SPeter Avalos 			return;
18141c99275SPeter Avalos 		cp += 4;	/* ctime */
182*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" %umin ", GET_U_1(cp) * 5);
183*ed775ee7SAntonio Huete Jimenez 		cp++;
18441c99275SPeter Avalos 		PRINT;
185*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(".");
18641c99275SPeter Avalos 		PRINT;
18741c99275SPeter Avalos 		break;
18841c99275SPeter Avalos 
18941c99275SPeter Avalos 	case AUTH_MSG_APPL_REQUEST:
19041c99275SPeter Avalos 		cp += 2;
191*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("v%u ", GET_U_1(cp));
192*ed775ee7SAntonio Huete Jimenez 		cp++;
19341c99275SPeter Avalos 		PRINT;
194*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" (%u)", GET_U_1(cp));
195*ed775ee7SAntonio Huete Jimenez 		cp++;
196*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" (%u)", GET_U_1(cp));
19741c99275SPeter Avalos 		break;
19841c99275SPeter Avalos 
19941c99275SPeter Avalos 	case AUTH_MSG_KDC_REPLY:
200411677aeSAaron LI 		if ((cp = krb4_print_hdr(ndo, cp)) == NULL)
20141c99275SPeter Avalos 			return;
20241c99275SPeter Avalos 		cp += 10;	/* timestamp + n + exp + kvno */
20341c99275SPeter Avalos 		len = KTOHSP(kp, cp);
204*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" (%u)", len);
20541c99275SPeter Avalos 		break;
20641c99275SPeter Avalos 
20741c99275SPeter Avalos 	case AUTH_MSG_ERR_REPLY:
208411677aeSAaron LI 		if ((cp = krb4_print_hdr(ndo, cp)) == NULL)
20941c99275SPeter Avalos 			return;
21041c99275SPeter Avalos 		cp += 4; 	  /* timestamp */
211*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" %s ", tok2str(kerr2str, NULL, KTOHSP(kp, cp)));
21241c99275SPeter Avalos 		cp += 4;
21341c99275SPeter Avalos 		PRINT;
21441c99275SPeter Avalos 		break;
21541c99275SPeter Avalos 
21641c99275SPeter Avalos 	default:
217*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("(unknown)");
21841c99275SPeter Avalos 		break;
21941c99275SPeter Avalos 	}
22041c99275SPeter Avalos 
22141c99275SPeter Avalos 	return;
22241c99275SPeter Avalos trunc:
223*ed775ee7SAntonio Huete Jimenez 	nd_print_trunc(ndo);
22441c99275SPeter Avalos }
22541c99275SPeter Avalos 
22641c99275SPeter Avalos void
krb_print(netdissect_options * ndo,const u_char * dat)227411677aeSAaron LI krb_print(netdissect_options *ndo,
228411677aeSAaron LI           const u_char *dat)
22941c99275SPeter Avalos {
230*ed775ee7SAntonio Huete Jimenez 	const struct krb *kp;
23141c99275SPeter Avalos 
232*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "krb";
233411677aeSAaron LI 	kp = (const struct krb *)dat;
23441c99275SPeter Avalos 
235411677aeSAaron LI 	if (dat >= ndo->ndo_snapend) {
236*ed775ee7SAntonio Huete Jimenez 		nd_print_trunc(ndo);
23741c99275SPeter Avalos 		return;
23841c99275SPeter Avalos 	}
23941c99275SPeter Avalos 
240*ed775ee7SAntonio Huete Jimenez 	switch (GET_U_1(kp->pvno)) {
24141c99275SPeter Avalos 
24241c99275SPeter Avalos 	case 1:
24341c99275SPeter Avalos 	case 2:
24441c99275SPeter Avalos 	case 3:
245*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" v%u", GET_U_1(kp->pvno));
24641c99275SPeter Avalos 		break;
24741c99275SPeter Avalos 
24841c99275SPeter Avalos 	case 4:
249*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" v%u", GET_U_1(kp->pvno));
250411677aeSAaron LI 		krb4_print(ndo, (const u_char *)kp);
25141c99275SPeter Avalos 		break;
25241c99275SPeter Avalos 
25341c99275SPeter Avalos 	case 106:
25441c99275SPeter Avalos 	case 107:
255*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" v5");
25641c99275SPeter Avalos 		/* Decode ASN.1 here "someday" */
25741c99275SPeter Avalos 		break;
25841c99275SPeter Avalos 	}
25941c99275SPeter Avalos }
260