2
* EAP peer method: EAP-FAST (RFC 4851)
3
* Copyright (c) 2004-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.
19
#include "eap_tls_common.h"
20
#include "config_ssid.h"
24
#include "eap_fast_pac.h"
26
#ifdef EAP_FAST_DYNAMIC
27
#include "eap_fast_pac.c"
28
#endif /* EAP_FAST_DYNAMIC */
31
* - test session resumption and enable it if it interoperates
32
* - password change (pending mschapv2 packet; replay decrypted packet)
35
#define EAP_FAST_VERSION 1
36
#define EAP_FAST_KEY_LEN 64
37
#define EAP_FAST_SIMCK_LEN 40
38
#define EAP_FAST_SKS_LEN 40
40
#define TLS_EXT_PAC_OPAQUE 35
43
static void eap_fast_deinit(struct eap_sm *sm, void *priv);
47
* draft-cam-winget-eap-fast-provisioning-04.txt:
48
* Section 3.4 - Key Derivations Used in the EAP-FAST Provisioning Exchange
50
struct eap_fast_key_block_provisioning {
51
/* Extra key material after TLS key_block */
52
u8 session_key_seed[EAP_FAST_SKS_LEN];
53
u8 server_challenge[16]; /* MSCHAPv2 ServerChallenge */
54
u8 client_challenge[16]; /* MSCHAPv2 ClientChallenge */
58
struct eap_fast_data {
59
struct eap_ssl_data ssl;
63
const struct eap_method *phase2_method;
67
struct eap_method_type phase2_type;
68
struct eap_method_type *phase2_types;
69
size_t num_phase2_types;
70
int resuming; /* starting a resumed session */
71
struct eap_fast_key_block_provisioning *key_block_p;
72
#define EAP_FAST_PROV_UNAUTH 1
73
#define EAP_FAST_PROV_AUTH 2
74
int provisioning_allowed; /* Allowed PAC provisioning modes */
75
int provisioning; /* doing PAC provisioning (not the normal auth) */
76
int anon_provisioning; /* doing anonymous (unauthenticated)
79
u8 key_data[EAP_FAST_KEY_LEN];
80
u8 emsk[EAP_EMSK_LEN];
83
struct eap_fast_pac *pac;
84
struct eap_fast_pac *current_pac;
85
size_t max_pac_list_len;
86
int use_pac_binary_format;
88
int tls_master_secret_set;
90
u8 simck[EAP_FAST_SIMCK_LEN];
93
u8 *pending_phase2_req;
94
size_t pending_phase2_req_len;
98
static int eap_fast_parse_phase1(struct eap_fast_data *data,
103
pos = os_strstr(phase1, "fast_provisioning=");
105
data->provisioning_allowed = atoi(pos + 18);
106
wpa_printf(MSG_DEBUG, "EAP-FAST: Automatic PAC provisioning "
107
"mode: %d", data->provisioning_allowed);
110
pos = os_strstr(phase1, "fast_max_pac_list_len=");
112
data->max_pac_list_len = atoi(pos + 22);
113
if (data->max_pac_list_len == 0)
114
data->max_pac_list_len = 1;
115
wpa_printf(MSG_DEBUG, "EAP-FAST: Maximum PAC list length: %lu",
116
(unsigned long) data->max_pac_list_len);
119
pos = os_strstr(phase1, "fast_pac_format=binary");
121
data->use_pac_binary_format = 1;
122
wpa_printf(MSG_DEBUG, "EAP-FAST: Using binary format for PAC "
130
static void * eap_fast_init(struct eap_sm *sm)
132
struct eap_fast_data *data;
133
struct wpa_ssid *config = eap_get_config(sm);
135
data = os_zalloc(sizeof(*data));
138
data->fast_version = EAP_FAST_VERSION;
139
data->max_pac_list_len = 10;
141
if (config && config->phase1 &&
142
eap_fast_parse_phase1(data, config->phase1) < 0) {
143
eap_fast_deinit(sm, data);
147
if (eap_peer_select_phase2_methods(config, "auth=",
149
&data->num_phase2_types) < 0) {
150
eap_fast_deinit(sm, data);
154
data->phase2_type.vendor = EAP_VENDOR_IETF;
155
data->phase2_type.method = EAP_TYPE_NONE;
157
if (eap_peer_tls_ssl_init(sm, &data->ssl, config)) {
158
wpa_printf(MSG_INFO, "EAP-FAST: Failed to initialize SSL.");
159
eap_fast_deinit(sm, data);
164
* The local RADIUS server in a Cisco AP does not seem to like empty
165
* fragments before data, so disable that workaround for CBC.
166
* TODO: consider making this configurable
168
tls_connection_enable_workaround(sm->ssl_ctx, data->ssl.conn);
170
if (data->use_pac_binary_format &&
171
eap_fast_load_pac_bin(sm, &data->pac, config->pac_file) < 0) {
172
eap_fast_deinit(sm, data);
176
if (!data->use_pac_binary_format &&
177
eap_fast_load_pac(sm, &data->pac, config->pac_file) < 0) {
178
eap_fast_deinit(sm, data);
181
eap_fast_pac_list_truncate(data->pac, data->max_pac_list_len);
183
if (data->pac == NULL && !data->provisioning_allowed) {
184
wpa_printf(MSG_INFO, "EAP-FAST: No PAC configured and "
185
"provisioning disabled");
186
eap_fast_deinit(sm, data);
194
static void eap_fast_deinit(struct eap_sm *sm, void *priv)
196
struct eap_fast_data *data = priv;
197
struct eap_fast_pac *pac, *prev;
201
if (data->phase2_priv && data->phase2_method)
202
data->phase2_method->deinit(sm, data->phase2_priv);
203
os_free(data->phase2_types);
204
os_free(data->key_block_p);
205
eap_peer_tls_ssl_deinit(sm, &data->ssl);
212
eap_fast_free_pac(prev);
214
os_free(data->pending_phase2_req);
219
static int eap_fast_derive_msk(struct eap_fast_data *data)
221
/* Derive EAP Master Session Keys (section 5.4) */
222
sha1_t_prf(data->simck, EAP_FAST_SIMCK_LEN,
223
"Session Key Generating Function", (u8 *) "", 0,
224
data->key_data, EAP_FAST_KEY_LEN);
225
wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: Derived key (MSK)",
226
data->key_data, EAP_FAST_KEY_LEN);
228
sha1_t_prf(data->simck, EAP_FAST_SIMCK_LEN,
229
"Extended Session Key Generating Function",
230
(u8 *) "", 0, data->emsk, EAP_EMSK_LEN);
231
wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: Derived key (EMSK)",
232
data->emsk, EAP_EMSK_LEN);
240
static int eap_fast_set_tls_master_secret(struct eap_sm *sm,
241
struct eap_fast_data *data,
242
const u8 *tls, size_t tls_len)
244
struct tls_keys keys;
245
u8 master_secret[48], *seed;
246
const u8 *server_random;
247
size_t seed_len, server_random_len;
249
if (data->tls_master_secret_set || !data->current_pac ||
250
tls_connection_get_keys(sm->ssl_ctx, data->ssl.conn, &keys) ||
251
keys.client_random == NULL) {
255
wpa_hexdump(MSG_DEBUG, "EAP-FAST: client_random",
256
keys.client_random, keys.client_random_len);
259
* TLS master secret is needed before TLS library has processed this
260
* message which includes both ServerHello and an encrypted handshake
261
* message, so we need to parse server_random from this message before
262
* passing it to TLS library.
264
* Example TLS packet header:
265
* (16 03 01 00 2a 02 00 00 26 03 01 <32 bytes server_random>)
266
* Content Type: Handshake: 0x16
267
* Version: TLS 1.0 (0x0301)
268
* Lenghth: 42 (0x002a)
269
* Handshake Type: Server Hello: 0x02
270
* Length: 38 (0x000026)
271
* Version TLS 1.0 (0x0301)
274
if (tls_len < 43 || tls[0] != 0x16 ||
275
tls[1] != 0x03 || tls[2] != 0x01 ||
276
tls[5] != 0x02 || tls[9] != 0x03 || tls[10] != 0x01) {
277
wpa_hexdump(MSG_DEBUG, "EAP-FAST: unrecognized TLS "
278
"ServerHello", tls, tls_len);
281
server_random = tls + 11;
282
server_random_len = 32;
283
wpa_hexdump(MSG_DEBUG, "EAP-FAST: server_random",
284
server_random, server_random_len);
286
seed_len = keys.client_random_len + server_random_len;
287
seed = os_malloc(seed_len);
290
os_memcpy(seed, server_random, server_random_len);
291
os_memcpy(seed + server_random_len,
292
keys.client_random, keys.client_random_len);
294
wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: T-PRF seed", seed, seed_len);
295
wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: PAC-Key",
296
data->current_pac->pac_key, EAP_FAST_PAC_KEY_LEN);
298
* RFC 4851, Section 5.1:
299
* master_secret = T-PRF(PAC-Key, "PAC to master secret label hash",
300
* server_random + client_random, 48)
302
sha1_t_prf(data->current_pac->pac_key, EAP_FAST_PAC_KEY_LEN,
303
"PAC to master secret label hash",
304
seed, seed_len, master_secret, sizeof(master_secret));
306
wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: TLS pre-master-secret",
307
master_secret, sizeof(master_secret));
309
data->tls_master_secret_set = 1;
311
return tls_connection_set_master_key(sm->ssl_ctx, data->ssl.conn,
313
sizeof(master_secret));
317
static u8 * eap_fast_derive_key(struct eap_sm *sm, struct eap_ssl_data *data,
318
char *label, size_t len)
320
struct tls_keys keys;
321
u8 *rnd = NULL, *out;
324
block_size = tls_connection_get_keyblock_size(sm->ssl_ctx, data->conn);
328
out = os_malloc(block_size + len);
332
if (tls_connection_prf(sm->ssl_ctx, data->conn, label, 1, out,
333
block_size + len) == 0) {
334
os_memmove(out, out + block_size, len);
338
if (tls_connection_get_keys(sm->ssl_ctx, data->conn, &keys))
341
rnd = os_malloc(keys.client_random_len + keys.server_random_len);
345
os_memcpy(rnd, keys.server_random, keys.server_random_len);
346
os_memcpy(rnd + keys.server_random_len, keys.client_random,
347
keys.client_random_len);
349
wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: master_secret for key "
350
"expansion", keys.master_key, keys.master_key_len);
351
if (tls_prf(keys.master_key, keys.master_key_len,
352
label, rnd, keys.client_random_len +
353
keys.server_random_len, out, block_size + len))
356
os_memmove(out, out + block_size, len);
366
static void eap_fast_derive_key_auth(struct eap_sm *sm,
367
struct eap_fast_data *data)
371
/* RFC 4851, Section 5.1:
372
* Extra key material after TLS key_block: session_key_seed[40]
375
sks = eap_fast_derive_key(sm, &data->ssl, "key expansion",
378
wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to derive "
384
* RFC 4851, Section 5.2:
385
* S-IMCK[0] = session_key_seed
387
wpa_hexdump_key(MSG_DEBUG,
388
"EAP-FAST: session_key_seed (SKS = S-IMCK[0])",
389
sks, EAP_FAST_SKS_LEN);
391
os_memcpy(data->simck, sks, EAP_FAST_SIMCK_LEN);
396
static void eap_fast_derive_key_provisioning(struct eap_sm *sm,
397
struct eap_fast_data *data)
399
os_free(data->key_block_p);
400
data->key_block_p = (struct eap_fast_key_block_provisioning *)
401
eap_fast_derive_key(sm, &data->ssl, "key expansion",
402
sizeof(*data->key_block_p));
403
if (data->key_block_p == NULL) {
404
wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to derive key block");
408
* RFC 4851, Section 5.2:
409
* S-IMCK[0] = session_key_seed
411
wpa_hexdump_key(MSG_DEBUG,
412
"EAP-FAST: session_key_seed (SKS = S-IMCK[0])",
413
data->key_block_p->session_key_seed,
414
sizeof(data->key_block_p->session_key_seed));
416
os_memcpy(data->simck, data->key_block_p->session_key_seed,
418
wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: server_challenge",
419
data->key_block_p->server_challenge,
420
sizeof(data->key_block_p->server_challenge));
421
wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: client_challenge",
422
data->key_block_p->client_challenge,
423
sizeof(data->key_block_p->client_challenge));
427
static void eap_fast_derive_keys(struct eap_sm *sm, struct eap_fast_data *data)
429
if (data->anon_provisioning)
430
eap_fast_derive_key_provisioning(sm, data);
432
eap_fast_derive_key_auth(sm, data);
436
static int eap_fast_init_phase2_method(struct eap_sm *sm,
437
struct eap_fast_data *data)
439
data->phase2_method =
440
eap_peer_get_eap_method(data->phase2_type.vendor,
441
data->phase2_type.method);
442
if (data->phase2_method == NULL)
445
if (data->key_block_p) {
446
sm->auth_challenge = data->key_block_p->server_challenge;
447
sm->peer_challenge = data->key_block_p->client_challenge;
450
sm->mschapv2_full_key = 1;
451
data->phase2_priv = data->phase2_method->init(sm);
453
sm->mschapv2_full_key = 0;
454
sm->auth_challenge = NULL;
455
sm->peer_challenge = NULL;
457
return data->phase2_priv == NULL ? -1 : 0;
461
static int eap_fast_select_phase2_method(struct eap_fast_data *data, u8 type)
465
if (data->anon_provisioning && type != EAP_TYPE_MSCHAPV2) {
466
wpa_printf(MSG_INFO, "EAP-FAST: Only EAP-MSCHAPv2 is allowed "
467
"during unauthenticated provisioning; reject phase2"
472
for (i = 0; i < data->num_phase2_types; i++) {
473
if (data->phase2_types[i].vendor != EAP_VENDOR_IETF ||
474
data->phase2_types[i].method != type)
477
data->phase2_type.vendor = data->phase2_types[i].vendor;
478
data->phase2_type.method = data->phase2_types[i].method;
479
wpa_printf(MSG_DEBUG, "EAP-FAST: Selected Phase 2 EAP "
480
"vendor %d method %d",
481
data->phase2_type.vendor,
482
data->phase2_type.method);
486
if (type != data->phase2_type.method || type == EAP_TYPE_NONE)
493
static int eap_fast_phase2_request(struct eap_sm *sm,
494
struct eap_fast_data *data,
495
struct eap_method_ret *ret,
497
u8 **resp, size_t *resp_len)
499
size_t len = be_to_host16(hdr->length);
501
struct eap_method_ret iret;
502
struct wpa_ssid *config = eap_get_config(sm);
504
if (len <= sizeof(struct eap_hdr)) {
505
wpa_printf(MSG_INFO, "EAP-FAST: too short "
506
"Phase 2 request (len=%lu)", (unsigned long) len);
509
pos = (u8 *) (hdr + 1);
510
wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 Request: type=%d", *pos);
511
if (*pos == EAP_TYPE_IDENTITY) {
512
*resp = eap_sm_buildIdentity(sm, hdr->identifier, resp_len, 1);
516
if (data->phase2_type.vendor == EAP_VENDOR_IETF &&
517
data->phase2_type.method == EAP_TYPE_NONE &&
518
eap_fast_select_phase2_method(data, *pos) < 0) {
519
if (eap_peer_tls_phase2_nak(data->phase2_types,
520
data->num_phase2_types,
521
hdr, resp, resp_len))
526
if (data->phase2_priv == NULL &&
527
eap_fast_init_phase2_method(sm, data) < 0) {
528
wpa_printf(MSG_INFO, "EAP-FAST: Failed to initialize "
529
"Phase 2 EAP method %d", *pos);
530
ret->methodState = METHOD_DONE;
531
ret->decision = DECISION_FAIL;
535
os_memset(&iret, 0, sizeof(iret));
536
*resp = data->phase2_method->process(sm, data->phase2_priv, &iret,
537
(u8 *) hdr, len, resp_len);
539
(iret.methodState == METHOD_DONE &&
540
iret.decision == DECISION_FAIL)) {
541
ret->methodState = METHOD_DONE;
542
ret->decision = DECISION_FAIL;
543
} else if ((iret.methodState == METHOD_DONE ||
544
iret.methodState == METHOD_MAY_CONT) &&
545
(iret.decision == DECISION_UNCOND_SUCC ||
546
iret.decision == DECISION_COND_SUCC)) {
547
data->phase2_success = 1;
550
if (*resp == NULL && config &&
551
(config->pending_req_identity || config->pending_req_password ||
552
config->pending_req_otp || config->pending_req_new_password)) {
553
os_free(data->pending_phase2_req);
554
data->pending_phase2_req = os_malloc(len);
555
if (data->pending_phase2_req) {
556
os_memcpy(data->pending_phase2_req, hdr, len);
557
data->pending_phase2_req_len = len;
559
} else if (*resp == NULL)
566
static u8 * eap_fast_tlv_nak(int vendor_id, int tlv_type, size_t *len)
568
struct eap_tlv_nak_tlv *nak;
570
nak = os_malloc(*len);
573
nak->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY | EAP_TLV_NAK_TLV);
574
nak->length = host_to_be16(6);
575
nak->vendor_id = host_to_be32(vendor_id);
576
nak->nak_type = host_to_be16(tlv_type);
581
static u8 * eap_fast_tlv_result(int status, int intermediate, size_t *len)
583
struct eap_tlv_intermediate_result_tlv *result;
584
*len = sizeof(*result);
585
result = os_malloc(*len);
588
result->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
590
EAP_TLV_INTERMEDIATE_RESULT_TLV :
591
EAP_TLV_RESULT_TLV));
592
result->length = host_to_be16(2);
593
result->status = host_to_be16(status);
594
return (u8 *) result;
598
static u8 * eap_fast_tlv_pac_ack(size_t *len)
600
struct eap_tlv_result_tlv *res;
601
struct eap_tlv_pac_ack_tlv *ack;
603
*len = sizeof(*res) + sizeof(*ack);
604
res = os_zalloc(*len);
608
res->tlv_type = host_to_be16(EAP_TLV_RESULT_TLV |
609
EAP_TLV_TYPE_MANDATORY);
610
res->length = host_to_be16(sizeof(*res) - sizeof(struct eap_tlv_hdr));
611
res->status = host_to_be16(EAP_TLV_RESULT_SUCCESS);
613
ack = (struct eap_tlv_pac_ack_tlv *) (res + 1);
614
ack->tlv_type = host_to_be16(EAP_TLV_PAC_TLV |
615
EAP_TLV_TYPE_MANDATORY);
616
ack->length = host_to_be16(sizeof(*ack) - sizeof(struct eap_tlv_hdr));
617
ack->pac_type = host_to_be16(PAC_TYPE_PAC_ACKNOWLEDGEMENT);
618
ack->pac_len = host_to_be16(2);
619
ack->result = host_to_be16(EAP_TLV_RESULT_SUCCESS);
625
static u8 * eap_fast_tlv_eap_payload(u8 *buf, size_t *len)
627
struct eap_tlv_hdr *tlv;
632
/* Encapsulate EAP packet in EAP Payload TLV */
633
tlv = os_malloc(sizeof(*tlv) + *len);
635
wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to "
636
"allocate memory for TLV "
641
tlv->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
642
EAP_TLV_EAP_PAYLOAD_TLV);
643
tlv->length = host_to_be16(*len);
644
os_memcpy(tlv + 1, buf, *len);
646
*len += sizeof(*tlv);
651
static u8 * eap_fast_process_eap_payload_tlv(
652
struct eap_sm *sm, struct eap_fast_data *data,
653
struct eap_method_ret *ret, const struct eap_hdr *req,
654
u8 *eap_payload_tlv, size_t eap_payload_tlv_len, size_t *resp_len)
659
if (eap_payload_tlv_len < sizeof(*hdr)) {
660
wpa_printf(MSG_DEBUG, "EAP-FAST: too short EAP "
661
"Payload TLV (len=%lu)",
662
(unsigned long) eap_payload_tlv_len);
666
hdr = (struct eap_hdr *) eap_payload_tlv;
667
if (be_to_host16(hdr->length) > eap_payload_tlv_len) {
668
wpa_printf(MSG_DEBUG, "EAP-FAST: EAP packet overflow in "
673
if (hdr->code != EAP_CODE_REQUEST) {
674
wpa_printf(MSG_INFO, "EAP-FAST: Unexpected code=%d in "
675
"Phase 2 EAP header", hdr->code);
679
if (eap_fast_phase2_request(sm, data, ret, hdr, &resp, resp_len)) {
680
wpa_printf(MSG_INFO, "EAP-FAST: Phase2 Request processing "
685
return eap_fast_tlv_eap_payload(resp, resp_len);
689
static int eap_fast_validate_crypto_binding(
690
struct eap_tlv_crypto_binding__tlv *_bind)
692
wpa_printf(MSG_DEBUG, "EAP-FAST: Crypto-Binding TLV: Version %d "
693
"Received Version %d SubType %d",
694
_bind->version, _bind->received_version, _bind->subtype);
695
wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: NONCE",
696
_bind->nonce, sizeof(_bind->nonce));
697
wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Compound MAC",
698
_bind->compound_mac, sizeof(_bind->compound_mac));
700
if (_bind->version != EAP_FAST_VERSION ||
701
_bind->received_version != EAP_FAST_VERSION ||
702
_bind->subtype != EAP_TLV_CRYPTO_BINDING_SUBTYPE_REQUEST) {
703
wpa_printf(MSG_INFO, "EAP-FAST: Invalid version/subtype in "
704
"Crypto-Binding TLV: Version %d "
705
"Received Version %d SubType %d",
706
_bind->version, _bind->received_version,
715
static void eap_fast_write_crypto_binding(
716
struct eap_tlv_crypto_binding__tlv *rbind,
717
struct eap_tlv_crypto_binding__tlv *_bind, const u8 *cmk)
719
rbind->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
720
EAP_TLV_CRYPTO_BINDING_TLV_);
721
rbind->length = host_to_be16(sizeof(*rbind) -
722
sizeof(struct eap_tlv_hdr));
723
rbind->version = EAP_FAST_VERSION;
724
rbind->received_version = _bind->version;
725
rbind->subtype = EAP_TLV_CRYPTO_BINDING_SUBTYPE_RESPONSE;
726
os_memcpy(rbind->nonce, _bind->nonce, sizeof(_bind->nonce));
727
inc_byte_array(rbind->nonce, sizeof(rbind->nonce));
728
hmac_sha1(cmk, 20, (u8 *) rbind, sizeof(*rbind), rbind->compound_mac);
730
wpa_printf(MSG_DEBUG, "EAP-FAST: Reply Crypto-Binding TLV: Version %d "
731
"Received Version %d SubType %d",
732
rbind->version, rbind->received_version, rbind->subtype);
733
wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: NONCE",
734
rbind->nonce, sizeof(rbind->nonce));
735
wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Compound MAC",
736
rbind->compound_mac, sizeof(rbind->compound_mac));
740
static int eap_fast_get_phase2_key(struct eap_sm *sm,
741
struct eap_fast_data *data,
742
u8 *isk, size_t isk_len)
747
os_memset(isk, 0, isk_len);
749
if (data->phase2_method == NULL || data->phase2_priv == NULL) {
750
wpa_printf(MSG_DEBUG, "EAP-FAST: Phase 2 method not "
755
if (data->phase2_method->isKeyAvailable == NULL ||
756
data->phase2_method->getKey == NULL)
759
if (!data->phase2_method->isKeyAvailable(sm, data->phase2_priv) ||
760
(key = data->phase2_method->getKey(sm, data->phase2_priv,
761
&key_len)) == NULL) {
762
wpa_printf(MSG_DEBUG, "EAP-FAST: Could not get key material "
767
if (key_len > isk_len)
769
os_memcpy(isk, key, key_len);
776
static int eap_fast_get_cmk(struct eap_sm *sm, struct eap_fast_data *data,
779
u8 isk[32], imck[60];
781
wpa_printf(MSG_DEBUG, "EAP-FAST: Determining CMK[%d] for Compound MIC "
782
"calculation", data->simck_idx + 1);
785
* RFC 4851, Section 5.2:
786
* IMCK[j] = T-PRF(S-IMCK[j-1], "Inner Methods Compound Keys",
788
* S-IMCK[j] = first 40 octets of IMCK[j]
789
* CMK[j] = last 20 octets of IMCK[j]
792
if (eap_fast_get_phase2_key(sm, data, isk, sizeof(isk)) < 0)
794
wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: ISK[j]", isk, sizeof(isk));
795
sha1_t_prf(data->simck, EAP_FAST_SIMCK_LEN,
796
"Inner Methods Compound Keys",
797
isk, sizeof(isk), imck, sizeof(imck));
799
os_memcpy(data->simck, imck, EAP_FAST_SIMCK_LEN);
800
wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: S-IMCK[j]",
801
data->simck, EAP_FAST_SIMCK_LEN);
802
os_memcpy(cmk, imck + EAP_FAST_SIMCK_LEN, 20);
803
wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: CMK[j]", cmk, 20);
809
static u8 * eap_fast_write_pac_request(u8 *pos, u16 pac_type)
811
struct eap_tlv_hdr *pac;
812
struct eap_tlv_request_action_tlv *act;
813
struct eap_tlv_pac_type_tlv *type;
815
act = (struct eap_tlv_request_action_tlv *) pos;
816
act->tlv_type = host_to_be16(EAP_TLV_REQUEST_ACTION_TLV);
817
act->length = host_to_be16(2);
818
act->action = host_to_be16(EAP_TLV_ACTION_PROCESS_TLV);
820
pac = (struct eap_tlv_hdr *) (act + 1);
821
pac->tlv_type = host_to_be16(EAP_TLV_PAC_TLV);
822
pac->length = host_to_be16(sizeof(*type));
824
type = (struct eap_tlv_pac_type_tlv *) (pac + 1);
825
type->tlv_type = host_to_be16(PAC_TYPE_PAC_TYPE);
826
type->length = host_to_be16(2);
827
type->pac_type = host_to_be16(pac_type);
829
return (u8 *) (type + 1);
833
static u8 * eap_fast_process_crypto_binding(
834
struct eap_sm *sm, struct eap_fast_data *data,
835
struct eap_method_ret *ret,
836
struct eap_tlv_crypto_binding__tlv *_bind, size_t bind_len,
837
size_t *resp_len, int final)
840
struct eap_tlv_intermediate_result_tlv *rresult;
841
u8 cmk[20], cmac[20];
842
int res, req_tunnel_pac = 0;
844
if (eap_fast_validate_crypto_binding(_bind) < 0) {
845
return eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 1,
849
if (eap_fast_get_cmk(sm, data, cmk) < 0)
852
/* Validate received Compound MAC */
853
os_memcpy(cmac, _bind->compound_mac, sizeof(cmac));
854
os_memset(_bind->compound_mac, 0, sizeof(cmac));
855
wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Crypto-Binding TLV for Compound "
856
"MAC calculation", (u8 *) _bind, bind_len);
857
hmac_sha1(cmk, 20, (u8 *) _bind, bind_len, _bind->compound_mac);
858
res = os_memcmp(cmac, _bind->compound_mac, sizeof(cmac));
859
wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Received Compound MAC",
861
wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Calculated Compound MAC",
862
_bind->compound_mac, sizeof(cmac));
864
wpa_printf(MSG_INFO, "EAP-FAST: Compound MAC did not match");
865
resp = eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 1,
867
os_memcpy(_bind->compound_mac, cmac, sizeof(cmac));
872
* Compound MAC was valid, so authentication succeeded. Reply with
873
* crypto binding to allow server to complete authentication.
876
if (data->current_pac == NULL && data->provisioning &&
877
!data->anon_provisioning) {
879
* Need to request Tunnel PAC when using authenticated
882
wpa_printf(MSG_DEBUG, "EAP-FAST: Request Tunnel PAC");
886
*resp_len = sizeof(*rresult) +
887
sizeof(struct eap_tlv_crypto_binding__tlv);
889
*resp_len += sizeof(struct eap_tlv_hdr) +
890
sizeof(struct eap_tlv_request_action_tlv) +
891
sizeof(struct eap_tlv_pac_type_tlv);
892
resp = os_zalloc(*resp_len);
897
* Both intermediate and final Result TLVs are identical, so ok to use
898
* the same structure definition for them.
900
rresult = (struct eap_tlv_intermediate_result_tlv *) resp;
901
rresult->tlv_type = host_to_be16(EAP_TLV_TYPE_MANDATORY |
902
(final ? EAP_TLV_RESULT_TLV :
903
EAP_TLV_INTERMEDIATE_RESULT_TLV));
904
rresult->length = host_to_be16(2);
905
rresult->status = host_to_be16(EAP_TLV_RESULT_SUCCESS);
907
if (!data->anon_provisioning && data->phase2_success &&
908
eap_fast_derive_msk(data) < 0) {
909
wpa_printf(MSG_INFO, "EAP-FAST: Failed to generate MSK");
910
ret->methodState = METHOD_DONE;
911
ret->decision = DECISION_FAIL;
912
rresult->status = host_to_be16(EAP_TLV_RESULT_FAILURE);
913
data->phase2_success = 0;
916
pos = (u8 *) (rresult + 1);
917
eap_fast_write_crypto_binding((struct eap_tlv_crypto_binding__tlv *)
919
pos += sizeof(struct eap_tlv_crypto_binding__tlv);
922
eap_fast_write_pac_request(pos, PAC_TYPE_TUNNEL_PAC);
924
if (final && data->phase2_success) {
925
if (data->anon_provisioning) {
926
wpa_printf(MSG_DEBUG, "EAP-FAST: Unauthenticated "
927
"provisioning completed successfully.");
928
ret->methodState = METHOD_DONE;
929
ret->decision = DECISION_FAIL;
931
wpa_printf(MSG_DEBUG, "EAP-FAST: Authentication "
932
"completed successfully.");
933
if (data->provisioning)
934
ret->methodState = METHOD_MAY_CONT;
936
ret->methodState = METHOD_DONE;
937
ret->decision = DECISION_UNCOND_SUCC;
945
static void eap_fast_parse_pac_tlv(struct eap_fast_pac *entry, int type,
946
u8 *pos, size_t len, int *pac_key_found)
948
switch (type & 0x7fff) {
949
case PAC_TYPE_PAC_KEY:
950
wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: PAC-Key", pos, len);
951
if (len != EAP_FAST_PAC_KEY_LEN) {
952
wpa_printf(MSG_DEBUG, "EAP-FAST: Invalid PAC-Key "
953
"length %lu", (unsigned long) len);
957
os_memcpy(entry->pac_key, pos, len);
959
case PAC_TYPE_PAC_OPAQUE:
960
wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Opaque", pos, len);
961
entry->pac_opaque = pos;
962
entry->pac_opaque_len = len;
964
case PAC_TYPE_PAC_INFO:
965
wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Info", pos, len);
966
entry->pac_info = pos;
967
entry->pac_info_len = len;
970
wpa_printf(MSG_DEBUG, "EAP-FAST: Ignored unknown PAC type %d",
977
static int eap_fast_process_pac_tlv(struct eap_fast_pac *entry,
978
u8 *pac, size_t pac_len)
980
struct pac_tlv_hdr *hdr;
983
int type, pac_key_found = 0;
988
while (left > sizeof(*hdr)) {
989
hdr = (struct pac_tlv_hdr *) pos;
990
type = be_to_host16(hdr->type);
991
len = be_to_host16(hdr->len);
993
left -= sizeof(*hdr);
995
wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV overrun "
996
"(type=%d len=%lu left=%lu)",
997
type, (unsigned long) len,
998
(unsigned long) left);
1002
eap_fast_parse_pac_tlv(entry, type, pos, len, &pac_key_found);
1008
if (!pac_key_found || !entry->pac_opaque || !entry->pac_info) {
1009
wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV does not include "
1010
"all the required fields");
1018
static int eap_fast_parse_pac_info(struct eap_fast_pac *entry, int type,
1019
u8 *pos, size_t len)
1025
switch (type & 0x7fff) {
1026
case PAC_TYPE_CRED_LIFETIME:
1028
wpa_hexdump(MSG_DEBUG, "EAP-FAST: PAC-Info - "
1029
"Invalid CRED_LIFETIME length - ignored",
1035
* This is not currently saved separately in PAC files since
1036
* the server can automatically initiate PAC update when
1037
* needed. Anyway, the information is available from PAC-Info
1038
* dump if it is needed for something in the future.
1040
lifetime = WPA_GET_BE32(pos);
1042
wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info - CRED_LIFETIME %d "
1044
lifetime, (lifetime - (u32) now.sec) / 86400);
1047
wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: PAC-Info - A-ID",
1050
entry->a_id_len = len;
1053
wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: PAC-Info - I-ID",
1056
entry->i_id_len = len;
1058
case PAC_TYPE_A_ID_INFO:
1059
wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: PAC-Info - A-ID-Info",
1061
entry->a_id_info = pos;
1062
entry->a_id_info_len = len;
1064
case PAC_TYPE_PAC_TYPE:
1066
* draft-cam-winget-eap-fast-provisioning-04.txt,
1067
* Section 4.2.6 - PAC-Type TLV
1070
wpa_printf(MSG_INFO, "EAP-FAST: Invalid PAC-Type "
1071
"length %lu (expected 2)",
1072
(unsigned long) len);
1073
wpa_hexdump_ascii(MSG_DEBUG,
1074
"EAP-FAST: PAC-Info - PAC-Type",
1078
pac_type = WPA_GET_BE16(pos);
1079
if (pac_type != PAC_TYPE_TUNNEL_PAC &&
1080
pac_type != PAC_TYPE_USER_AUTHORIZATION &&
1081
pac_type != PAC_TYPE_MACHINE_AUTHENTICATION) {
1082
wpa_printf(MSG_INFO, "EAP-FAST: Unsupported PAC Type "
1087
wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info - PAC-Type %d",
1089
entry->pac_type = pac_type;
1092
wpa_printf(MSG_DEBUG, "EAP-FAST: Ignored unknown PAC-Info "
1101
static int eap_fast_process_pac_info(struct eap_fast_pac *entry)
1103
struct pac_tlv_hdr *hdr;
1108
/* draft-cam-winget-eap-fast-provisioning-04.txt, Section 4.2.4 */
1110
/* PAC-Type defaults to Tunnel PAC (Type 1) */
1111
entry->pac_type = PAC_TYPE_TUNNEL_PAC;
1113
pos = entry->pac_info;
1114
left = entry->pac_info_len;
1115
while (left > sizeof(*hdr)) {
1116
hdr = (struct pac_tlv_hdr *) pos;
1117
type = be_to_host16(hdr->type);
1118
len = be_to_host16(hdr->len);
1119
pos += sizeof(*hdr);
1120
left -= sizeof(*hdr);
1122
wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info overrun "
1123
"(type=%d len=%lu left=%lu)",
1124
type, (unsigned long) len,
1125
(unsigned long) left);
1129
if (eap_fast_parse_pac_info(entry, type, pos, len) < 0)
1136
if (entry->a_id == NULL || entry->a_id_info == NULL) {
1137
wpa_printf(MSG_DEBUG, "EAP-FAST: PAC-Info does not include "
1138
"all the required fields");
1146
static u8 * eap_fast_process_pac(struct eap_sm *sm, struct eap_fast_data *data,
1147
struct eap_method_ret *ret,
1148
u8 *pac, size_t pac_len, size_t *resp_len)
1150
struct wpa_ssid *config = eap_get_config(sm);
1151
struct eap_fast_pac entry;
1153
os_memset(&entry, 0, sizeof(entry));
1154
if (eap_fast_process_pac_tlv(&entry, pac, pac_len) ||
1155
eap_fast_process_pac_info(&entry))
1156
return eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 0,
1159
eap_fast_add_pac(&data->pac, &data->current_pac, &entry);
1160
eap_fast_pac_list_truncate(data->pac, data->max_pac_list_len);
1161
if (data->use_pac_binary_format)
1162
eap_fast_save_pac_bin(sm, data->pac, config->pac_file);
1164
eap_fast_save_pac(sm, data->pac, config->pac_file);
1166
if (data->provisioning) {
1167
if (data->anon_provisioning) {
1169
* Unauthenticated provisioning does not provide keying
1170
* material and must end with an EAP-Failure.
1171
* Authentication will be done separately after this.
1174
ret->decision = DECISION_FAIL;
1177
* Server may or may not allow authenticated
1178
* provisioning also for key generation.
1180
ret->decision = DECISION_COND_SUCC;
1182
wpa_printf(MSG_DEBUG, "EAP-FAST: Send PAC-Acknowledgement TLV "
1183
"- Provisioning completed successfully");
1186
* This is PAC refreshing, i.e., normal authentication that is
1187
* expected to be completed with an EAP-Success.
1189
wpa_printf(MSG_DEBUG, "EAP-FAST: Send PAC-Acknowledgement TLV "
1190
"- PAC refreshing completed successfully");
1191
ret->decision = DECISION_UNCOND_SUCC;
1193
ret->methodState = METHOD_DONE;
1194
return eap_fast_tlv_pac_ack(resp_len);
1198
struct eap_fast_tlv_parse {
1199
u8 *eap_payload_tlv;
1200
size_t eap_payload_tlv_len;
1203
struct eap_tlv_crypto_binding__tlv *crypto_binding;
1204
size_t crypto_binding_len;
1210
static int eap_fast_parse_tlv(struct eap_fast_tlv_parse *tlv,
1211
int tlv_type, u8 *pos, int len)
1214
case EAP_TLV_EAP_PAYLOAD_TLV:
1215
wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: EAP Payload TLV",
1217
tlv->eap_payload_tlv = pos;
1218
tlv->eap_payload_tlv_len = len;
1220
case EAP_TLV_RESULT_TLV:
1221
wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Result TLV", pos, len);
1223
wpa_printf(MSG_DEBUG, "EAP-FAST: Too short "
1225
tlv->result = EAP_TLV_RESULT_FAILURE;
1228
tlv->result = WPA_GET_BE16(pos);
1229
if (tlv->result != EAP_TLV_RESULT_SUCCESS &&
1230
tlv->result != EAP_TLV_RESULT_FAILURE) {
1231
wpa_printf(MSG_DEBUG, "EAP-FAST: Unknown Result %d",
1233
tlv->result = EAP_TLV_RESULT_FAILURE;
1235
wpa_printf(MSG_DEBUG, "EAP-FAST: Result: %s",
1236
tlv->result == EAP_TLV_RESULT_SUCCESS ?
1237
"Success" : "Failure");
1239
case EAP_TLV_INTERMEDIATE_RESULT_TLV:
1240
wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Intermediate Result TLV",
1243
wpa_printf(MSG_DEBUG, "EAP-FAST: Too short "
1244
"Intermediate Result TLV");
1245
tlv->iresult = EAP_TLV_RESULT_FAILURE;
1248
tlv->iresult = WPA_GET_BE16(pos);
1249
if (tlv->iresult != EAP_TLV_RESULT_SUCCESS &&
1250
tlv->iresult != EAP_TLV_RESULT_FAILURE) {
1251
wpa_printf(MSG_DEBUG, "EAP-FAST: Unknown Intermediate "
1252
"Result %d", tlv->iresult);
1253
tlv->iresult = EAP_TLV_RESULT_FAILURE;
1255
wpa_printf(MSG_DEBUG, "EAP-FAST: Intermediate Result: %s",
1256
tlv->iresult == EAP_TLV_RESULT_SUCCESS ?
1257
"Success" : "Failure");
1259
case EAP_TLV_CRYPTO_BINDING_TLV_:
1260
wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Crypto-Binding TLV",
1262
tlv->crypto_binding_len = sizeof(struct eap_tlv_hdr) + len;
1263
if (tlv->crypto_binding_len < sizeof(*tlv->crypto_binding)) {
1264
wpa_printf(MSG_DEBUG, "EAP-FAST: Too short "
1265
"Crypto-Binding TLV");
1266
tlv->iresult = EAP_TLV_RESULT_FAILURE;
1269
tlv->crypto_binding = (struct eap_tlv_crypto_binding__tlv *)
1270
(pos - sizeof(struct eap_tlv_hdr));
1272
case EAP_TLV_PAC_TLV:
1273
wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: PAC TLV", pos, len);
1286
static int eap_fast_parse_decrypted(u8 *decrypted, size_t decrypted_len,
1287
struct eap_fast_tlv_parse *tlv,
1288
u8 **resp, size_t *resp_len)
1290
int mandatory, tlv_type, len, res;
1293
os_memset(tlv, 0, sizeof(*tlv));
1295
/* Parse TLVs from the decrypted Phase 2 data */
1297
end = decrypted + decrypted_len;
1298
while (pos + 4 < end) {
1299
mandatory = pos[0] & 0x80;
1300
tlv_type = WPA_GET_BE16(pos) & 0x3fff;
1302
len = WPA_GET_BE16(pos);
1304
if (pos + len > end) {
1305
wpa_printf(MSG_INFO, "EAP-FAST: TLV overflow");
1308
wpa_printf(MSG_DEBUG, "EAP-FAST: Received Phase 2: "
1309
"TLV type %d length %d%s",
1310
tlv_type, len, mandatory ? " (mandatory)" : "");
1312
res = eap_fast_parse_tlv(tlv, tlv_type, pos, len);
1317
wpa_printf(MSG_DEBUG, "EAP-FAST: Nak unknown "
1318
"mandatory TLV type %d", tlv_type);
1319
*resp = eap_fast_tlv_nak(0, tlv_type,
1323
wpa_printf(MSG_DEBUG, "EAP-FAST: ignored "
1324
"unknown optional TLV type %d",
1336
static int eap_fast_encrypt_response(struct eap_sm *sm,
1337
struct eap_fast_data *data,
1338
u8 *resp, size_t resp_len,
1340
u8 **out_data, size_t *out_len)
1345
wpa_hexdump(MSG_DEBUG, "EAP-FAST: Encrypting Phase 2 data",
1347
if (eap_peer_tls_encrypt(sm, &data->ssl, EAP_TYPE_FAST,
1348
data->fast_version, identifier,
1349
resp, resp_len, out_data, out_len)) {
1350
wpa_printf(MSG_INFO, "EAP-FAST: Failed to encrypt a Phase 2 "
1359
static int eap_fast_process_decrypted(struct eap_sm *sm,
1360
struct eap_fast_data *data,
1361
struct eap_method_ret *ret,
1362
const struct eap_hdr *req,
1363
u8 *decrypted, size_t decrypted_len,
1364
u8 **out_data, size_t *out_len)
1368
struct eap_fast_tlv_parse tlv;
1370
if (eap_fast_parse_decrypted(decrypted, decrypted_len, &tlv,
1371
&resp, &resp_len) < 0)
1374
return eap_fast_encrypt_response(sm, data, resp, resp_len,
1378
if (tlv.result == EAP_TLV_RESULT_FAILURE) {
1379
resp = eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 0,
1381
return eap_fast_encrypt_response(sm, data, resp, resp_len,
1386
if (tlv.iresult == EAP_TLV_RESULT_FAILURE) {
1387
resp = eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 1,
1389
return eap_fast_encrypt_response(sm, data, resp, resp_len,
1394
if (tlv.eap_payload_tlv) {
1395
resp = eap_fast_process_eap_payload_tlv(
1396
sm, data, ret, req, tlv.eap_payload_tlv,
1397
tlv.eap_payload_tlv_len, &resp_len);
1398
return eap_fast_encrypt_response(sm, data, resp, resp_len,
1403
if (tlv.crypto_binding) {
1404
int final = tlv.result == EAP_TLV_RESULT_SUCCESS;
1405
resp = eap_fast_process_crypto_binding(sm, data, ret,
1407
tlv.crypto_binding_len,
1409
return eap_fast_encrypt_response(sm, data, resp, resp_len,
1414
if (tlv.pac && tlv.result != EAP_TLV_RESULT_SUCCESS) {
1415
wpa_printf(MSG_DEBUG, "EAP-FAST: PAC TLV without Result TLV "
1416
"acknowledging success");
1417
resp = eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 0,
1419
return eap_fast_encrypt_response(sm, data, resp, resp_len,
1424
if (tlv.pac && tlv.result == EAP_TLV_RESULT_SUCCESS) {
1425
resp = eap_fast_process_pac(sm, data, ret, tlv.pac,
1426
tlv.pac_len, &resp_len);
1427
return eap_fast_encrypt_response(sm, data, resp, resp_len,
1432
wpa_printf(MSG_DEBUG, "EAP-FAST: No recognized TLVs - send "
1433
"empty response packet");
1434
return eap_fast_encrypt_response(sm, data, os_malloc(1), 0,
1440
static int eap_fast_decrypt(struct eap_sm *sm, struct eap_fast_data *data,
1441
struct eap_method_ret *ret,
1442
const struct eap_hdr *req,
1443
const u8 *in_data, size_t in_len,
1444
u8 **out_data, size_t *out_len)
1447
size_t len_decrypted;
1450
wpa_printf(MSG_DEBUG, "EAP-FAST: Received %lu bytes encrypted data for"
1451
" Phase 2", (unsigned long) in_len);
1453
if (data->pending_phase2_req) {
1454
wpa_printf(MSG_DEBUG, "EAP-FAST: Pending Phase 2 request - "
1455
"skip decryption and use old data");
1456
/* Clear TLS reassembly state. */
1457
eap_peer_tls_reset_input(&data->ssl);
1458
in_decrypted = data->pending_phase2_req;
1459
data->pending_phase2_req = NULL;
1460
len_decrypted = data->pending_phase2_req_len;
1465
/* Received TLS ACK - requesting more fragments */
1466
return eap_peer_tls_encrypt(sm, &data->ssl, EAP_TYPE_FAST,
1468
req->identifier, NULL, 0,
1472
res = eap_peer_tls_decrypt(sm, &data->ssl, in_data, in_len,
1473
&in_decrypted, &len_decrypted);
1478
wpa_hexdump(MSG_MSGDUMP, "EAP-FAST: Decrypted Phase 2 TLV(s)",
1479
in_decrypted, len_decrypted);
1481
if (len_decrypted < 4) {
1482
os_free(in_decrypted);
1483
wpa_printf(MSG_INFO, "EAP-FAST: Too short Phase 2 "
1484
"TLV frame (len=%d)", len_decrypted);
1488
res = eap_fast_process_decrypted(sm, data, ret, req,
1489
in_decrypted, len_decrypted,
1492
os_free(in_decrypted);
1498
static const u8 * eap_fast_get_a_id(const u8 *buf, size_t len, size_t *id_len)
1501
struct pac_tlv_hdr *hdr;
1504
* Parse authority identity (A-ID) from the EAP-FAST/Start. This
1505
* supports both raw A-ID and one inside an A-ID TLV.
1509
if (len > sizeof(*hdr)) {
1511
hdr = (struct pac_tlv_hdr *) buf;
1512
tlen = be_to_host16(hdr->len);
1513
if (be_to_host16(hdr->type) == PAC_TYPE_A_ID &&
1514
sizeof(*hdr) + tlen <= len) {
1515
wpa_printf(MSG_DEBUG, "EAP-FAST: A-ID was in TLV "
1517
a_id = (u8 *) (hdr + 1);
1521
wpa_hexdump_ascii(MSG_DEBUG, "EAP-FAST: A-ID", a_id, *id_len);
1527
static void eap_fast_select_pac(struct eap_fast_data *data,
1528
const u8 *a_id, size_t a_id_len)
1530
data->current_pac = eap_fast_get_pac(data->pac, a_id, a_id_len,
1531
PAC_TYPE_TUNNEL_PAC);
1532
if (data->current_pac == NULL) {
1534
* Tunnel PAC was not available for this A-ID. Try to use
1535
* Machine Authentication PAC, if one is available.
1537
data->current_pac = eap_fast_get_pac(
1538
data->pac, a_id, a_id_len,
1539
PAC_TYPE_MACHINE_AUTHENTICATION);
1542
if (data->current_pac) {
1543
wpa_printf(MSG_DEBUG, "EAP-FAST: PAC found for this A-ID "
1544
"(PAC-Type %d)", data->current_pac->pac_type);
1545
wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-FAST: A-ID-Info",
1546
data->current_pac->a_id_info,
1547
data->current_pac->a_id_info_len);
1552
static int eap_fast_use_pac_opaque(struct eap_sm *sm,
1553
struct eap_fast_data *data,
1554
struct eap_fast_pac *pac)
1557
size_t tlv_len, olen;
1558
struct eap_tlv_hdr *ehdr;
1560
olen = pac->pac_opaque_len;
1561
tlv_len = sizeof(*ehdr) + olen;
1562
tlv = os_malloc(tlv_len);
1564
ehdr = (struct eap_tlv_hdr *) tlv;
1565
ehdr->tlv_type = host_to_be16(PAC_TYPE_PAC_OPAQUE);
1566
ehdr->length = host_to_be16(olen);
1567
os_memcpy(ehdr + 1, pac->pac_opaque, olen);
1570
tls_connection_client_hello_ext(sm->ssl_ctx, data->ssl.conn,
1572
tlv, tlv_len) < 0) {
1573
wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to add PAC-Opaque TLS "
1584
static int eap_fast_clear_pac_opaque_ext(struct eap_sm *sm,
1585
struct eap_fast_data *data)
1587
if (tls_connection_client_hello_ext(sm->ssl_ctx, data->ssl.conn,
1588
TLS_EXT_PAC_OPAQUE, NULL, 0) < 0) {
1589
wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to remove PAC-Opaque "
1597
static int eap_fast_set_provisioning_ciphers(struct eap_sm *sm,
1598
struct eap_fast_data *data)
1603
if (data->provisioning_allowed & EAP_FAST_PROV_UNAUTH) {
1604
wpa_printf(MSG_DEBUG, "EAP-FAST: Enabling unauthenticated "
1605
"provisioning TLS cipher suites");
1606
ciphers[count++] = TLS_CIPHER_ANON_DH_AES128_SHA;
1609
if (data->provisioning_allowed & EAP_FAST_PROV_AUTH) {
1610
wpa_printf(MSG_DEBUG, "EAP-FAST: Enabling authenticated "
1611
"provisioning TLS cipher suites");
1612
ciphers[count++] = TLS_CIPHER_RSA_DHE_AES128_SHA;
1613
ciphers[count++] = TLS_CIPHER_AES128_SHA;
1614
ciphers[count++] = TLS_CIPHER_RC4_SHA;
1617
ciphers[count++] = TLS_CIPHER_NONE;
1619
if (tls_connection_set_cipher_list(sm->ssl_ctx, data->ssl.conn,
1621
wpa_printf(MSG_INFO, "EAP-FAST: Could not configure TLS "
1622
"cipher suites for provisioning");
1630
static int eap_fast_process_start(struct eap_sm *sm,
1631
struct eap_fast_data *data, u8 flags,
1632
const u8 *pos, size_t left)
1637
/* EAP-FAST Version negotiation (section 3.1) */
1638
wpa_printf(MSG_DEBUG, "EAP-FAST: Start (server ver=%d, own ver=%d)",
1639
flags & EAP_PEAP_VERSION_MASK, data->fast_version);
1640
if ((flags & EAP_PEAP_VERSION_MASK) < data->fast_version)
1641
data->fast_version = flags & EAP_PEAP_VERSION_MASK;
1642
wpa_printf(MSG_DEBUG, "EAP-FAST: Using FAST version %d",
1643
data->fast_version);
1645
a_id = eap_fast_get_a_id(pos, left, &a_id_len);
1646
eap_fast_select_pac(data, a_id, a_id_len);
1648
if (data->resuming && data->current_pac) {
1649
wpa_printf(MSG_DEBUG, "EAP-FAST: Trying to resume session - "
1650
"do not add PAC-Opaque to TLS ClientHello");
1651
if (eap_fast_clear_pac_opaque_ext(sm, data) < 0)
1653
} else if (data->current_pac) {
1655
* PAC found for the A-ID and we are not resuming an old
1656
* session, so add PAC-Opaque extension to ClientHello.
1658
if (eap_fast_use_pac_opaque(sm, data, data->current_pac) < 0)
1661
/* No PAC found, so we must provision one. */
1662
if (!data->provisioning_allowed) {
1663
wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC found and "
1664
"provisioning disabled");
1667
wpa_printf(MSG_DEBUG, "EAP-FAST: No PAC found - "
1668
"starting provisioning");
1669
if (eap_fast_set_provisioning_ciphers(sm, data) < 0 ||
1670
eap_fast_clear_pac_opaque_ext(sm, data) < 0)
1672
data->provisioning = 1;
1679
static u8 * eap_fast_process(struct eap_sm *sm, void *priv,
1680
struct eap_method_ret *ret,
1681
const u8 *reqData, size_t reqDataLen,
1682
size_t *respDataLen)
1684
const struct eap_hdr *req;
1687
u8 flags, *resp, id;
1689
struct eap_fast_data *data = priv;
1691
pos = eap_peer_tls_process_init(sm, &data->ssl, EAP_TYPE_FAST, ret,
1692
reqData, reqDataLen, &left, &flags);
1696
req = (const struct eap_hdr *) reqData;
1697
id = req->identifier;
1699
if (flags & EAP_TLS_FLAGS_START) {
1700
if (eap_fast_process_start(sm, data, flags, pos, left) < 0)
1703
left = 0; /* A-ID is not used in further packet processing */
1707
if (tls_connection_established(sm->ssl_ctx, data->ssl.conn) &&
1709
/* Process tunneled (encrypted) phase 2 data. */
1710
res = eap_fast_decrypt(sm, data, ret, req, pos, left,
1711
&resp, respDataLen);
1713
ret->methodState = METHOD_DONE;
1714
ret->decision = DECISION_FAIL;
1716
* Ack possible Alert that may have caused failure in
1723
* Try to configure the TLS master secret based on PAC-Key
1724
* and server/client random values. If the needed values are
1725
* not yet available, the function returns 0, so we only abort
1726
* on failure case when configuring the TLS library fails, not
1727
* if the key material is not yet available.
1729
if (eap_fast_set_tls_master_secret(sm, data, pos, left) < 0) {
1730
wpa_printf(MSG_DEBUG, "EAP-FAST: Failed to configure "
1731
"TLS master secret");
1732
ret->methodState = METHOD_DONE;
1733
ret->decision = DECISION_FAIL;
1737
/* Continue processing TLS handshake (phase 1). */
1738
res = eap_peer_tls_process_helper(sm, &data->ssl,
1740
data->fast_version, id, pos,
1741
left, &resp, respDataLen);
1743
if (tls_connection_established(sm->ssl_ctx, data->ssl.conn)) {
1745
wpa_printf(MSG_DEBUG,
1746
"EAP-FAST: TLS done, proceed to Phase 2");
1747
if (data->provisioning &&
1748
(!(data->provisioning_allowed &
1749
EAP_FAST_PROV_AUTH) ||
1750
tls_get_cipher(sm->ssl_ctx, data->ssl.conn,
1751
cipher, sizeof(cipher)) < 0 ||
1752
os_strstr(cipher, "ADH-") ||
1753
os_strstr(cipher, "anon"))) {
1754
wpa_printf(MSG_DEBUG, "EAP-FAST: Using "
1755
"anonymous (unauthenticated) "
1757
data->anon_provisioning = 1;
1759
data->anon_provisioning = 0;
1761
eap_fast_derive_keys(sm, data);
1766
* Application data included in the handshake message.
1768
os_free(data->pending_phase2_req);
1769
data->pending_phase2_req = resp;
1770
data->pending_phase2_req_len = *respDataLen;
1773
res = eap_fast_decrypt(sm, data, ret, req, pos, left,
1774
&resp, respDataLen);
1780
return eap_peer_tls_build_ack(&data->ssl, respDataLen, id,
1782
data->fast_version);
1790
static Boolean eap_fast_has_reauth_data(struct eap_sm *sm, void *priv)
1792
struct eap_fast_data *data = priv;
1793
return tls_connection_established(sm->ssl_ctx, data->ssl.conn);
1797
static void eap_fast_deinit_for_reauth(struct eap_sm *sm, void *priv)
1799
struct eap_fast_data *data = priv;
1800
os_free(data->key_block_p);
1801
data->key_block_p = NULL;
1802
os_free(data->pending_phase2_req);
1803
data->pending_phase2_req = NULL;
1807
static void * eap_fast_init_for_reauth(struct eap_sm *sm, void *priv)
1809
struct eap_fast_data *data = priv;
1810
if (eap_peer_tls_reauth_init(sm, &data->ssl)) {
1814
if (data->phase2_priv && data->phase2_method &&
1815
data->phase2_method->init_for_reauth)
1816
data->phase2_method->init_for_reauth(sm, data->phase2_priv);
1817
data->phase2_success = 0;
1819
data->provisioning = 0;
1820
data->anon_provisioning = 0;
1821
data->simck_idx = 0;
1827
static int eap_fast_get_status(struct eap_sm *sm, void *priv, char *buf,
1828
size_t buflen, int verbose)
1830
struct eap_fast_data *data = priv;
1833
len = eap_peer_tls_status(sm, &data->ssl, buf, buflen, verbose);
1834
if (data->phase2_method) {
1835
ret = os_snprintf(buf + len, buflen - len,
1836
"EAP-FAST Phase2 method=%s\n",
1837
data->phase2_method->name);
1838
if (ret < 0 || (size_t) ret >= buflen - len)
1846
static Boolean eap_fast_isKeyAvailable(struct eap_sm *sm, void *priv)
1848
struct eap_fast_data *data = priv;
1849
return data->success;
1853
static u8 * eap_fast_getKey(struct eap_sm *sm, void *priv, size_t *len)
1855
struct eap_fast_data *data = priv;
1861
key = os_malloc(EAP_FAST_KEY_LEN);
1865
*len = EAP_FAST_KEY_LEN;
1866
os_memcpy(key, data->key_data, EAP_FAST_KEY_LEN);
1872
static u8 * eap_fast_get_emsk(struct eap_sm *sm, void *priv, size_t *len)
1874
struct eap_fast_data *data = priv;
1880
key = os_malloc(EAP_EMSK_LEN);
1884
*len = EAP_EMSK_LEN;
1885
os_memcpy(key, data->emsk, EAP_EMSK_LEN);
1891
int eap_peer_fast_register(void)
1893
struct eap_method *eap;
1896
eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
1897
EAP_VENDOR_IETF, EAP_TYPE_FAST, "FAST");
1901
eap->init = eap_fast_init;
1902
eap->deinit = eap_fast_deinit;
1903
eap->process = eap_fast_process;
1904
eap->isKeyAvailable = eap_fast_isKeyAvailable;
1905
eap->getKey = eap_fast_getKey;
1906
eap->get_status = eap_fast_get_status;
1908
eap->has_reauth_data = eap_fast_has_reauth_data;
1909
eap->deinit_for_reauth = eap_fast_deinit_for_reauth;
1910
eap->init_for_reauth = eap_fast_init_for_reauth;
1912
eap->get_emsk = eap_fast_get_emsk;
1914
ret = eap_peer_method_register(eap);
1916
eap_peer_method_free(eap);