Home | History | Annotate | Line # | Download | only in dist
print-krb.c revision 1.1.1.4
      1      1.1  christos /*
      2      1.1  christos  * Copyright (c) 1995, 1996, 1997
      3      1.1  christos  *	The Regents of the University of California.  All rights reserved.
      4      1.1  christos  *
      5      1.1  christos  * Redistribution and use in source and binary forms, with or without
      6      1.1  christos  * modification, are permitted provided that: (1) source code distributions
      7      1.1  christos  * retain the above copyright notice and this paragraph in its entirety, (2)
      8      1.1  christos  * distributions including binary code include the above copyright notice and
      9      1.1  christos  * this paragraph in its entirety in the documentation or other materials
     10      1.1  christos  * provided with the distribution, and (3) all advertising materials mentioning
     11      1.1  christos  * features or use of this software display the following acknowledgement:
     12      1.1  christos  * ``This product includes software developed by the University of California,
     13      1.1  christos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
     14      1.1  christos  * the University nor the names of its contributors may be used to endorse
     15      1.1  christos  * or promote products derived from this software without specific prior
     16      1.1  christos  * written permission.
     17      1.1  christos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
     18      1.1  christos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
     19      1.1  christos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     20      1.1  christos  *
     21      1.1  christos  * Initial contribution from John Hawkinson (jhawk (at) mit.edu).
     22      1.1  christos  */
     23      1.1  christos 
     24  1.1.1.4  christos #define NETDISSECT_REWORKED
     25      1.1  christos #ifdef HAVE_CONFIG_H
     26      1.1  christos #include "config.h"
     27      1.1  christos #endif
     28      1.1  christos 
     29      1.1  christos #include <tcpdump-stdinc.h>
     30      1.1  christos 
     31      1.1  christos #include "interface.h"
     32      1.1  christos #include "extract.h"
     33      1.1  christos 
     34  1.1.1.4  christos static const char tstr[] = " [|kerberos]";
     35  1.1.1.4  christos 
     36  1.1.1.4  christos static const u_char *c_print(netdissect_options *, register const u_char *, register const u_char *);
     37  1.1.1.4  christos static const u_char *krb4_print_hdr(netdissect_options *, const u_char *);
     38  1.1.1.4  christos static void krb4_print(netdissect_options *, const u_char *);
     39      1.1  christos 
     40      1.1  christos #define AUTH_MSG_KDC_REQUEST			1<<1
     41      1.1  christos #define AUTH_MSG_KDC_REPLY			2<<1
     42      1.1  christos #define AUTH_MSG_APPL_REQUEST			3<<1
     43      1.1  christos #define AUTH_MSG_APPL_REQUEST_MUTUAL		4<<1
     44      1.1  christos #define AUTH_MSG_ERR_REPLY			5<<1
     45      1.1  christos #define AUTH_MSG_PRIVATE			6<<1
     46      1.1  christos #define AUTH_MSG_SAFE				7<<1
     47      1.1  christos #define AUTH_MSG_APPL_ERR			8<<1
     48      1.1  christos #define AUTH_MSG_DIE				63<<1
     49      1.1  christos 
     50      1.1  christos #define KERB_ERR_OK				0
     51      1.1  christos #define KERB_ERR_NAME_EXP			1
     52      1.1  christos #define KERB_ERR_SERVICE_EXP			2
     53      1.1  christos #define KERB_ERR_AUTH_EXP			3
     54      1.1  christos #define KERB_ERR_PKT_VER			4
     55      1.1  christos #define KERB_ERR_NAME_MAST_KEY_VER		5
     56      1.1  christos #define KERB_ERR_SERV_MAST_KEY_VER		6
     57      1.1  christos #define KERB_ERR_BYTE_ORDER			7
     58      1.1  christos #define KERB_ERR_PRINCIPAL_UNKNOWN		8
     59      1.1  christos #define KERB_ERR_PRINCIPAL_NOT_UNIQUE		9
     60      1.1  christos #define KERB_ERR_NULL_KEY			10
     61      1.1  christos 
     62      1.1  christos struct krb {
     63  1.1.1.4  christos 	uint8_t pvno;		/* Protocol Version */
     64  1.1.1.4  christos 	uint8_t type;		/* Type+B */
     65      1.1  christos };
     66      1.1  christos 
     67  1.1.1.3  christos static const struct tok type2str[] = {
     68      1.1  christos 	{ AUTH_MSG_KDC_REQUEST,		"KDC_REQUEST" },
     69      1.1  christos 	{ AUTH_MSG_KDC_REPLY,		"KDC_REPLY" },
     70      1.1  christos 	{ AUTH_MSG_APPL_REQUEST,	"APPL_REQUEST" },
     71      1.1  christos 	{ AUTH_MSG_APPL_REQUEST_MUTUAL,	"APPL_REQUEST_MUTUAL" },
     72      1.1  christos 	{ AUTH_MSG_ERR_REPLY,		"ERR_REPLY" },
     73      1.1  christos 	{ AUTH_MSG_PRIVATE,		"PRIVATE" },
     74      1.1  christos 	{ AUTH_MSG_SAFE,		"SAFE" },
     75      1.1  christos 	{ AUTH_MSG_APPL_ERR,		"APPL_ERR" },
     76      1.1  christos 	{ AUTH_MSG_DIE,			"DIE" },
     77      1.1  christos 	{ 0,				NULL }
     78      1.1  christos };
     79      1.1  christos 
     80  1.1.1.3  christos static const struct tok kerr2str[] = {
     81      1.1  christos 	{ KERB_ERR_OK,			"OK" },
     82      1.1  christos 	{ KERB_ERR_NAME_EXP,		"NAME_EXP" },
     83      1.1  christos 	{ KERB_ERR_SERVICE_EXP,		"SERVICE_EXP" },
     84      1.1  christos 	{ KERB_ERR_AUTH_EXP,		"AUTH_EXP" },
     85      1.1  christos 	{ KERB_ERR_PKT_VER,		"PKT_VER" },
     86      1.1  christos 	{ KERB_ERR_NAME_MAST_KEY_VER,	"NAME_MAST_KEY_VER" },
     87      1.1  christos 	{ KERB_ERR_SERV_MAST_KEY_VER,	"SERV_MAST_KEY_VER" },
     88      1.1  christos 	{ KERB_ERR_BYTE_ORDER,		"BYTE_ORDER" },
     89      1.1  christos 	{ KERB_ERR_PRINCIPAL_UNKNOWN,	"PRINCIPAL_UNKNOWN" },
     90      1.1  christos 	{ KERB_ERR_PRINCIPAL_NOT_UNIQUE,"PRINCIPAL_NOT_UNIQUE" },
     91      1.1  christos 	{ KERB_ERR_NULL_KEY,		"NULL_KEY"},
     92      1.1  christos 	{ 0,				NULL}
     93      1.1  christos };
     94      1.1  christos 
     95      1.1  christos static const u_char *
     96  1.1.1.4  christos c_print(netdissect_options *ndo,
     97  1.1.1.4  christos         register const u_char *s, register const u_char *ep)
     98      1.1  christos {
     99      1.1  christos 	register u_char c;
    100      1.1  christos 	register int flag;
    101      1.1  christos 
    102      1.1  christos 	flag = 1;
    103      1.1  christos 	while (s < ep) {
    104      1.1  christos 		c = *s++;
    105      1.1  christos 		if (c == '\0') {
    106      1.1  christos 			flag = 0;
    107      1.1  christos 			break;
    108      1.1  christos 		}
    109  1.1.1.4  christos 		if (!ND_ISASCII(c)) {
    110  1.1.1.4  christos 			c = ND_TOASCII(c);
    111  1.1.1.4  christos 			ND_PRINT((ndo, "M-"));
    112      1.1  christos 		}
    113  1.1.1.4  christos 		if (!ND_ISPRINT(c)) {
    114      1.1  christos 			c ^= 0x40;	/* DEL to ?, others to alpha */
    115  1.1.1.4  christos 			ND_PRINT((ndo, "^"));
    116      1.1  christos 		}
    117  1.1.1.4  christos 		ND_PRINT((ndo, "%c", c));
    118      1.1  christos 	}
    119      1.1  christos 	if (flag)
    120      1.1  christos 		return NULL;
    121      1.1  christos 	return (s);
    122      1.1  christos }
    123      1.1  christos 
    124      1.1  christos static const u_char *
    125  1.1.1.4  christos krb4_print_hdr(netdissect_options *ndo,
    126  1.1.1.4  christos                const u_char *cp)
    127      1.1  christos {
    128      1.1  christos 	cp += 2;
    129      1.1  christos 
    130  1.1.1.4  christos #define PRINT		if ((cp = c_print(ndo, cp, ndo->ndo_snapend)) == NULL) goto trunc
    131      1.1  christos 
    132      1.1  christos 	PRINT;
    133  1.1.1.4  christos 	ND_PRINT((ndo, "."));
    134      1.1  christos 	PRINT;
    135  1.1.1.4  christos 	ND_PRINT((ndo, "@"));
    136      1.1  christos 	PRINT;
    137      1.1  christos 	return (cp);
    138      1.1  christos 
    139      1.1  christos trunc:
    140  1.1.1.4  christos 	ND_PRINT((ndo, "%s", tstr));
    141      1.1  christos 	return (NULL);
    142      1.1  christos 
    143      1.1  christos #undef PRINT
    144      1.1  christos }
    145      1.1  christos 
    146      1.1  christos static void
    147  1.1.1.4  christos krb4_print(netdissect_options *ndo,
    148  1.1.1.4  christos            const u_char *cp)
    149      1.1  christos {
    150      1.1  christos 	register const struct krb *kp;
    151      1.1  christos 	u_char type;
    152      1.1  christos 	u_short len;
    153      1.1  christos 
    154  1.1.1.4  christos #define PRINT		if ((cp = c_print(ndo, cp, ndo->ndo_snapend)) == NULL) goto trunc
    155      1.1  christos /*  True if struct krb is little endian */
    156      1.1  christos #define IS_LENDIAN(kp)	(((kp)->type & 0x01) != 0)
    157      1.1  christos #define KTOHSP(kp, cp)	(IS_LENDIAN(kp) ? EXTRACT_LE_16BITS(cp) : EXTRACT_16BITS(cp))
    158      1.1  christos 
    159      1.1  christos 	kp = (struct krb *)cp;
    160      1.1  christos 
    161  1.1.1.4  christos 	if ((&kp->type) >= ndo->ndo_snapend) {
    162  1.1.1.4  christos 		ND_PRINT((ndo, "%s", tstr));
    163      1.1  christos 		return;
    164      1.1  christos 	}
    165      1.1  christos 
    166      1.1  christos 	type = kp->type & (0xFF << 1);
    167      1.1  christos 
    168  1.1.1.4  christos 	ND_PRINT((ndo, " %s %s: ",
    169  1.1.1.4  christos 	    IS_LENDIAN(kp) ? "le" : "be", tok2str(type2str, NULL, type)));
    170      1.1  christos 
    171      1.1  christos 	switch (type) {
    172      1.1  christos 
    173      1.1  christos 	case AUTH_MSG_KDC_REQUEST:
    174  1.1.1.4  christos 		if ((cp = krb4_print_hdr(ndo, cp)) == NULL)
    175      1.1  christos 			return;
    176      1.1  christos 		cp += 4;	/* ctime */
    177  1.1.1.4  christos 		ND_TCHECK(*cp);
    178  1.1.1.4  christos 		ND_PRINT((ndo, " %dmin ", *cp++ * 5));
    179      1.1  christos 		PRINT;
    180  1.1.1.4  christos 		ND_PRINT((ndo, "."));
    181      1.1  christos 		PRINT;
    182      1.1  christos 		break;
    183      1.1  christos 
    184      1.1  christos 	case AUTH_MSG_APPL_REQUEST:
    185      1.1  christos 		cp += 2;
    186  1.1.1.4  christos 		ND_TCHECK(*cp);
    187  1.1.1.4  christos 		ND_PRINT((ndo, "v%d ", *cp++));
    188      1.1  christos 		PRINT;
    189  1.1.1.4  christos 		ND_TCHECK(*cp);
    190  1.1.1.4  christos 		ND_PRINT((ndo, " (%d)", *cp++));
    191  1.1.1.4  christos 		ND_TCHECK(*cp);
    192  1.1.1.4  christos 		ND_PRINT((ndo, " (%d)", *cp));
    193      1.1  christos 		break;
    194      1.1  christos 
    195      1.1  christos 	case AUTH_MSG_KDC_REPLY:
    196  1.1.1.4  christos 		if ((cp = krb4_print_hdr(ndo, cp)) == NULL)
    197      1.1  christos 			return;
    198      1.1  christos 		cp += 10;	/* timestamp + n + exp + kvno */
    199  1.1.1.4  christos 		ND_TCHECK2(*cp, sizeof(short));
    200      1.1  christos 		len = KTOHSP(kp, cp);
    201  1.1.1.4  christos 		ND_PRINT((ndo, " (%d)", len));
    202      1.1  christos 		break;
    203      1.1  christos 
    204      1.1  christos 	case AUTH_MSG_ERR_REPLY:
    205  1.1.1.4  christos 		if ((cp = krb4_print_hdr(ndo, cp)) == NULL)
    206      1.1  christos 			return;
    207      1.1  christos 		cp += 4; 	  /* timestamp */
    208  1.1.1.4  christos 		ND_TCHECK2(*cp, sizeof(short));
    209  1.1.1.4  christos 		ND_PRINT((ndo, " %s ", tok2str(kerr2str, NULL, KTOHSP(kp, cp))));
    210      1.1  christos 		cp += 4;
    211      1.1  christos 		PRINT;
    212      1.1  christos 		break;
    213      1.1  christos 
    214      1.1  christos 	default:
    215  1.1.1.4  christos 		ND_PRINT((ndo, "(unknown)"));
    216      1.1  christos 		break;
    217      1.1  christos 	}
    218      1.1  christos 
    219      1.1  christos 	return;
    220      1.1  christos trunc:
    221  1.1.1.4  christos 	ND_PRINT((ndo, "%s", tstr));
    222      1.1  christos }
    223      1.1  christos 
    224      1.1  christos void
    225  1.1.1.4  christos krb_print(netdissect_options *ndo,
    226  1.1.1.4  christos           const u_char *dat)
    227      1.1  christos {
    228      1.1  christos 	register const struct krb *kp;
    229      1.1  christos 
    230      1.1  christos 	kp = (struct krb *)dat;
    231      1.1  christos 
    232  1.1.1.4  christos 	if (dat >= ndo->ndo_snapend) {
    233  1.1.1.4  christos 		ND_PRINT((ndo, "%s", tstr));
    234      1.1  christos 		return;
    235      1.1  christos 	}
    236      1.1  christos 
    237      1.1  christos 	switch (kp->pvno) {
    238      1.1  christos 
    239      1.1  christos 	case 1:
    240      1.1  christos 	case 2:
    241      1.1  christos 	case 3:
    242  1.1.1.4  christos 		ND_PRINT((ndo, " v%d", kp->pvno));
    243      1.1  christos 		break;
    244      1.1  christos 
    245      1.1  christos 	case 4:
    246  1.1.1.4  christos 		ND_PRINT((ndo, " v%d", kp->pvno));
    247  1.1.1.4  christos 		krb4_print(ndo, (const u_char *)kp);
    248      1.1  christos 		break;
    249      1.1  christos 
    250      1.1  christos 	case 106:
    251      1.1  christos 	case 107:
    252  1.1.1.4  christos 		ND_PRINT((ndo, " v5"));
    253      1.1  christos 		/* Decode ASN.1 here "someday" */
    254      1.1  christos 		break;
    255      1.1  christos 	}
    256      1.1  christos 	return;
    257      1.1  christos }
    258