Home | History | Annotate | Line # | Download | only in dist
print-krb.c revision 1.8
      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.2  christos #include <sys/cdefs.h>
     25  1.1  christos #ifndef lint
     26  1.8  christos __RCSID("$NetBSD: print-krb.c,v 1.8 2023/08/17 20:19:40 christos Exp $");
     27  1.1  christos #endif
     28  1.1  christos 
     29  1.7       spz /* \summary: Kerberos printer */
     30  1.7       spz 
     31  1.1  christos #ifdef HAVE_CONFIG_H
     32  1.8  christos #include <config.h>
     33  1.1  christos #endif
     34  1.1  christos 
     35  1.8  christos #include "netdissect-stdinc.h"
     36  1.1  christos 
     37  1.6  christos #include "netdissect.h"
     38  1.1  christos #include "extract.h"
     39  1.1  christos 
     40  1.8  christos /*
     41  1.8  christos  * Kerberos 4:
     42  1.8  christos  *
     43  1.8  christos  * Athena Technical Plan
     44  1.8  christos  * Section E.2.1
     45  1.8  christos  * Kerberos Authentication and Authorization System
     46  1.8  christos  * by S. P. Miller, B. C. Neuman, J. I. Schiller, and J. H. Saltzer
     47  1.8  christos  *
     48  1.8  christos  * https://web.mit.edu/Saltzer/www/publications/athenaplan/e.2.1.pdf
     49  1.8  christos  *
     50  1.8  christos  * 7. Appendix I Design Specifications
     51  1.8  christos  *
     52  1.8  christos  * Kerberos 5:
     53  1.8  christos  *
     54  1.8  christos  * RFC 1510, RFC 2630, etc.
     55  1.8  christos  */
     56  1.5  christos 
     57  1.8  christos 
     58  1.8  christos static const u_char *c_print(netdissect_options *, const u_char *, const u_char *);
     59  1.5  christos static const u_char *krb4_print_hdr(netdissect_options *, const u_char *);
     60  1.5  christos static void krb4_print(netdissect_options *, const u_char *);
     61  1.1  christos 
     62  1.1  christos #define AUTH_MSG_KDC_REQUEST			1<<1
     63  1.1  christos #define AUTH_MSG_KDC_REPLY			2<<1
     64  1.1  christos #define AUTH_MSG_APPL_REQUEST			3<<1
     65  1.1  christos #define AUTH_MSG_APPL_REQUEST_MUTUAL		4<<1
     66  1.1  christos #define AUTH_MSG_ERR_REPLY			5<<1
     67  1.1  christos #define AUTH_MSG_PRIVATE			6<<1
     68  1.1  christos #define AUTH_MSG_SAFE				7<<1
     69  1.1  christos #define AUTH_MSG_APPL_ERR			8<<1
     70  1.1  christos #define AUTH_MSG_DIE				63<<1
     71  1.1  christos 
     72  1.1  christos #define KERB_ERR_OK				0
     73  1.1  christos #define KERB_ERR_NAME_EXP			1
     74  1.1  christos #define KERB_ERR_SERVICE_EXP			2
     75  1.1  christos #define KERB_ERR_AUTH_EXP			3
     76  1.1  christos #define KERB_ERR_PKT_VER			4
     77  1.1  christos #define KERB_ERR_NAME_MAST_KEY_VER		5
     78  1.1  christos #define KERB_ERR_SERV_MAST_KEY_VER		6
     79  1.1  christos #define KERB_ERR_BYTE_ORDER			7
     80  1.1  christos #define KERB_ERR_PRINCIPAL_UNKNOWN		8
     81  1.1  christos #define KERB_ERR_PRINCIPAL_NOT_UNIQUE		9
     82  1.1  christos #define KERB_ERR_NULL_KEY			10
     83  1.1  christos 
     84  1.1  christos struct krb {
     85  1.8  christos 	nd_uint8_t pvno;	/* Protocol Version */
     86  1.8  christos 	nd_uint8_t type;	/* Type+B */
     87  1.1  christos };
     88  1.1  christos 
     89  1.4  christos static const struct tok type2str[] = {
     90  1.1  christos 	{ AUTH_MSG_KDC_REQUEST,		"KDC_REQUEST" },
     91  1.1  christos 	{ AUTH_MSG_KDC_REPLY,		"KDC_REPLY" },
     92  1.1  christos 	{ AUTH_MSG_APPL_REQUEST,	"APPL_REQUEST" },
     93  1.1  christos 	{ AUTH_MSG_APPL_REQUEST_MUTUAL,	"APPL_REQUEST_MUTUAL" },
     94  1.1  christos 	{ AUTH_MSG_ERR_REPLY,		"ERR_REPLY" },
     95  1.1  christos 	{ AUTH_MSG_PRIVATE,		"PRIVATE" },
     96  1.1  christos 	{ AUTH_MSG_SAFE,		"SAFE" },
     97  1.1  christos 	{ AUTH_MSG_APPL_ERR,		"APPL_ERR" },
     98  1.1  christos 	{ AUTH_MSG_DIE,			"DIE" },
     99  1.1  christos 	{ 0,				NULL }
    100  1.1  christos };
    101  1.1  christos 
    102  1.4  christos static const struct tok kerr2str[] = {
    103  1.1  christos 	{ KERB_ERR_OK,			"OK" },
    104  1.1  christos 	{ KERB_ERR_NAME_EXP,		"NAME_EXP" },
    105  1.1  christos 	{ KERB_ERR_SERVICE_EXP,		"SERVICE_EXP" },
    106  1.1  christos 	{ KERB_ERR_AUTH_EXP,		"AUTH_EXP" },
    107  1.1  christos 	{ KERB_ERR_PKT_VER,		"PKT_VER" },
    108  1.1  christos 	{ KERB_ERR_NAME_MAST_KEY_VER,	"NAME_MAST_KEY_VER" },
    109  1.1  christos 	{ KERB_ERR_SERV_MAST_KEY_VER,	"SERV_MAST_KEY_VER" },
    110  1.1  christos 	{ KERB_ERR_BYTE_ORDER,		"BYTE_ORDER" },
    111  1.1  christos 	{ KERB_ERR_PRINCIPAL_UNKNOWN,	"PRINCIPAL_UNKNOWN" },
    112  1.1  christos 	{ KERB_ERR_PRINCIPAL_NOT_UNIQUE,"PRINCIPAL_NOT_UNIQUE" },
    113  1.1  christos 	{ KERB_ERR_NULL_KEY,		"NULL_KEY"},
    114  1.1  christos 	{ 0,				NULL}
    115  1.1  christos };
    116  1.1  christos 
    117  1.1  christos static const u_char *
    118  1.5  christos c_print(netdissect_options *ndo,
    119  1.8  christos         const u_char *s, const u_char *ep)
    120  1.1  christos {
    121  1.8  christos 	u_char c;
    122  1.8  christos 	int flag;
    123  1.1  christos 
    124  1.1  christos 	flag = 1;
    125  1.1  christos 	while (s < ep) {
    126  1.8  christos 		c = GET_U_1(s);
    127  1.8  christos 		s++;
    128  1.1  christos 		if (c == '\0') {
    129  1.1  christos 			flag = 0;
    130  1.1  christos 			break;
    131  1.1  christos 		}
    132  1.8  christos 		fn_print_char(ndo, c);
    133  1.1  christos 	}
    134  1.1  christos 	if (flag)
    135  1.1  christos 		return NULL;
    136  1.1  christos 	return (s);
    137  1.1  christos }
    138  1.1  christos 
    139  1.1  christos static const u_char *
    140  1.5  christos krb4_print_hdr(netdissect_options *ndo,
    141  1.5  christos                const u_char *cp)
    142  1.1  christos {
    143  1.1  christos 	cp += 2;
    144  1.1  christos 
    145  1.5  christos #define PRINT		if ((cp = c_print(ndo, cp, ndo->ndo_snapend)) == NULL) goto trunc
    146  1.1  christos 
    147  1.1  christos 	PRINT;
    148  1.8  christos 	ND_PRINT(".");
    149  1.1  christos 	PRINT;
    150  1.8  christos 	ND_PRINT("@");
    151  1.1  christos 	PRINT;
    152  1.1  christos 	return (cp);
    153  1.1  christos 
    154  1.1  christos trunc:
    155  1.8  christos 	nd_print_trunc(ndo);
    156  1.1  christos 	return (NULL);
    157  1.1  christos 
    158  1.1  christos #undef PRINT
    159  1.1  christos }
    160  1.1  christos 
    161  1.1  christos static void
    162  1.5  christos krb4_print(netdissect_options *ndo,
    163  1.5  christos            const u_char *cp)
    164  1.1  christos {
    165  1.8  christos 	const struct krb *kp;
    166  1.1  christos 	u_char type;
    167  1.1  christos 	u_short len;
    168  1.1  christos 
    169  1.5  christos #define PRINT		if ((cp = c_print(ndo, cp, ndo->ndo_snapend)) == NULL) goto trunc
    170  1.1  christos /*  True if struct krb is little endian */
    171  1.8  christos #define IS_LENDIAN(kp)	((GET_U_1((kp)->type) & 0x01) != 0)
    172  1.8  christos #define KTOHSP(kp, cp)	(IS_LENDIAN(kp) ? GET_LE_U_2(cp) : GET_BE_U_2(cp))
    173  1.1  christos 
    174  1.6  christos 	kp = (const struct krb *)cp;
    175  1.1  christos 
    176  1.8  christos 	type = GET_U_1(kp->type) & (0xFF << 1);
    177  1.1  christos 
    178  1.8  christos 	ND_PRINT(" %s %s: ",
    179  1.8  christos 	    IS_LENDIAN(kp) ? "le" : "be", tok2str(type2str, NULL, type));
    180  1.1  christos 
    181  1.1  christos 	switch (type) {
    182  1.1  christos 
    183  1.1  christos 	case AUTH_MSG_KDC_REQUEST:
    184  1.5  christos 		if ((cp = krb4_print_hdr(ndo, cp)) == NULL)
    185  1.1  christos 			return;
    186  1.1  christos 		cp += 4;	/* ctime */
    187  1.8  christos 		ND_PRINT(" %umin ", GET_U_1(cp) * 5);
    188  1.8  christos 		cp++;
    189  1.1  christos 		PRINT;
    190  1.8  christos 		ND_PRINT(".");
    191  1.1  christos 		PRINT;
    192  1.1  christos 		break;
    193  1.1  christos 
    194  1.1  christos 	case AUTH_MSG_APPL_REQUEST:
    195  1.1  christos 		cp += 2;
    196  1.8  christos 		ND_PRINT("v%u ", GET_U_1(cp));
    197  1.8  christos 		cp++;
    198  1.1  christos 		PRINT;
    199  1.8  christos 		ND_PRINT(" (%u)", GET_U_1(cp));
    200  1.8  christos 		cp++;
    201  1.8  christos 		ND_PRINT(" (%u)", GET_U_1(cp));
    202  1.1  christos 		break;
    203  1.1  christos 
    204  1.1  christos 	case AUTH_MSG_KDC_REPLY:
    205  1.5  christos 		if ((cp = krb4_print_hdr(ndo, cp)) == NULL)
    206  1.1  christos 			return;
    207  1.1  christos 		cp += 10;	/* timestamp + n + exp + kvno */
    208  1.1  christos 		len = KTOHSP(kp, cp);
    209  1.8  christos 		ND_PRINT(" (%u)", len);
    210  1.1  christos 		break;
    211  1.1  christos 
    212  1.1  christos 	case AUTH_MSG_ERR_REPLY:
    213  1.5  christos 		if ((cp = krb4_print_hdr(ndo, cp)) == NULL)
    214  1.1  christos 			return;
    215  1.8  christos 		cp += 4;	  /* timestamp */
    216  1.8  christos 		ND_PRINT(" %s ", tok2str(kerr2str, NULL, KTOHSP(kp, cp)));
    217  1.1  christos 		cp += 4;
    218  1.1  christos 		PRINT;
    219  1.1  christos 		break;
    220  1.1  christos 
    221  1.1  christos 	default:
    222  1.8  christos 		ND_PRINT("(unknown)");
    223  1.1  christos 		break;
    224  1.1  christos 	}
    225  1.1  christos 
    226  1.1  christos 	return;
    227  1.1  christos trunc:
    228  1.8  christos 	nd_print_trunc(ndo);
    229  1.1  christos }
    230  1.1  christos 
    231  1.1  christos void
    232  1.5  christos krb_print(netdissect_options *ndo,
    233  1.5  christos           const u_char *dat)
    234  1.1  christos {
    235  1.8  christos 	const struct krb *kp;
    236  1.1  christos 
    237  1.8  christos 	ndo->ndo_protocol = "krb";
    238  1.6  christos 	kp = (const struct krb *)dat;
    239  1.1  christos 
    240  1.5  christos 	if (dat >= ndo->ndo_snapend) {
    241  1.8  christos 		nd_print_trunc(ndo);
    242  1.1  christos 		return;
    243  1.1  christos 	}
    244  1.1  christos 
    245  1.8  christos 	switch (GET_U_1(kp->pvno)) {
    246  1.1  christos 
    247  1.1  christos 	case 1:
    248  1.1  christos 	case 2:
    249  1.1  christos 	case 3:
    250  1.8  christos 		ND_PRINT(" v%u", GET_U_1(kp->pvno));
    251  1.1  christos 		break;
    252  1.1  christos 
    253  1.1  christos 	case 4:
    254  1.8  christos 		ND_PRINT(" v%u", GET_U_1(kp->pvno));
    255  1.5  christos 		krb4_print(ndo, (const u_char *)kp);
    256  1.1  christos 		break;
    257  1.1  christos 
    258  1.1  christos 	case 106:
    259  1.1  christos 	case 107:
    260  1.8  christos 		ND_PRINT(" v5");
    261  1.1  christos 		/* Decode ASN.1 here "someday" */
    262  1.1  christos 		break;
    263  1.1  christos 	}
    264  1.1  christos }
    265