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

Generated by: LCOV version 1.10