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