2 * WPA Supplicant - test code
3 * Copyright (c) 2003-2006, Jouni Malinen <jkmaline@cc.hut.fi>
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.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
14 * IEEE 802.1X Supplicant test code (to be used in place of wpa_supplicant.c.
15 * Not used in production version.
25 #ifndef CONFIG_NATIVE_WINDOWS
26 #include <netinet/in.h>
27 #include <arpa/inet.h>
28 #endif /* CONFIG_NATIVE_WINDOWS */
37 #include "wpa_supplicant.h"
38 #include "wpa_supplicant_i.h"
40 #include "radius_client.h"
41 #include "l2_packet.h"
42 #include "ctrl_iface.h"
43 #include "pcsc_funcs.h"
46 extern int wpa_debug_level;
47 extern int wpa_debug_show_keys;
49 struct wpa_driver_ops *wpa_supplicant_drivers[] = { };
52 struct eapol_test_data {
53 struct wpa_supplicant *wpa_s;
55 int eapol_test_num_reauths;
57 int num_mppe_ok, num_mppe_mismatch;
60 struct radius_msg *last_recv_radius;
61 struct in_addr own_ip_addr;
62 struct radius_client_data *radius;
63 struct hostapd_radius_servers *radius_conf;
65 u8 *last_eap_radius; /* last received EAP Response from Authentication
67 size_t last_eap_radius_len;
69 u8 authenticator_pmk[PMK_LEN];
70 size_t authenticator_pmk_len;
71 int radius_access_accept_received;
72 int radius_access_reject_received;
76 size_t eap_identity_len;
79 static struct eapol_test_data eapol_test;
82 static void send_eap_request_identity(void *eloop_ctx, void *timeout_ctx);
85 void hostapd_logger(void *ctx, u8 *addr, unsigned int module, int level,
92 maxlen = strlen(fmt) + 100;
93 format = malloc(maxlen);
101 snprintf(format, maxlen, "STA " MACSTR ": %s",
104 snprintf(format, maxlen, "%s", fmt);
115 const char * hostapd_ip_txt(const struct hostapd_ip_addr *addr, char *buf,
118 if (buflen == 0 || addr == NULL)
121 if (addr->af == AF_INET) {
122 snprintf(buf, buflen, "%s", inet_ntoa(addr->u.v4));
127 if (addr->af == AF_INET6) {
128 if (inet_ntop(AF_INET6, &addr->u.v6, buf, buflen) == NULL)
131 #endif /* CONFIG_IPV6 */
137 static void ieee802_1x_encapsulate_radius(struct eapol_test_data *e,
138 const u8 *eap, size_t len)
140 struct radius_msg *msg;
142 const struct eap_hdr *hdr;
145 wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS "
148 e->radius_identifier = radius_client_get_id(e->radius);
149 msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST,
150 e->radius_identifier);
152 printf("Could not create net RADIUS packet\n");
156 radius_msg_make_authenticator(msg, (u8 *) e, sizeof(*e));
158 hdr = (const struct eap_hdr *) eap;
159 pos = (const u8 *) (hdr + 1);
160 if (len > sizeof(*hdr) && hdr->code == EAP_CODE_RESPONSE &&
161 pos[0] == EAP_TYPE_IDENTITY) {
163 free(e->eap_identity);
164 e->eap_identity_len = len - sizeof(*hdr) - 1;
165 e->eap_identity = malloc(e->eap_identity_len);
166 if (e->eap_identity) {
167 memcpy(e->eap_identity, pos, e->eap_identity_len);
168 wpa_hexdump(MSG_DEBUG, "Learned identity from "
169 "EAP-Response-Identity",
170 e->eap_identity, e->eap_identity_len);
174 if (e->eap_identity &&
175 !radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME,
176 e->eap_identity, e->eap_identity_len)) {
177 printf("Could not add User-Name\n");
181 if (!radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS,
182 (u8 *) &e->own_ip_addr, 4)) {
183 printf("Could not add NAS-IP-Address\n");
187 snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
188 MAC2STR(e->wpa_s->own_addr));
189 if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
190 (u8 *) buf, strlen(buf))) {
191 printf("Could not add Calling-Station-Id\n");
195 /* TODO: should probably check MTU from driver config; 2304 is max for
196 * IEEE 802.11, but use 1400 to avoid problems with too large packets
198 if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) {
199 printf("Could not add Framed-MTU\n");
203 if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE,
204 RADIUS_NAS_PORT_TYPE_IEEE_802_11)) {
205 printf("Could not add NAS-Port-Type\n");
209 snprintf(buf, sizeof(buf), "CONNECT 11Mbps 802.11b");
210 if (!radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
211 (u8 *) buf, strlen(buf))) {
212 printf("Could not add Connect-Info\n");
216 if (eap && !radius_msg_add_eap(msg, eap, len)) {
217 printf("Could not add EAP-Message\n");
221 /* State attribute must be copied if and only if this packet is
222 * Access-Request reply to the previous Access-Challenge */
223 if (e->last_recv_radius && e->last_recv_radius->hdr->code ==
224 RADIUS_CODE_ACCESS_CHALLENGE) {
225 int res = radius_msg_copy_attr(msg, e->last_recv_radius,
228 printf("Could not copy State attribute from previous "
229 "Access-Challenge\n");
233 wpa_printf(MSG_DEBUG, " Copied RADIUS State "
238 radius_client_send(e->radius, msg, RADIUS_AUTH, e->wpa_s->own_addr);
242 radius_msg_free(msg);
247 static int eapol_test_eapol_send(void *ctx, int type, const u8 *buf,
250 /* struct wpa_supplicant *wpa_s = ctx; */
251 printf("WPA: eapol_test_eapol_send(type=%d len=%d)\n", type, len);
252 if (type == IEEE802_1X_TYPE_EAP_PACKET) {
253 wpa_hexdump(MSG_DEBUG, "TX EAP -> RADIUS", buf, len);
254 ieee802_1x_encapsulate_radius(&eapol_test, buf, len);
260 static void eapol_test_set_config_blob(void *ctx,
261 struct wpa_config_blob *blob)
263 struct wpa_supplicant *wpa_s = ctx;
264 wpa_config_set_blob(wpa_s->conf, blob);
268 static const struct wpa_config_blob *
269 eapol_test_get_config_blob(void *ctx, const char *name)
271 struct wpa_supplicant *wpa_s = ctx;
272 return wpa_config_get_blob(wpa_s->conf, name);
276 static void eapol_test_eapol_done_cb(void *ctx)
278 printf("WPA: EAPOL processing complete\n");
282 static void eapol_sm_reauth(void *eloop_ctx, void *timeout_ctx)
284 struct eapol_test_data *e = eloop_ctx;
285 printf("\n\n\n\n\neapol_test: Triggering EAP reauthentication\n\n");
286 e->radius_access_accept_received = 0;
287 send_eap_request_identity(e->wpa_s, NULL);
291 static int eapol_test_compare_pmk(struct eapol_test_data *e)
296 if (eapol_sm_get_key(e->wpa_s->eapol, pmk, PMK_LEN) == 0) {
297 wpa_hexdump(MSG_DEBUG, "PMK from EAPOL", pmk, PMK_LEN);
298 if (memcmp(pmk, e->authenticator_pmk, PMK_LEN) != 0)
299 printf("WARNING: PMK mismatch\n");
300 else if (e->radius_access_accept_received)
302 } else if (e->authenticator_pmk_len == 16 &&
303 eapol_sm_get_key(e->wpa_s->eapol, pmk, 16) == 0) {
304 wpa_hexdump(MSG_DEBUG, "LEAP PMK from EAPOL", pmk, 16);
305 if (memcmp(pmk, e->authenticator_pmk, 16) != 0)
306 printf("WARNING: PMK mismatch\n");
307 else if (e->radius_access_accept_received)
309 } else if (e->radius_access_accept_received && e->no_mppe_keys) {
310 /* No keying material expected */
315 e->num_mppe_mismatch++;
316 else if (!e->no_mppe_keys)
323 static void eapol_sm_cb(struct eapol_sm *eapol, int success, void *ctx)
325 struct eapol_test_data *e = ctx;
326 printf("eapol_sm_cb: success=%d\n", success);
327 e->eapol_test_num_reauths--;
328 if (e->eapol_test_num_reauths < 0)
331 eapol_test_compare_pmk(e);
332 eloop_register_timeout(0, 100000, eapol_sm_reauth, e, NULL);
337 static int test_eapol(struct eapol_test_data *e, struct wpa_supplicant *wpa_s,
338 struct wpa_ssid *ssid)
340 struct eapol_config eapol_conf;
341 struct eapol_ctx *ctx;
343 ctx = malloc(sizeof(*ctx));
345 printf("Failed to allocate EAPOL context.\n");
348 memset(ctx, 0, sizeof(*ctx));
350 ctx->msg_ctx = wpa_s;
351 ctx->scard_ctx = wpa_s->scard;
352 ctx->cb = eapol_sm_cb;
354 ctx->eapol_send_ctx = wpa_s;
356 ctx->eapol_done_cb = eapol_test_eapol_done_cb;
357 ctx->eapol_send = eapol_test_eapol_send;
358 ctx->set_config_blob = eapol_test_set_config_blob;
359 ctx->get_config_blob = eapol_test_get_config_blob;
360 ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
361 ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
362 ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
364 wpa_s->eapol = eapol_sm_init(ctx);
365 if (wpa_s->eapol == NULL) {
367 printf("Failed to initialize EAPOL state machines.\n");
371 wpa_s->current_ssid = ssid;
372 memset(&eapol_conf, 0, sizeof(eapol_conf));
373 eapol_conf.accept_802_1x_keys = 1;
374 eapol_conf.required_keys = 0;
375 eapol_conf.fast_reauth = wpa_s->conf->fast_reauth;
376 eapol_conf.workaround = ssid->eap_workaround;
377 eapol_sm_notify_config(wpa_s->eapol, ssid, &eapol_conf);
378 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
381 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
382 /* 802.1X::portControl = Auto */
383 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
389 static void test_eapol_clean(struct eapol_test_data *e,
390 struct wpa_supplicant *wpa_s)
392 radius_client_deinit(e->radius);
393 free(e->last_eap_radius);
394 if (e->last_recv_radius) {
395 radius_msg_free(e->last_recv_radius);
396 free(e->last_recv_radius);
398 free(e->eap_identity);
399 e->eap_identity = NULL;
400 eapol_sm_deinit(wpa_s->eapol);
402 if (e->radius_conf && e->radius_conf->auth_server) {
403 free(e->radius_conf->auth_server->shared_secret);
404 free(e->radius_conf->auth_server);
406 free(e->radius_conf);
407 e->radius_conf = NULL;
408 scard_deinit(wpa_s->scard);
409 wpa_supplicant_ctrl_iface_deinit(wpa_s);
410 wpa_config_free(wpa_s->conf);
414 static void send_eap_request_identity(void *eloop_ctx, void *timeout_ctx)
416 struct wpa_supplicant *wpa_s = eloop_ctx;
418 struct ieee802_1x_hdr *hdr;
421 hdr = (struct ieee802_1x_hdr *) buf;
422 hdr->version = EAPOL_VERSION;
423 hdr->type = IEEE802_1X_TYPE_EAP_PACKET;
424 hdr->length = htons(5);
426 eap = (struct eap_hdr *) (hdr + 1);
427 eap->code = EAP_CODE_REQUEST;
429 eap->length = htons(5);
430 pos = (u8 *) (eap + 1);
431 *pos = EAP_TYPE_IDENTITY;
433 printf("Sending fake EAP-Request-Identity\n");
434 eapol_sm_rx_eapol(wpa_s->eapol, wpa_s->bssid, buf,
439 static void eapol_test_timeout(void *eloop_ctx, void *timeout_ctx)
441 struct eapol_test_data *e = eloop_ctx;
442 printf("EAPOL test timed out\n");
443 e->auth_timed_out = 1;
448 static char *eap_type_text(u8 type)
451 case EAP_TYPE_IDENTITY: return "Identity";
452 case EAP_TYPE_NOTIFICATION: return "Notification";
453 case EAP_TYPE_NAK: return "Nak";
454 case EAP_TYPE_TLS: return "TLS";
455 case EAP_TYPE_TTLS: return "TTLS";
456 case EAP_TYPE_PEAP: return "PEAP";
457 case EAP_TYPE_SIM: return "SIM";
458 case EAP_TYPE_GTC: return "GTC";
459 case EAP_TYPE_MD5: return "MD5";
460 case EAP_TYPE_OTP: return "OTP";
461 default: return "Unknown";
466 static void ieee802_1x_decapsulate_radius(struct eapol_test_data *e)
473 struct radius_msg *msg;
475 if (e->last_recv_radius == NULL)
478 msg = e->last_recv_radius;
480 eap = radius_msg_get_eap(msg, &len);
482 /* draft-aboba-radius-rfc2869bis-20.txt, Chap. 2.6.3:
483 * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
485 wpa_printf(MSG_DEBUG, "could not extract "
486 "EAP-Message from RADIUS message");
487 free(e->last_eap_radius);
488 e->last_eap_radius = NULL;
489 e->last_eap_radius_len = 0;
493 if (len < sizeof(*hdr)) {
494 wpa_printf(MSG_DEBUG, "too short EAP packet "
495 "received from authentication server");
500 if (len > sizeof(*hdr))
501 eap_type = eap[sizeof(*hdr)];
503 hdr = (struct eap_hdr *) eap;
505 case EAP_CODE_REQUEST:
506 snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
507 eap_type >= 0 ? eap_type_text(eap_type) : "??",
510 case EAP_CODE_RESPONSE:
511 snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
512 eap_type >= 0 ? eap_type_text(eap_type) : "??",
515 case EAP_CODE_SUCCESS:
516 snprintf(buf, sizeof(buf), "EAP Success");
517 /* LEAP uses EAP Success within an authentication, so must not
518 * stop here with eloop_terminate(); */
520 case EAP_CODE_FAILURE:
521 snprintf(buf, sizeof(buf), "EAP Failure");
525 snprintf(buf, sizeof(buf), "unknown EAP code");
526 wpa_hexdump(MSG_DEBUG, "Decapsulated EAP packet", eap, len);
529 wpa_printf(MSG_DEBUG, "decapsulated EAP packet (code=%d "
530 "id=%d len=%d) from RADIUS server: %s",
531 hdr->code, hdr->identifier, ntohs(hdr->length), buf);
533 /* sta->eapol_sm->be_auth.idFromServer = hdr->identifier; */
535 free(e->last_eap_radius);
536 e->last_eap_radius = eap;
537 e->last_eap_radius_len = len;
540 struct ieee802_1x_hdr *hdr;
541 hdr = malloc(sizeof(*hdr) + len);
543 hdr->version = EAPOL_VERSION;
544 hdr->type = IEEE802_1X_TYPE_EAP_PACKET;
545 hdr->length = htons(len);
546 memcpy((u8 *) (hdr + 1), eap, len);
547 eapol_sm_rx_eapol(e->wpa_s->eapol, e->wpa_s->bssid,
548 (u8 *) hdr, sizeof(*hdr) + len);
554 static void ieee802_1x_get_keys(struct eapol_test_data *e,
555 struct radius_msg *msg, struct radius_msg *req,
556 u8 *shared_secret, size_t shared_secret_len)
558 struct radius_ms_mppe_keys *keys;
560 keys = radius_msg_get_ms_keys(msg, req, shared_secret,
562 if (keys && keys->send == NULL && keys->recv == NULL) {
564 keys = radius_msg_get_cisco_keys(msg, req, shared_secret,
570 wpa_hexdump(MSG_DEBUG, "MS-MPPE-Send-Key (sign)",
571 keys->send, keys->send_len);
574 wpa_hexdump(MSG_DEBUG, "MS-MPPE-Recv-Key (crypt)",
575 keys->recv, keys->recv_len);
576 e->authenticator_pmk_len =
577 keys->recv_len > PMK_LEN ? PMK_LEN :
579 memcpy(e->authenticator_pmk, keys->recv,
580 e->authenticator_pmk_len);
590 /* Process the RADIUS frames from Authentication Server */
591 static RadiusRxResult
592 ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
593 u8 *shared_secret, size_t shared_secret_len,
596 struct eapol_test_data *e = data;
598 /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
599 * present when packet contains an EAP-Message attribute */
600 if (msg->hdr->code == RADIUS_CODE_ACCESS_REJECT &&
601 radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
603 radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
604 wpa_printf(MSG_DEBUG, "Allowing RADIUS "
605 "Access-Reject without Message-Authenticator "
606 "since it does not include EAP-Message\n");
607 } else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
609 printf("Incoming RADIUS packet did not have correct "
610 "Message-Authenticator - dropped\n");
611 return RADIUS_RX_UNKNOWN;
614 if (msg->hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
615 msg->hdr->code != RADIUS_CODE_ACCESS_REJECT &&
616 msg->hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
617 printf("Unknown RADIUS message code\n");
618 return RADIUS_RX_UNKNOWN;
621 e->radius_identifier = -1;
622 wpa_printf(MSG_DEBUG, "RADIUS packet matching with station");
624 if (e->last_recv_radius) {
625 radius_msg_free(e->last_recv_radius);
626 free(e->last_recv_radius);
629 e->last_recv_radius = msg;
631 switch (msg->hdr->code) {
632 case RADIUS_CODE_ACCESS_ACCEPT:
633 e->radius_access_accept_received = 1;
634 ieee802_1x_get_keys(e, msg, req, shared_secret,
637 case RADIUS_CODE_ACCESS_REJECT:
638 e->radius_access_reject_received = 1;
642 ieee802_1x_decapsulate_radius(e);
644 if ((msg->hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
645 e->eapol_test_num_reauths < 0) ||
646 msg->hdr->code == RADIUS_CODE_ACCESS_REJECT) {
650 return RADIUS_RX_QUEUED;
654 static void wpa_init_conf(struct eapol_test_data *e,
655 struct wpa_supplicant *wpa_s, const char *authsrv,
656 int port, const char *secret)
658 struct hostapd_radius_server *as;
662 wpa_s->own_addr[5] = 2;
663 e->own_ip_addr.s_addr = htonl((127 << 24) | 1);
664 strncpy(wpa_s->ifname, "test", sizeof(wpa_s->ifname));
666 e->radius_conf = malloc(sizeof(struct hostapd_radius_servers));
667 assert(e->radius_conf != NULL);
668 memset(e->radius_conf, 0, sizeof(struct hostapd_radius_servers));
669 e->radius_conf->num_auth_servers = 1;
670 as = malloc(sizeof(struct hostapd_radius_server));
672 memset(as, 0, sizeof(*as));
673 #ifdef CONFIG_NATIVE_WINDOWS
677 sscanf(authsrv, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
678 pos = (u8 *) &as->addr.u.v4;
684 #else /* CONFIG_NATIVE_WINDOWS */
685 inet_aton(authsrv, &as->addr.u.v4);
686 #endif /* CONFIG_NATIVE_WINDOWS */
687 as->addr.af = AF_INET;
689 as->shared_secret = (u8 *) strdup(secret);
690 as->shared_secret_len = strlen(secret);
691 e->radius_conf->auth_server = as;
692 e->radius_conf->auth_servers = as;
693 e->radius_conf->msg_dumps = 1;
695 e->radius = radius_client_init(wpa_s, e->radius_conf);
696 assert(e->radius != NULL);
698 res = radius_client_register(e->radius, RADIUS_AUTH,
699 ieee802_1x_receive_auth, e);
704 static int scard_test(void)
706 struct scard_data *scard;
709 unsigned char rand[16];
711 unsigned char sres[4];
713 #endif /* PCSC_FUNCS */
714 #define num_triplets 5
715 unsigned char rand_[num_triplets][16];
716 unsigned char sres_[num_triplets][4];
717 unsigned char kc_[num_triplets][8];
720 #define AKA_RAND_LEN 16
721 #define AKA_AUTN_LEN 16
722 #define AKA_AUTS_LEN 14
723 #define RES_MAX_LEN 16
726 unsigned char aka_rand[AKA_RAND_LEN];
727 unsigned char aka_autn[AKA_AUTN_LEN];
728 unsigned char aka_auts[AKA_AUTS_LEN];
729 unsigned char aka_res[RES_MAX_LEN];
731 unsigned char aka_ik[IK_LEN];
732 unsigned char aka_ck[CK_LEN];
734 scard = scard_init(SCARD_TRY_BOTH);
737 if (scard_set_pin(scard, "1234")) {
738 wpa_printf(MSG_WARNING, "PIN validation failed");
744 if (scard_get_imsi(scard, imsi, &len))
746 wpa_hexdump_ascii(MSG_DEBUG, "SCARD: IMSI", (u8 *) imsi, len);
747 /* NOTE: Permanent Username: 1 | IMSI */
749 memset(rand, 0, sizeof(rand));
750 if (scard_gsm_auth(scard, rand, sres, kc))
753 memset(rand, 0xff, sizeof(rand));
754 if (scard_gsm_auth(scard, rand, sres, kc))
757 for (i = 0; i < num_triplets; i++) {
758 memset(rand_[i], i, sizeof(rand_[i]));
759 if (scard_gsm_auth(scard, rand_[i], sres_[i], kc_[i]))
763 for (i = 0; i < num_triplets; i++) {
765 for (j = 0; j < len; j++)
766 printf("%c", imsi[j]);
768 for (j = 0; j < 16; j++)
769 printf("%02X", rand_[i][j]);
771 for (j = 0; j < 4; j++)
772 printf("%02X", sres_[i][j]);
774 for (j = 0; j < 8; j++)
775 printf("%02X", kc_[i][j]);
779 wpa_printf(MSG_DEBUG, "Trying to use UMTS authentication");
782 memset(aka_rand, 0xaa, 16);
783 memcpy(aka_autn, "\x86\x71\x31\xcb\xa2\xfc\x61\xdf"
784 "\xa3\xb3\x97\x9d\x07\x32\xa2\x12", 16);
786 res = scard_umts_auth(scard, aka_rand, aka_autn, aka_res, &aka_res_len,
787 aka_ik, aka_ck, aka_auts);
789 wpa_printf(MSG_DEBUG, "UMTS auth completed successfully");
790 wpa_hexdump(MSG_DEBUG, "RES", aka_res, aka_res_len);
791 wpa_hexdump(MSG_DEBUG, "IK", aka_ik, IK_LEN);
792 wpa_hexdump(MSG_DEBUG, "CK", aka_ck, CK_LEN);
793 } else if (res == -2) {
794 wpa_printf(MSG_DEBUG, "UMTS auth resulted in synchronization "
796 wpa_hexdump(MSG_DEBUG, "AUTS", aka_auts, AKA_AUTS_LEN);
798 wpa_printf(MSG_DEBUG, "UMTS auth failed");
809 static int scard_get_triplets(int argc, char *argv[])
811 struct scard_data *scard;
814 unsigned char rand[16];
815 unsigned char sres[4];
820 if (argc < 2 || ((num_triplets = atoi(argv[1])) <= 0)) {
821 printf("invalid parameters for sim command\n");
825 if (argc <= 2 || strcmp(argv[2], "debug") != 0) {
826 /* disable debug output */
827 wpa_debug_level = 99;
830 scard = scard_init(SCARD_GSM_SIM_ONLY);
832 printf("Failed to open smartcard connection\n");
835 if (scard_set_pin(scard, argv[0])) {
836 wpa_printf(MSG_WARNING, "PIN validation failed");
842 if (scard_get_imsi(scard, imsi, &len)) {
847 for (i = 0; i < num_triplets; i++) {
848 memset(rand, i, sizeof(rand));
849 if (scard_gsm_auth(scard, rand, sres, kc))
852 /* IMSI:Kc:SRES:RAND */
853 for (j = 0; j < len; j++)
854 printf("%c", imsi[j]);
856 for (j = 0; j < 8; j++)
857 printf("%02X", kc[j]);
859 for (j = 0; j < 4; j++)
860 printf("%02X", sres[j]);
862 for (j = 0; j < 16; j++)
863 printf("%02X", rand[j]);
873 static void eapol_test_terminate(int sig, void *eloop_ctx,
876 struct wpa_supplicant *wpa_s = eloop_ctx;
877 wpa_msg(wpa_s, MSG_INFO, "Signal %d received - terminating", sig);
882 static void usage(void)
885 "eapol_test [-nWS] -c<conf> [-a<AS IP>] [-p<AS port>] "
886 "[-s<AS secret>] [-r<count>]\n"
888 "eapol_test sim <PIN> <num triplets> [debug]\n"
891 " -c<conf> = configuration file\n"
892 " -a<AS IP> = IP address of the authentication server, "
893 "default 127.0.0.1\n"
894 " -p<AS port> = UDP port of the authentication server, "
896 " -s<AS secret> = shared secret with the authentication "
897 "server, default 'radius'\n"
898 " -r<count> = number of re-authentications\n"
899 " -W = wait for a control interface monitor before starting\n"
900 " -S = save configuration after authentiation\n"
901 " -n = no MPPE keys expected\n");
905 int main(int argc, char *argv[])
907 struct wpa_supplicant wpa_s;
908 int c, ret = 1, wait_for_monitor = 0, save_config = 0;
909 char *as_addr = "127.0.0.1";
911 char *as_secret = "radius";
914 #ifdef CONFIG_NATIVE_WINDOWS
916 if (WSAStartup(MAKEWORD(2, 0), &wsaData)) {
917 printf("Could not find a usable WinSock.dll\n");
920 #endif /* CONFIG_NATIVE_WINDOWS */
922 memset(&eapol_test, 0, sizeof(eapol_test));
925 wpa_debug_show_keys = 1;
928 c = getopt(argc, argv, "a:c:np:r:s:SW");
939 eapol_test.no_mppe_keys++;
942 as_port = atoi(optarg);
945 eapol_test.eapol_test_num_reauths = atoi(optarg);
962 if (argc > optind && strcmp(argv[optind], "scard") == 0) {
966 if (argc > optind && strcmp(argv[optind], "sim") == 0) {
967 return scard_get_triplets(argc - optind - 1,
973 printf("Configuration file is required.\n");
979 memset(&wpa_s, 0, sizeof(wpa_s));
980 eapol_test.wpa_s = &wpa_s;
981 wpa_s.conf = wpa_config_read(conf);
982 if (wpa_s.conf == NULL) {
983 printf("Failed to parse configuration file '%s'.\n", conf);
986 if (wpa_s.conf->ssid == NULL) {
987 printf("No networks defined.\n");
991 wpa_init_conf(&eapol_test, &wpa_s, as_addr, as_port, as_secret);
992 if (wpa_supplicant_ctrl_iface_init(&wpa_s)) {
993 printf("Failed to initialize control interface '%s'.\n"
994 "You may have another eapol_test process already "
995 "running or the file was\n"
996 "left by an unclean termination of eapol_test in "
997 "which case you will need\n"
998 "to manually remove this file before starting "
999 "eapol_test again.\n",
1000 wpa_s.conf->ctrl_interface);
1003 if (wpa_supplicant_scard_init(&wpa_s, wpa_s.conf->ssid))
1006 if (test_eapol(&eapol_test, &wpa_s, wpa_s.conf->ssid))
1009 if (wait_for_monitor)
1010 wpa_supplicant_ctrl_iface_wait(&wpa_s);
1012 eloop_register_timeout(30, 0, eapol_test_timeout, &eapol_test, NULL);
1013 eloop_register_timeout(0, 0, send_eap_request_identity, &wpa_s, NULL);
1014 eloop_register_signal(SIGINT, eapol_test_terminate, NULL);
1015 eloop_register_signal(SIGTERM, eapol_test_terminate, NULL);
1016 #ifndef CONFIG_NATIVE_WINDOWS
1017 eloop_register_signal(SIGHUP, eapol_test_terminate, NULL);
1018 #endif /* CONFIG_NATIVE_WINDOWS */
1021 if (eapol_test_compare_pmk(&eapol_test) == 0)
1023 if (eapol_test.auth_timed_out)
1025 if (eapol_test.radius_access_reject_received)
1029 wpa_config_write(conf, wpa_s.conf);
1031 test_eapol_clean(&eapol_test, &wpa_s);
1035 printf("MPPE keys OK: %d mismatch: %d\n",
1036 eapol_test.num_mppe_ok, eapol_test.num_mppe_mismatch);
1037 if (eapol_test.num_mppe_mismatch)
1040 printf("FAILURE\n");
1042 printf("SUCCESS\n");
1044 #ifdef CONFIG_NATIVE_WINDOWS
1046 #endif /* CONFIG_NATIVE_WINDOWS */