LCOV - code coverage report
Current view: top level - src/eap_server - eap_server_pax.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1443382998 Lines: 229 314 72.9 %
Date: 2015-09-27 Functions: 15 15 100.0 %

          Line data    Source code
       1             : /*
       2             :  * hostapd / EAP-PAX (RFC 4746) server
       3             :  * Copyright (c) 2005-2007, Jouni Malinen <j@w1.fi>
       4             :  *
       5             :  * This software may be distributed under the terms of the BSD license.
       6             :  * See README for more details.
       7             :  */
       8             : 
       9             : #include "includes.h"
      10             : 
      11             : #include "common.h"
      12             : #include "crypto/random.h"
      13             : #include "eap_server/eap_i.h"
      14             : #include "eap_common/eap_pax_common.h"
      15             : 
      16             : /*
      17             :  * Note: only PAX_STD subprotocol is currently supported
      18             :  *
      19             :  * TODO: Add support with PAX_SEC with the mandatory to implement ciphersuite
      20             :  * (HMAC_SHA1_128, IANA DH Group 14 (2048 bits), RSA-PKCS1-V1_5) and
      21             :  * recommended ciphersuite (HMAC_SHA256_128, IANA DH Group 15 (3072 bits),
      22             :  * RSAES-OAEP).
      23             :  */
      24             : 
      25             : struct eap_pax_data {
      26             :         enum { PAX_STD_1, PAX_STD_3, SUCCESS, FAILURE } state;
      27             :         u8 mac_id;
      28             :         union {
      29             :                 u8 e[2 * EAP_PAX_RAND_LEN];
      30             :                 struct {
      31             :                         u8 x[EAP_PAX_RAND_LEN]; /* server rand */
      32             :                         u8 y[EAP_PAX_RAND_LEN]; /* client rand */
      33             :                 } r;
      34             :         } rand;
      35             :         u8 ak[EAP_PAX_AK_LEN];
      36             :         u8 mk[EAP_PAX_MK_LEN];
      37             :         u8 ck[EAP_PAX_CK_LEN];
      38             :         u8 ick[EAP_PAX_ICK_LEN];
      39             :         u8 mid[EAP_PAX_MID_LEN];
      40             :         int keys_set;
      41             :         char *cid;
      42             :         size_t cid_len;
      43             : };
      44             : 
      45             : 
      46          39 : static void * eap_pax_init(struct eap_sm *sm)
      47             : {
      48             :         struct eap_pax_data *data;
      49             : 
      50          39 :         data = os_zalloc(sizeof(*data));
      51          39 :         if (data == NULL)
      52           0 :                 return NULL;
      53          39 :         data->state = PAX_STD_1;
      54             :         /*
      55             :          * TODO: make this configurable once EAP_PAX_HMAC_SHA256_128 is
      56             :          * supported
      57             :          */
      58          39 :         data->mac_id = EAP_PAX_MAC_HMAC_SHA1_128;
      59             : 
      60          39 :         return data;
      61             : }
      62             : 
      63             : 
      64          39 : static void eap_pax_reset(struct eap_sm *sm, void *priv)
      65             : {
      66          39 :         struct eap_pax_data *data = priv;
      67          39 :         os_free(data->cid);
      68          39 :         bin_clear_free(data, sizeof(*data));
      69          39 : }
      70             : 
      71             : 
      72          39 : static struct wpabuf * eap_pax_build_std_1(struct eap_sm *sm,
      73             :                                            struct eap_pax_data *data, u8 id)
      74             : {
      75             :         struct wpabuf *req;
      76             :         struct eap_pax_hdr *pax;
      77             :         u8 *pos;
      78             : 
      79          39 :         wpa_printf(MSG_DEBUG, "EAP-PAX: PAX_STD-1 (sending)");
      80             : 
      81          39 :         if (random_get_bytes(data->rand.r.x, EAP_PAX_RAND_LEN)) {
      82           0 :                 wpa_printf(MSG_ERROR, "EAP-PAX: Failed to get random data");
      83           0 :                 data->state = FAILURE;
      84           0 :                 return NULL;
      85             :         }
      86             : 
      87          39 :         req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_PAX,
      88             :                             sizeof(*pax) + 2 + EAP_PAX_RAND_LEN +
      89             :                             EAP_PAX_ICV_LEN, EAP_CODE_REQUEST, id);
      90          39 :         if (req == NULL) {
      91           0 :                 wpa_printf(MSG_ERROR, "EAP-PAX: Failed to allocate memory "
      92             :                            "request");
      93           0 :                 data->state = FAILURE;
      94           0 :                 return NULL;
      95             :         }
      96             : 
      97          39 :         pax = wpabuf_put(req, sizeof(*pax));
      98          39 :         pax->op_code = EAP_PAX_OP_STD_1;
      99          39 :         pax->flags = 0;
     100          39 :         pax->mac_id = data->mac_id;
     101          39 :         pax->dh_group_id = EAP_PAX_DH_GROUP_NONE;
     102          39 :         pax->public_key_id = EAP_PAX_PUBLIC_KEY_NONE;
     103             : 
     104          39 :         wpabuf_put_be16(req, EAP_PAX_RAND_LEN);
     105          39 :         wpabuf_put_data(req, data->rand.r.x, EAP_PAX_RAND_LEN);
     106          39 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: A = X (server rand)",
     107          39 :                     data->rand.r.x, EAP_PAX_RAND_LEN);
     108             : 
     109          39 :         pos = wpabuf_put(req, EAP_PAX_MAC_LEN);
     110          78 :         eap_pax_mac(data->mac_id, (u8 *) "", 0,
     111          78 :                     wpabuf_mhead(req), wpabuf_len(req) - EAP_PAX_ICV_LEN,
     112             :                     NULL, 0, NULL, 0, pos);
     113          39 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: ICV", pos, EAP_PAX_ICV_LEN);
     114             : 
     115          39 :         return req;
     116             : }
     117             : 
     118             : 
     119          38 : static struct wpabuf * eap_pax_build_std_3(struct eap_sm *sm,
     120             :                                            struct eap_pax_data *data, u8 id)
     121             : {
     122             :         struct wpabuf *req;
     123             :         struct eap_pax_hdr *pax;
     124             :         u8 *pos;
     125             : 
     126          38 :         wpa_printf(MSG_DEBUG, "EAP-PAX: PAX_STD-3 (sending)");
     127             : 
     128          38 :         req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_PAX,
     129             :                             sizeof(*pax) + 2 + EAP_PAX_MAC_LEN +
     130             :                             EAP_PAX_ICV_LEN, EAP_CODE_REQUEST, id);
     131          38 :         if (req == NULL) {
     132           0 :                 wpa_printf(MSG_ERROR, "EAP-PAX: Failed to allocate memory "
     133             :                            "request");
     134           0 :                 data->state = FAILURE;
     135           0 :                 return NULL;
     136             :         }
     137             : 
     138          38 :         pax = wpabuf_put(req, sizeof(*pax));
     139          38 :         pax->op_code = EAP_PAX_OP_STD_3;
     140          38 :         pax->flags = 0;
     141          38 :         pax->mac_id = data->mac_id;
     142          38 :         pax->dh_group_id = EAP_PAX_DH_GROUP_NONE;
     143          38 :         pax->public_key_id = EAP_PAX_PUBLIC_KEY_NONE;
     144             : 
     145          38 :         wpabuf_put_be16(req, EAP_PAX_MAC_LEN);
     146          38 :         pos = wpabuf_put(req, EAP_PAX_MAC_LEN);
     147          76 :         eap_pax_mac(data->mac_id, data->ck, EAP_PAX_CK_LEN,
     148          38 :                     data->rand.r.y, EAP_PAX_RAND_LEN,
     149          38 :                     (u8 *) data->cid, data->cid_len, NULL, 0, pos);
     150          38 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: MAC_CK(B, CID)",
     151             :                     pos, EAP_PAX_MAC_LEN);
     152             : 
     153             :         /* Optional ADE could be added here, if needed */
     154             : 
     155          38 :         pos = wpabuf_put(req, EAP_PAX_MAC_LEN);
     156          76 :         eap_pax_mac(data->mac_id, data->ick, EAP_PAX_ICK_LEN,
     157          76 :                     wpabuf_mhead(req), wpabuf_len(req) - EAP_PAX_ICV_LEN,
     158             :                     NULL, 0, NULL, 0, pos);
     159          38 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: ICV", pos, EAP_PAX_ICV_LEN);
     160             : 
     161          38 :         return req;
     162             : }
     163             : 
     164             : 
     165          77 : static struct wpabuf * eap_pax_buildReq(struct eap_sm *sm, void *priv, u8 id)
     166             : {
     167          77 :         struct eap_pax_data *data = priv;
     168             : 
     169          77 :         switch (data->state) {
     170             :         case PAX_STD_1:
     171          39 :                 return eap_pax_build_std_1(sm, data, id);
     172             :         case PAX_STD_3:
     173          38 :                 return eap_pax_build_std_3(sm, data, id);
     174             :         default:
     175           0 :                 wpa_printf(MSG_DEBUG, "EAP-PAX: Unknown state %d in buildReq",
     176           0 :                            data->state);
     177           0 :                 break;
     178             :         }
     179           0 :         return NULL;
     180             : }
     181             : 
     182             : 
     183          77 : static Boolean eap_pax_check(struct eap_sm *sm, void *priv,
     184             :                              struct wpabuf *respData)
     185             : {
     186          77 :         struct eap_pax_data *data = priv;
     187             :         struct eap_pax_hdr *resp;
     188             :         const u8 *pos;
     189             :         size_t len, mlen;
     190             :         u8 icvbuf[EAP_PAX_ICV_LEN], *icv;
     191             : 
     192          77 :         pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_PAX, respData, &len);
     193          77 :         if (pos == NULL || len < sizeof(*resp)) {
     194           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: Invalid frame");
     195           0 :                 return TRUE;
     196             :         }
     197             : 
     198          77 :         mlen = sizeof(struct eap_hdr) + 1 + len;
     199          77 :         resp = (struct eap_pax_hdr *) pos;
     200             : 
     201         385 :         wpa_printf(MSG_DEBUG, "EAP-PAX: received frame: op_code 0x%x "
     202             :                    "flags 0x%x mac_id 0x%x dh_group_id 0x%x "
     203             :                    "public_key_id 0x%x",
     204         308 :                    resp->op_code, resp->flags, resp->mac_id, resp->dh_group_id,
     205          77 :                    resp->public_key_id);
     206          77 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: received payload",
     207          77 :                     (u8 *) (resp + 1), len - sizeof(*resp) - EAP_PAX_ICV_LEN);
     208             : 
     209         116 :         if (data->state == PAX_STD_1 &&
     210          39 :             resp->op_code != EAP_PAX_OP_STD_2) {
     211           0 :                 wpa_printf(MSG_DEBUG, "EAP-PAX: Expected PAX_STD-2 - "
     212           0 :                            "ignore op %d", resp->op_code);
     213           0 :                 return TRUE;
     214             :         }
     215             : 
     216         115 :         if (data->state == PAX_STD_3 &&
     217          38 :             resp->op_code != EAP_PAX_OP_ACK) {
     218           0 :                 wpa_printf(MSG_DEBUG, "EAP-PAX: Expected PAX-ACK - "
     219           0 :                            "ignore op %d", resp->op_code);
     220           0 :                 return TRUE;
     221             :         }
     222             : 
     223         115 :         if (resp->op_code != EAP_PAX_OP_STD_2 &&
     224          38 :             resp->op_code != EAP_PAX_OP_ACK) {
     225           0 :                 wpa_printf(MSG_DEBUG, "EAP-PAX: Unknown op_code 0x%x",
     226           0 :                            resp->op_code);
     227             :         }
     228             : 
     229          77 :         if (data->mac_id != resp->mac_id) {
     230           0 :                 wpa_printf(MSG_DEBUG, "EAP-PAX: Expected MAC ID 0x%x, "
     231           0 :                            "received 0x%x", data->mac_id, resp->mac_id);
     232           0 :                 return TRUE;
     233             :         }
     234             : 
     235          77 :         if (resp->dh_group_id != EAP_PAX_DH_GROUP_NONE) {
     236           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: Expected DH Group ID 0x%x, "
     237             :                            "received 0x%x", EAP_PAX_DH_GROUP_NONE,
     238           0 :                            resp->dh_group_id);
     239           0 :                 return TRUE;
     240             :         }
     241             : 
     242          77 :         if (resp->public_key_id != EAP_PAX_PUBLIC_KEY_NONE) {
     243           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: Expected Public Key ID 0x%x, "
     244             :                            "received 0x%x", EAP_PAX_PUBLIC_KEY_NONE,
     245           0 :                            resp->public_key_id);
     246           0 :                 return TRUE;
     247             :         }
     248             : 
     249          77 :         if (resp->flags & EAP_PAX_FLAGS_MF) {
     250             :                 /* TODO: add support for reassembling fragments */
     251           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: fragmentation not supported");
     252           0 :                 return TRUE;
     253             :         }
     254             : 
     255          77 :         if (resp->flags & EAP_PAX_FLAGS_CE) {
     256           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: Unexpected CE flag");
     257           0 :                 return TRUE;
     258             :         }
     259             : 
     260          77 :         if (data->keys_set) {
     261          38 :                 if (len - sizeof(*resp) < EAP_PAX_ICV_LEN) {
     262           0 :                         wpa_printf(MSG_INFO, "EAP-PAX: No ICV in the packet");
     263           0 :                         return TRUE;
     264             :                 }
     265          38 :                 icv = wpabuf_mhead_u8(respData) + mlen - EAP_PAX_ICV_LEN;
     266          38 :                 wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: ICV", icv, EAP_PAX_ICV_LEN);
     267          76 :                 eap_pax_mac(data->mac_id, data->ick, EAP_PAX_ICK_LEN,
     268          38 :                             wpabuf_mhead(respData),
     269          38 :                             wpabuf_len(respData) - EAP_PAX_ICV_LEN,
     270             :                             NULL, 0, NULL, 0, icvbuf);
     271          38 :                 if (os_memcmp_const(icvbuf, icv, EAP_PAX_ICV_LEN) != 0) {
     272           0 :                         wpa_printf(MSG_INFO, "EAP-PAX: Invalid ICV");
     273           0 :                         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: Expected ICV",
     274             :                                     icvbuf, EAP_PAX_ICV_LEN);
     275           0 :                         return TRUE;
     276             :                 }
     277             :         }
     278             : 
     279          77 :         return FALSE;
     280             : }
     281             : 
     282             : 
     283          39 : static void eap_pax_process_std_2(struct eap_sm *sm,
     284             :                                   struct eap_pax_data *data,
     285             :                                   struct wpabuf *respData)
     286             : {
     287             :         struct eap_pax_hdr *resp;
     288             :         u8 mac[EAP_PAX_MAC_LEN], icvbuf[EAP_PAX_ICV_LEN];
     289             :         const u8 *pos;
     290             :         size_t len, left, cid_len;
     291             :         int i;
     292             : 
     293          39 :         if (data->state != PAX_STD_1)
     294           1 :                 return;
     295             : 
     296          39 :         wpa_printf(MSG_DEBUG, "EAP-PAX: Received PAX_STD-2");
     297             : 
     298          39 :         pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_PAX, respData, &len);
     299          39 :         if (pos == NULL || len < sizeof(*resp) + EAP_PAX_ICV_LEN)
     300           0 :                 return;
     301             : 
     302          39 :         resp = (struct eap_pax_hdr *) pos;
     303          39 :         pos = (u8 *) (resp + 1);
     304          39 :         left = len - sizeof(*resp);
     305             : 
     306          78 :         if (left < 2 + EAP_PAX_RAND_LEN ||
     307          39 :             WPA_GET_BE16(pos) != EAP_PAX_RAND_LEN) {
     308           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: Too short PAX_STD-2 (B)");
     309           0 :                 return;
     310             :         }
     311          39 :         pos += 2;
     312          39 :         left -= 2;
     313          39 :         os_memcpy(data->rand.r.y, pos, EAP_PAX_RAND_LEN);
     314          39 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: Y (client rand)",
     315          39 :                     data->rand.r.y, EAP_PAX_RAND_LEN);
     316          39 :         pos += EAP_PAX_RAND_LEN;
     317          39 :         left -= EAP_PAX_RAND_LEN;
     318             : 
     319          39 :         if (left < 2 || (size_t) 2 + WPA_GET_BE16(pos) > left) {
     320           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: Too short PAX_STD-2 (CID)");
     321           0 :                 return;
     322             :         }
     323          39 :         cid_len = WPA_GET_BE16(pos);
     324          39 :         if (cid_len > 1500) {
     325           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: Too long CID");
     326           0 :                 return;
     327             :         }
     328          39 :         data->cid_len = cid_len;
     329          39 :         os_free(data->cid);
     330          39 :         data->cid = os_malloc(data->cid_len);
     331          39 :         if (data->cid == NULL) {
     332           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: Failed to allocate memory for "
     333             :                            "CID");
     334           0 :                 return;
     335             :         }
     336          39 :         os_memcpy(data->cid, pos + 2, data->cid_len);
     337          39 :         pos += 2 + data->cid_len;
     338          39 :         left -= 2 + data->cid_len;
     339          78 :         wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-PAX: CID",
     340          39 :                           (u8 *) data->cid, data->cid_len);
     341             : 
     342          78 :         if (left < 2 + EAP_PAX_MAC_LEN ||
     343          39 :             WPA_GET_BE16(pos) != EAP_PAX_MAC_LEN) {
     344           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: Too short PAX_STD-2 (MAC_CK)");
     345           0 :                 return;
     346             :         }
     347          39 :         pos += 2;
     348          39 :         left -= 2;
     349          39 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: MAC_CK(A, B, CID)",
     350             :                     pos, EAP_PAX_MAC_LEN);
     351             : 
     352          39 :         if (eap_user_get(sm, (u8 *) data->cid, data->cid_len, 0) < 0) {
     353           0 :                 wpa_hexdump_ascii(MSG_DEBUG, "EAP-PAX: unknown CID",
     354           0 :                                   (u8 *) data->cid, data->cid_len);
     355           0 :                 data->state = FAILURE;
     356           0 :                 return;
     357             :         }
     358             : 
     359          78 :         for (i = 0;
     360          39 :              i < EAP_MAX_METHODS &&
     361          78 :                      (sm->user->methods[i].vendor != EAP_VENDOR_IETF ||
     362          39 :                       sm->user->methods[i].method != EAP_TYPE_NONE);
     363           0 :              i++) {
     364          78 :                 if (sm->user->methods[i].vendor == EAP_VENDOR_IETF &&
     365          39 :                     sm->user->methods[i].method == EAP_TYPE_PAX)
     366          39 :                         break;
     367             :         }
     368             : 
     369          78 :         if (i >= EAP_MAX_METHODS ||
     370          78 :             sm->user->methods[i].vendor != EAP_VENDOR_IETF ||
     371          39 :             sm->user->methods[i].method != EAP_TYPE_PAX) {
     372           0 :                 wpa_hexdump_ascii(MSG_DEBUG,
     373             :                                   "EAP-PAX: EAP-PAX not enabled for CID",
     374           0 :                                   (u8 *) data->cid, data->cid_len);
     375           0 :                 data->state = FAILURE;
     376           0 :                 return;
     377             :         }
     378             : 
     379          78 :         if (sm->user->password == NULL ||
     380          39 :             sm->user->password_len != EAP_PAX_AK_LEN) {
     381           0 :                 wpa_hexdump_ascii(MSG_DEBUG, "EAP-PAX: invalid password in "
     382             :                                   "user database for CID",
     383           0 :                                   (u8 *) data->cid, data->cid_len);
     384           0 :                 data->state = FAILURE;
     385           0 :                 return;
     386             :         }
     387          39 :         os_memcpy(data->ak, sm->user->password, EAP_PAX_AK_LEN);
     388             : 
     389          39 :         if (eap_pax_initial_key_derivation(data->mac_id, data->ak,
     390          39 :                                            data->rand.e, data->mk, data->ck,
     391          39 :                                            data->ick, data->mid) < 0) {
     392           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: Failed to complete initial "
     393             :                            "key derivation");
     394           0 :                 data->state = FAILURE;
     395           0 :                 return;
     396             :         }
     397          39 :         data->keys_set = 1;
     398             : 
     399          78 :         eap_pax_mac(data->mac_id, data->ck, EAP_PAX_CK_LEN,
     400          39 :                     data->rand.r.x, EAP_PAX_RAND_LEN,
     401          39 :                     data->rand.r.y, EAP_PAX_RAND_LEN,
     402          39 :                     (u8 *) data->cid, data->cid_len, mac);
     403          39 :         if (os_memcmp_const(mac, pos, EAP_PAX_MAC_LEN) != 0) {
     404           1 :                 wpa_printf(MSG_INFO, "EAP-PAX: Invalid MAC_CK(A, B, CID) in "
     405             :                            "PAX_STD-2");
     406           1 :                 wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: Expected MAC_CK(A, B, CID)",
     407             :                             mac, EAP_PAX_MAC_LEN);
     408           1 :                 data->state = FAILURE;
     409           1 :                 return;
     410             :         }
     411             : 
     412          38 :         pos += EAP_PAX_MAC_LEN;
     413          38 :         left -= EAP_PAX_MAC_LEN;
     414             : 
     415          38 :         if (left < EAP_PAX_ICV_LEN) {
     416           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: Too short ICV (%lu) in "
     417             :                            "PAX_STD-2", (unsigned long) left);
     418           0 :                 return;
     419             :         }
     420          38 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: ICV", pos, EAP_PAX_ICV_LEN);
     421          76 :         eap_pax_mac(data->mac_id, data->ick, EAP_PAX_ICK_LEN,
     422          38 :                     wpabuf_head(respData),
     423          38 :                     wpabuf_len(respData) - EAP_PAX_ICV_LEN, NULL, 0, NULL, 0,
     424             :                     icvbuf);
     425          38 :         if (os_memcmp_const(icvbuf, pos, EAP_PAX_ICV_LEN) != 0) {
     426           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: Invalid ICV in PAX_STD-2");
     427           0 :                 wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: Expected ICV",
     428             :                             icvbuf, EAP_PAX_ICV_LEN);
     429           0 :                 return;
     430             :         }
     431          38 :         pos += EAP_PAX_ICV_LEN;
     432          38 :         left -= EAP_PAX_ICV_LEN;
     433             : 
     434          38 :         if (left > 0) {
     435           0 :                 wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: ignored extra payload",
     436             :                             pos, left);
     437             :         }
     438             : 
     439          38 :         data->state = PAX_STD_3;
     440             : }
     441             : 
     442             : 
     443          38 : static void eap_pax_process_ack(struct eap_sm *sm,
     444             :                                 struct eap_pax_data *data,
     445             :                                 struct wpabuf *respData)
     446             : {
     447          38 :         if (data->state != PAX_STD_3)
     448          38 :                 return;
     449             : 
     450          38 :         wpa_printf(MSG_DEBUG, "EAP-PAX: Received PAX-ACK - authentication "
     451             :                    "completed successfully");
     452          38 :         data->state = SUCCESS;
     453             : }
     454             : 
     455             : 
     456          77 : static void eap_pax_process(struct eap_sm *sm, void *priv,
     457             :                             struct wpabuf *respData)
     458             : {
     459          77 :         struct eap_pax_data *data = priv;
     460             :         struct eap_pax_hdr *resp;
     461             :         const u8 *pos;
     462             :         size_t len;
     463             : 
     464          77 :         if (sm->user == NULL || sm->user->password == NULL) {
     465           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: Plaintext password not "
     466             :                            "configured");
     467           0 :                 data->state = FAILURE;
     468           0 :                 return;
     469             :         }
     470             : 
     471          77 :         pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_PAX, respData, &len);
     472          77 :         if (pos == NULL || len < sizeof(*resp))
     473           0 :                 return;
     474             : 
     475          77 :         resp = (struct eap_pax_hdr *) pos;
     476             : 
     477          77 :         switch (resp->op_code) {
     478             :         case EAP_PAX_OP_STD_2:
     479          39 :                 eap_pax_process_std_2(sm, data, respData);
     480          39 :                 break;
     481             :         case EAP_PAX_OP_ACK:
     482          38 :                 eap_pax_process_ack(sm, data, respData);
     483          38 :                 break;
     484             :         }
     485             : }
     486             : 
     487             : 
     488          78 : static Boolean eap_pax_isDone(struct eap_sm *sm, void *priv)
     489             : {
     490          78 :         struct eap_pax_data *data = priv;
     491          78 :         return data->state == SUCCESS || data->state == FAILURE;
     492             : }
     493             : 
     494             : 
     495          39 : static u8 * eap_pax_getKey(struct eap_sm *sm, void *priv, size_t *len)
     496             : {
     497          39 :         struct eap_pax_data *data = priv;
     498             :         u8 *key;
     499             : 
     500          39 :         if (data->state != SUCCESS)
     501           1 :                 return NULL;
     502             : 
     503          38 :         key = os_malloc(EAP_MSK_LEN);
     504          38 :         if (key == NULL)
     505           0 :                 return NULL;
     506             : 
     507          38 :         *len = EAP_MSK_LEN;
     508          38 :         eap_pax_kdf(data->mac_id, data->mk, EAP_PAX_MK_LEN,
     509          38 :                     "Master Session Key", data->rand.e, 2 * EAP_PAX_RAND_LEN,
     510             :                     EAP_MSK_LEN, key);
     511             : 
     512          38 :         return key;
     513             : }
     514             : 
     515             : 
     516           2 : static u8 * eap_pax_get_emsk(struct eap_sm *sm, void *priv, size_t *len)
     517             : {
     518           2 :         struct eap_pax_data *data = priv;
     519             :         u8 *key;
     520             : 
     521           2 :         if (data->state != SUCCESS)
     522           0 :                 return NULL;
     523             : 
     524           2 :         key = os_malloc(EAP_EMSK_LEN);
     525           2 :         if (key == NULL)
     526           0 :                 return NULL;
     527             : 
     528           2 :         *len = EAP_EMSK_LEN;
     529           2 :         eap_pax_kdf(data->mac_id, data->mk, EAP_PAX_MK_LEN,
     530             :                     "Extended Master Session Key",
     531           2 :                     data->rand.e, 2 * EAP_PAX_RAND_LEN,
     532             :                     EAP_EMSK_LEN, key);
     533             : 
     534           2 :         return key;
     535             : }
     536             : 
     537             : 
     538          40 : static Boolean eap_pax_isSuccess(struct eap_sm *sm, void *priv)
     539             : {
     540          40 :         struct eap_pax_data *data = priv;
     541          40 :         return data->state == SUCCESS;
     542             : }
     543             : 
     544             : 
     545          39 : static u8 * eap_pax_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
     546             : {
     547          39 :         struct eap_pax_data *data = priv;
     548             :         u8 *sid;
     549             : 
     550          39 :         if (data->state != SUCCESS)
     551           1 :                 return NULL;
     552             : 
     553          38 :         sid = os_malloc(1 + EAP_PAX_MID_LEN);
     554          38 :         if (sid == NULL)
     555           0 :                 return NULL;
     556             : 
     557          38 :         *len = 1 + EAP_PAX_MID_LEN;
     558          38 :         sid[0] = EAP_TYPE_PAX;
     559          38 :         os_memcpy(sid + 1, data->mid, EAP_PAX_MID_LEN);
     560             : 
     561          38 :         return sid;
     562             : }
     563             : 
     564             : 
     565          25 : int eap_server_pax_register(void)
     566             : {
     567             :         struct eap_method *eap;
     568             :         int ret;
     569             : 
     570          25 :         eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
     571             :                                       EAP_VENDOR_IETF, EAP_TYPE_PAX, "PAX");
     572          25 :         if (eap == NULL)
     573           0 :                 return -1;
     574             : 
     575          25 :         eap->init = eap_pax_init;
     576          25 :         eap->reset = eap_pax_reset;
     577          25 :         eap->buildReq = eap_pax_buildReq;
     578          25 :         eap->check = eap_pax_check;
     579          25 :         eap->process = eap_pax_process;
     580          25 :         eap->isDone = eap_pax_isDone;
     581          25 :         eap->getKey = eap_pax_getKey;
     582          25 :         eap->isSuccess = eap_pax_isSuccess;
     583          25 :         eap->get_emsk = eap_pax_get_emsk;
     584          25 :         eap->getSessionId = eap_pax_get_session_id;
     585             : 
     586          25 :         ret = eap_server_method_register(eap);
     587          25 :         if (ret)
     588           0 :                 eap_server_method_free(eap);
     589          25 :         return ret;
     590             : }

Generated by: LCOV version 1.10