2
* WPA Supplicant - test code
3
* Copyright (c) 2003-2007, 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.
23
#include "eapol_supp/eapol_supp_sm.h"
24
#include "eap_peer/eap.h"
27
#include "eap_peer/eap_i.h"
28
#include "wpa_supplicant_i.h"
29
#include "radius/radius.h"
30
#include "radius/radius_client.h"
31
#include "ctrl_iface.h"
32
#include "pcsc_funcs.h"
35
extern int wpa_debug_level;
36
extern int wpa_debug_show_keys;
38
struct wpa_driver_ops *wpa_supplicant_drivers[] = { NULL };
41
struct eapol_test_data {
42
struct wpa_supplicant *wpa_s;
44
int eapol_test_num_reauths;
46
int num_mppe_ok, num_mppe_mismatch;
49
struct radius_msg *last_recv_radius;
50
struct in_addr own_ip_addr;
51
struct radius_client_data *radius;
52
struct hostapd_radius_servers *radius_conf;
54
u8 *last_eap_radius; /* last received EAP Response from Authentication
56
size_t last_eap_radius_len;
58
u8 authenticator_pmk[PMK_LEN];
59
size_t authenticator_pmk_len;
60
int radius_access_accept_received;
61
int radius_access_reject_received;
65
size_t eap_identity_len;
68
u8 own_addr[ETH_ALEN];
71
static struct eapol_test_data eapol_test;
74
static void send_eap_request_identity(void *eloop_ctx, void *timeout_ctx);
77
static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module,
78
int level, const char *txt, size_t len)
81
wpa_printf(MSG_DEBUG, "STA " MACSTR ": %s\n",
84
wpa_printf(MSG_DEBUG, "%s", txt);
88
static void ieee802_1x_encapsulate_radius(struct eapol_test_data *e,
89
const u8 *eap, size_t len)
91
struct radius_msg *msg;
93
const struct eap_hdr *hdr;
96
wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS "
99
e->radius_identifier = radius_client_get_id(e->radius);
100
msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST,
101
e->radius_identifier);
103
printf("Could not create net RADIUS packet\n");
107
radius_msg_make_authenticator(msg, (u8 *) e, sizeof(*e));
109
hdr = (const struct eap_hdr *) eap;
110
pos = (const u8 *) (hdr + 1);
111
if (len > sizeof(*hdr) && hdr->code == EAP_CODE_RESPONSE &&
112
pos[0] == EAP_TYPE_IDENTITY) {
114
os_free(e->eap_identity);
115
e->eap_identity_len = len - sizeof(*hdr) - 1;
116
e->eap_identity = os_malloc(e->eap_identity_len);
117
if (e->eap_identity) {
118
os_memcpy(e->eap_identity, pos, e->eap_identity_len);
119
wpa_hexdump(MSG_DEBUG, "Learned identity from "
120
"EAP-Response-Identity",
121
e->eap_identity, e->eap_identity_len);
125
if (e->eap_identity &&
126
!radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME,
127
e->eap_identity, e->eap_identity_len)) {
128
printf("Could not add User-Name\n");
132
if (!radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS,
133
(u8 *) &e->own_ip_addr, 4)) {
134
printf("Could not add NAS-IP-Address\n");
138
os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
139
MAC2STR(e->wpa_s->own_addr));
140
if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
141
(u8 *) buf, os_strlen(buf))) {
142
printf("Could not add Calling-Station-Id\n");
146
/* TODO: should probably check MTU from driver config; 2304 is max for
147
* IEEE 802.11, but use 1400 to avoid problems with too large packets
149
if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) {
150
printf("Could not add Framed-MTU\n");
154
if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE,
155
RADIUS_NAS_PORT_TYPE_IEEE_802_11)) {
156
printf("Could not add NAS-Port-Type\n");
160
os_snprintf(buf, sizeof(buf), "%s", e->connect_info);
161
if (!radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
162
(u8 *) buf, os_strlen(buf))) {
163
printf("Could not add Connect-Info\n");
167
if (eap && !radius_msg_add_eap(msg, eap, len)) {
168
printf("Could not add EAP-Message\n");
172
/* State attribute must be copied if and only if this packet is
173
* Access-Request reply to the previous Access-Challenge */
174
if (e->last_recv_radius && e->last_recv_radius->hdr->code ==
175
RADIUS_CODE_ACCESS_CHALLENGE) {
176
int res = radius_msg_copy_attr(msg, e->last_recv_radius,
179
printf("Could not copy State attribute from previous "
180
"Access-Challenge\n");
184
wpa_printf(MSG_DEBUG, " Copied RADIUS State "
189
radius_client_send(e->radius, msg, RADIUS_AUTH, e->wpa_s->own_addr);
193
radius_msg_free(msg);
198
static int eapol_test_eapol_send(void *ctx, int type, const u8 *buf,
201
/* struct wpa_supplicant *wpa_s = ctx; */
202
printf("WPA: eapol_test_eapol_send(type=%d len=%lu)\n",
203
type, (unsigned long) len);
204
if (type == IEEE802_1X_TYPE_EAP_PACKET) {
205
wpa_hexdump(MSG_DEBUG, "TX EAP -> RADIUS", buf, len);
206
ieee802_1x_encapsulate_radius(&eapol_test, buf, len);
212
static void eapol_test_set_config_blob(void *ctx,
213
struct wpa_config_blob *blob)
215
struct wpa_supplicant *wpa_s = ctx;
216
wpa_config_set_blob(wpa_s->conf, blob);
220
static const struct wpa_config_blob *
221
eapol_test_get_config_blob(void *ctx, const char *name)
223
struct wpa_supplicant *wpa_s = ctx;
224
return wpa_config_get_blob(wpa_s->conf, name);
228
static void eapol_test_eapol_done_cb(void *ctx)
230
printf("WPA: EAPOL processing complete\n");
234
static void eapol_sm_reauth(void *eloop_ctx, void *timeout_ctx)
236
struct eapol_test_data *e = eloop_ctx;
237
printf("\n\n\n\n\neapol_test: Triggering EAP reauthentication\n\n");
238
e->radius_access_accept_received = 0;
239
send_eap_request_identity(e->wpa_s, NULL);
243
static int eapol_test_compare_pmk(struct eapol_test_data *e)
248
if (eapol_sm_get_key(e->wpa_s->eapol, pmk, PMK_LEN) == 0) {
249
wpa_hexdump(MSG_DEBUG, "PMK from EAPOL", pmk, PMK_LEN);
250
if (os_memcmp(pmk, e->authenticator_pmk, PMK_LEN) != 0) {
251
printf("WARNING: PMK mismatch\n");
252
wpa_hexdump(MSG_DEBUG, "PMK from AS",
253
e->authenticator_pmk, PMK_LEN);
254
} else if (e->radius_access_accept_received)
256
} else if (e->authenticator_pmk_len == 16 &&
257
eapol_sm_get_key(e->wpa_s->eapol, pmk, 16) == 0) {
258
wpa_hexdump(MSG_DEBUG, "LEAP PMK from EAPOL", pmk, 16);
259
if (os_memcmp(pmk, e->authenticator_pmk, 16) != 0) {
260
printf("WARNING: PMK mismatch\n");
261
wpa_hexdump(MSG_DEBUG, "PMK from AS",
262
e->authenticator_pmk, 16);
263
} else if (e->radius_access_accept_received)
265
} else if (e->radius_access_accept_received && e->no_mppe_keys) {
266
/* No keying material expected */
270
if (ret && !e->no_mppe_keys)
271
e->num_mppe_mismatch++;
272
else if (!e->no_mppe_keys)
279
static void eapol_sm_cb(struct eapol_sm *eapol, int success, void *ctx)
281
struct eapol_test_data *e = ctx;
282
printf("eapol_sm_cb: success=%d\n", success);
283
e->eapol_test_num_reauths--;
284
if (e->eapol_test_num_reauths < 0)
287
eapol_test_compare_pmk(e);
288
eloop_register_timeout(0, 100000, eapol_sm_reauth, e, NULL);
293
static int test_eapol(struct eapol_test_data *e, struct wpa_supplicant *wpa_s,
294
struct wpa_ssid *ssid)
296
struct eapol_config eapol_conf;
297
struct eapol_ctx *ctx;
299
ctx = os_zalloc(sizeof(*ctx));
301
printf("Failed to allocate EAPOL context.\n");
305
ctx->msg_ctx = wpa_s;
306
ctx->scard_ctx = wpa_s->scard;
307
ctx->cb = eapol_sm_cb;
309
ctx->eapol_send_ctx = wpa_s;
311
ctx->eapol_done_cb = eapol_test_eapol_done_cb;
312
ctx->eapol_send = eapol_test_eapol_send;
313
ctx->set_config_blob = eapol_test_set_config_blob;
314
ctx->get_config_blob = eapol_test_get_config_blob;
315
#ifdef EAP_TLS_OPENSSL
316
ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
317
ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
318
ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
319
#endif /* EAP_TLS_OPENSSL */
321
wpa_s->eapol = eapol_sm_init(ctx);
322
if (wpa_s->eapol == NULL) {
324
printf("Failed to initialize EAPOL state machines.\n");
328
wpa_s->current_ssid = ssid;
329
os_memset(&eapol_conf, 0, sizeof(eapol_conf));
330
eapol_conf.accept_802_1x_keys = 1;
331
eapol_conf.required_keys = 0;
332
eapol_conf.fast_reauth = wpa_s->conf->fast_reauth;
333
eapol_conf.workaround = ssid->eap_workaround;
334
eapol_sm_notify_config(wpa_s->eapol, &ssid->eap, &eapol_conf);
335
eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
338
eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
339
/* 802.1X::portControl = Auto */
340
eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
346
static void test_eapol_clean(struct eapol_test_data *e,
347
struct wpa_supplicant *wpa_s)
349
radius_client_deinit(e->radius);
350
os_free(e->last_eap_radius);
351
if (e->last_recv_radius) {
352
radius_msg_free(e->last_recv_radius);
353
os_free(e->last_recv_radius);
355
os_free(e->eap_identity);
356
e->eap_identity = NULL;
357
eapol_sm_deinit(wpa_s->eapol);
359
if (e->radius_conf && e->radius_conf->auth_server) {
360
os_free(e->radius_conf->auth_server->shared_secret);
361
os_free(e->radius_conf->auth_server);
363
os_free(e->radius_conf);
364
e->radius_conf = NULL;
365
scard_deinit(wpa_s->scard);
366
if (wpa_s->ctrl_iface) {
367
wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
368
wpa_s->ctrl_iface = NULL;
370
wpa_config_free(wpa_s->conf);
374
static void send_eap_request_identity(void *eloop_ctx, void *timeout_ctx)
376
struct wpa_supplicant *wpa_s = eloop_ctx;
378
struct ieee802_1x_hdr *hdr;
381
hdr = (struct ieee802_1x_hdr *) buf;
382
hdr->version = EAPOL_VERSION;
383
hdr->type = IEEE802_1X_TYPE_EAP_PACKET;
384
hdr->length = htons(5);
386
eap = (struct eap_hdr *) (hdr + 1);
387
eap->code = EAP_CODE_REQUEST;
389
eap->length = htons(5);
390
pos = (u8 *) (eap + 1);
391
*pos = EAP_TYPE_IDENTITY;
393
printf("Sending fake EAP-Request-Identity\n");
394
eapol_sm_rx_eapol(wpa_s->eapol, wpa_s->bssid, buf,
399
static void eapol_test_timeout(void *eloop_ctx, void *timeout_ctx)
401
struct eapol_test_data *e = eloop_ctx;
402
printf("EAPOL test timed out\n");
403
e->auth_timed_out = 1;
408
static char *eap_type_text(u8 type)
411
case EAP_TYPE_IDENTITY: return "Identity";
412
case EAP_TYPE_NOTIFICATION: return "Notification";
413
case EAP_TYPE_NAK: return "Nak";
414
case EAP_TYPE_TLS: return "TLS";
415
case EAP_TYPE_TTLS: return "TTLS";
416
case EAP_TYPE_PEAP: return "PEAP";
417
case EAP_TYPE_SIM: return "SIM";
418
case EAP_TYPE_GTC: return "GTC";
419
case EAP_TYPE_MD5: return "MD5";
420
case EAP_TYPE_OTP: return "OTP";
421
case EAP_TYPE_FAST: return "FAST";
422
case EAP_TYPE_SAKE: return "SAKE";
423
case EAP_TYPE_PSK: return "PSK";
424
default: return "Unknown";
429
static void ieee802_1x_decapsulate_radius(struct eapol_test_data *e)
436
struct radius_msg *msg;
438
if (e->last_recv_radius == NULL)
441
msg = e->last_recv_radius;
443
eap = radius_msg_get_eap(msg, &len);
445
/* draft-aboba-radius-rfc2869bis-20.txt, Chap. 2.6.3:
446
* RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
448
wpa_printf(MSG_DEBUG, "could not extract "
449
"EAP-Message from RADIUS message");
450
os_free(e->last_eap_radius);
451
e->last_eap_radius = NULL;
452
e->last_eap_radius_len = 0;
456
if (len < sizeof(*hdr)) {
457
wpa_printf(MSG_DEBUG, "too short EAP packet "
458
"received from authentication server");
463
if (len > sizeof(*hdr))
464
eap_type = eap[sizeof(*hdr)];
466
hdr = (struct eap_hdr *) eap;
468
case EAP_CODE_REQUEST:
469
os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
470
eap_type >= 0 ? eap_type_text(eap_type) : "??",
473
case EAP_CODE_RESPONSE:
474
os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
475
eap_type >= 0 ? eap_type_text(eap_type) : "??",
478
case EAP_CODE_SUCCESS:
479
os_strlcpy(buf, "EAP Success", sizeof(buf));
480
/* LEAP uses EAP Success within an authentication, so must not
481
* stop here with eloop_terminate(); */
483
case EAP_CODE_FAILURE:
484
os_strlcpy(buf, "EAP Failure", sizeof(buf));
488
os_strlcpy(buf, "unknown EAP code", sizeof(buf));
489
wpa_hexdump(MSG_DEBUG, "Decapsulated EAP packet", eap, len);
492
wpa_printf(MSG_DEBUG, "decapsulated EAP packet (code=%d "
493
"id=%d len=%d) from RADIUS server: %s",
494
hdr->code, hdr->identifier, ntohs(hdr->length), buf);
496
/* sta->eapol_sm->be_auth.idFromServer = hdr->identifier; */
498
os_free(e->last_eap_radius);
499
e->last_eap_radius = eap;
500
e->last_eap_radius_len = len;
503
struct ieee802_1x_hdr *dot1x;
504
dot1x = os_malloc(sizeof(*dot1x) + len);
505
assert(dot1x != NULL);
506
dot1x->version = EAPOL_VERSION;
507
dot1x->type = IEEE802_1X_TYPE_EAP_PACKET;
508
dot1x->length = htons(len);
509
os_memcpy((u8 *) (dot1x + 1), eap, len);
510
eapol_sm_rx_eapol(e->wpa_s->eapol, e->wpa_s->bssid,
511
(u8 *) dot1x, sizeof(*dot1x) + len);
517
static void ieee802_1x_get_keys(struct eapol_test_data *e,
518
struct radius_msg *msg, struct radius_msg *req,
519
u8 *shared_secret, size_t shared_secret_len)
521
struct radius_ms_mppe_keys *keys;
523
keys = radius_msg_get_ms_keys(msg, req, shared_secret,
525
if (keys && keys->send == NULL && keys->recv == NULL) {
527
keys = radius_msg_get_cisco_keys(msg, req, shared_secret,
533
wpa_hexdump(MSG_DEBUG, "MS-MPPE-Send-Key (sign)",
534
keys->send, keys->send_len);
537
wpa_hexdump(MSG_DEBUG, "MS-MPPE-Recv-Key (crypt)",
538
keys->recv, keys->recv_len);
539
e->authenticator_pmk_len =
540
keys->recv_len > PMK_LEN ? PMK_LEN :
542
os_memcpy(e->authenticator_pmk, keys->recv,
543
e->authenticator_pmk_len);
553
/* Process the RADIUS frames from Authentication Server */
554
static RadiusRxResult
555
ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
556
u8 *shared_secret, size_t shared_secret_len,
559
struct eapol_test_data *e = data;
561
/* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
562
* present when packet contains an EAP-Message attribute */
563
if (msg->hdr->code == RADIUS_CODE_ACCESS_REJECT &&
564
radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
566
radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
567
wpa_printf(MSG_DEBUG, "Allowing RADIUS "
568
"Access-Reject without Message-Authenticator "
569
"since it does not include EAP-Message\n");
570
} else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
572
printf("Incoming RADIUS packet did not have correct "
573
"Message-Authenticator - dropped\n");
574
return RADIUS_RX_UNKNOWN;
577
if (msg->hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
578
msg->hdr->code != RADIUS_CODE_ACCESS_REJECT &&
579
msg->hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
580
printf("Unknown RADIUS message code\n");
581
return RADIUS_RX_UNKNOWN;
584
e->radius_identifier = -1;
585
wpa_printf(MSG_DEBUG, "RADIUS packet matching with station");
587
if (e->last_recv_radius) {
588
radius_msg_free(e->last_recv_radius);
589
os_free(e->last_recv_radius);
592
e->last_recv_radius = msg;
594
switch (msg->hdr->code) {
595
case RADIUS_CODE_ACCESS_ACCEPT:
596
e->radius_access_accept_received = 1;
597
ieee802_1x_get_keys(e, msg, req, shared_secret,
600
case RADIUS_CODE_ACCESS_REJECT:
601
e->radius_access_reject_received = 1;
605
ieee802_1x_decapsulate_radius(e);
607
if ((msg->hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
608
e->eapol_test_num_reauths < 0) ||
609
msg->hdr->code == RADIUS_CODE_ACCESS_REJECT) {
613
return RADIUS_RX_QUEUED;
617
static void wpa_init_conf(struct eapol_test_data *e,
618
struct wpa_supplicant *wpa_s, const char *authsrv,
619
int port, const char *secret)
621
struct hostapd_radius_server *as;
625
os_memcpy(wpa_s->own_addr, e->own_addr, ETH_ALEN);
626
e->own_ip_addr.s_addr = htonl((127 << 24) | 1);
627
os_strlcpy(wpa_s->ifname, "test", sizeof(wpa_s->ifname));
629
e->radius_conf = os_zalloc(sizeof(struct hostapd_radius_servers));
630
assert(e->radius_conf != NULL);
631
e->radius_conf->num_auth_servers = 1;
632
as = os_zalloc(sizeof(struct hostapd_radius_server));
634
#if defined(CONFIG_NATIVE_WINDOWS) || defined(CONFIG_ANSI_C_EXTRA)
638
sscanf(authsrv, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
639
pos = (u8 *) &as->addr.u.v4;
645
#else /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
646
inet_aton(authsrv, &as->addr.u.v4);
647
#endif /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
648
as->addr.af = AF_INET;
650
as->shared_secret = (u8 *) os_strdup(secret);
651
as->shared_secret_len = os_strlen(secret);
652
e->radius_conf->auth_server = as;
653
e->radius_conf->auth_servers = as;
654
e->radius_conf->msg_dumps = 1;
656
e->radius = radius_client_init(wpa_s, e->radius_conf);
657
assert(e->radius != NULL);
659
res = radius_client_register(e->radius, RADIUS_AUTH,
660
ieee802_1x_receive_auth, e);
665
static int scard_test(void)
667
struct scard_data *scard;
670
unsigned char _rand[16];
672
unsigned char sres[4];
674
#endif /* PCSC_FUNCS */
675
#define num_triplets 5
676
unsigned char rand_[num_triplets][16];
677
unsigned char sres_[num_triplets][4];
678
unsigned char kc_[num_triplets][8];
682
#define AKA_RAND_LEN 16
683
#define AKA_AUTN_LEN 16
684
#define AKA_AUTS_LEN 14
685
#define RES_MAX_LEN 16
688
unsigned char aka_rand[AKA_RAND_LEN];
689
unsigned char aka_autn[AKA_AUTN_LEN];
690
unsigned char aka_auts[AKA_AUTS_LEN];
691
unsigned char aka_res[RES_MAX_LEN];
693
unsigned char aka_ik[IK_LEN];
694
unsigned char aka_ck[CK_LEN];
696
scard = scard_init(SCARD_TRY_BOTH);
699
if (scard_set_pin(scard, "1234")) {
700
wpa_printf(MSG_WARNING, "PIN validation failed");
706
if (scard_get_imsi(scard, imsi, &len))
708
wpa_hexdump_ascii(MSG_DEBUG, "SCARD: IMSI", (u8 *) imsi, len);
709
/* NOTE: Permanent Username: 1 | IMSI */
711
os_memset(_rand, 0, sizeof(_rand));
712
if (scard_gsm_auth(scard, _rand, sres, kc))
715
os_memset(_rand, 0xff, sizeof(_rand));
716
if (scard_gsm_auth(scard, _rand, sres, kc))
719
for (i = 0; i < num_triplets; i++) {
720
os_memset(rand_[i], i, sizeof(rand_[i]));
721
if (scard_gsm_auth(scard, rand_[i], sres_[i], kc_[i]))
725
for (i = 0; i < num_triplets; i++) {
727
for (j = 0; j < len; j++)
728
printf("%c", imsi[j]);
730
for (j = 0; j < 16; j++)
731
printf("%02X", rand_[i][j]);
733
for (j = 0; j < 4; j++)
734
printf("%02X", sres_[i][j]);
736
for (j = 0; j < 8; j++)
737
printf("%02X", kc_[i][j]);
741
wpa_printf(MSG_DEBUG, "Trying to use UMTS authentication");
744
os_memset(aka_rand, 0xaa, 16);
745
os_memcpy(aka_autn, "\x86\x71\x31\xcb\xa2\xfc\x61\xdf"
746
"\xa3\xb3\x97\x9d\x07\x32\xa2\x12", 16);
748
res = scard_umts_auth(scard, aka_rand, aka_autn, aka_res, &aka_res_len,
749
aka_ik, aka_ck, aka_auts);
751
wpa_printf(MSG_DEBUG, "UMTS auth completed successfully");
752
wpa_hexdump(MSG_DEBUG, "RES", aka_res, aka_res_len);
753
wpa_hexdump(MSG_DEBUG, "IK", aka_ik, IK_LEN);
754
wpa_hexdump(MSG_DEBUG, "CK", aka_ck, CK_LEN);
755
} else if (res == -2) {
756
wpa_printf(MSG_DEBUG, "UMTS auth resulted in synchronization "
758
wpa_hexdump(MSG_DEBUG, "AUTS", aka_auts, AKA_AUTS_LEN);
760
wpa_printf(MSG_DEBUG, "UMTS auth failed");
771
static int scard_get_triplets(int argc, char *argv[])
773
struct scard_data *scard;
776
unsigned char _rand[16];
777
unsigned char sres[4];
783
if (argc < 2 || ((num_triplets = atoi(argv[1])) <= 0)) {
784
printf("invalid parameters for sim command\n");
788
if (argc <= 2 || os_strcmp(argv[2], "debug") != 0) {
789
/* disable debug output */
790
wpa_debug_level = 99;
793
scard = scard_init(SCARD_GSM_SIM_ONLY);
795
printf("Failed to open smartcard connection\n");
798
if (scard_set_pin(scard, argv[0])) {
799
wpa_printf(MSG_WARNING, "PIN validation failed");
805
if (scard_get_imsi(scard, imsi, &len)) {
810
for (i = 0; i < num_triplets; i++) {
811
os_memset(_rand, i, sizeof(_rand));
812
if (scard_gsm_auth(scard, _rand, sres, kc))
815
/* IMSI:Kc:SRES:RAND */
816
for (j = 0; j < len; j++)
817
printf("%c", imsi[j]);
819
for (j = 0; j < 8; j++)
820
printf("%02X", kc[j]);
822
for (j = 0; j < 4; j++)
823
printf("%02X", sres[j]);
825
for (j = 0; j < 16; j++)
826
printf("%02X", _rand[j]);
836
static void eapol_test_terminate(int sig, void *eloop_ctx,
839
struct wpa_supplicant *wpa_s = eloop_ctx;
840
wpa_msg(wpa_s, MSG_INFO, "Signal %d received - terminating", sig);
845
static void usage(void)
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"
853
"eapol_test sim <PIN> <num triplets> [debug]\n"
856
" -c<conf> = configuration file\n"
857
" -a<AS IP> = IP address of the authentication server, "
858
"default 127.0.0.1\n"
859
" -p<AS port> = UDP port of the authentication server, "
861
" -s<AS secret> = shared secret with the authentication "
862
"server, default 'radius'\n"
863
" -r<count> = number of re-authentications\n"
864
" -W = wait for a control interface monitor before starting\n"
865
" -S = save configuration after authentiation\n"
866
" -n = no MPPE keys expected\n"
867
" -t<timeout> = sets timeout in seconds (default: 30 s)\n"
868
" -C<Connect-Info> = RADIUS Connect-Info (default: "
869
"CONNECT 11Mbps 802.11b)\n"
870
" -M<client MAC address> = Set own MAC address "
871
"(Calling-Station-Id,\n"
872
" default: 02:00:00:00:00:01)\n");
876
int main(int argc, char *argv[])
878
struct wpa_supplicant wpa_s;
879
int c, ret = 1, wait_for_monitor = 0, save_config = 0;
880
char *as_addr = "127.0.0.1";
882
char *as_secret = "radius";
886
if (os_program_init())
889
hostapd_logger_register_cb(hostapd_logger_cb);
891
os_memset(&eapol_test, 0, sizeof(eapol_test));
892
eapol_test.connect_info = "CONNECT 11Mbps 802.11b";
893
os_memcpy(eapol_test.own_addr, "\x02\x00\x00\x00\x00\x01", ETH_ALEN);
896
wpa_debug_show_keys = 1;
899
c = getopt(argc, argv, "a:c:C:M:np:r:s:St:W");
910
eapol_test.connect_info = optarg;
913
if (hwaddr_aton(optarg, eapol_test.own_addr)) {
919
eapol_test.no_mppe_keys++;
922
as_port = atoi(optarg);
925
eapol_test.eapol_test_num_reauths = atoi(optarg);
934
timeout = atoi(optarg);
945
if (argc > optind && os_strcmp(argv[optind], "scard") == 0) {
949
if (argc > optind && os_strcmp(argv[optind], "sim") == 0) {
950
return scard_get_triplets(argc - optind - 1,
956
printf("Configuration file is required.\n");
960
if (eap_peer_register_methods()) {
961
wpa_printf(MSG_ERROR, "Failed to register EAP methods");
965
if (eloop_init(&wpa_s)) {
966
wpa_printf(MSG_ERROR, "Failed to initialize event loop");
970
os_memset(&wpa_s, 0, sizeof(wpa_s));
971
eapol_test.wpa_s = &wpa_s;
972
wpa_s.conf = wpa_config_read(conf);
973
if (wpa_s.conf == NULL) {
974
printf("Failed to parse configuration file '%s'.\n", conf);
977
if (wpa_s.conf->ssid == NULL) {
978
printf("No networks defined.\n");
982
wpa_init_conf(&eapol_test, &wpa_s, as_addr, as_port, as_secret);
983
wpa_s.ctrl_iface = wpa_supplicant_ctrl_iface_init(&wpa_s);
984
if (wpa_s.ctrl_iface == NULL) {
985
printf("Failed to initialize control interface '%s'.\n"
986
"You may have another eapol_test process already "
987
"running or the file was\n"
988
"left by an unclean termination of eapol_test in "
989
"which case you will need\n"
990
"to manually remove this file before starting "
991
"eapol_test again.\n",
992
wpa_s.conf->ctrl_interface);
995
if (wpa_supplicant_scard_init(&wpa_s, wpa_s.conf->ssid))
998
if (test_eapol(&eapol_test, &wpa_s, wpa_s.conf->ssid))
1001
if (wait_for_monitor)
1002
wpa_supplicant_ctrl_iface_wait(wpa_s.ctrl_iface);
1004
eloop_register_timeout(timeout, 0, eapol_test_timeout, &eapol_test,
1006
eloop_register_timeout(0, 0, send_eap_request_identity, &wpa_s, NULL);
1007
eloop_register_signal_terminate(eapol_test_terminate, NULL);
1008
eloop_register_signal_reconfig(eapol_test_terminate, NULL);
1011
eloop_cancel_timeout(eapol_test_timeout, &eapol_test, NULL);
1012
eloop_cancel_timeout(eapol_sm_reauth, &eapol_test, NULL);
1014
if (eapol_test_compare_pmk(&eapol_test) == 0 ||
1015
eapol_test.no_mppe_keys)
1017
if (eapol_test.auth_timed_out)
1019
if (eapol_test.radius_access_reject_received)
1023
wpa_config_write(conf, wpa_s.conf);
1025
test_eapol_clean(&eapol_test, &wpa_s);
1027
eap_peer_unregister_methods();
1031
printf("MPPE keys OK: %d mismatch: %d\n",
1032
eapol_test.num_mppe_ok, eapol_test.num_mppe_mismatch);
1033
if (eapol_test.num_mppe_mismatch)
1036
printf("FAILURE\n");
1038
printf("SUCCESS\n");
1040
os_program_deinit();