| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (c) 1995, 1996, 1997 | 
 | 3 |  *	The Regents of the University of California.  All rights reserved. | 
 | 4 |  * | 
 | 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 | 
 | 16 |  * written permission. | 
 | 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. | 
 | 20 |  * | 
 | 21 |  * Initial contribution from John Hawkinson (jhawk@mit.edu). | 
 | 22 |  */ | 
 | 23 |  | 
| Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 24 | /* \summary: Kerberos printer */ | 
 | 25 |  | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 26 | #ifdef HAVE_CONFIG_H | 
 | 27 | #include "config.h" | 
 | 28 | #endif | 
 | 29 |  | 
| Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 30 | #include <netdissect-stdinc.h> | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 31 |  | 
| Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 32 | #include "netdissect.h" | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 33 | #include "extract.h" | 
 | 34 |  | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 35 | static const char tstr[] = " [|kerberos]"; | 
 | 36 |  | 
 | 37 | static const u_char *c_print(netdissect_options *, register const u_char *, register const u_char *); | 
 | 38 | static const u_char *krb4_print_hdr(netdissect_options *, const u_char *); | 
 | 39 | static void krb4_print(netdissect_options *, const u_char *); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 40 |  | 
 | 41 | #define AUTH_MSG_KDC_REQUEST			1<<1 | 
 | 42 | #define AUTH_MSG_KDC_REPLY			2<<1 | 
 | 43 | #define AUTH_MSG_APPL_REQUEST			3<<1 | 
 | 44 | #define AUTH_MSG_APPL_REQUEST_MUTUAL		4<<1 | 
 | 45 | #define AUTH_MSG_ERR_REPLY			5<<1 | 
 | 46 | #define AUTH_MSG_PRIVATE			6<<1 | 
 | 47 | #define AUTH_MSG_SAFE				7<<1 | 
 | 48 | #define AUTH_MSG_APPL_ERR			8<<1 | 
 | 49 | #define AUTH_MSG_DIE				63<<1 | 
 | 50 |  | 
 | 51 | #define KERB_ERR_OK				0 | 
 | 52 | #define KERB_ERR_NAME_EXP			1 | 
 | 53 | #define KERB_ERR_SERVICE_EXP			2 | 
 | 54 | #define KERB_ERR_AUTH_EXP			3 | 
 | 55 | #define KERB_ERR_PKT_VER			4 | 
 | 56 | #define KERB_ERR_NAME_MAST_KEY_VER		5 | 
 | 57 | #define KERB_ERR_SERV_MAST_KEY_VER		6 | 
 | 58 | #define KERB_ERR_BYTE_ORDER			7 | 
 | 59 | #define KERB_ERR_PRINCIPAL_UNKNOWN		8 | 
 | 60 | #define KERB_ERR_PRINCIPAL_NOT_UNIQUE		9 | 
 | 61 | #define KERB_ERR_NULL_KEY			10 | 
 | 62 |  | 
 | 63 | struct krb { | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 64 | 	uint8_t pvno;		/* Protocol Version */ | 
 | 65 | 	uint8_t type;		/* Type+B */ | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 66 | }; | 
 | 67 |  | 
| JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 68 | static const struct tok type2str[] = { | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 69 | 	{ AUTH_MSG_KDC_REQUEST,		"KDC_REQUEST" }, | 
 | 70 | 	{ AUTH_MSG_KDC_REPLY,		"KDC_REPLY" }, | 
 | 71 | 	{ AUTH_MSG_APPL_REQUEST,	"APPL_REQUEST" }, | 
 | 72 | 	{ AUTH_MSG_APPL_REQUEST_MUTUAL,	"APPL_REQUEST_MUTUAL" }, | 
 | 73 | 	{ AUTH_MSG_ERR_REPLY,		"ERR_REPLY" }, | 
 | 74 | 	{ AUTH_MSG_PRIVATE,		"PRIVATE" }, | 
 | 75 | 	{ AUTH_MSG_SAFE,		"SAFE" }, | 
 | 76 | 	{ AUTH_MSG_APPL_ERR,		"APPL_ERR" }, | 
 | 77 | 	{ AUTH_MSG_DIE,			"DIE" }, | 
 | 78 | 	{ 0,				NULL } | 
 | 79 | }; | 
 | 80 |  | 
| JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 81 | static const struct tok kerr2str[] = { | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 82 | 	{ KERB_ERR_OK,			"OK" }, | 
 | 83 | 	{ KERB_ERR_NAME_EXP,		"NAME_EXP" }, | 
 | 84 | 	{ KERB_ERR_SERVICE_EXP,		"SERVICE_EXP" }, | 
 | 85 | 	{ KERB_ERR_AUTH_EXP,		"AUTH_EXP" }, | 
 | 86 | 	{ KERB_ERR_PKT_VER,		"PKT_VER" }, | 
 | 87 | 	{ KERB_ERR_NAME_MAST_KEY_VER,	"NAME_MAST_KEY_VER" }, | 
 | 88 | 	{ KERB_ERR_SERV_MAST_KEY_VER,	"SERV_MAST_KEY_VER" }, | 
 | 89 | 	{ KERB_ERR_BYTE_ORDER,		"BYTE_ORDER" }, | 
 | 90 | 	{ KERB_ERR_PRINCIPAL_UNKNOWN,	"PRINCIPAL_UNKNOWN" }, | 
 | 91 | 	{ KERB_ERR_PRINCIPAL_NOT_UNIQUE,"PRINCIPAL_NOT_UNIQUE" }, | 
 | 92 | 	{ KERB_ERR_NULL_KEY,		"NULL_KEY"}, | 
 | 93 | 	{ 0,				NULL} | 
 | 94 | }; | 
 | 95 |  | 
 | 96 | static const u_char * | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 97 | c_print(netdissect_options *ndo, | 
 | 98 |         register const u_char *s, register const u_char *ep) | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 99 | { | 
 | 100 | 	register u_char c; | 
 | 101 | 	register int flag; | 
 | 102 |  | 
 | 103 | 	flag = 1; | 
 | 104 | 	while (s < ep) { | 
 | 105 | 		c = *s++; | 
 | 106 | 		if (c == '\0') { | 
 | 107 | 			flag = 0; | 
 | 108 | 			break; | 
 | 109 | 		} | 
| JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 110 | 		if (!ND_ISASCII(c)) { | 
 | 111 | 			c = ND_TOASCII(c); | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 112 | 			ND_PRINT((ndo, "M-")); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 113 | 		} | 
| JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 114 | 		if (!ND_ISPRINT(c)) { | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 115 | 			c ^= 0x40;	/* DEL to ?, others to alpha */ | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 116 | 			ND_PRINT((ndo, "^")); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 117 | 		} | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 118 | 		ND_PRINT((ndo, "%c", c)); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 119 | 	} | 
 | 120 | 	if (flag) | 
 | 121 | 		return NULL; | 
 | 122 | 	return (s); | 
 | 123 | } | 
 | 124 |  | 
 | 125 | static const u_char * | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 126 | krb4_print_hdr(netdissect_options *ndo, | 
 | 127 |                const u_char *cp) | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 128 | { | 
 | 129 | 	cp += 2; | 
 | 130 |  | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 131 | #define PRINT		if ((cp = c_print(ndo, cp, ndo->ndo_snapend)) == NULL) goto trunc | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 132 |  | 
 | 133 | 	PRINT; | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 134 | 	ND_PRINT((ndo, ".")); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 135 | 	PRINT; | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 136 | 	ND_PRINT((ndo, "@")); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 137 | 	PRINT; | 
 | 138 | 	return (cp); | 
 | 139 |  | 
 | 140 | trunc: | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 141 | 	ND_PRINT((ndo, "%s", tstr)); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 142 | 	return (NULL); | 
 | 143 |  | 
 | 144 | #undef PRINT | 
 | 145 | } | 
 | 146 |  | 
 | 147 | static void | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 148 | krb4_print(netdissect_options *ndo, | 
 | 149 |            const u_char *cp) | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 150 | { | 
 | 151 | 	register const struct krb *kp; | 
 | 152 | 	u_char type; | 
 | 153 | 	u_short len; | 
 | 154 |  | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 155 | #define PRINT		if ((cp = c_print(ndo, cp, ndo->ndo_snapend)) == NULL) goto trunc | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 156 | /*  True if struct krb is little endian */ | 
 | 157 | #define IS_LENDIAN(kp)	(((kp)->type & 0x01) != 0) | 
 | 158 | #define KTOHSP(kp, cp)	(IS_LENDIAN(kp) ? EXTRACT_LE_16BITS(cp) : EXTRACT_16BITS(cp)) | 
 | 159 |  | 
| Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 160 | 	kp = (const struct krb *)cp; | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 161 |  | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 162 | 	if ((&kp->type) >= ndo->ndo_snapend) { | 
 | 163 | 		ND_PRINT((ndo, "%s", tstr)); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 164 | 		return; | 
 | 165 | 	} | 
 | 166 |  | 
 | 167 | 	type = kp->type & (0xFF << 1); | 
 | 168 |  | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 169 | 	ND_PRINT((ndo, " %s %s: ", | 
 | 170 | 	    IS_LENDIAN(kp) ? "le" : "be", tok2str(type2str, NULL, type))); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 171 |  | 
 | 172 | 	switch (type) { | 
 | 173 |  | 
 | 174 | 	case AUTH_MSG_KDC_REQUEST: | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 175 | 		if ((cp = krb4_print_hdr(ndo, cp)) == NULL) | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 176 | 			return; | 
 | 177 | 		cp += 4;	/* ctime */ | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 178 | 		ND_TCHECK(*cp); | 
 | 179 | 		ND_PRINT((ndo, " %dmin ", *cp++ * 5)); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 180 | 		PRINT; | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 181 | 		ND_PRINT((ndo, ".")); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 182 | 		PRINT; | 
 | 183 | 		break; | 
 | 184 |  | 
 | 185 | 	case AUTH_MSG_APPL_REQUEST: | 
 | 186 | 		cp += 2; | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 187 | 		ND_TCHECK(*cp); | 
 | 188 | 		ND_PRINT((ndo, "v%d ", *cp++)); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 189 | 		PRINT; | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 190 | 		ND_TCHECK(*cp); | 
 | 191 | 		ND_PRINT((ndo, " (%d)", *cp++)); | 
 | 192 | 		ND_TCHECK(*cp); | 
 | 193 | 		ND_PRINT((ndo, " (%d)", *cp)); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 194 | 		break; | 
 | 195 |  | 
 | 196 | 	case AUTH_MSG_KDC_REPLY: | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 197 | 		if ((cp = krb4_print_hdr(ndo, cp)) == NULL) | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 198 | 			return; | 
 | 199 | 		cp += 10;	/* timestamp + n + exp + kvno */ | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 200 | 		ND_TCHECK2(*cp, sizeof(short)); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 201 | 		len = KTOHSP(kp, cp); | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 202 | 		ND_PRINT((ndo, " (%d)", len)); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 203 | 		break; | 
 | 204 |  | 
 | 205 | 	case AUTH_MSG_ERR_REPLY: | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 206 | 		if ((cp = krb4_print_hdr(ndo, cp)) == NULL) | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 207 | 			return; | 
 | 208 | 		cp += 4; 	  /* timestamp */ | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 209 | 		ND_TCHECK2(*cp, sizeof(short)); | 
 | 210 | 		ND_PRINT((ndo, " %s ", tok2str(kerr2str, NULL, KTOHSP(kp, cp)))); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 211 | 		cp += 4; | 
 | 212 | 		PRINT; | 
 | 213 | 		break; | 
 | 214 |  | 
 | 215 | 	default: | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 216 | 		ND_PRINT((ndo, "(unknown)")); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 217 | 		break; | 
 | 218 | 	} | 
 | 219 |  | 
 | 220 | 	return; | 
 | 221 | trunc: | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 222 | 	ND_PRINT((ndo, "%s", tstr)); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 223 | } | 
 | 224 |  | 
 | 225 | void | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 226 | krb_print(netdissect_options *ndo, | 
 | 227 |           const u_char *dat) | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 228 | { | 
 | 229 | 	register const struct krb *kp; | 
 | 230 |  | 
| Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 231 | 	kp = (const struct krb *)dat; | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 232 |  | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 233 | 	if (dat >= ndo->ndo_snapend) { | 
 | 234 | 		ND_PRINT((ndo, "%s", tstr)); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 235 | 		return; | 
 | 236 | 	} | 
 | 237 |  | 
 | 238 | 	switch (kp->pvno) { | 
 | 239 |  | 
 | 240 | 	case 1: | 
 | 241 | 	case 2: | 
 | 242 | 	case 3: | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 243 | 		ND_PRINT((ndo, " v%d", kp->pvno)); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 244 | 		break; | 
 | 245 |  | 
 | 246 | 	case 4: | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 247 | 		ND_PRINT((ndo, " v%d", kp->pvno)); | 
 | 248 | 		krb4_print(ndo, (const u_char *)kp); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 249 | 		break; | 
 | 250 |  | 
 | 251 | 	case 106: | 
 | 252 | 	case 107: | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 253 | 		ND_PRINT((ndo, " v5")); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 254 | 		/* Decode ASN.1 here "someday" */ | 
 | 255 | 		break; | 
 | 256 | 	} | 
 | 257 | 	return; | 
 | 258 | } |