2 * WPA Supplicant - test code
3 * Copyright (c) 2003-2006, Jouni Malinen <j@w1.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.
28 #include "wpa_supplicant.h"
29 #include "wpa_supplicant_i.h"
31 #include "radius_client.h"
32 #include "l2_packet.h"
33 #include "ctrl_iface.h"
34 #include "pcsc_funcs.h"
37 extern int wpa_debug_level;
38 extern int wpa_debug_show_keys;
40 struct wpa_driver_ops *wpa_supplicant_drivers[] = { NULL };
43 struct eapol_test_data {
44 struct wpa_supplicant *wpa_s;
46 int eapol_test_num_reauths;
48 int num_mppe_ok, num_mppe_mismatch;
51 struct radius_msg *last_recv_radius;
52 struct in_addr own_ip_addr;
53 struct radius_client_data *radius;
54 struct hostapd_radius_servers *radius_conf;
56 u8 *last_eap_radius; /* last received EAP Response from Authentication
58 size_t last_eap_radius_len;
60 u8 authenticator_pmk[PMK_LEN];
61 size_t authenticator_pmk_len;
62 int radius_access_accept_received;
63 int radius_access_reject_received;
67 size_t eap_identity_len;
70 u8 own_addr[ETH_ALEN];
73 static struct eapol_test_data eapol_test;
76 static void send_eap_request_identity(void *eloop_ctx, void *timeout_ctx);
79 void hostapd_logger(void *ctx, const u8 *addr, unsigned int module, int level,
86 maxlen = os_strlen(fmt) + 100;
87 format = os_malloc(maxlen);
95 os_snprintf(format, maxlen, "STA " MACSTR ": %s",
98 os_snprintf(format, maxlen, "%s", fmt);
109 const char * hostapd_ip_txt(const struct hostapd_ip_addr *addr, char *buf,
112 if (buflen == 0 || addr == NULL)
115 if (addr->af == AF_INET) {
116 os_snprintf(buf, buflen, "%s", inet_ntoa(addr->u.v4));
121 if (addr->af == AF_INET6) {
122 if (inet_ntop(AF_INET6, &addr->u.v6, buf, buflen) == NULL)
125 #endif /* CONFIG_IPV6 */
131 int hostapd_ip_diff(struct hostapd_ip_addr *a, struct hostapd_ip_addr *b)
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 os_free(e->eap_identity);
164 e->eap_identity_len = len - sizeof(*hdr) - 1;
165 e->eap_identity = os_malloc(e->eap_identity_len);
166 if (e->eap_identity) {
167 os_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 os_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, os_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 os_snprintf(buf, sizeof(buf), "%s", e->connect_info);
210 if (!radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
211 (u8 *) buf, os_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 (os_memcmp(pmk, e->authenticator_pmk, PMK_LEN) != 0) {
299 printf("WARNING: PMK mismatch\n");
300 wpa_hexdump(MSG_DEBUG, "PMK from AS",
301 e->authenticator_pmk, PMK_LEN);
302 } else if (e->radius_access_accept_received)
304 } else if (e->authenticator_pmk_len == 16 &&
305 eapol_sm_get_key(e->wpa_s->eapol, pmk, 16) == 0) {
306 wpa_hexdump(MSG_DEBUG, "LEAP PMK from EAPOL", pmk, 16);
307 if (os_memcmp(pmk, e->authenticator_pmk, 16) != 0) {
308 printf("WARNING: PMK mismatch\n");
309 wpa_hexdump(MSG_DEBUG, "PMK from AS",
310 e->authenticator_pmk, 16);
311 } else if (e->radius_access_accept_received)
313 } else if (e->radius_access_accept_received && e->no_mppe_keys) {
314 /* No keying material expected */
318 if (ret && !e->no_mppe_keys)
319 e->num_mppe_mismatch++;
320 else if (!e->no_mppe_keys)
327 static void eapol_sm_cb(struct eapol_sm *eapol, int success, void *ctx)
329 struct eapol_test_data *e = ctx;
330 printf("eapol_sm_cb: success=%d\n", success);
331 e->eapol_test_num_reauths--;
332 if (e->eapol_test_num_reauths < 0)
335 eapol_test_compare_pmk(e);
336 eloop_register_timeout(0, 100000, eapol_sm_reauth, e, NULL);
341 static int test_eapol(struct eapol_test_data *e, struct wpa_supplicant *wpa_s,
342 struct wpa_ssid *ssid)
344 struct eapol_config eapol_conf;
345 struct eapol_ctx *ctx;
347 ctx = os_zalloc(sizeof(*ctx));
349 printf("Failed to allocate EAPOL context.\n");
353 ctx->msg_ctx = wpa_s;
354 ctx->scard_ctx = wpa_s->scard;
355 ctx->cb = eapol_sm_cb;
357 ctx->eapol_send_ctx = wpa_s;
359 ctx->eapol_done_cb = eapol_test_eapol_done_cb;
360 ctx->eapol_send = eapol_test_eapol_send;
361 ctx->set_config_blob = eapol_test_set_config_blob;
362 ctx->get_config_blob = eapol_test_get_config_blob;
363 ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
364 ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
365 ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
367 wpa_s->eapol = eapol_sm_init(ctx);
368 if (wpa_s->eapol == NULL) {
370 printf("Failed to initialize EAPOL state machines.\n");
374 wpa_s->current_ssid = ssid;
375 os_memset(&eapol_conf, 0, sizeof(eapol_conf));
376 eapol_conf.accept_802_1x_keys = 1;
377 eapol_conf.required_keys = 0;
378 eapol_conf.fast_reauth = wpa_s->conf->fast_reauth;
379 eapol_conf.workaround = ssid->eap_workaround;
380 eapol_sm_notify_config(wpa_s->eapol, ssid, &eapol_conf);
381 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
384 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
385 /* 802.1X::portControl = Auto */
386 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
392 static void test_eapol_clean(struct eapol_test_data *e,
393 struct wpa_supplicant *wpa_s)
395 radius_client_deinit(e->radius);
396 os_free(e->last_eap_radius);
397 if (e->last_recv_radius) {
398 radius_msg_free(e->last_recv_radius);
399 os_free(e->last_recv_radius);
401 os_free(e->eap_identity);
402 e->eap_identity = NULL;
403 eapol_sm_deinit(wpa_s->eapol);
405 if (e->radius_conf && e->radius_conf->auth_server) {
406 os_free(e->radius_conf->auth_server->shared_secret);
407 os_free(e->radius_conf->auth_server);
409 os_free(e->radius_conf);
410 e->radius_conf = NULL;
411 scard_deinit(wpa_s->scard);
412 if (wpa_s->ctrl_iface) {
413 wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
414 wpa_s->ctrl_iface = NULL;
416 wpa_config_free(wpa_s->conf);
420 static void send_eap_request_identity(void *eloop_ctx, void *timeout_ctx)
422 struct wpa_supplicant *wpa_s = eloop_ctx;
424 struct ieee802_1x_hdr *hdr;
427 hdr = (struct ieee802_1x_hdr *) buf;
428 hdr->version = EAPOL_VERSION;
429 hdr->type = IEEE802_1X_TYPE_EAP_PACKET;
430 hdr->length = htons(5);
432 eap = (struct eap_hdr *) (hdr + 1);
433 eap->code = EAP_CODE_REQUEST;
435 eap->length = htons(5);
436 pos = (u8 *) (eap + 1);
437 *pos = EAP_TYPE_IDENTITY;
439 printf("Sending fake EAP-Request-Identity\n");
440 eapol_sm_rx_eapol(wpa_s->eapol, wpa_s->bssid, buf,
445 static void eapol_test_timeout(void *eloop_ctx, void *timeout_ctx)
447 struct eapol_test_data *e = eloop_ctx;
448 printf("EAPOL test timed out\n");
449 e->auth_timed_out = 1;
454 static char *eap_type_text(u8 type)
457 case EAP_TYPE_IDENTITY: return "Identity";
458 case EAP_TYPE_NOTIFICATION: return "Notification";
459 case EAP_TYPE_NAK: return "Nak";
460 case EAP_TYPE_TLS: return "TLS";
461 case EAP_TYPE_TTLS: return "TTLS";
462 case EAP_TYPE_PEAP: return "PEAP";
463 case EAP_TYPE_SIM: return "SIM";
464 case EAP_TYPE_GTC: return "GTC";
465 case EAP_TYPE_MD5: return "MD5";
466 case EAP_TYPE_OTP: return "OTP";
467 case EAP_TYPE_FAST: return "FAST";
468 case EAP_TYPE_SAKE: return "SAKE";
469 case EAP_TYPE_PSK: return "PSK";
470 default: return "Unknown";
475 static void ieee802_1x_decapsulate_radius(struct eapol_test_data *e)
482 struct radius_msg *msg;
484 if (e->last_recv_radius == NULL)
487 msg = e->last_recv_radius;
489 eap = radius_msg_get_eap(msg, &len);
491 /* draft-aboba-radius-rfc2869bis-20.txt, Chap. 2.6.3:
492 * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
494 wpa_printf(MSG_DEBUG, "could not extract "
495 "EAP-Message from RADIUS message");
496 os_free(e->last_eap_radius);
497 e->last_eap_radius = NULL;
498 e->last_eap_radius_len = 0;
502 if (len < sizeof(*hdr)) {
503 wpa_printf(MSG_DEBUG, "too short EAP packet "
504 "received from authentication server");
509 if (len > sizeof(*hdr))
510 eap_type = eap[sizeof(*hdr)];
512 hdr = (struct eap_hdr *) eap;
514 case EAP_CODE_REQUEST:
515 os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
516 eap_type >= 0 ? eap_type_text(eap_type) : "??",
519 case EAP_CODE_RESPONSE:
520 os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
521 eap_type >= 0 ? eap_type_text(eap_type) : "??",
524 case EAP_CODE_SUCCESS:
525 os_snprintf(buf, sizeof(buf), "EAP Success");
526 /* LEAP uses EAP Success within an authentication, so must not
527 * stop here with eloop_terminate(); */
529 case EAP_CODE_FAILURE:
530 os_snprintf(buf, sizeof(buf), "EAP Failure");
534 os_snprintf(buf, sizeof(buf), "unknown EAP code");
535 wpa_hexdump(MSG_DEBUG, "Decapsulated EAP packet", eap, len);
538 wpa_printf(MSG_DEBUG, "decapsulated EAP packet (code=%d "
539 "id=%d len=%d) from RADIUS server: %s",
540 hdr->code, hdr->identifier, ntohs(hdr->length), buf);
542 /* sta->eapol_sm->be_auth.idFromServer = hdr->identifier; */
544 os_free(e->last_eap_radius);
545 e->last_eap_radius = eap;
546 e->last_eap_radius_len = len;
549 struct ieee802_1x_hdr *dot1x;
550 dot1x = os_malloc(sizeof(*dot1x) + len);
551 assert(dot1x != NULL);
552 dot1x->version = EAPOL_VERSION;
553 dot1x->type = IEEE802_1X_TYPE_EAP_PACKET;
554 dot1x->length = htons(len);
555 os_memcpy((u8 *) (dot1x + 1), eap, len);
556 eapol_sm_rx_eapol(e->wpa_s->eapol, e->wpa_s->bssid,
557 (u8 *) dot1x, sizeof(*dot1x) + len);
563 static void ieee802_1x_get_keys(struct eapol_test_data *e,
564 struct radius_msg *msg, struct radius_msg *req,
565 u8 *shared_secret, size_t shared_secret_len)
567 struct radius_ms_mppe_keys *keys;
569 keys = radius_msg_get_ms_keys(msg, req, shared_secret,
571 if (keys && keys->send == NULL && keys->recv == NULL) {
573 keys = radius_msg_get_cisco_keys(msg, req, shared_secret,
579 wpa_hexdump(MSG_DEBUG, "MS-MPPE-Send-Key (sign)",
580 keys->send, keys->send_len);
583 wpa_hexdump(MSG_DEBUG, "MS-MPPE-Recv-Key (crypt)",
584 keys->recv, keys->recv_len);
585 e->authenticator_pmk_len =
586 keys->recv_len > PMK_LEN ? PMK_LEN :
588 os_memcpy(e->authenticator_pmk, keys->recv,
589 e->authenticator_pmk_len);
599 /* Process the RADIUS frames from Authentication Server */
600 static RadiusRxResult
601 ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
602 u8 *shared_secret, size_t shared_secret_len,
605 struct eapol_test_data *e = data;
607 /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
608 * present when packet contains an EAP-Message attribute */
609 if (msg->hdr->code == RADIUS_CODE_ACCESS_REJECT &&
610 radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
612 radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
613 wpa_printf(MSG_DEBUG, "Allowing RADIUS "
614 "Access-Reject without Message-Authenticator "
615 "since it does not include EAP-Message\n");
616 } else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
618 printf("Incoming RADIUS packet did not have correct "
619 "Message-Authenticator - dropped\n");
620 return RADIUS_RX_UNKNOWN;
623 if (msg->hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
624 msg->hdr->code != RADIUS_CODE_ACCESS_REJECT &&
625 msg->hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
626 printf("Unknown RADIUS message code\n");
627 return RADIUS_RX_UNKNOWN;
630 e->radius_identifier = -1;
631 wpa_printf(MSG_DEBUG, "RADIUS packet matching with station");
633 if (e->last_recv_radius) {
634 radius_msg_free(e->last_recv_radius);
635 os_free(e->last_recv_radius);
638 e->last_recv_radius = msg;
640 switch (msg->hdr->code) {
641 case RADIUS_CODE_ACCESS_ACCEPT:
642 e->radius_access_accept_received = 1;
643 ieee802_1x_get_keys(e, msg, req, shared_secret,
646 case RADIUS_CODE_ACCESS_REJECT:
647 e->radius_access_reject_received = 1;
651 ieee802_1x_decapsulate_radius(e);
653 if ((msg->hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
654 e->eapol_test_num_reauths < 0) ||
655 msg->hdr->code == RADIUS_CODE_ACCESS_REJECT) {
659 return RADIUS_RX_QUEUED;
663 static void wpa_init_conf(struct eapol_test_data *e,
664 struct wpa_supplicant *wpa_s, const char *authsrv,
665 int port, const char *secret)
667 struct hostapd_radius_server *as;
671 os_memcpy(wpa_s->own_addr, e->own_addr, ETH_ALEN);
672 e->own_ip_addr.s_addr = htonl((127 << 24) | 1);
673 os_strncpy(wpa_s->ifname, "test", sizeof(wpa_s->ifname));
675 e->radius_conf = os_zalloc(sizeof(struct hostapd_radius_servers));
676 assert(e->radius_conf != NULL);
677 e->radius_conf->num_auth_servers = 1;
678 as = os_zalloc(sizeof(struct hostapd_radius_server));
680 #if defined(CONFIG_NATIVE_WINDOWS) || defined(CONFIG_ANSI_C_EXTRA)
684 sscanf(authsrv, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
685 pos = (u8 *) &as->addr.u.v4;
691 #else /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
692 inet_aton(authsrv, &as->addr.u.v4);
693 #endif /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
694 as->addr.af = AF_INET;
696 as->shared_secret = (u8 *) os_strdup(secret);
697 as->shared_secret_len = os_strlen(secret);
698 e->radius_conf->auth_server = as;
699 e->radius_conf->auth_servers = as;
700 e->radius_conf->msg_dumps = 1;
702 e->radius = radius_client_init(wpa_s, e->radius_conf);
703 assert(e->radius != NULL);
705 res = radius_client_register(e->radius, RADIUS_AUTH,
706 ieee802_1x_receive_auth, e);
711 static int scard_test(void)
713 struct scard_data *scard;
716 unsigned char _rand[16];
718 unsigned char sres[4];
720 #endif /* PCSC_FUNCS */
721 #define num_triplets 5
722 unsigned char rand_[num_triplets][16];
723 unsigned char sres_[num_triplets][4];
724 unsigned char kc_[num_triplets][8];
728 #define AKA_RAND_LEN 16
729 #define AKA_AUTN_LEN 16
730 #define AKA_AUTS_LEN 14
731 #define RES_MAX_LEN 16
734 unsigned char aka_rand[AKA_RAND_LEN];
735 unsigned char aka_autn[AKA_AUTN_LEN];
736 unsigned char aka_auts[AKA_AUTS_LEN];
737 unsigned char aka_res[RES_MAX_LEN];
739 unsigned char aka_ik[IK_LEN];
740 unsigned char aka_ck[CK_LEN];
742 scard = scard_init(SCARD_TRY_BOTH);
745 if (scard_set_pin(scard, "1234")) {
746 wpa_printf(MSG_WARNING, "PIN validation failed");
752 if (scard_get_imsi(scard, imsi, &len))
754 wpa_hexdump_ascii(MSG_DEBUG, "SCARD: IMSI", (u8 *) imsi, len);
755 /* NOTE: Permanent Username: 1 | IMSI */
757 os_memset(_rand, 0, sizeof(_rand));
758 if (scard_gsm_auth(scard, _rand, sres, kc))
761 os_memset(_rand, 0xff, sizeof(_rand));
762 if (scard_gsm_auth(scard, _rand, sres, kc))
765 for (i = 0; i < num_triplets; i++) {
766 os_memset(rand_[i], i, sizeof(rand_[i]));
767 if (scard_gsm_auth(scard, rand_[i], sres_[i], kc_[i]))
771 for (i = 0; i < num_triplets; i++) {
773 for (j = 0; j < len; j++)
774 printf("%c", imsi[j]);
776 for (j = 0; j < 16; j++)
777 printf("%02X", rand_[i][j]);
779 for (j = 0; j < 4; j++)
780 printf("%02X", sres_[i][j]);
782 for (j = 0; j < 8; j++)
783 printf("%02X", kc_[i][j]);
787 wpa_printf(MSG_DEBUG, "Trying to use UMTS authentication");
790 os_memset(aka_rand, 0xaa, 16);
791 os_memcpy(aka_autn, "\x86\x71\x31\xcb\xa2\xfc\x61\xdf"
792 "\xa3\xb3\x97\x9d\x07\x32\xa2\x12", 16);
794 res = scard_umts_auth(scard, aka_rand, aka_autn, aka_res, &aka_res_len,
795 aka_ik, aka_ck, aka_auts);
797 wpa_printf(MSG_DEBUG, "UMTS auth completed successfully");
798 wpa_hexdump(MSG_DEBUG, "RES", aka_res, aka_res_len);
799 wpa_hexdump(MSG_DEBUG, "IK", aka_ik, IK_LEN);
800 wpa_hexdump(MSG_DEBUG, "CK", aka_ck, CK_LEN);
801 } else if (res == -2) {
802 wpa_printf(MSG_DEBUG, "UMTS auth resulted in synchronization "
804 wpa_hexdump(MSG_DEBUG, "AUTS", aka_auts, AKA_AUTS_LEN);
806 wpa_printf(MSG_DEBUG, "UMTS auth failed");
817 static int scard_get_triplets(int argc, char *argv[])
819 struct scard_data *scard;
822 unsigned char _rand[16];
823 unsigned char sres[4];
829 if (argc < 2 || ((num_triplets = atoi(argv[1])) <= 0)) {
830 printf("invalid parameters for sim command\n");
834 if (argc <= 2 || os_strcmp(argv[2], "debug") != 0) {
835 /* disable debug output */
836 wpa_debug_level = 99;
839 scard = scard_init(SCARD_GSM_SIM_ONLY);
841 printf("Failed to open smartcard connection\n");
844 if (scard_set_pin(scard, argv[0])) {
845 wpa_printf(MSG_WARNING, "PIN validation failed");
851 if (scard_get_imsi(scard, imsi, &len)) {
856 for (i = 0; i < num_triplets; i++) {
857 os_memset(_rand, i, sizeof(_rand));
858 if (scard_gsm_auth(scard, _rand, sres, kc))
861 /* IMSI:Kc:SRES:RAND */
862 for (j = 0; j < len; j++)
863 printf("%c", imsi[j]);
865 for (j = 0; j < 8; j++)
866 printf("%02X", kc[j]);
868 for (j = 0; j < 4; j++)
869 printf("%02X", sres[j]);
871 for (j = 0; j < 16; j++)
872 printf("%02X", _rand[j]);
882 static void eapol_test_terminate(int sig, void *eloop_ctx,
885 struct wpa_supplicant *wpa_s = eloop_ctx;
886 wpa_msg(wpa_s, MSG_INFO, "Signal %d received - terminating", sig);
891 static void usage(void)
894 "eapol_test [-nWS] -c<conf> [-a<AS IP>] [-p<AS port>] "
895 "[-s<AS secret>] \\\n"
896 " [-r<count>] [-t<timeout>] [-C<Connect-Info>] \\\n"
897 " [-M<client MAC address>]\n"
899 "eapol_test sim <PIN> <num triplets> [debug]\n"
902 " -c<conf> = configuration file\n"
903 " -a<AS IP> = IP address of the authentication server, "
904 "default 127.0.0.1\n"
905 " -p<AS port> = UDP port of the authentication server, "
907 " -s<AS secret> = shared secret with the authentication "
908 "server, default 'radius'\n"
909 " -r<count> = number of re-authentications\n"
910 " -W = wait for a control interface monitor before starting\n"
911 " -S = save configuration after authentiation\n"
912 " -n = no MPPE keys expected\n"
913 " -t<timeout> = sets timeout in seconds (default: 30 s)\n"
914 " -C<Connect-Info> = RADIUS Connect-Info (default: "
915 "CONNECT 11Mbps 802.11b)\n"
916 " -M<client MAC address> = Set own MAC address "
917 "(Calling-Station-Id,\n"
918 " default: 02:00:00:00:00:01)\n");
922 int main(int argc, char *argv[])
924 struct wpa_supplicant wpa_s;
925 int c, ret = 1, wait_for_monitor = 0, save_config = 0;
926 char *as_addr = "127.0.0.1";
928 char *as_secret = "radius";
932 if (os_program_init())
935 os_memset(&eapol_test, 0, sizeof(eapol_test));
936 eapol_test.connect_info = "CONNECT 11Mbps 802.11b";
937 os_memcpy(eapol_test.own_addr, "\x02\x00\x00\x00\x00\x01", ETH_ALEN);
940 wpa_debug_show_keys = 1;
943 c = getopt(argc, argv, "a:c:C:M:np:r:s:St:W");
954 eapol_test.connect_info = optarg;
957 if (hwaddr_aton(optarg, eapol_test.own_addr)) {
963 eapol_test.no_mppe_keys++;
966 as_port = atoi(optarg);
969 eapol_test.eapol_test_num_reauths = atoi(optarg);
978 timeout = atoi(optarg);
989 if (argc > optind && os_strcmp(argv[optind], "scard") == 0) {
993 if (argc > optind && os_strcmp(argv[optind], "sim") == 0) {
994 return scard_get_triplets(argc - optind - 1,
1000 printf("Configuration file is required.\n");
1004 if (eap_peer_register_methods()) {
1005 wpa_printf(MSG_ERROR, "Failed to register EAP methods");
1009 if (eloop_init(&wpa_s)) {
1010 wpa_printf(MSG_ERROR, "Failed to initialize event loop");
1014 os_memset(&wpa_s, 0, sizeof(wpa_s));
1015 eapol_test.wpa_s = &wpa_s;
1016 wpa_s.conf = wpa_config_read(conf);
1017 if (wpa_s.conf == NULL) {
1018 printf("Failed to parse configuration file '%s'.\n", conf);
1021 if (wpa_s.conf->ssid == NULL) {
1022 printf("No networks defined.\n");
1026 wpa_init_conf(&eapol_test, &wpa_s, as_addr, as_port, as_secret);
1027 wpa_s.ctrl_iface = wpa_supplicant_ctrl_iface_init(&wpa_s);
1028 if (wpa_s.ctrl_iface == NULL) {
1029 printf("Failed to initialize control interface '%s'.\n"
1030 "You may have another eapol_test process already "
1031 "running or the file was\n"
1032 "left by an unclean termination of eapol_test in "
1033 "which case you will need\n"
1034 "to manually remove this file before starting "
1035 "eapol_test again.\n",
1036 wpa_s.conf->ctrl_interface);
1039 if (wpa_supplicant_scard_init(&wpa_s, wpa_s.conf->ssid))
1042 if (test_eapol(&eapol_test, &wpa_s, wpa_s.conf->ssid))
1045 if (wait_for_monitor)
1046 wpa_supplicant_ctrl_iface_wait(wpa_s.ctrl_iface);
1048 eloop_register_timeout(timeout, 0, eapol_test_timeout, &eapol_test,
1050 eloop_register_timeout(0, 0, send_eap_request_identity, &wpa_s, NULL);
1051 eloop_register_signal_terminate(eapol_test_terminate, NULL);
1052 eloop_register_signal_reconfig(eapol_test_terminate, NULL);
1055 if (eapol_test_compare_pmk(&eapol_test) == 0 ||
1056 eapol_test.no_mppe_keys)
1058 if (eapol_test.auth_timed_out)
1060 if (eapol_test.radius_access_reject_received)
1064 wpa_config_write(conf, wpa_s.conf);
1066 test_eapol_clean(&eapol_test, &wpa_s);
1068 eap_peer_unregister_methods();
1072 printf("MPPE keys OK: %d mismatch: %d\n",
1073 eapol_test.num_mppe_ok, eapol_test.num_mppe_mismatch);
1074 if (eapol_test.num_mppe_mismatch)
1077 printf("FAILURE\n");
1079 printf("SUCCESS\n");
1081 os_program_deinit();