eapol_test.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  1. /*
  2. * WPA Supplicant - test code
  3. * Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. *
  14. * IEEE 802.1X Supplicant test code (to be used in place of wpa_supplicant.c.
  15. * Not used in production version.
  16. */
  17. #include "includes.h"
  18. #include <assert.h>
  19. #include "common.h"
  20. #include "config.h"
  21. #include "eapol_supp/eapol_supp_sm.h"
  22. #include "eap_peer/eap.h"
  23. #include "eap_server/eap_methods.h"
  24. #include "eloop.h"
  25. #include "rsn_supp/wpa.h"
  26. #include "eap_peer/eap_i.h"
  27. #include "wpa_supplicant_i.h"
  28. #include "radius/radius.h"
  29. #include "radius/radius_client.h"
  30. #include "common/wpa_ctrl.h"
  31. #include "ctrl_iface.h"
  32. #include "pcsc_funcs.h"
  33. extern int wpa_debug_level;
  34. extern int wpa_debug_show_keys;
  35. struct wpa_driver_ops *wpa_drivers[] = { NULL };
  36. struct extra_radius_attr {
  37. u8 type;
  38. char syntax;
  39. char *data;
  40. struct extra_radius_attr *next;
  41. };
  42. struct eapol_test_data {
  43. struct wpa_supplicant *wpa_s;
  44. int eapol_test_num_reauths;
  45. int no_mppe_keys;
  46. int num_mppe_ok, num_mppe_mismatch;
  47. u8 radius_identifier;
  48. struct radius_msg *last_recv_radius;
  49. struct in_addr own_ip_addr;
  50. struct radius_client_data *radius;
  51. struct hostapd_radius_servers *radius_conf;
  52. u8 *last_eap_radius; /* last received EAP Response from Authentication
  53. * Server */
  54. size_t last_eap_radius_len;
  55. u8 authenticator_pmk[PMK_LEN];
  56. size_t authenticator_pmk_len;
  57. int radius_access_accept_received;
  58. int radius_access_reject_received;
  59. int auth_timed_out;
  60. u8 *eap_identity;
  61. size_t eap_identity_len;
  62. char *connect_info;
  63. u8 own_addr[ETH_ALEN];
  64. struct extra_radius_attr *extra_attrs;
  65. };
  66. static struct eapol_test_data eapol_test;
  67. static void send_eap_request_identity(void *eloop_ctx, void *timeout_ctx);
  68. static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module,
  69. int level, const char *txt, size_t len)
  70. {
  71. if (addr)
  72. wpa_printf(MSG_DEBUG, "STA " MACSTR ": %s\n",
  73. MAC2STR(addr), txt);
  74. else
  75. wpa_printf(MSG_DEBUG, "%s", txt);
  76. }
  77. static int add_extra_attr(struct radius_msg *msg,
  78. struct extra_radius_attr *attr)
  79. {
  80. size_t len;
  81. char *pos;
  82. u32 val;
  83. char buf[128];
  84. switch (attr->syntax) {
  85. case 's':
  86. os_snprintf(buf, sizeof(buf), "%s", attr->data);
  87. len = os_strlen(buf);
  88. break;
  89. case 'n':
  90. buf[0] = '\0';
  91. len = 1;
  92. break;
  93. case 'x':
  94. pos = attr->data;
  95. if (pos[0] == '0' && pos[1] == 'x')
  96. pos += 2;
  97. len = os_strlen(pos);
  98. if ((len & 1) || (len / 2) > sizeof(buf)) {
  99. printf("Invalid extra attribute hexstring\n");
  100. return -1;
  101. }
  102. len /= 2;
  103. if (hexstr2bin(pos, (u8 *) buf, len) < 0) {
  104. printf("Invalid extra attribute hexstring\n");
  105. return -1;
  106. }
  107. break;
  108. case 'd':
  109. val = htonl(atoi(attr->data));
  110. os_memcpy(buf, &val, 4);
  111. len = 4;
  112. break;
  113. default:
  114. printf("Incorrect extra attribute syntax specification\n");
  115. return -1;
  116. }
  117. if (!radius_msg_add_attr(msg, attr->type, (u8 *) buf, len)) {
  118. printf("Could not add attribute %d\n", attr->type);
  119. return -1;
  120. }
  121. return 0;
  122. }
  123. static int add_extra_attrs(struct radius_msg *msg,
  124. struct extra_radius_attr *attrs)
  125. {
  126. struct extra_radius_attr *p;
  127. for (p = attrs; p; p = p->next) {
  128. if (add_extra_attr(msg, p) < 0)
  129. return -1;
  130. }
  131. return 0;
  132. }
  133. static struct extra_radius_attr *
  134. find_extra_attr(struct extra_radius_attr *attrs, u8 type)
  135. {
  136. struct extra_radius_attr *p;
  137. for (p = attrs; p; p = p->next) {
  138. if (p->type == type)
  139. return p;
  140. }
  141. return NULL;
  142. }
  143. static void ieee802_1x_encapsulate_radius(struct eapol_test_data *e,
  144. const u8 *eap, size_t len)
  145. {
  146. struct radius_msg *msg;
  147. char buf[128];
  148. const struct eap_hdr *hdr;
  149. const u8 *pos;
  150. wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS "
  151. "packet");
  152. e->radius_identifier = radius_client_get_id(e->radius);
  153. msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST,
  154. e->radius_identifier);
  155. if (msg == NULL) {
  156. printf("Could not create net RADIUS packet\n");
  157. return;
  158. }
  159. radius_msg_make_authenticator(msg, (u8 *) e, sizeof(*e));
  160. hdr = (const struct eap_hdr *) eap;
  161. pos = (const u8 *) (hdr + 1);
  162. if (len > sizeof(*hdr) && hdr->code == EAP_CODE_RESPONSE &&
  163. pos[0] == EAP_TYPE_IDENTITY) {
  164. pos++;
  165. os_free(e->eap_identity);
  166. e->eap_identity_len = len - sizeof(*hdr) - 1;
  167. e->eap_identity = os_malloc(e->eap_identity_len);
  168. if (e->eap_identity) {
  169. os_memcpy(e->eap_identity, pos, e->eap_identity_len);
  170. wpa_hexdump(MSG_DEBUG, "Learned identity from "
  171. "EAP-Response-Identity",
  172. e->eap_identity, e->eap_identity_len);
  173. }
  174. }
  175. if (e->eap_identity &&
  176. !radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME,
  177. e->eap_identity, e->eap_identity_len)) {
  178. printf("Could not add User-Name\n");
  179. goto fail;
  180. }
  181. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_NAS_IP_ADDRESS) &&
  182. !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS,
  183. (u8 *) &e->own_ip_addr, 4)) {
  184. printf("Could not add NAS-IP-Address\n");
  185. goto fail;
  186. }
  187. os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
  188. MAC2STR(e->wpa_s->own_addr));
  189. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_CALLING_STATION_ID)
  190. &&
  191. !radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
  192. (u8 *) buf, os_strlen(buf))) {
  193. printf("Could not add Calling-Station-Id\n");
  194. goto fail;
  195. }
  196. /* TODO: should probably check MTU from driver config; 2304 is max for
  197. * IEEE 802.11, but use 1400 to avoid problems with too large packets
  198. */
  199. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_FRAMED_MTU) &&
  200. !radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) {
  201. printf("Could not add Framed-MTU\n");
  202. goto fail;
  203. }
  204. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_NAS_PORT_TYPE) &&
  205. !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE,
  206. RADIUS_NAS_PORT_TYPE_IEEE_802_11)) {
  207. printf("Could not add NAS-Port-Type\n");
  208. goto fail;
  209. }
  210. os_snprintf(buf, sizeof(buf), "%s", e->connect_info);
  211. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_CONNECT_INFO) &&
  212. !radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
  213. (u8 *) buf, os_strlen(buf))) {
  214. printf("Could not add Connect-Info\n");
  215. goto fail;
  216. }
  217. if (add_extra_attrs(msg, e->extra_attrs) < 0)
  218. goto fail;
  219. if (eap && !radius_msg_add_eap(msg, eap, len)) {
  220. printf("Could not add EAP-Message\n");
  221. goto fail;
  222. }
  223. /* State attribute must be copied if and only if this packet is
  224. * Access-Request reply to the previous Access-Challenge */
  225. if (e->last_recv_radius &&
  226. radius_msg_get_hdr(e->last_recv_radius)->code ==
  227. RADIUS_CODE_ACCESS_CHALLENGE) {
  228. int res = radius_msg_copy_attr(msg, e->last_recv_radius,
  229. RADIUS_ATTR_STATE);
  230. if (res < 0) {
  231. printf("Could not copy State attribute from previous "
  232. "Access-Challenge\n");
  233. goto fail;
  234. }
  235. if (res > 0) {
  236. wpa_printf(MSG_DEBUG, " Copied RADIUS State "
  237. "Attribute");
  238. }
  239. }
  240. radius_client_send(e->radius, msg, RADIUS_AUTH, e->wpa_s->own_addr);
  241. return;
  242. fail:
  243. radius_msg_free(msg);
  244. }
  245. static int eapol_test_eapol_send(void *ctx, int type, const u8 *buf,
  246. size_t len)
  247. {
  248. /* struct wpa_supplicant *wpa_s = ctx; */
  249. printf("WPA: eapol_test_eapol_send(type=%d len=%lu)\n",
  250. type, (unsigned long) len);
  251. if (type == IEEE802_1X_TYPE_EAP_PACKET) {
  252. wpa_hexdump(MSG_DEBUG, "TX EAP -> RADIUS", buf, len);
  253. ieee802_1x_encapsulate_radius(&eapol_test, buf, len);
  254. }
  255. return 0;
  256. }
  257. static void eapol_test_set_config_blob(void *ctx,
  258. struct wpa_config_blob *blob)
  259. {
  260. struct wpa_supplicant *wpa_s = ctx;
  261. wpa_config_set_blob(wpa_s->conf, blob);
  262. }
  263. static const struct wpa_config_blob *
  264. eapol_test_get_config_blob(void *ctx, const char *name)
  265. {
  266. struct wpa_supplicant *wpa_s = ctx;
  267. return wpa_config_get_blob(wpa_s->conf, name);
  268. }
  269. static void eapol_test_eapol_done_cb(void *ctx)
  270. {
  271. printf("WPA: EAPOL processing complete\n");
  272. }
  273. static void eapol_sm_reauth(void *eloop_ctx, void *timeout_ctx)
  274. {
  275. struct eapol_test_data *e = eloop_ctx;
  276. printf("\n\n\n\n\neapol_test: Triggering EAP reauthentication\n\n");
  277. e->radius_access_accept_received = 0;
  278. send_eap_request_identity(e->wpa_s, NULL);
  279. }
  280. static int eapol_test_compare_pmk(struct eapol_test_data *e)
  281. {
  282. u8 pmk[PMK_LEN];
  283. int ret = 1;
  284. if (eapol_sm_get_key(e->wpa_s->eapol, pmk, PMK_LEN) == 0) {
  285. wpa_hexdump(MSG_DEBUG, "PMK from EAPOL", pmk, PMK_LEN);
  286. if (os_memcmp(pmk, e->authenticator_pmk, PMK_LEN) != 0) {
  287. printf("WARNING: PMK mismatch\n");
  288. wpa_hexdump(MSG_DEBUG, "PMK from AS",
  289. e->authenticator_pmk, PMK_LEN);
  290. } else if (e->radius_access_accept_received)
  291. ret = 0;
  292. } else if (e->authenticator_pmk_len == 16 &&
  293. eapol_sm_get_key(e->wpa_s->eapol, pmk, 16) == 0) {
  294. wpa_hexdump(MSG_DEBUG, "LEAP PMK from EAPOL", pmk, 16);
  295. if (os_memcmp(pmk, e->authenticator_pmk, 16) != 0) {
  296. printf("WARNING: PMK mismatch\n");
  297. wpa_hexdump(MSG_DEBUG, "PMK from AS",
  298. e->authenticator_pmk, 16);
  299. } else if (e->radius_access_accept_received)
  300. ret = 0;
  301. } else if (e->radius_access_accept_received && e->no_mppe_keys) {
  302. /* No keying material expected */
  303. ret = 0;
  304. }
  305. if (ret && !e->no_mppe_keys)
  306. e->num_mppe_mismatch++;
  307. else if (!e->no_mppe_keys)
  308. e->num_mppe_ok++;
  309. return ret;
  310. }
  311. static void eapol_sm_cb(struct eapol_sm *eapol, int success, void *ctx)
  312. {
  313. struct eapol_test_data *e = ctx;
  314. printf("eapol_sm_cb: success=%d\n", success);
  315. e->eapol_test_num_reauths--;
  316. if (e->eapol_test_num_reauths < 0)
  317. eloop_terminate();
  318. else {
  319. eapol_test_compare_pmk(e);
  320. eloop_register_timeout(0, 100000, eapol_sm_reauth, e, NULL);
  321. }
  322. }
  323. static void eapol_test_cert_cb(void *ctx, int depth, const char *subject,
  324. const char *cert_hash,
  325. const struct wpabuf *cert)
  326. {
  327. struct eapol_test_data *e = ctx;
  328. wpa_msg(e->wpa_s, MSG_INFO, WPA_EVENT_EAP_PEER_CERT
  329. "depth=%d subject='%s'%s%s",
  330. depth, subject,
  331. cert_hash ? " hash=" : "",
  332. cert_hash ? cert_hash : "");
  333. if (cert) {
  334. char *cert_hex;
  335. size_t len = wpabuf_len(cert) * 2 + 1;
  336. cert_hex = os_malloc(len);
  337. if (cert_hex) {
  338. wpa_snprintf_hex(cert_hex, len, wpabuf_head(cert),
  339. wpabuf_len(cert));
  340. wpa_msg_ctrl(e->wpa_s, MSG_INFO,
  341. WPA_EVENT_EAP_PEER_CERT
  342. "depth=%d subject='%s' cert=%s",
  343. depth, subject, cert_hex);
  344. os_free(cert_hex);
  345. }
  346. }
  347. }
  348. static int test_eapol(struct eapol_test_data *e, struct wpa_supplicant *wpa_s,
  349. struct wpa_ssid *ssid)
  350. {
  351. struct eapol_config eapol_conf;
  352. struct eapol_ctx *ctx;
  353. ctx = os_zalloc(sizeof(*ctx));
  354. if (ctx == NULL) {
  355. printf("Failed to allocate EAPOL context.\n");
  356. return -1;
  357. }
  358. ctx->ctx = wpa_s;
  359. ctx->msg_ctx = wpa_s;
  360. ctx->scard_ctx = wpa_s->scard;
  361. ctx->cb = eapol_sm_cb;
  362. ctx->cb_ctx = e;
  363. ctx->eapol_send_ctx = wpa_s;
  364. ctx->preauth = 0;
  365. ctx->eapol_done_cb = eapol_test_eapol_done_cb;
  366. ctx->eapol_send = eapol_test_eapol_send;
  367. ctx->set_config_blob = eapol_test_set_config_blob;
  368. ctx->get_config_blob = eapol_test_get_config_blob;
  369. ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
  370. ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
  371. ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
  372. ctx->cert_cb = eapol_test_cert_cb;
  373. wpa_s->eapol = eapol_sm_init(ctx);
  374. if (wpa_s->eapol == NULL) {
  375. os_free(ctx);
  376. printf("Failed to initialize EAPOL state machines.\n");
  377. return -1;
  378. }
  379. wpa_s->current_ssid = ssid;
  380. os_memset(&eapol_conf, 0, sizeof(eapol_conf));
  381. eapol_conf.accept_802_1x_keys = 1;
  382. eapol_conf.required_keys = 0;
  383. eapol_conf.fast_reauth = wpa_s->conf->fast_reauth;
  384. eapol_conf.workaround = ssid->eap_workaround;
  385. eapol_sm_notify_config(wpa_s->eapol, &ssid->eap, &eapol_conf);
  386. eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
  387. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  388. /* 802.1X::portControl = Auto */
  389. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  390. return 0;
  391. }
  392. static void test_eapol_clean(struct eapol_test_data *e,
  393. struct wpa_supplicant *wpa_s)
  394. {
  395. struct extra_radius_attr *p, *prev;
  396. radius_client_deinit(e->radius);
  397. os_free(e->last_eap_radius);
  398. radius_msg_free(e->last_recv_radius);
  399. e->last_recv_radius = NULL;
  400. os_free(e->eap_identity);
  401. e->eap_identity = NULL;
  402. eapol_sm_deinit(wpa_s->eapol);
  403. wpa_s->eapol = NULL;
  404. if (e->radius_conf && e->radius_conf->auth_server) {
  405. os_free(e->radius_conf->auth_server->shared_secret);
  406. os_free(e->radius_conf->auth_server);
  407. }
  408. os_free(e->radius_conf);
  409. e->radius_conf = NULL;
  410. scard_deinit(wpa_s->scard);
  411. if (wpa_s->ctrl_iface) {
  412. wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
  413. wpa_s->ctrl_iface = NULL;
  414. }
  415. wpa_config_free(wpa_s->conf);
  416. p = e->extra_attrs;
  417. while (p) {
  418. prev = p;
  419. p = p->next;
  420. os_free(prev);
  421. }
  422. }
  423. static void send_eap_request_identity(void *eloop_ctx, void *timeout_ctx)
  424. {
  425. struct wpa_supplicant *wpa_s = eloop_ctx;
  426. u8 buf[100], *pos;
  427. struct ieee802_1x_hdr *hdr;
  428. struct eap_hdr *eap;
  429. hdr = (struct ieee802_1x_hdr *) buf;
  430. hdr->version = EAPOL_VERSION;
  431. hdr->type = IEEE802_1X_TYPE_EAP_PACKET;
  432. hdr->length = htons(5);
  433. eap = (struct eap_hdr *) (hdr + 1);
  434. eap->code = EAP_CODE_REQUEST;
  435. eap->identifier = 0;
  436. eap->length = htons(5);
  437. pos = (u8 *) (eap + 1);
  438. *pos = EAP_TYPE_IDENTITY;
  439. printf("Sending fake EAP-Request-Identity\n");
  440. eapol_sm_rx_eapol(wpa_s->eapol, wpa_s->bssid, buf,
  441. sizeof(*hdr) + 5);
  442. }
  443. static void eapol_test_timeout(void *eloop_ctx, void *timeout_ctx)
  444. {
  445. struct eapol_test_data *e = eloop_ctx;
  446. printf("EAPOL test timed out\n");
  447. e->auth_timed_out = 1;
  448. eloop_terminate();
  449. }
  450. static char *eap_type_text(u8 type)
  451. {
  452. switch (type) {
  453. case EAP_TYPE_IDENTITY: return "Identity";
  454. case EAP_TYPE_NOTIFICATION: return "Notification";
  455. case EAP_TYPE_NAK: return "Nak";
  456. case EAP_TYPE_TLS: return "TLS";
  457. case EAP_TYPE_TTLS: return "TTLS";
  458. case EAP_TYPE_PEAP: return "PEAP";
  459. case EAP_TYPE_SIM: return "SIM";
  460. case EAP_TYPE_GTC: return "GTC";
  461. case EAP_TYPE_MD5: return "MD5";
  462. case EAP_TYPE_OTP: return "OTP";
  463. case EAP_TYPE_FAST: return "FAST";
  464. case EAP_TYPE_SAKE: return "SAKE";
  465. case EAP_TYPE_PSK: return "PSK";
  466. default: return "Unknown";
  467. }
  468. }
  469. static void ieee802_1x_decapsulate_radius(struct eapol_test_data *e)
  470. {
  471. u8 *eap;
  472. size_t len;
  473. struct eap_hdr *hdr;
  474. int eap_type = -1;
  475. char buf[64];
  476. struct radius_msg *msg;
  477. if (e->last_recv_radius == NULL)
  478. return;
  479. msg = e->last_recv_radius;
  480. eap = radius_msg_get_eap(msg, &len);
  481. if (eap == NULL) {
  482. /* draft-aboba-radius-rfc2869bis-20.txt, Chap. 2.6.3:
  483. * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
  484. * attribute */
  485. wpa_printf(MSG_DEBUG, "could not extract "
  486. "EAP-Message from RADIUS message");
  487. os_free(e->last_eap_radius);
  488. e->last_eap_radius = NULL;
  489. e->last_eap_radius_len = 0;
  490. return;
  491. }
  492. if (len < sizeof(*hdr)) {
  493. wpa_printf(MSG_DEBUG, "too short EAP packet "
  494. "received from authentication server");
  495. os_free(eap);
  496. return;
  497. }
  498. if (len > sizeof(*hdr))
  499. eap_type = eap[sizeof(*hdr)];
  500. hdr = (struct eap_hdr *) eap;
  501. switch (hdr->code) {
  502. case EAP_CODE_REQUEST:
  503. os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
  504. eap_type >= 0 ? eap_type_text(eap_type) : "??",
  505. eap_type);
  506. break;
  507. case EAP_CODE_RESPONSE:
  508. os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
  509. eap_type >= 0 ? eap_type_text(eap_type) : "??",
  510. eap_type);
  511. break;
  512. case EAP_CODE_SUCCESS:
  513. os_strlcpy(buf, "EAP Success", sizeof(buf));
  514. /* LEAP uses EAP Success within an authentication, so must not
  515. * stop here with eloop_terminate(); */
  516. break;
  517. case EAP_CODE_FAILURE:
  518. os_strlcpy(buf, "EAP Failure", sizeof(buf));
  519. eloop_terminate();
  520. break;
  521. default:
  522. os_strlcpy(buf, "unknown EAP code", sizeof(buf));
  523. wpa_hexdump(MSG_DEBUG, "Decapsulated EAP packet", eap, len);
  524. break;
  525. }
  526. wpa_printf(MSG_DEBUG, "decapsulated EAP packet (code=%d "
  527. "id=%d len=%d) from RADIUS server: %s",
  528. hdr->code, hdr->identifier, ntohs(hdr->length), buf);
  529. /* sta->eapol_sm->be_auth.idFromServer = hdr->identifier; */
  530. os_free(e->last_eap_radius);
  531. e->last_eap_radius = eap;
  532. e->last_eap_radius_len = len;
  533. {
  534. struct ieee802_1x_hdr *dot1x;
  535. dot1x = os_malloc(sizeof(*dot1x) + len);
  536. assert(dot1x != NULL);
  537. dot1x->version = EAPOL_VERSION;
  538. dot1x->type = IEEE802_1X_TYPE_EAP_PACKET;
  539. dot1x->length = htons(len);
  540. os_memcpy((u8 *) (dot1x + 1), eap, len);
  541. eapol_sm_rx_eapol(e->wpa_s->eapol, e->wpa_s->bssid,
  542. (u8 *) dot1x, sizeof(*dot1x) + len);
  543. os_free(dot1x);
  544. }
  545. }
  546. static void ieee802_1x_get_keys(struct eapol_test_data *e,
  547. struct radius_msg *msg, struct radius_msg *req,
  548. const u8 *shared_secret,
  549. size_t shared_secret_len)
  550. {
  551. struct radius_ms_mppe_keys *keys;
  552. keys = radius_msg_get_ms_keys(msg, req, shared_secret,
  553. shared_secret_len);
  554. if (keys && keys->send == NULL && keys->recv == NULL) {
  555. os_free(keys);
  556. keys = radius_msg_get_cisco_keys(msg, req, shared_secret,
  557. shared_secret_len);
  558. }
  559. if (keys) {
  560. if (keys->send) {
  561. wpa_hexdump(MSG_DEBUG, "MS-MPPE-Send-Key (sign)",
  562. keys->send, keys->send_len);
  563. }
  564. if (keys->recv) {
  565. wpa_hexdump(MSG_DEBUG, "MS-MPPE-Recv-Key (crypt)",
  566. keys->recv, keys->recv_len);
  567. e->authenticator_pmk_len =
  568. keys->recv_len > PMK_LEN ? PMK_LEN :
  569. keys->recv_len;
  570. os_memcpy(e->authenticator_pmk, keys->recv,
  571. e->authenticator_pmk_len);
  572. if (e->authenticator_pmk_len == 16 && keys->send &&
  573. keys->send_len == 16) {
  574. /* MS-CHAP-v2 derives 16 octet keys */
  575. wpa_printf(MSG_DEBUG, "Use MS-MPPE-Send-Key "
  576. "to extend PMK to 32 octets");
  577. os_memcpy(e->authenticator_pmk +
  578. e->authenticator_pmk_len,
  579. keys->send, keys->send_len);
  580. e->authenticator_pmk_len += keys->send_len;
  581. }
  582. }
  583. os_free(keys->send);
  584. os_free(keys->recv);
  585. os_free(keys);
  586. }
  587. }
  588. /* Process the RADIUS frames from Authentication Server */
  589. static RadiusRxResult
  590. ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
  591. const u8 *shared_secret, size_t shared_secret_len,
  592. void *data)
  593. {
  594. struct eapol_test_data *e = data;
  595. struct radius_hdr *hdr = radius_msg_get_hdr(msg);
  596. /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
  597. * present when packet contains an EAP-Message attribute */
  598. if (hdr->code == RADIUS_CODE_ACCESS_REJECT &&
  599. radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
  600. 0) < 0 &&
  601. radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
  602. wpa_printf(MSG_DEBUG, "Allowing RADIUS "
  603. "Access-Reject without Message-Authenticator "
  604. "since it does not include EAP-Message\n");
  605. } else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
  606. req, 1)) {
  607. printf("Incoming RADIUS packet did not have correct "
  608. "Message-Authenticator - dropped\n");
  609. return RADIUS_RX_UNKNOWN;
  610. }
  611. if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
  612. hdr->code != RADIUS_CODE_ACCESS_REJECT &&
  613. hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
  614. printf("Unknown RADIUS message code\n");
  615. return RADIUS_RX_UNKNOWN;
  616. }
  617. e->radius_identifier = -1;
  618. wpa_printf(MSG_DEBUG, "RADIUS packet matching with station");
  619. radius_msg_free(e->last_recv_radius);
  620. e->last_recv_radius = msg;
  621. switch (hdr->code) {
  622. case RADIUS_CODE_ACCESS_ACCEPT:
  623. e->radius_access_accept_received = 1;
  624. ieee802_1x_get_keys(e, msg, req, shared_secret,
  625. shared_secret_len);
  626. break;
  627. case RADIUS_CODE_ACCESS_REJECT:
  628. e->radius_access_reject_received = 1;
  629. break;
  630. }
  631. ieee802_1x_decapsulate_radius(e);
  632. if ((hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
  633. e->eapol_test_num_reauths < 0) ||
  634. hdr->code == RADIUS_CODE_ACCESS_REJECT) {
  635. eloop_terminate();
  636. }
  637. return RADIUS_RX_QUEUED;
  638. }
  639. static void wpa_init_conf(struct eapol_test_data *e,
  640. struct wpa_supplicant *wpa_s, const char *authsrv,
  641. int port, const char *secret,
  642. const char *cli_addr)
  643. {
  644. struct hostapd_radius_server *as;
  645. int res;
  646. wpa_s->bssid[5] = 1;
  647. os_memcpy(wpa_s->own_addr, e->own_addr, ETH_ALEN);
  648. e->own_ip_addr.s_addr = htonl((127 << 24) | 1);
  649. os_strlcpy(wpa_s->ifname, "test", sizeof(wpa_s->ifname));
  650. e->radius_conf = os_zalloc(sizeof(struct hostapd_radius_servers));
  651. assert(e->radius_conf != NULL);
  652. e->radius_conf->num_auth_servers = 1;
  653. as = os_zalloc(sizeof(struct hostapd_radius_server));
  654. assert(as != NULL);
  655. #if defined(CONFIG_NATIVE_WINDOWS) || defined(CONFIG_ANSI_C_EXTRA)
  656. {
  657. int a[4];
  658. u8 *pos;
  659. sscanf(authsrv, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
  660. pos = (u8 *) &as->addr.u.v4;
  661. *pos++ = a[0];
  662. *pos++ = a[1];
  663. *pos++ = a[2];
  664. *pos++ = a[3];
  665. }
  666. #else /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
  667. inet_aton(authsrv, &as->addr.u.v4);
  668. #endif /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
  669. as->addr.af = AF_INET;
  670. as->port = port;
  671. as->shared_secret = (u8 *) os_strdup(secret);
  672. as->shared_secret_len = os_strlen(secret);
  673. e->radius_conf->auth_server = as;
  674. e->radius_conf->auth_servers = as;
  675. e->radius_conf->msg_dumps = 1;
  676. if (cli_addr) {
  677. if (hostapd_parse_ip_addr(cli_addr,
  678. &e->radius_conf->client_addr) == 0)
  679. e->radius_conf->force_client_addr = 1;
  680. else {
  681. wpa_printf(MSG_ERROR, "Invalid IP address '%s'",
  682. cli_addr);
  683. assert(0);
  684. }
  685. }
  686. e->radius = radius_client_init(wpa_s, e->radius_conf);
  687. assert(e->radius != NULL);
  688. res = radius_client_register(e->radius, RADIUS_AUTH,
  689. ieee802_1x_receive_auth, e);
  690. assert(res == 0);
  691. }
  692. static int scard_test(void)
  693. {
  694. struct scard_data *scard;
  695. size_t len;
  696. char imsi[20];
  697. unsigned char _rand[16];
  698. #ifdef PCSC_FUNCS
  699. unsigned char sres[4];
  700. unsigned char kc[8];
  701. #endif /* PCSC_FUNCS */
  702. #define num_triplets 5
  703. unsigned char rand_[num_triplets][16];
  704. unsigned char sres_[num_triplets][4];
  705. unsigned char kc_[num_triplets][8];
  706. int i, res;
  707. size_t j;
  708. #define AKA_RAND_LEN 16
  709. #define AKA_AUTN_LEN 16
  710. #define AKA_AUTS_LEN 14
  711. #define RES_MAX_LEN 16
  712. #define IK_LEN 16
  713. #define CK_LEN 16
  714. unsigned char aka_rand[AKA_RAND_LEN];
  715. unsigned char aka_autn[AKA_AUTN_LEN];
  716. unsigned char aka_auts[AKA_AUTS_LEN];
  717. unsigned char aka_res[RES_MAX_LEN];
  718. size_t aka_res_len;
  719. unsigned char aka_ik[IK_LEN];
  720. unsigned char aka_ck[CK_LEN];
  721. scard = scard_init(SCARD_TRY_BOTH);
  722. if (scard == NULL)
  723. return -1;
  724. if (scard_set_pin(scard, "1234")) {
  725. wpa_printf(MSG_WARNING, "PIN validation failed");
  726. scard_deinit(scard);
  727. return -1;
  728. }
  729. len = sizeof(imsi);
  730. if (scard_get_imsi(scard, imsi, &len))
  731. goto failed;
  732. wpa_hexdump_ascii(MSG_DEBUG, "SCARD: IMSI", (u8 *) imsi, len);
  733. /* NOTE: Permanent Username: 1 | IMSI */
  734. os_memset(_rand, 0, sizeof(_rand));
  735. if (scard_gsm_auth(scard, _rand, sres, kc))
  736. goto failed;
  737. os_memset(_rand, 0xff, sizeof(_rand));
  738. if (scard_gsm_auth(scard, _rand, sres, kc))
  739. goto failed;
  740. for (i = 0; i < num_triplets; i++) {
  741. os_memset(rand_[i], i, sizeof(rand_[i]));
  742. if (scard_gsm_auth(scard, rand_[i], sres_[i], kc_[i]))
  743. goto failed;
  744. }
  745. for (i = 0; i < num_triplets; i++) {
  746. printf("1");
  747. for (j = 0; j < len; j++)
  748. printf("%c", imsi[j]);
  749. printf(",");
  750. for (j = 0; j < 16; j++)
  751. printf("%02X", rand_[i][j]);
  752. printf(",");
  753. for (j = 0; j < 4; j++)
  754. printf("%02X", sres_[i][j]);
  755. printf(",");
  756. for (j = 0; j < 8; j++)
  757. printf("%02X", kc_[i][j]);
  758. printf("\n");
  759. }
  760. wpa_printf(MSG_DEBUG, "Trying to use UMTS authentication");
  761. /* seq 39 (0x28) */
  762. os_memset(aka_rand, 0xaa, 16);
  763. os_memcpy(aka_autn, "\x86\x71\x31\xcb\xa2\xfc\x61\xdf"
  764. "\xa3\xb3\x97\x9d\x07\x32\xa2\x12", 16);
  765. res = scard_umts_auth(scard, aka_rand, aka_autn, aka_res, &aka_res_len,
  766. aka_ik, aka_ck, aka_auts);
  767. if (res == 0) {
  768. wpa_printf(MSG_DEBUG, "UMTS auth completed successfully");
  769. wpa_hexdump(MSG_DEBUG, "RES", aka_res, aka_res_len);
  770. wpa_hexdump(MSG_DEBUG, "IK", aka_ik, IK_LEN);
  771. wpa_hexdump(MSG_DEBUG, "CK", aka_ck, CK_LEN);
  772. } else if (res == -2) {
  773. wpa_printf(MSG_DEBUG, "UMTS auth resulted in synchronization "
  774. "failure");
  775. wpa_hexdump(MSG_DEBUG, "AUTS", aka_auts, AKA_AUTS_LEN);
  776. } else {
  777. wpa_printf(MSG_DEBUG, "UMTS auth failed");
  778. }
  779. failed:
  780. scard_deinit(scard);
  781. return 0;
  782. #undef num_triplets
  783. }
  784. static int scard_get_triplets(int argc, char *argv[])
  785. {
  786. struct scard_data *scard;
  787. size_t len;
  788. char imsi[20];
  789. unsigned char _rand[16];
  790. unsigned char sres[4];
  791. unsigned char kc[8];
  792. int num_triplets;
  793. int i;
  794. size_t j;
  795. if (argc < 2 || ((num_triplets = atoi(argv[1])) <= 0)) {
  796. printf("invalid parameters for sim command\n");
  797. return -1;
  798. }
  799. if (argc <= 2 || os_strcmp(argv[2], "debug") != 0) {
  800. /* disable debug output */
  801. wpa_debug_level = 99;
  802. }
  803. scard = scard_init(SCARD_GSM_SIM_ONLY);
  804. if (scard == NULL) {
  805. printf("Failed to open smartcard connection\n");
  806. return -1;
  807. }
  808. if (scard_set_pin(scard, argv[0])) {
  809. wpa_printf(MSG_WARNING, "PIN validation failed");
  810. scard_deinit(scard);
  811. return -1;
  812. }
  813. len = sizeof(imsi);
  814. if (scard_get_imsi(scard, imsi, &len)) {
  815. scard_deinit(scard);
  816. return -1;
  817. }
  818. for (i = 0; i < num_triplets; i++) {
  819. os_memset(_rand, i, sizeof(_rand));
  820. if (scard_gsm_auth(scard, _rand, sres, kc))
  821. break;
  822. /* IMSI:Kc:SRES:RAND */
  823. for (j = 0; j < len; j++)
  824. printf("%c", imsi[j]);
  825. printf(":");
  826. for (j = 0; j < 8; j++)
  827. printf("%02X", kc[j]);
  828. printf(":");
  829. for (j = 0; j < 4; j++)
  830. printf("%02X", sres[j]);
  831. printf(":");
  832. for (j = 0; j < 16; j++)
  833. printf("%02X", _rand[j]);
  834. printf("\n");
  835. }
  836. scard_deinit(scard);
  837. return 0;
  838. }
  839. static void eapol_test_terminate(int sig, void *signal_ctx)
  840. {
  841. struct wpa_supplicant *wpa_s = signal_ctx;
  842. wpa_msg(wpa_s, MSG_INFO, "Signal %d received - terminating", sig);
  843. eloop_terminate();
  844. }
  845. static void usage(void)
  846. {
  847. printf("usage:\n"
  848. "eapol_test [-nWS] -c<conf> [-a<AS IP>] [-p<AS port>] "
  849. "[-s<AS secret>]\\\n"
  850. " [-r<count>] [-t<timeout>] [-C<Connect-Info>] \\\n"
  851. " [-M<client MAC address>] \\\n"
  852. " [-N<attr spec>] \\\n"
  853. " [-A<client IP>]\n"
  854. "eapol_test scard\n"
  855. "eapol_test sim <PIN> <num triplets> [debug]\n"
  856. "\n");
  857. printf("options:\n"
  858. " -c<conf> = configuration file\n"
  859. " -a<AS IP> = IP address of the authentication server, "
  860. "default 127.0.0.1\n"
  861. " -p<AS port> = UDP port of the authentication server, "
  862. "default 1812\n"
  863. " -s<AS secret> = shared secret with the authentication "
  864. "server, default 'radius'\n"
  865. " -A<client IP> = IP address of the client, default: select "
  866. "automatically\n"
  867. " -r<count> = number of re-authentications\n"
  868. " -W = wait for a control interface monitor before starting\n"
  869. " -S = save configuration after authentication\n"
  870. " -n = no MPPE keys expected\n"
  871. " -t<timeout> = sets timeout in seconds (default: 30 s)\n"
  872. " -C<Connect-Info> = RADIUS Connect-Info (default: "
  873. "CONNECT 11Mbps 802.11b)\n"
  874. " -M<client MAC address> = Set own MAC address "
  875. "(Calling-Station-Id,\n"
  876. " default: 02:00:00:00:00:01)\n"
  877. " -N<attr spec> = send arbitrary attribute specified by:\n"
  878. " attr_id:syntax:value or attr_id\n"
  879. " attr_id - number id of the attribute\n"
  880. " syntax - one of: s, d, x\n"
  881. " s = string\n"
  882. " d = integer\n"
  883. " x = octet string\n"
  884. " value - attribute value.\n"
  885. " When only attr_id is specified, NULL will be used as "
  886. "value.\n"
  887. " Multiple attributes can be specified by using the "
  888. "option several times.\n");
  889. }
  890. int main(int argc, char *argv[])
  891. {
  892. struct wpa_supplicant wpa_s;
  893. int c, ret = 1, wait_for_monitor = 0, save_config = 0;
  894. char *as_addr = "127.0.0.1";
  895. int as_port = 1812;
  896. char *as_secret = "radius";
  897. char *cli_addr = NULL;
  898. char *conf = NULL;
  899. int timeout = 30;
  900. char *pos;
  901. struct extra_radius_attr *p = NULL, *p1;
  902. if (os_program_init())
  903. return -1;
  904. hostapd_logger_register_cb(hostapd_logger_cb);
  905. os_memset(&eapol_test, 0, sizeof(eapol_test));
  906. eapol_test.connect_info = "CONNECT 11Mbps 802.11b";
  907. os_memcpy(eapol_test.own_addr, "\x02\x00\x00\x00\x00\x01", ETH_ALEN);
  908. wpa_debug_level = 0;
  909. wpa_debug_show_keys = 1;
  910. for (;;) {
  911. c = getopt(argc, argv, "a:A:c:C:M:nN:p:r:s:St:W");
  912. if (c < 0)
  913. break;
  914. switch (c) {
  915. case 'a':
  916. as_addr = optarg;
  917. break;
  918. case 'A':
  919. cli_addr = optarg;
  920. break;
  921. case 'c':
  922. conf = optarg;
  923. break;
  924. case 'C':
  925. eapol_test.connect_info = optarg;
  926. break;
  927. case 'M':
  928. if (hwaddr_aton(optarg, eapol_test.own_addr)) {
  929. usage();
  930. return -1;
  931. }
  932. break;
  933. case 'n':
  934. eapol_test.no_mppe_keys++;
  935. break;
  936. case 'p':
  937. as_port = atoi(optarg);
  938. break;
  939. case 'r':
  940. eapol_test.eapol_test_num_reauths = atoi(optarg);
  941. break;
  942. case 's':
  943. as_secret = optarg;
  944. break;
  945. case 'S':
  946. save_config++;
  947. break;
  948. case 't':
  949. timeout = atoi(optarg);
  950. break;
  951. case 'W':
  952. wait_for_monitor++;
  953. break;
  954. case 'N':
  955. p1 = os_zalloc(sizeof(p1));
  956. if (p1 == NULL)
  957. break;
  958. if (!p)
  959. eapol_test.extra_attrs = p1;
  960. else
  961. p->next = p1;
  962. p = p1;
  963. p->type = atoi(optarg);
  964. pos = os_strchr(optarg, ':');
  965. if (pos == NULL) {
  966. p->syntax = 'n';
  967. p->data = NULL;
  968. break;
  969. }
  970. pos++;
  971. if (pos[0] == '\0' || pos[1] != ':') {
  972. printf("Incorrect format of attribute "
  973. "specification\n");
  974. break;
  975. }
  976. p->syntax = pos[0];
  977. p->data = pos + 2;
  978. break;
  979. default:
  980. usage();
  981. return -1;
  982. }
  983. }
  984. if (argc > optind && os_strcmp(argv[optind], "scard") == 0) {
  985. return scard_test();
  986. }
  987. if (argc > optind && os_strcmp(argv[optind], "sim") == 0) {
  988. return scard_get_triplets(argc - optind - 1,
  989. &argv[optind + 1]);
  990. }
  991. if (conf == NULL) {
  992. usage();
  993. printf("Configuration file is required.\n");
  994. return -1;
  995. }
  996. if (eap_register_methods()) {
  997. wpa_printf(MSG_ERROR, "Failed to register EAP methods");
  998. return -1;
  999. }
  1000. if (eloop_init()) {
  1001. wpa_printf(MSG_ERROR, "Failed to initialize event loop");
  1002. return -1;
  1003. }
  1004. os_memset(&wpa_s, 0, sizeof(wpa_s));
  1005. eapol_test.wpa_s = &wpa_s;
  1006. wpa_s.conf = wpa_config_read(conf);
  1007. if (wpa_s.conf == NULL) {
  1008. printf("Failed to parse configuration file '%s'.\n", conf);
  1009. return -1;
  1010. }
  1011. if (wpa_s.conf->ssid == NULL) {
  1012. printf("No networks defined.\n");
  1013. return -1;
  1014. }
  1015. wpa_init_conf(&eapol_test, &wpa_s, as_addr, as_port, as_secret,
  1016. cli_addr);
  1017. wpa_s.ctrl_iface = wpa_supplicant_ctrl_iface_init(&wpa_s);
  1018. if (wpa_s.ctrl_iface == NULL) {
  1019. printf("Failed to initialize control interface '%s'.\n"
  1020. "You may have another eapol_test process already "
  1021. "running or the file was\n"
  1022. "left by an unclean termination of eapol_test in "
  1023. "which case you will need\n"
  1024. "to manually remove this file before starting "
  1025. "eapol_test again.\n",
  1026. wpa_s.conf->ctrl_interface);
  1027. return -1;
  1028. }
  1029. if (wpa_supplicant_scard_init(&wpa_s, wpa_s.conf->ssid))
  1030. return -1;
  1031. if (test_eapol(&eapol_test, &wpa_s, wpa_s.conf->ssid))
  1032. return -1;
  1033. if (wait_for_monitor)
  1034. wpa_supplicant_ctrl_iface_wait(wpa_s.ctrl_iface);
  1035. eloop_register_timeout(timeout, 0, eapol_test_timeout, &eapol_test,
  1036. NULL);
  1037. eloop_register_timeout(0, 0, send_eap_request_identity, &wpa_s, NULL);
  1038. eloop_register_signal_terminate(eapol_test_terminate, &wpa_s);
  1039. eloop_register_signal_reconfig(eapol_test_terminate, &wpa_s);
  1040. eloop_run();
  1041. eloop_cancel_timeout(eapol_test_timeout, &eapol_test, NULL);
  1042. eloop_cancel_timeout(eapol_sm_reauth, &eapol_test, NULL);
  1043. if (eapol_test_compare_pmk(&eapol_test) == 0 ||
  1044. eapol_test.no_mppe_keys)
  1045. ret = 0;
  1046. if (eapol_test.auth_timed_out)
  1047. ret = -2;
  1048. if (eapol_test.radius_access_reject_received)
  1049. ret = -3;
  1050. if (save_config)
  1051. wpa_config_write(conf, wpa_s.conf);
  1052. test_eapol_clean(&eapol_test, &wpa_s);
  1053. eap_peer_unregister_methods();
  1054. #ifdef CONFIG_AP
  1055. eap_server_unregister_methods();
  1056. #endif /* CONFIG_AP */
  1057. eloop_destroy();
  1058. printf("MPPE keys OK: %d mismatch: %d\n",
  1059. eapol_test.num_mppe_ok, eapol_test.num_mppe_mismatch);
  1060. if (eapol_test.num_mppe_mismatch)
  1061. ret = -4;
  1062. if (ret)
  1063. printf("FAILURE\n");
  1064. else
  1065. printf("SUCCESS\n");
  1066. os_program_deinit();
  1067. return ret;
  1068. }