LCOV - code coverage report
Current view: top level - src/eap_peer - eap_pax.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1475438200 Lines: 274 294 93.2 %
Date: 2016-10-02 Functions: 11 11 100.0 %

          Line data    Source code
       1             : /*
       2             :  * EAP peer method: EAP-PAX (RFC 4746)
       3             :  * Copyright (c) 2005-2008, 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_common/eap_pax_common.h"
      14             : #include "eap_i.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_INIT, PAX_STD_2_SENT, PAX_DONE } state;
      27             :         u8 mac_id, dh_group_id, public_key_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             :         char *cid;
      36             :         size_t cid_len;
      37             :         u8 ak[EAP_PAX_AK_LEN];
      38             :         u8 mk[EAP_PAX_MK_LEN];
      39             :         u8 ck[EAP_PAX_CK_LEN];
      40             :         u8 ick[EAP_PAX_ICK_LEN];
      41             :         u8 mid[EAP_PAX_MID_LEN];
      42             : };
      43             : 
      44             : 
      45             : static void eap_pax_deinit(struct eap_sm *sm, void *priv);
      46             : 
      47             : 
      48          88 : static void * eap_pax_init(struct eap_sm *sm)
      49             : {
      50             :         struct eap_pax_data *data;
      51             :         const u8 *identity, *password;
      52             :         size_t identity_len, password_len;
      53             : 
      54          88 :         identity = eap_get_config_identity(sm, &identity_len);
      55          88 :         password = eap_get_config_password(sm, &password_len);
      56          88 :         if (!identity || !password) {
      57           1 :                 wpa_printf(MSG_INFO, "EAP-PAX: CID (nai) or key (password) "
      58             :                            "not configured");
      59           1 :                 return NULL;
      60             :         }
      61             : 
      62          87 :         if (password_len != EAP_PAX_AK_LEN) {
      63           1 :                 wpa_printf(MSG_INFO, "EAP-PAX: Invalid PSK length");
      64           1 :                 return NULL;
      65             :         }
      66             : 
      67          86 :         data = os_zalloc(sizeof(*data));
      68          86 :         if (data == NULL)
      69           1 :                 return NULL;
      70          85 :         data->state = PAX_INIT;
      71             : 
      72          85 :         data->cid = os_malloc(identity_len);
      73          85 :         if (data->cid == NULL) {
      74           1 :                 eap_pax_deinit(sm, data);
      75           1 :                 return NULL;
      76             :         }
      77          84 :         os_memcpy(data->cid, identity, identity_len);
      78          84 :         data->cid_len = identity_len;
      79             : 
      80          84 :         os_memcpy(data->ak, password, EAP_PAX_AK_LEN);
      81             : 
      82          84 :         return data;
      83             : }
      84             : 
      85             : 
      86          85 : static void eap_pax_deinit(struct eap_sm *sm, void *priv)
      87             : {
      88          85 :         struct eap_pax_data *data = priv;
      89          85 :         os_free(data->cid);
      90          85 :         bin_clear_free(data, sizeof(*data));
      91          85 : }
      92             : 
      93             : 
      94         130 : static struct wpabuf * eap_pax_alloc_resp(const struct eap_pax_hdr *req,
      95             :                                           u8 id, u8 op_code, size_t plen)
      96             : {
      97             :         struct wpabuf *resp;
      98             :         struct eap_pax_hdr *pax;
      99             : 
     100         130 :         resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_PAX,
     101             :                              sizeof(*pax) + plen, EAP_CODE_RESPONSE, id);
     102         130 :         if (resp == NULL)
     103           2 :                 return NULL;
     104             : 
     105         128 :         pax = wpabuf_put(resp, sizeof(*pax));
     106         128 :         pax->op_code = op_code;
     107         128 :         pax->flags = 0;
     108         128 :         pax->mac_id = req->mac_id;
     109         128 :         pax->dh_group_id = req->dh_group_id;
     110         128 :         pax->public_key_id = req->public_key_id;
     111             : 
     112         128 :         return resp;
     113             : }
     114             : 
     115             : 
     116          75 : static struct wpabuf * eap_pax_process_std_1(struct eap_pax_data *data,
     117             :                                              struct eap_method_ret *ret, u8 id,
     118             :                                              const struct eap_pax_hdr *req,
     119             :                                              size_t req_plen)
     120             : {
     121             :         struct wpabuf *resp;
     122             :         const u8 *pos;
     123             :         u8 *rpos;
     124             :         size_t left, plen;
     125             : 
     126          75 :         wpa_printf(MSG_DEBUG, "EAP-PAX: PAX_STD-1 (received)");
     127             : 
     128          75 :         if (data->state != PAX_INIT) {
     129           1 :                 wpa_printf(MSG_INFO, "EAP-PAX: PAX_STD-1 received in "
     130           1 :                            "unexpected state (%d) - ignored", data->state);
     131           1 :                 ret->ignore = TRUE;
     132           1 :                 return NULL;
     133             :         }
     134             : 
     135          74 :         if (req->flags & EAP_PAX_FLAGS_CE) {
     136           1 :                 wpa_printf(MSG_INFO, "EAP-PAX: PAX_STD-1 with CE flag set - "
     137             :                            "ignored");
     138           1 :                 ret->ignore = TRUE;
     139           1 :                 return NULL;
     140             :         }
     141             : 
     142          73 :         left = req_plen - sizeof(*req);
     143             : 
     144          73 :         if (left < 2 + EAP_PAX_RAND_LEN) {
     145           1 :                 wpa_printf(MSG_INFO, "EAP-PAX: PAX_STD-1 with too short "
     146             :                            "payload");
     147           1 :                 ret->ignore = TRUE;
     148           1 :                 return NULL;
     149             :         }
     150             : 
     151          72 :         pos = (const u8 *) (req + 1);
     152          72 :         if (WPA_GET_BE16(pos) != EAP_PAX_RAND_LEN) {
     153           1 :                 wpa_printf(MSG_INFO, "EAP-PAX: PAX_STD-1 with incorrect A "
     154             :                            "length %d (expected %d)",
     155           1 :                            WPA_GET_BE16(pos), EAP_PAX_RAND_LEN);
     156           1 :                 ret->ignore = TRUE;
     157           1 :                 return NULL;
     158             :         }
     159             : 
     160          71 :         pos += 2;
     161          71 :         left -= 2;
     162          71 :         os_memcpy(data->rand.r.x, pos, EAP_PAX_RAND_LEN);
     163          71 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: X (server rand)",
     164          71 :                     data->rand.r.x, EAP_PAX_RAND_LEN);
     165          71 :         pos += EAP_PAX_RAND_LEN;
     166          71 :         left -= EAP_PAX_RAND_LEN;
     167             : 
     168          71 :         if (left > 0) {
     169           1 :                 wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: ignored extra payload",
     170             :                             pos, left);
     171             :         }
     172             : 
     173          71 :         if (random_get_bytes(data->rand.r.y, EAP_PAX_RAND_LEN)) {
     174           1 :                 wpa_printf(MSG_ERROR, "EAP-PAX: Failed to get random data");
     175           1 :                 ret->ignore = TRUE;
     176           1 :                 return NULL;
     177             :         }
     178          70 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: Y (client rand)",
     179          70 :                     data->rand.r.y, EAP_PAX_RAND_LEN);
     180             : 
     181          70 :         if (eap_pax_initial_key_derivation(req->mac_id, data->ak, data->rand.e,
     182          70 :                                            data->mk, data->ck, data->ick,
     183          70 :                                            data->mid) < 0) {
     184           1 :                 ret->ignore = TRUE;
     185           1 :                 return NULL;
     186             :         }
     187             : 
     188          69 :         wpa_printf(MSG_DEBUG, "EAP-PAX: PAX_STD-2 (sending)");
     189             : 
     190          69 :         plen = 2 + EAP_PAX_RAND_LEN + 2 + data->cid_len + 2 + EAP_PAX_MAC_LEN +
     191             :                 EAP_PAX_ICV_LEN;
     192          69 :         resp = eap_pax_alloc_resp(req, id, EAP_PAX_OP_STD_2, plen);
     193          69 :         if (resp == NULL)
     194           1 :                 return NULL;
     195             : 
     196          68 :         wpabuf_put_be16(resp, EAP_PAX_RAND_LEN);
     197          68 :         wpabuf_put_data(resp, data->rand.r.y, EAP_PAX_RAND_LEN);
     198          68 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: B = Y (client rand)",
     199          68 :                     data->rand.r.y, EAP_PAX_RAND_LEN);
     200             : 
     201          68 :         wpabuf_put_be16(resp, data->cid_len);
     202          68 :         wpabuf_put_data(resp, data->cid, data->cid_len);
     203         136 :         wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-PAX: CID",
     204          68 :                           (u8 *) data->cid, data->cid_len);
     205             : 
     206          68 :         wpabuf_put_be16(resp, EAP_PAX_MAC_LEN);
     207          68 :         rpos = wpabuf_put(resp, EAP_PAX_MAC_LEN);
     208         136 :         eap_pax_mac(req->mac_id, data->ck, EAP_PAX_CK_LEN,
     209          68 :                     data->rand.r.x, EAP_PAX_RAND_LEN,
     210          68 :                     data->rand.r.y, EAP_PAX_RAND_LEN,
     211          68 :                     (u8 *) data->cid, data->cid_len, rpos);
     212          68 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: MAC_CK(A, B, CID)",
     213             :                     rpos, EAP_PAX_MAC_LEN);
     214             : 
     215             :         /* Optional ADE could be added here, if needed */
     216             : 
     217          68 :         rpos = wpabuf_put(resp, EAP_PAX_ICV_LEN);
     218         136 :         eap_pax_mac(req->mac_id, data->ick, EAP_PAX_ICK_LEN,
     219         136 :                     wpabuf_head(resp), wpabuf_len(resp) - EAP_PAX_ICV_LEN,
     220             :                     NULL, 0, NULL, 0, rpos);
     221          68 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: ICV", rpos, EAP_PAX_ICV_LEN);
     222             : 
     223          68 :         data->state = PAX_STD_2_SENT;
     224          68 :         data->mac_id = req->mac_id;
     225          68 :         data->dh_group_id = req->dh_group_id;
     226          68 :         data->public_key_id = req->public_key_id;
     227             : 
     228          68 :         return resp;
     229             : }
     230             : 
     231             : 
     232          63 : static struct wpabuf * eap_pax_process_std_3(struct eap_pax_data *data,
     233             :                                              struct eap_method_ret *ret, u8 id,
     234             :                                              const struct eap_pax_hdr *req,
     235             :                                              size_t req_plen)
     236             : {
     237             :         struct wpabuf *resp;
     238             :         u8 *rpos, mac[EAP_PAX_MAC_LEN];
     239             :         const u8 *pos;
     240             :         size_t left;
     241             : 
     242          63 :         wpa_printf(MSG_DEBUG, "EAP-PAX: PAX_STD-3 (received)");
     243             : 
     244          63 :         if (data->state != PAX_STD_2_SENT) {
     245           1 :                 wpa_printf(MSG_INFO, "EAP-PAX: PAX_STD-3 received in "
     246           1 :                            "unexpected state (%d) - ignored", data->state);
     247           1 :                 ret->ignore = TRUE;
     248           1 :                 return NULL;
     249             :         }
     250             : 
     251          62 :         if (req->flags & EAP_PAX_FLAGS_CE) {
     252           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: PAX_STD-3 with CE flag set - "
     253             :                            "ignored");
     254           0 :                 ret->ignore = TRUE;
     255           0 :                 return NULL;
     256             :         }
     257             : 
     258          62 :         left = req_plen - sizeof(*req);
     259             : 
     260          62 :         if (left < 2 + EAP_PAX_MAC_LEN) {
     261           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: PAX_STD-3 with too short "
     262             :                            "payload");
     263           0 :                 ret->ignore = TRUE;
     264           0 :                 return NULL;
     265             :         }
     266             : 
     267          62 :         pos = (const u8 *) (req + 1);
     268          62 :         if (WPA_GET_BE16(pos) != EAP_PAX_MAC_LEN) {
     269           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: PAX_STD-3 with incorrect "
     270             :                            "MAC_CK length %d (expected %d)",
     271           0 :                            WPA_GET_BE16(pos), EAP_PAX_MAC_LEN);
     272           0 :                 ret->ignore = TRUE;
     273           0 :                 return NULL;
     274             :         }
     275          62 :         pos += 2;
     276          62 :         left -= 2;
     277          62 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: MAC_CK(B, CID)",
     278             :                     pos, EAP_PAX_MAC_LEN);
     279         124 :         if (eap_pax_mac(data->mac_id, data->ck, EAP_PAX_CK_LEN,
     280          62 :                         data->rand.r.y, EAP_PAX_RAND_LEN,
     281          62 :                         (u8 *) data->cid, data->cid_len, NULL, 0, mac) < 0) {
     282           1 :                 wpa_printf(MSG_INFO,
     283             :                            "EAP-PAX: Could not derive MAC_CK(B, CID)");
     284           1 :                 ret->methodState = METHOD_DONE;
     285           1 :                 ret->decision = DECISION_FAIL;
     286           1 :                 return NULL;
     287             :         }
     288             : 
     289          61 :         if (os_memcmp_const(pos, mac, EAP_PAX_MAC_LEN) != 0) {
     290           0 :                 wpa_printf(MSG_INFO, "EAP-PAX: Invalid MAC_CK(B, CID) "
     291             :                            "received");
     292           0 :                 wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: expected MAC_CK(B, CID)",
     293             :                             mac, EAP_PAX_MAC_LEN);
     294           0 :                 ret->methodState = METHOD_DONE;
     295           0 :                 ret->decision = DECISION_FAIL;
     296           0 :                 return NULL;
     297             :         }
     298             : 
     299          61 :         pos += EAP_PAX_MAC_LEN;
     300          61 :         left -= EAP_PAX_MAC_LEN;
     301             : 
     302          61 :         if (left > 0) {
     303           0 :                 wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: ignored extra payload",
     304             :                             pos, left);
     305             :         }
     306             : 
     307          61 :         wpa_printf(MSG_DEBUG, "EAP-PAX: PAX-ACK (sending)");
     308             : 
     309          61 :         resp = eap_pax_alloc_resp(req, id, EAP_PAX_OP_ACK, EAP_PAX_ICV_LEN);
     310          61 :         if (resp == NULL)
     311           1 :                 return NULL;
     312             : 
     313             :         /* Optional ADE could be added here, if needed */
     314             : 
     315          60 :         rpos = wpabuf_put(resp, EAP_PAX_ICV_LEN);
     316         120 :         if (eap_pax_mac(data->mac_id, data->ick, EAP_PAX_ICK_LEN,
     317         120 :                         wpabuf_head(resp), wpabuf_len(resp) - EAP_PAX_ICV_LEN,
     318             :                         NULL, 0, NULL, 0, rpos) < 0) {
     319           1 :                 wpabuf_free(resp);
     320           1 :                 return NULL;
     321             :         }
     322          59 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: ICV", rpos, EAP_PAX_ICV_LEN);
     323             : 
     324          59 :         data->state = PAX_DONE;
     325          59 :         ret->methodState = METHOD_DONE;
     326          59 :         ret->decision = DECISION_UNCOND_SUCC;
     327          59 :         ret->allowNotifications = FALSE;
     328             : 
     329          59 :         return resp;
     330             : }
     331             : 
     332             : 
     333         151 : static struct wpabuf * eap_pax_process(struct eap_sm *sm, void *priv,
     334             :                                        struct eap_method_ret *ret,
     335             :                                        const struct wpabuf *reqData)
     336             : {
     337         151 :         struct eap_pax_data *data = priv;
     338             :         const struct eap_pax_hdr *req;
     339             :         struct wpabuf *resp;
     340             :         u8 icvbuf[EAP_PAX_ICV_LEN], id;
     341             :         const u8 *icv, *pos;
     342             :         size_t len;
     343             :         u16 flen, mlen;
     344             : 
     345         151 :         pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_PAX, reqData, &len);
     346         151 :         if (pos == NULL || len < sizeof(*req) + EAP_PAX_ICV_LEN) {
     347           3 :                 ret->ignore = TRUE;
     348           3 :                 return NULL;
     349             :         }
     350         148 :         id = eap_get_id(reqData);
     351         148 :         req = (const struct eap_pax_hdr *) pos;
     352         148 :         flen = len - EAP_PAX_ICV_LEN;
     353         148 :         mlen = wpabuf_len(reqData) - EAP_PAX_ICV_LEN;
     354             : 
     355         740 :         wpa_printf(MSG_DEBUG, "EAP-PAX: received frame: op_code 0x%x "
     356             :                    "flags 0x%x mac_id 0x%x dh_group_id 0x%x "
     357             :                    "public_key_id 0x%x",
     358         592 :                    req->op_code, req->flags, req->mac_id, req->dh_group_id,
     359         148 :                    req->public_key_id);
     360         148 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: received payload",
     361             :                     pos, len - EAP_PAX_ICV_LEN);
     362             : 
     363         148 :         if (data->state != PAX_INIT && data->mac_id != req->mac_id) {
     364           2 :                 wpa_printf(MSG_INFO, "EAP-PAX: MAC ID changed during "
     365             :                            "authentication (was 0x%d, is 0x%d)",
     366           2 :                            data->mac_id, req->mac_id);
     367           1 :                 ret->ignore = TRUE;
     368           1 :                 return NULL;
     369             :         }
     370             : 
     371         147 :         if (data->state != PAX_INIT && data->dh_group_id != req->dh_group_id) {
     372           2 :                 wpa_printf(MSG_INFO, "EAP-PAX: DH Group ID changed during "
     373             :                            "authentication (was 0x%d, is 0x%d)",
     374           2 :                            data->dh_group_id, req->dh_group_id);
     375           1 :                 ret->ignore = TRUE;
     376           1 :                 return NULL;
     377             :         }
     378             : 
     379         211 :         if (data->state != PAX_INIT &&
     380          65 :             data->public_key_id != req->public_key_id) {
     381           2 :                 wpa_printf(MSG_INFO, "EAP-PAX: Public Key ID changed during "
     382             :                            "authentication (was 0x%d, is 0x%d)",
     383           2 :                            data->public_key_id, req->public_key_id);
     384           1 :                 ret->ignore = TRUE;
     385           1 :                 return NULL;
     386             :         }
     387             : 
     388             :         /* TODO: add support EAP_PAX_HMAC_SHA256_128 */
     389         145 :         if (req->mac_id != EAP_PAX_MAC_HMAC_SHA1_128) {
     390           1 :                 wpa_printf(MSG_INFO, "EAP-PAX: Unsupported MAC ID 0x%x",
     391           1 :                            req->mac_id);
     392           1 :                 ret->ignore = TRUE;
     393           1 :                 return NULL;
     394             :         }
     395             : 
     396         144 :         if (req->dh_group_id != EAP_PAX_DH_GROUP_NONE) {
     397           1 :                 wpa_printf(MSG_INFO, "EAP-PAX: Unsupported DH Group ID 0x%x",
     398           1 :                            req->dh_group_id);
     399           1 :                 ret->ignore = TRUE;
     400           1 :                 return NULL;
     401             :         }
     402             : 
     403         143 :         if (req->public_key_id != EAP_PAX_PUBLIC_KEY_NONE) {
     404           1 :                 wpa_printf(MSG_INFO, "EAP-PAX: Unsupported Public Key ID 0x%x",
     405           1 :                            req->public_key_id);
     406           1 :                 ret->ignore = TRUE;
     407           1 :                 return NULL;
     408             :         }
     409             : 
     410         142 :         if (req->flags & EAP_PAX_FLAGS_MF) {
     411             :                 /* TODO: add support for reassembling fragments */
     412           1 :                 wpa_printf(MSG_INFO, "EAP-PAX: fragmentation not supported - "
     413             :                            "ignored packet");
     414           1 :                 ret->ignore = TRUE;
     415           1 :                 return NULL;
     416             :         }
     417             : 
     418         141 :         icv = pos + len - EAP_PAX_ICV_LEN;
     419         141 :         wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: ICV", icv, EAP_PAX_ICV_LEN);
     420         141 :         if (req->op_code == EAP_PAX_OP_STD_1) {
     421         152 :                 eap_pax_mac(req->mac_id, (u8 *) "", 0,
     422          76 :                             wpabuf_head(reqData), mlen, NULL, 0, NULL, 0,
     423             :                             icvbuf);
     424             :         } else {
     425         130 :                 eap_pax_mac(req->mac_id, data->ick, EAP_PAX_ICK_LEN,
     426          65 :                             wpabuf_head(reqData), mlen, NULL, 0, NULL, 0,
     427             :                             icvbuf);
     428             :         }
     429         141 :         if (os_memcmp_const(icv, icvbuf, EAP_PAX_ICV_LEN) != 0) {
     430           2 :                 wpa_printf(MSG_DEBUG, "EAP-PAX: invalid ICV - ignoring the "
     431             :                            "message");
     432           2 :                 wpa_hexdump(MSG_MSGDUMP, "EAP-PAX: expected ICV",
     433             :                             icvbuf, EAP_PAX_ICV_LEN);
     434           2 :                 ret->ignore = TRUE;
     435           2 :                 return NULL;
     436             :         }
     437             : 
     438         139 :         ret->ignore = FALSE;
     439         139 :         ret->methodState = METHOD_MAY_CONT;
     440         139 :         ret->decision = DECISION_FAIL;
     441         139 :         ret->allowNotifications = TRUE;
     442             : 
     443         139 :         switch (req->op_code) {
     444             :         case EAP_PAX_OP_STD_1:
     445          75 :                 resp = eap_pax_process_std_1(data, ret, id, req, flen);
     446          75 :                 break;
     447             :         case EAP_PAX_OP_STD_3:
     448          63 :                 resp = eap_pax_process_std_3(data, ret, id, req, flen);
     449          63 :                 break;
     450             :         default:
     451           1 :                 wpa_printf(MSG_DEBUG, "EAP-PAX: ignoring message with unknown "
     452           1 :                            "op_code %d", req->op_code);
     453           1 :                 ret->ignore = TRUE;
     454           1 :                 return NULL;
     455             :         }
     456             : 
     457         138 :         if (ret->methodState == METHOD_DONE) {
     458          60 :                 ret->allowNotifications = FALSE;
     459             :         }
     460             : 
     461         138 :         return resp;
     462             : }
     463             : 
     464             : 
     465         131 : static Boolean eap_pax_isKeyAvailable(struct eap_sm *sm, void *priv)
     466             : {
     467         131 :         struct eap_pax_data *data = priv;
     468         131 :         return data->state == PAX_DONE;
     469             : }
     470             : 
     471             : 
     472          59 : static u8 * eap_pax_getKey(struct eap_sm *sm, void *priv, size_t *len)
     473             : {
     474          59 :         struct eap_pax_data *data = priv;
     475             :         u8 *key;
     476             : 
     477          59 :         if (data->state != PAX_DONE)
     478           0 :                 return NULL;
     479             : 
     480          59 :         key = os_malloc(EAP_MSK_LEN);
     481          59 :         if (key == NULL)
     482           1 :                 return NULL;
     483             : 
     484          58 :         *len = EAP_MSK_LEN;
     485          58 :         if (eap_pax_kdf(data->mac_id, data->mk, EAP_PAX_MK_LEN,
     486             :                         "Master Session Key",
     487          58 :                         data->rand.e, 2 * EAP_PAX_RAND_LEN,
     488             :                         EAP_MSK_LEN, key) < 0) {
     489           1 :                 os_free(key);
     490           1 :                 return NULL;
     491             :         }
     492             : 
     493          57 :         return key;
     494             : }
     495             : 
     496             : 
     497           5 : static u8 * eap_pax_get_emsk(struct eap_sm *sm, void *priv, size_t *len)
     498             : {
     499           5 :         struct eap_pax_data *data = priv;
     500             :         u8 *key;
     501             : 
     502           5 :         if (data->state != PAX_DONE)
     503           0 :                 return NULL;
     504             : 
     505           5 :         key = os_malloc(EAP_EMSK_LEN);
     506           5 :         if (key == NULL)
     507           1 :                 return NULL;
     508             : 
     509           4 :         *len = EAP_EMSK_LEN;
     510           4 :         if (eap_pax_kdf(data->mac_id, data->mk, EAP_PAX_MK_LEN,
     511             :                         "Extended Master Session Key",
     512           4 :                         data->rand.e, 2 * EAP_PAX_RAND_LEN,
     513             :                         EAP_EMSK_LEN, key) < 0) {
     514           1 :                 os_free(key);
     515           1 :                 return NULL;
     516             :         }
     517             : 
     518           3 :         return key;
     519             : }
     520             : 
     521             : 
     522          59 : static u8 * eap_pax_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
     523             : {
     524          59 :         struct eap_pax_data *data = priv;
     525             :         u8 *sid;
     526             : 
     527          59 :         if (data->state != PAX_DONE)
     528           0 :                 return NULL;
     529             : 
     530          59 :         sid = os_malloc(1 + EAP_PAX_MID_LEN);
     531          59 :         if (sid == NULL)
     532           1 :                 return NULL;
     533             : 
     534          58 :         *len = 1 + EAP_PAX_MID_LEN;
     535          58 :         sid[0] = EAP_TYPE_PAX;
     536          58 :         os_memcpy(sid + 1, data->mid, EAP_PAX_MID_LEN);
     537             : 
     538          58 :         return sid;
     539             : }
     540             : 
     541             : 
     542          49 : int eap_peer_pax_register(void)
     543             : {
     544             :         struct eap_method *eap;
     545             : 
     546          49 :         eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
     547             :                                     EAP_VENDOR_IETF, EAP_TYPE_PAX, "PAX");
     548          49 :         if (eap == NULL)
     549           0 :                 return -1;
     550             : 
     551          49 :         eap->init = eap_pax_init;
     552          49 :         eap->deinit = eap_pax_deinit;
     553          49 :         eap->process = eap_pax_process;
     554          49 :         eap->isKeyAvailable = eap_pax_isKeyAvailable;
     555          49 :         eap->getKey = eap_pax_getKey;
     556          49 :         eap->get_emsk = eap_pax_get_emsk;
     557          49 :         eap->getSessionId = eap_pax_get_session_id;
     558             : 
     559          49 :         return eap_peer_method_register(eap);
     560             : }

Generated by: LCOV version 1.10