automake build system
[mech_eap.orig] / src / eap_peer / eap_fast.c
index 8559ea8..5d3e69d 100644 (file)
 #include "includes.h"
 
 #include "common.h"
+#include "crypto/tls.h"
+#include "crypto/sha1.h"
+#include "eap_common/eap_tlv_common.h"
 #include "eap_i.h"
 #include "eap_tls_common.h"
 #include "eap_config.h"
-#include "tls.h"
-#include "eap_common/eap_tlv_common.h"
-#include "sha1.h"
 #include "eap_fast_pac.h"
 
 #ifdef EAP_FAST_DYNAMIC
@@ -343,10 +343,8 @@ static int eap_fast_init_phase2_method(struct eap_sm *sm,
                sm->peer_challenge = data->key_block_p->client_challenge;
        }
        sm->init_phase2 = 1;
-       sm->mschapv2_full_key = 1;
        data->phase2_priv = data->phase2_method->init(sm);
        sm->init_phase2 = 0;
-       sm->mschapv2_full_key = 0;
        sm->auth_challenge = NULL;
        sm->peer_challenge = NULL;
 
@@ -661,7 +659,18 @@ static int eap_fast_get_phase2_key(struct eap_sm *sm,
 
        if (key_len > isk_len)
                key_len = isk_len;
-       os_memcpy(isk, key, key_len);
+       if (key_len == 32 &&
+           data->phase2_method->vendor == EAP_VENDOR_IETF &&
+           data->phase2_method->method == EAP_TYPE_MSCHAPV2) {
+               /*
+                * EAP-FAST uses reverse order for MS-MPPE keys when deriving
+                * MSK from EAP-MSCHAPv2. Swap the keys here to get the correct
+                * ISK for EAP-FAST cryptobinding.
+                */
+               os_memcpy(isk, key + 16, 16);
+               os_memcpy(isk + 16, key, 16);
+       } else
+               os_memcpy(isk, key, key_len);
        os_free(key);
 
        return 0;
@@ -909,10 +918,7 @@ static int eap_fast_parse_pac_info(struct eap_fast_pac *entry, int type,
                entry->a_id_info_len = len;
                break;
        case PAC_TYPE_PAC_TYPE:
-               /*
-                * draft-cam-winget-eap-fast-provisioning-04.txt,
-                * Section 4.2.6 - PAC-Type TLV
-                */
+               /* RFC 5422, Section 4.2.6 - PAC-Type TLV */
                if (len != 2) {
                        wpa_printf(MSG_INFO, "EAP-FAST: Invalid PAC-Type "
                                   "length %lu (expected 2)",
@@ -952,7 +958,7 @@ static int eap_fast_process_pac_info(struct eap_fast_pac *entry)
        size_t left, len;
        int type;
 
-       /* draft-cam-winget-eap-fast-provisioning-04.txt, Section 4.2.4 */
+       /* RFC 5422, Section 4.2.4 */
 
        /* PAC-Type defaults to Tunnel PAC (Type 1) */
        entry->pac_type = PAC_TYPE_TUNNEL_PAC;
@@ -1194,7 +1200,9 @@ static int eap_fast_process_decrypted(struct eap_sm *sm,
        }
 
        if (data->current_pac == NULL && data->provisioning &&
-           !data->anon_provisioning) {
+           !data->anon_provisioning && !tlv.pac &&
+           (tlv.iresult == EAP_TLV_RESULT_SUCCESS ||
+            tlv.result == EAP_TLV_RESULT_SUCCESS)) {
                /*
                 * Need to request Tunnel PAC when using authenticated
                 * provisioning.
@@ -1206,10 +1214,10 @@ static int eap_fast_process_decrypted(struct eap_sm *sm,
 
        if (tlv.result == EAP_TLV_RESULT_SUCCESS && !failed) {
                tmp = eap_fast_tlv_result(EAP_TLV_RESULT_SUCCESS, 0);
-               resp = wpabuf_concat(resp, tmp);
+               resp = wpabuf_concat(tmp, resp);
        } else if (failed) {
                tmp = eap_fast_tlv_result(EAP_TLV_RESULT_FAILURE, 0);
-               resp = wpabuf_concat(resp, tmp);
+               resp = wpabuf_concat(tmp, resp);
        }
 
        if (resp && tlv.result == EAP_TLV_RESULT_SUCCESS && !failed &&
@@ -1437,9 +1445,9 @@ static int eap_fast_process_start(struct eap_sm *sm,
 
        /* EAP-FAST Version negotiation (section 3.1) */
        wpa_printf(MSG_DEBUG, "EAP-FAST: Start (server ver=%d, own ver=%d)",
-                  flags & EAP_PEAP_VERSION_MASK, data->fast_version);
-       if ((flags & EAP_PEAP_VERSION_MASK) < data->fast_version)
-               data->fast_version = flags & EAP_PEAP_VERSION_MASK;
+                  flags & EAP_TLS_VERSION_MASK, data->fast_version);
+       if ((flags & EAP_TLS_VERSION_MASK) < data->fast_version)
+               data->fast_version = flags & EAP_TLS_VERSION_MASK;
        wpa_printf(MSG_DEBUG, "EAP-FAST: Using FAST version %d",
                   data->fast_version);