print-eap.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*
  2. * Copyright (c) 2004 - Michael Richardson <mcr@xelerance.com>
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that: (1) source code distributions
  6. * retain the above copyright notice and this paragraph in its entirety, (2)
  7. * distributions including binary code include the above copyright notice and
  8. * this paragraph in its entirety in the documentation or other materials
  9. * provided with the distribution, and (3) all advertising materials mentioning
  10. * features or use of this software display the following acknowledgement:
  11. * ``This product includes software developed by the University of California,
  12. * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  13. * the University nor the names of its contributors may be used to endorse
  14. * or promote products derived from this software without specific prior
  15. * written permission.
  16. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19. */
  20. /* \summary: Extensible Authentication Protocol (EAP) printer */
  21. #ifdef HAVE_CONFIG_H
  22. #include "config.h"
  23. #endif
  24. #include <netdissect-stdinc.h>
  25. #include "netdissect.h"
  26. #include "extract.h"
  27. #define EAP_FRAME_TYPE_PACKET 0
  28. #define EAP_FRAME_TYPE_START 1
  29. #define EAP_FRAME_TYPE_LOGOFF 2
  30. #define EAP_FRAME_TYPE_KEY 3
  31. #define EAP_FRAME_TYPE_ENCAP_ASF_ALERT 4
  32. struct eap_frame_t {
  33. unsigned char version;
  34. unsigned char type;
  35. unsigned char length[2];
  36. };
  37. static const struct tok eap_frame_type_values[] = {
  38. { EAP_FRAME_TYPE_PACKET, "EAP packet" },
  39. { EAP_FRAME_TYPE_START, "EAPOL start" },
  40. { EAP_FRAME_TYPE_LOGOFF, "EAPOL logoff" },
  41. { EAP_FRAME_TYPE_KEY, "EAPOL key" },
  42. { EAP_FRAME_TYPE_ENCAP_ASF_ALERT, "Encapsulated ASF alert" },
  43. { 0, NULL}
  44. };
  45. /* RFC 3748 */
  46. struct eap_packet_t {
  47. unsigned char code;
  48. unsigned char id;
  49. unsigned char length[2];
  50. };
  51. #define EAP_REQUEST 1
  52. #define EAP_RESPONSE 2
  53. #define EAP_SUCCESS 3
  54. #define EAP_FAILURE 4
  55. static const struct tok eap_code_values[] = {
  56. { EAP_REQUEST, "Request" },
  57. { EAP_RESPONSE, "Response" },
  58. { EAP_SUCCESS, "Success" },
  59. { EAP_FAILURE, "Failure" },
  60. { 0, NULL}
  61. };
  62. #define EAP_TYPE_NO_PROPOSED 0
  63. #define EAP_TYPE_IDENTITY 1
  64. #define EAP_TYPE_NOTIFICATION 2
  65. #define EAP_TYPE_NAK 3
  66. #define EAP_TYPE_MD5_CHALLENGE 4
  67. #define EAP_TYPE_OTP 5
  68. #define EAP_TYPE_GTC 6
  69. #define EAP_TYPE_TLS 13 /* RFC 2716 */
  70. #define EAP_TYPE_SIM 18 /* RFC 4186 */
  71. #define EAP_TYPE_TTLS 21 /* draft-funk-eap-ttls-v0-01.txt */
  72. #define EAP_TYPE_AKA 23 /* RFC 4187 */
  73. #define EAP_TYPE_FAST 43 /* RFC 4851 */
  74. #define EAP_TYPE_EXPANDED_TYPES 254
  75. #define EAP_TYPE_EXPERIMENTAL 255
  76. static const struct tok eap_type_values[] = {
  77. { EAP_TYPE_NO_PROPOSED, "No proposed" },
  78. { EAP_TYPE_IDENTITY, "Identity" },
  79. { EAP_TYPE_NOTIFICATION, "Notification" },
  80. { EAP_TYPE_NAK, "Nak" },
  81. { EAP_TYPE_MD5_CHALLENGE, "MD5-challenge" },
  82. { EAP_TYPE_OTP, "OTP" },
  83. { EAP_TYPE_GTC, "GTC" },
  84. { EAP_TYPE_TLS, "TLS" },
  85. { EAP_TYPE_SIM, "SIM" },
  86. { EAP_TYPE_TTLS, "TTLS" },
  87. { EAP_TYPE_AKA, "AKA" },
  88. { EAP_TYPE_FAST, "FAST" },
  89. { EAP_TYPE_EXPANDED_TYPES, "Expanded types" },
  90. { EAP_TYPE_EXPERIMENTAL, "Experimental" },
  91. { 0, NULL}
  92. };
  93. #define EAP_TLS_EXTRACT_BIT_L(x) (((x)&0x80)>>7)
  94. /* RFC 2716 - EAP TLS bits */
  95. #define EAP_TLS_FLAGS_LEN_INCLUDED (1 << 7)
  96. #define EAP_TLS_FLAGS_MORE_FRAGMENTS (1 << 6)
  97. #define EAP_TLS_FLAGS_START (1 << 5)
  98. static const struct tok eap_tls_flags_values[] = {
  99. { EAP_TLS_FLAGS_LEN_INCLUDED, "L bit" },
  100. { EAP_TLS_FLAGS_MORE_FRAGMENTS, "More fragments bit"},
  101. { EAP_TLS_FLAGS_START, "Start bit"},
  102. { 0, NULL}
  103. };
  104. #define EAP_TTLS_VERSION(x) ((x)&0x07)
  105. /* EAP-AKA and EAP-SIM - RFC 4187 */
  106. #define EAP_AKA_CHALLENGE 1
  107. #define EAP_AKA_AUTH_REJECT 2
  108. #define EAP_AKA_SYNC_FAILURE 4
  109. #define EAP_AKA_IDENTITY 5
  110. #define EAP_SIM_START 10
  111. #define EAP_SIM_CHALLENGE 11
  112. #define EAP_AKA_NOTIFICATION 12
  113. #define EAP_AKA_REAUTH 13
  114. #define EAP_AKA_CLIENT_ERROR 14
  115. static const struct tok eap_aka_subtype_values[] = {
  116. { EAP_AKA_CHALLENGE, "Challenge" },
  117. { EAP_AKA_AUTH_REJECT, "Auth reject" },
  118. { EAP_AKA_SYNC_FAILURE, "Sync failure" },
  119. { EAP_AKA_IDENTITY, "Identity" },
  120. { EAP_SIM_START, "Start" },
  121. { EAP_SIM_CHALLENGE, "Challenge" },
  122. { EAP_AKA_NOTIFICATION, "Notification" },
  123. { EAP_AKA_REAUTH, "Reauth" },
  124. { EAP_AKA_CLIENT_ERROR, "Client error" },
  125. { 0, NULL}
  126. };
  127. /*
  128. * Print EAP requests / responses
  129. */
  130. void
  131. eap_print(netdissect_options *ndo,
  132. register const u_char *cp,
  133. u_int length)
  134. {
  135. const struct eap_frame_t *eap;
  136. const u_char *tptr;
  137. u_int tlen, type, subtype;
  138. int count=0, len;
  139. tptr = cp;
  140. tlen = length;
  141. eap = (const struct eap_frame_t *)cp;
  142. ND_TCHECK(*eap);
  143. /* in non-verbose mode just lets print the basic info */
  144. if (ndo->ndo_vflag < 1) {
  145. ND_PRINT((ndo, "%s (%u) v%u, len %u",
  146. tok2str(eap_frame_type_values, "unknown", eap->type),
  147. eap->type,
  148. eap->version,
  149. EXTRACT_16BITS(eap->length)));
  150. return;
  151. }
  152. ND_PRINT((ndo, "%s (%u) v%u, len %u",
  153. tok2str(eap_frame_type_values, "unknown", eap->type),
  154. eap->type,
  155. eap->version,
  156. EXTRACT_16BITS(eap->length)));
  157. tptr += sizeof(const struct eap_frame_t);
  158. tlen -= sizeof(const struct eap_frame_t);
  159. switch (eap->type) {
  160. case EAP_FRAME_TYPE_PACKET:
  161. ND_TCHECK_8BITS(tptr);
  162. type = *(tptr);
  163. ND_TCHECK_16BITS(tptr+2);
  164. len = EXTRACT_16BITS(tptr+2);
  165. ND_PRINT((ndo, ", %s (%u), id %u, len %u",
  166. tok2str(eap_code_values, "unknown", type),
  167. type,
  168. *(tptr+1),
  169. len));
  170. ND_TCHECK2(*tptr, len);
  171. if (type <= 2) { /* For EAP_REQUEST and EAP_RESPONSE only */
  172. ND_TCHECK_8BITS(tptr+4);
  173. subtype = *(tptr+4);
  174. ND_PRINT((ndo, "\n\t\t Type %s (%u)",
  175. tok2str(eap_type_values, "unknown", subtype),
  176. subtype));
  177. switch (subtype) {
  178. case EAP_TYPE_IDENTITY:
  179. if (len - 5 > 0) {
  180. ND_PRINT((ndo, ", Identity: "));
  181. safeputs(ndo, tptr + 5, len - 5);
  182. }
  183. break;
  184. case EAP_TYPE_NOTIFICATION:
  185. if (len - 5 > 0) {
  186. ND_PRINT((ndo, ", Notification: "));
  187. safeputs(ndo, tptr + 5, len - 5);
  188. }
  189. break;
  190. case EAP_TYPE_NAK:
  191. count = 5;
  192. /*
  193. * one or more octets indicating
  194. * the desired authentication
  195. * type one octet per type
  196. */
  197. while (count < len) {
  198. ND_TCHECK_8BITS(tptr+count);
  199. ND_PRINT((ndo, " %s (%u),",
  200. tok2str(eap_type_values, "unknown", *(tptr+count)),
  201. *(tptr + count)));
  202. count++;
  203. }
  204. break;
  205. case EAP_TYPE_TTLS:
  206. case EAP_TYPE_TLS:
  207. ND_TCHECK_8BITS(tptr + 5);
  208. if (subtype == EAP_TYPE_TTLS)
  209. ND_PRINT((ndo, " TTLSv%u",
  210. EAP_TTLS_VERSION(*(tptr + 5))));
  211. ND_PRINT((ndo, " flags [%s] 0x%02x,",
  212. bittok2str(eap_tls_flags_values, "none", *(tptr+5)),
  213. *(tptr + 5)));
  214. if (EAP_TLS_EXTRACT_BIT_L(*(tptr+5))) {
  215. ND_TCHECK_32BITS(tptr + 6);
  216. ND_PRINT((ndo, " len %u", EXTRACT_32BITS(tptr + 6)));
  217. }
  218. break;
  219. case EAP_TYPE_FAST:
  220. ND_TCHECK_8BITS(tptr + 5);
  221. ND_PRINT((ndo, " FASTv%u",
  222. EAP_TTLS_VERSION(*(tptr + 5))));
  223. ND_PRINT((ndo, " flags [%s] 0x%02x,",
  224. bittok2str(eap_tls_flags_values, "none", *(tptr+5)),
  225. *(tptr + 5)));
  226. if (EAP_TLS_EXTRACT_BIT_L(*(tptr+5))) {
  227. ND_TCHECK_32BITS(tptr + 6);
  228. ND_PRINT((ndo, " len %u", EXTRACT_32BITS(tptr + 6)));
  229. }
  230. /* FIXME - TLV attributes follow */
  231. break;
  232. case EAP_TYPE_AKA:
  233. case EAP_TYPE_SIM:
  234. ND_TCHECK_8BITS(tptr + 5);
  235. ND_PRINT((ndo, " subtype [%s] 0x%02x,",
  236. tok2str(eap_aka_subtype_values, "unknown", *(tptr+5)),
  237. *(tptr + 5)));
  238. /* FIXME - TLV attributes follow */
  239. break;
  240. case EAP_TYPE_MD5_CHALLENGE:
  241. case EAP_TYPE_OTP:
  242. case EAP_TYPE_GTC:
  243. case EAP_TYPE_EXPANDED_TYPES:
  244. case EAP_TYPE_EXPERIMENTAL:
  245. default:
  246. break;
  247. }
  248. }
  249. break;
  250. case EAP_FRAME_TYPE_LOGOFF:
  251. case EAP_FRAME_TYPE_ENCAP_ASF_ALERT:
  252. default:
  253. break;
  254. }
  255. return;
  256. trunc:
  257. ND_PRINT((ndo, "\n\t[|EAP]"));
  258. }
  259. /*
  260. * Local Variables:
  261. * c-basic-offset: 4
  262. * End:
  263. */