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.
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=%d)\n", type, len);
203
if (type == IEEE802_1X_TYPE_EAP_PACKET) {
204
wpa_hexdump(MSG_DEBUG, "TX EAP -> RADIUS", buf, len);
205
ieee802_1x_encapsulate_radius(&eapol_test, buf, len);
211
static void eapol_test_set_config_blob(void *ctx,
212
struct wpa_config_blob *blob)
214
struct wpa_supplicant *wpa_s = ctx;
215
wpa_config_set_blob(wpa_s->conf, blob);
219
static const struct wpa_config_blob *
220
eapol_test_get_config_blob(void *ctx, const char *name)
222
struct wpa_supplicant *wpa_s = ctx;
223
return wpa_config_get_blob(wpa_s->conf, name);
227
static void eapol_test_eapol_done_cb(void *ctx)
229
printf("WPA: EAPOL processing complete\n");
233
static void eapol_sm_reauth(void *eloop_ctx, void *timeout_ctx)
235
struct eapol_test_data *e = eloop_ctx;
236
printf("\n\n\n\n\neapol_test: Triggering EAP reauthentication\n\n");
237
e->radius_access_accept_received = 0;
238
send_eap_request_identity(e->wpa_s, NULL);
242
static int eapol_test_compare_pmk(struct eapol_test_data *e)
247
if (eapol_sm_get_key(e->wpa_s->eapol, pmk, PMK_LEN) == 0) {
248
wpa_hexdump(MSG_DEBUG, "PMK from EAPOL", pmk, PMK_LEN);
249
if (os_memcmp(pmk, e->authenticator_pmk, PMK_LEN) != 0) {
250
printf("WARNING: PMK mismatch\n");
251
wpa_hexdump(MSG_DEBUG, "PMK from AS",
252
e->authenticator_pmk, PMK_LEN);
253
} else if (e->radius_access_accept_received)
255
} else if (e->authenticator_pmk_len == 16 &&
256
eapol_sm_get_key(e->wpa_s->eapol, pmk, 16) == 0) {
257
wpa_hexdump(MSG_DEBUG, "LEAP PMK from EAPOL", pmk, 16);
258
if (os_memcmp(pmk, e->authenticator_pmk, 16) != 0) {
259
printf("WARNING: PMK mismatch\n");
260
wpa_hexdump(MSG_DEBUG, "PMK from AS",
261
e->authenticator_pmk, 16);
262
} else if (e->radius_access_accept_received)
264
} else if (e->radius_access_accept_received && e->no_mppe_keys) {
265
/* No keying material expected */
269
if (ret && !e->no_mppe_keys)
270
e->num_mppe_mismatch++;
271
else if (!e->no_mppe_keys)
278
static void eapol_sm_cb(struct eapol_sm *eapol, int success, void *ctx)
280
struct eapol_test_data *e = ctx;
281
printf("eapol_sm_cb: success=%d\n", success);
282
e->eapol_test_num_reauths--;
283
if (e->eapol_test_num_reauths < 0)
286
eapol_test_compare_pmk(e);
287
eloop_register_timeout(0, 100000, eapol_sm_reauth, e, NULL);
292
static int test_eapol(struct eapol_test_data *e, struct wpa_supplicant *wpa_s,
293
struct wpa_ssid *ssid)
295
struct eapol_config eapol_conf;
296
struct eapol_ctx *ctx;
298
ctx = os_zalloc(sizeof(*ctx));
300
printf("Failed to allocate EAPOL context.\n");
304
ctx->msg_ctx = wpa_s;
305
ctx->scard_ctx = wpa_s->scard;
306
ctx->cb = eapol_sm_cb;
308
ctx->eapol_send_ctx = wpa_s;
310
ctx->eapol_done_cb = eapol_test_eapol_done_cb;
311
ctx->eapol_send = eapol_test_eapol_send;
312
ctx->set_config_blob = eapol_test_set_config_blob;
313
ctx->get_config_blob = eapol_test_get_config_blob;
314
ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
315
ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
316
ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
318
wpa_s->eapol = eapol_sm_init(ctx);
319
if (wpa_s->eapol == NULL) {
321
printf("Failed to initialize EAPOL state machines.\n");
325
wpa_s->current_ssid = ssid;
326
os_memset(&eapol_conf, 0, sizeof(eapol_conf));
327
eapol_conf.accept_802_1x_keys = 1;
328
eapol_conf.required_keys = 0;
329
eapol_conf.fast_reauth = wpa_s->conf->fast_reauth;
330
eapol_conf.workaround = ssid->eap_workaround;
331
eapol_sm_notify_config(wpa_s->eapol, ssid, &eapol_conf);
332
eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
335
eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
336
/* 802.1X::portControl = Auto */
337
eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
343
static void test_eapol_clean(struct eapol_test_data *e,
344
struct wpa_supplicant *wpa_s)
346
radius_client_deinit(e->radius);
347
os_free(e->last_eap_radius);
348
if (e->last_recv_radius) {
349
radius_msg_free(e->last_recv_radius);
350
os_free(e->last_recv_radius);
352
os_free(e->eap_identity);
353
e->eap_identity = NULL;
354
eapol_sm_deinit(wpa_s->eapol);
356
if (e->radius_conf && e->radius_conf->auth_server) {
357
os_free(e->radius_conf->auth_server->shared_secret);
358
os_free(e->radius_conf->auth_server);
360
os_free(e->radius_conf);
361
e->radius_conf = NULL;
362
scard_deinit(wpa_s->scard);
363
if (wpa_s->ctrl_iface) {
364
wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
365
wpa_s->ctrl_iface = NULL;
367
wpa_config_free(wpa_s->conf);
371
static void send_eap_request_identity(void *eloop_ctx, void *timeout_ctx)
373
struct wpa_supplicant *wpa_s = eloop_ctx;
375
struct ieee802_1x_hdr *hdr;
378
hdr = (struct ieee802_1x_hdr *) buf;
379
hdr->version = EAPOL_VERSION;
380
hdr->type = IEEE802_1X_TYPE_EAP_PACKET;
381
hdr->length = htons(5);
383
eap = (struct eap_hdr *) (hdr + 1);
384
eap->code = EAP_CODE_REQUEST;
386
eap->length = htons(5);
387
pos = (u8 *) (eap + 1);
388
*pos = EAP_TYPE_IDENTITY;
390
printf("Sending fake EAP-Request-Identity\n");
391
eapol_sm_rx_eapol(wpa_s->eapol, wpa_s->bssid, buf,
396
static void eapol_test_timeout(void *eloop_ctx, void *timeout_ctx)
398
struct eapol_test_data *e = eloop_ctx;
399
printf("EAPOL test timed out\n");
400
e->auth_timed_out = 1;
405
static char *eap_type_text(u8 type)
408
case EAP_TYPE_IDENTITY: return "Identity";
409
case EAP_TYPE_NOTIFICATION: return "Notification";
410
case EAP_TYPE_NAK: return "Nak";
411
case EAP_TYPE_TLS: return "TLS";
412
case EAP_TYPE_TTLS: return "TTLS";
413
case EAP_TYPE_PEAP: return "PEAP";
414
case EAP_TYPE_SIM: return "SIM";
415
case EAP_TYPE_GTC: return "GTC";
416
case EAP_TYPE_MD5: return "MD5";
417
case EAP_TYPE_OTP: return "OTP";
418
case EAP_TYPE_FAST: return "FAST";
419
case EAP_TYPE_SAKE: return "SAKE";
420
case EAP_TYPE_PSK: return "PSK";
421
default: return "Unknown";
426
static void ieee802_1x_decapsulate_radius(struct eapol_test_data *e)
433
struct radius_msg *msg;
435
if (e->last_recv_radius == NULL)
438
msg = e->last_recv_radius;
440
eap = radius_msg_get_eap(msg, &len);
442
/* draft-aboba-radius-rfc2869bis-20.txt, Chap. 2.6.3:
443
* RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
445
wpa_printf(MSG_DEBUG, "could not extract "
446
"EAP-Message from RADIUS message");
447
os_free(e->last_eap_radius);
448
e->last_eap_radius = NULL;
449
e->last_eap_radius_len = 0;
453
if (len < sizeof(*hdr)) {
454
wpa_printf(MSG_DEBUG, "too short EAP packet "
455
"received from authentication server");
460
if (len > sizeof(*hdr))
461
eap_type = eap[sizeof(*hdr)];
463
hdr = (struct eap_hdr *) eap;
465
case EAP_CODE_REQUEST:
466
os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
467
eap_type >= 0 ? eap_type_text(eap_type) : "??",
470
case EAP_CODE_RESPONSE:
471
os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
472
eap_type >= 0 ? eap_type_text(eap_type) : "??",
475
case EAP_CODE_SUCCESS:
476
os_strlcpy(buf, "EAP Success", sizeof(buf));
477
/* LEAP uses EAP Success within an authentication, so must not
478
* stop here with eloop_terminate(); */
480
case EAP_CODE_FAILURE:
481
os_strlcpy(buf, "EAP Failure", sizeof(buf));
485
os_strlcpy(buf, "unknown EAP code", sizeof(buf));
486
wpa_hexdump(MSG_DEBUG, "Decapsulated EAP packet", eap, len);
489
wpa_printf(MSG_DEBUG, "decapsulated EAP packet (code=%d "
490
"id=%d len=%d) from RADIUS server: %s",
491
hdr->code, hdr->identifier, ntohs(hdr->length), buf);
493
/* sta->eapol_sm->be_auth.idFromServer = hdr->identifier; */
495
os_free(e->last_eap_radius);
496
e->last_eap_radius = eap;
497
e->last_eap_radius_len = len;
500
struct ieee802_1x_hdr *dot1x;
501
dot1x = os_malloc(sizeof(*dot1x) + len);
502
assert(dot1x != NULL);
503
dot1x->version = EAPOL_VERSION;
504
dot1x->type = IEEE802_1X_TYPE_EAP_PACKET;
505
dot1x->length = htons(len);
506
os_memcpy((u8 *) (dot1x + 1), eap, len);
507
eapol_sm_rx_eapol(e->wpa_s->eapol, e->wpa_s->bssid,
508
(u8 *) dot1x, sizeof(*dot1x) + len);
514
static void ieee802_1x_get_keys(struct eapol_test_data *e,
515
struct radius_msg *msg, struct radius_msg *req,
516
u8 *shared_secret, size_t shared_secret_len)
518
struct radius_ms_mppe_keys *keys;
520
keys = radius_msg_get_ms_keys(msg, req, shared_secret,
522
if (keys && keys->send == NULL && keys->recv == NULL) {
524
keys = radius_msg_get_cisco_keys(msg, req, shared_secret,
530
wpa_hexdump(MSG_DEBUG, "MS-MPPE-Send-Key (sign)",
531
keys->send, keys->send_len);
534
wpa_hexdump(MSG_DEBUG, "MS-MPPE-Recv-Key (crypt)",
535
keys->recv, keys->recv_len);
536
e->authenticator_pmk_len =
537
keys->recv_len > PMK_LEN ? PMK_LEN :
539
os_memcpy(e->authenticator_pmk, keys->recv,
540
e->authenticator_pmk_len);
550
/* Process the RADIUS frames from Authentication Server */
551
static RadiusRxResult
552
ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
553
u8 *shared_secret, size_t shared_secret_len,
556
struct eapol_test_data *e = data;
558
/* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
559
* present when packet contains an EAP-Message attribute */
560
if (msg->hdr->code == RADIUS_CODE_ACCESS_REJECT &&
561
radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
563
radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
564
wpa_printf(MSG_DEBUG, "Allowing RADIUS "
565
"Access-Reject without Message-Authenticator "
566
"since it does not include EAP-Message\n");
567
} else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
569
printf("Incoming RADIUS packet did not have correct "
570
"Message-Authenticator - dropped\n");
571
return RADIUS_RX_UNKNOWN;
574
if (msg->hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
575
msg->hdr->code != RADIUS_CODE_ACCESS_REJECT &&
576
msg->hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
577
printf("Unknown RADIUS message code\n");
578
return RADIUS_RX_UNKNOWN;
581
e->radius_identifier = -1;
582
wpa_printf(MSG_DEBUG, "RADIUS packet matching with station");
584
if (e->last_recv_radius) {
585
radius_msg_free(e->last_recv_radius);
586
os_free(e->last_recv_radius);
589
e->last_recv_radius = msg;
591
switch (msg->hdr->code) {
592
case RADIUS_CODE_ACCESS_ACCEPT:
593
e->radius_access_accept_received = 1;
594
ieee802_1x_get_keys(e, msg, req, shared_secret,
597
case RADIUS_CODE_ACCESS_REJECT:
598
e->radius_access_reject_received = 1;
602
ieee802_1x_decapsulate_radius(e);
604
if ((msg->hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
605
e->eapol_test_num_reauths < 0) ||
606
msg->hdr->code == RADIUS_CODE_ACCESS_REJECT) {
610
return RADIUS_RX_QUEUED;
614
static void wpa_init_conf(struct eapol_test_data *e,
615
struct wpa_supplicant *wpa_s, const char *authsrv,
616
int port, const char *secret)
618
struct hostapd_radius_server *as;
622
os_memcpy(wpa_s->own_addr, e->own_addr, ETH_ALEN);
623
e->own_ip_addr.s_addr = htonl((127 << 24) | 1);
624
os_strlcpy(wpa_s->ifname, "test", sizeof(wpa_s->ifname));
626
e->radius_conf = os_zalloc(sizeof(struct hostapd_radius_servers));
627
assert(e->radius_conf != NULL);
628
e->radius_conf->num_auth_servers = 1;
629
as = os_zalloc(sizeof(struct hostapd_radius_server));
631
#if defined(CONFIG_NATIVE_WINDOWS) || defined(CONFIG_ANSI_C_EXTRA)
635
sscanf(authsrv, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
636
pos = (u8 *) &as->addr.u.v4;
642
#else /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
643
inet_aton(authsrv, &as->addr.u.v4);
644
#endif /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
645
as->addr.af = AF_INET;
647
as->shared_secret = (u8 *) os_strdup(secret);
648
as->shared_secret_len = os_strlen(secret);
649
e->radius_conf->auth_server = as;
650
e->radius_conf->auth_servers = as;
651
e->radius_conf->msg_dumps = 1;
653
e->radius = radius_client_init(wpa_s, e->radius_conf);
654
assert(e->radius != NULL);
656
res = radius_client_register(e->radius, RADIUS_AUTH,
657
ieee802_1x_receive_auth, e);
662
static int scard_test(void)
664
struct scard_data *scard;
667
unsigned char _rand[16];
669
unsigned char sres[4];
671
#endif /* PCSC_FUNCS */
672
#define num_triplets 5
673
unsigned char rand_[num_triplets][16];
674
unsigned char sres_[num_triplets][4];
675
unsigned char kc_[num_triplets][8];
679
#define AKA_RAND_LEN 16
680
#define AKA_AUTN_LEN 16
681
#define AKA_AUTS_LEN 14
682
#define RES_MAX_LEN 16
685
unsigned char aka_rand[AKA_RAND_LEN];
686
unsigned char aka_autn[AKA_AUTN_LEN];
687
unsigned char aka_auts[AKA_AUTS_LEN];
688
unsigned char aka_res[RES_MAX_LEN];
690
unsigned char aka_ik[IK_LEN];
691
unsigned char aka_ck[CK_LEN];
693
scard = scard_init(SCARD_TRY_BOTH);
696
if (scard_set_pin(scard, "1234")) {
697
wpa_printf(MSG_WARNING, "PIN validation failed");
703
if (scard_get_imsi(scard, imsi, &len))
705
wpa_hexdump_ascii(MSG_DEBUG, "SCARD: IMSI", (u8 *) imsi, len);
706
/* NOTE: Permanent Username: 1 | IMSI */
708
os_memset(_rand, 0, sizeof(_rand));
709
if (scard_gsm_auth(scard, _rand, sres, kc))
712
os_memset(_rand, 0xff, sizeof(_rand));
713
if (scard_gsm_auth(scard, _rand, sres, kc))
716
for (i = 0; i < num_triplets; i++) {
717
os_memset(rand_[i], i, sizeof(rand_[i]));
718
if (scard_gsm_auth(scard, rand_[i], sres_[i], kc_[i]))
722
for (i = 0; i < num_triplets; i++) {
724
for (j = 0; j < len; j++)
725
printf("%c", imsi[j]);
727
for (j = 0; j < 16; j++)
728
printf("%02X", rand_[i][j]);
730
for (j = 0; j < 4; j++)
731
printf("%02X", sres_[i][j]);
733
for (j = 0; j < 8; j++)
734
printf("%02X", kc_[i][j]);
738
wpa_printf(MSG_DEBUG, "Trying to use UMTS authentication");
741
os_memset(aka_rand, 0xaa, 16);
742
os_memcpy(aka_autn, "\x86\x71\x31\xcb\xa2\xfc\x61\xdf"
743
"\xa3\xb3\x97\x9d\x07\x32\xa2\x12", 16);
745
res = scard_umts_auth(scard, aka_rand, aka_autn, aka_res, &aka_res_len,
746
aka_ik, aka_ck, aka_auts);
748
wpa_printf(MSG_DEBUG, "UMTS auth completed successfully");
749
wpa_hexdump(MSG_DEBUG, "RES", aka_res, aka_res_len);
750
wpa_hexdump(MSG_DEBUG, "IK", aka_ik, IK_LEN);
751
wpa_hexdump(MSG_DEBUG, "CK", aka_ck, CK_LEN);
752
} else if (res == -2) {
753
wpa_printf(MSG_DEBUG, "UMTS auth resulted in synchronization "
755
wpa_hexdump(MSG_DEBUG, "AUTS", aka_auts, AKA_AUTS_LEN);
757
wpa_printf(MSG_DEBUG, "UMTS auth failed");
768
static int scard_get_triplets(int argc, char *argv[])
770
struct scard_data *scard;
773
unsigned char _rand[16];
774
unsigned char sres[4];
780
if (argc < 2 || ((num_triplets = atoi(argv[1])) <= 0)) {
781
printf("invalid parameters for sim command\n");
785
if (argc <= 2 || os_strcmp(argv[2], "debug") != 0) {
786
/* disable debug output */
787
wpa_debug_level = 99;
790
scard = scard_init(SCARD_GSM_SIM_ONLY);
792
printf("Failed to open smartcard connection\n");
795
if (scard_set_pin(scard, argv[0])) {
796
wpa_printf(MSG_WARNING, "PIN validation failed");
802
if (scard_get_imsi(scard, imsi, &len)) {
807
for (i = 0; i < num_triplets; i++) {
808
os_memset(_rand, i, sizeof(_rand));
809
if (scard_gsm_auth(scard, _rand, sres, kc))
812
/* IMSI:Kc:SRES:RAND */
813
for (j = 0; j < len; j++)
814
printf("%c", imsi[j]);
816
for (j = 0; j < 8; j++)
817
printf("%02X", kc[j]);
819
for (j = 0; j < 4; j++)
820
printf("%02X", sres[j]);
822
for (j = 0; j < 16; j++)
823
printf("%02X", _rand[j]);
833
static void eapol_test_terminate(int sig, void *eloop_ctx,
836
struct wpa_supplicant *wpa_s = eloop_ctx;
837
wpa_msg(wpa_s, MSG_INFO, "Signal %d received - terminating", sig);
842
static void usage(void)
845
"eapol_test [-nWS] -c<conf> [-a<AS IP>] [-p<AS port>] "
846
"[-s<AS secret>] \\\n"
847
" [-r<count>] [-t<timeout>] [-C<Connect-Info>] \\\n"
848
" [-M<client MAC address>]\n"
850
"eapol_test sim <PIN> <num triplets> [debug]\n"
853
" -c<conf> = configuration file\n"
854
" -a<AS IP> = IP address of the authentication server, "
855
"default 127.0.0.1\n"
856
" -p<AS port> = UDP port of the authentication server, "
858
" -s<AS secret> = shared secret with the authentication "
859
"server, default 'radius'\n"
860
" -r<count> = number of re-authentications\n"
861
" -W = wait for a control interface monitor before starting\n"
862
" -S = save configuration after authentiation\n"
863
" -n = no MPPE keys expected\n"
864
" -t<timeout> = sets timeout in seconds (default: 30 s)\n"
865
" -C<Connect-Info> = RADIUS Connect-Info (default: "
866
"CONNECT 11Mbps 802.11b)\n"
867
" -M<client MAC address> = Set own MAC address "
868
"(Calling-Station-Id,\n"
869
" default: 02:00:00:00:00:01)\n");
873
int main(int argc, char *argv[])
875
struct wpa_supplicant wpa_s;
876
int c, ret = 1, wait_for_monitor = 0, save_config = 0;
877
char *as_addr = "127.0.0.1";
879
char *as_secret = "radius";
883
if (os_program_init())
886
hostapd_logger_register_cb(hostapd_logger_cb);
888
os_memset(&eapol_test, 0, sizeof(eapol_test));
889
eapol_test.connect_info = "CONNECT 11Mbps 802.11b";
890
os_memcpy(eapol_test.own_addr, "\x02\x00\x00\x00\x00\x01", ETH_ALEN);
893
wpa_debug_show_keys = 1;
896
c = getopt(argc, argv, "a:c:C:M:np:r:s:St:W");
907
eapol_test.connect_info = optarg;
910
if (hwaddr_aton(optarg, eapol_test.own_addr)) {
916
eapol_test.no_mppe_keys++;
919
as_port = atoi(optarg);
922
eapol_test.eapol_test_num_reauths = atoi(optarg);
931
timeout = atoi(optarg);
942
if (argc > optind && os_strcmp(argv[optind], "scard") == 0) {
946
if (argc > optind && os_strcmp(argv[optind], "sim") == 0) {
947
return scard_get_triplets(argc - optind - 1,
953
printf("Configuration file is required.\n");
957
if (eap_peer_register_methods()) {
958
wpa_printf(MSG_ERROR, "Failed to register EAP methods");
962
if (eloop_init(&wpa_s)) {
963
wpa_printf(MSG_ERROR, "Failed to initialize event loop");
967
os_memset(&wpa_s, 0, sizeof(wpa_s));
968
eapol_test.wpa_s = &wpa_s;
969
wpa_s.conf = wpa_config_read(conf);
970
if (wpa_s.conf == NULL) {
971
printf("Failed to parse configuration file '%s'.\n", conf);
974
if (wpa_s.conf->ssid == NULL) {
975
printf("No networks defined.\n");
979
wpa_init_conf(&eapol_test, &wpa_s, as_addr, as_port, as_secret);
980
wpa_s.ctrl_iface = wpa_supplicant_ctrl_iface_init(&wpa_s);
981
if (wpa_s.ctrl_iface == NULL) {
982
printf("Failed to initialize control interface '%s'.\n"
983
"You may have another eapol_test process already "
984
"running or the file was\n"
985
"left by an unclean termination of eapol_test in "
986
"which case you will need\n"
987
"to manually remove this file before starting "
988
"eapol_test again.\n",
989
wpa_s.conf->ctrl_interface);
992
if (wpa_supplicant_scard_init(&wpa_s, wpa_s.conf->ssid))
995
if (test_eapol(&eapol_test, &wpa_s, wpa_s.conf->ssid))
998
if (wait_for_monitor)
999
wpa_supplicant_ctrl_iface_wait(wpa_s.ctrl_iface);
1001
eloop_register_timeout(timeout, 0, eapol_test_timeout, &eapol_test,
1003
eloop_register_timeout(0, 0, send_eap_request_identity, &wpa_s, NULL);
1004
eloop_register_signal_terminate(eapol_test_terminate, NULL);
1005
eloop_register_signal_reconfig(eapol_test_terminate, NULL);
1008
if (eapol_test_compare_pmk(&eapol_test) == 0 ||
1009
eapol_test.no_mppe_keys)
1011
if (eapol_test.auth_timed_out)
1013
if (eapol_test.radius_access_reject_received)
1017
wpa_config_write(conf, wpa_s.conf);
1019
test_eapol_clean(&eapol_test, &wpa_s);
1021
eap_peer_unregister_methods();
1025
printf("MPPE keys OK: %d mismatch: %d\n",
1026
eapol_test.num_mppe_ok, eapol_test.num_mppe_mismatch);
1027
if (eapol_test.num_mppe_mismatch)
1030
printf("FAILURE\n");
1032
printf("SUCCESS\n");
1034
os_program_deinit();