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