LCOV - code coverage report
Current view: top level - src/eap_peer - eap_otp.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1422976643 Lines: 40 45 88.9 %
Date: 2015-02-03 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :  * EAP peer method: EAP-OTP (RFC 3748)
       3             :  * Copyright (c) 2004-2006, 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 "eap_i.h"
      13             : 
      14             : 
      15           2 : static void * eap_otp_init(struct eap_sm *sm)
      16             : {
      17             :         /* No need for private data. However, must return non-NULL to indicate
      18             :          * success. */
      19           2 :         return (void *) 1;
      20             : }
      21             : 
      22             : 
      23           2 : static void eap_otp_deinit(struct eap_sm *sm, void *priv)
      24             : {
      25           2 : }
      26             : 
      27             : 
      28           3 : static struct wpabuf * eap_otp_process(struct eap_sm *sm, void *priv,
      29             :                                        struct eap_method_ret *ret,
      30             :                                        const struct wpabuf *reqData)
      31             : {
      32             :         struct wpabuf *resp;
      33             :         const u8 *pos, *password;
      34             :         size_t password_len, len;
      35             :         int otp;
      36             : 
      37           3 :         pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_OTP, reqData, &len);
      38           3 :         if (pos == NULL) {
      39           0 :                 ret->ignore = TRUE;
      40           0 :                 return NULL;
      41             :         }
      42           3 :         wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-OTP: Request message",
      43             :                           pos, len);
      44             : 
      45           3 :         password = eap_get_config_otp(sm, &password_len);
      46           3 :         if (password)
      47           1 :                 otp = 1;
      48             :         else {
      49           2 :                 password = eap_get_config_password(sm, &password_len);
      50           2 :                 otp = 0;
      51             :         }
      52             : 
      53           3 :         if (password == NULL) {
      54           1 :                 wpa_printf(MSG_INFO, "EAP-OTP: Password not configured");
      55           1 :                 eap_sm_request_otp(sm, (const char *) pos, len);
      56           1 :                 ret->ignore = TRUE;
      57           1 :                 return NULL;
      58             :         }
      59             : 
      60           2 :         ret->ignore = FALSE;
      61             : 
      62           2 :         ret->methodState = METHOD_DONE;
      63           2 :         ret->decision = DECISION_COND_SUCC;
      64           2 :         ret->allowNotifications = FALSE;
      65             : 
      66           2 :         resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_OTP, password_len,
      67           2 :                              EAP_CODE_RESPONSE, eap_get_id(reqData));
      68           2 :         if (resp == NULL)
      69           0 :                 return NULL;
      70           2 :         wpabuf_put_data(resp, password, password_len);
      71           2 :         wpa_hexdump_ascii_key(MSG_MSGDUMP, "EAP-OTP: Response",
      72             :                               password, password_len);
      73             : 
      74           2 :         if (otp) {
      75           1 :                 wpa_printf(MSG_DEBUG, "EAP-OTP: Forgetting used password");
      76           1 :                 eap_clear_config_otp(sm);
      77             :         }
      78             : 
      79           2 :         return resp;
      80             : }
      81             : 
      82             : 
      83          30 : int eap_peer_otp_register(void)
      84             : {
      85             :         struct eap_method *eap;
      86             :         int ret;
      87             : 
      88          30 :         eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
      89             :                                     EAP_VENDOR_IETF, EAP_TYPE_OTP, "OTP");
      90          30 :         if (eap == NULL)
      91           0 :                 return -1;
      92             : 
      93          30 :         eap->init = eap_otp_init;
      94          30 :         eap->deinit = eap_otp_deinit;
      95          30 :         eap->process = eap_otp_process;
      96             : 
      97          30 :         ret = eap_peer_method_register(eap);
      98          30 :         if (ret)
      99           0 :                 eap_peer_method_free(eap);
     100          30 :         return ret;
     101             : }

Generated by: LCOV version 1.10