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 1393793999 Lines: 9 45 20.0 %
Date: 2014-03-02 Functions: 1 4 25.0 %
Branches: 2 14 14.3 %

           Branch data     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                 :          0 : 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                 :          0 :         return (void *) 1;
      20                 :            : }
      21                 :            : 
      22                 :            : 
      23                 :          0 : static void eap_otp_deinit(struct eap_sm *sm, void *priv)
      24                 :            : {
      25                 :          0 : }
      26                 :            : 
      27                 :            : 
      28                 :          0 : 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                 :          0 :         pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_OTP, reqData, &len);
      38         [ #  # ]:          0 :         if (pos == NULL) {
      39                 :          0 :                 ret->ignore = TRUE;
      40                 :          0 :                 return NULL;
      41                 :            :         }
      42                 :          0 :         wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-OTP: Request message",
      43                 :            :                           pos, len);
      44                 :            : 
      45                 :          0 :         password = eap_get_config_otp(sm, &password_len);
      46         [ #  # ]:          0 :         if (password)
      47                 :          0 :                 otp = 1;
      48                 :            :         else {
      49                 :          0 :                 password = eap_get_config_password(sm, &password_len);
      50                 :          0 :                 otp = 0;
      51                 :            :         }
      52                 :            : 
      53         [ #  # ]:          0 :         if (password == NULL) {
      54                 :          0 :                 wpa_printf(MSG_INFO, "EAP-OTP: Password not configured");
      55                 :          0 :                 eap_sm_request_otp(sm, (const char *) pos, len);
      56                 :          0 :                 ret->ignore = TRUE;
      57                 :          0 :                 return NULL;
      58                 :            :         }
      59                 :            : 
      60                 :          0 :         ret->ignore = FALSE;
      61                 :            : 
      62                 :          0 :         ret->methodState = METHOD_DONE;
      63                 :          0 :         ret->decision = DECISION_COND_SUCC;
      64                 :          0 :         ret->allowNotifications = FALSE;
      65                 :            : 
      66                 :          0 :         resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_OTP, password_len,
      67                 :          0 :                              EAP_CODE_RESPONSE, eap_get_id(reqData));
      68         [ #  # ]:          0 :         if (resp == NULL)
      69                 :          0 :                 return NULL;
      70                 :          0 :         wpabuf_put_data(resp, password, password_len);
      71                 :          0 :         wpa_hexdump_ascii_key(MSG_MSGDUMP, "EAP-OTP: Response",
      72                 :            :                               password, password_len);
      73                 :            : 
      74         [ #  # ]:          0 :         if (otp) {
      75                 :          0 :                 wpa_printf(MSG_DEBUG, "EAP-OTP: Forgetting used password");
      76                 :          0 :                 eap_clear_config_otp(sm);
      77                 :            :         }
      78                 :            : 
      79                 :          0 :         return resp;
      80                 :            : }
      81                 :            : 
      82                 :            : 
      83                 :          4 : int eap_peer_otp_register(void)
      84                 :            : {
      85                 :            :         struct eap_method *eap;
      86                 :            :         int ret;
      87                 :            : 
      88                 :          4 :         eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
      89                 :            :                                     EAP_VENDOR_IETF, EAP_TYPE_OTP, "OTP");
      90         [ -  + ]:          4 :         if (eap == NULL)
      91                 :          0 :                 return -1;
      92                 :            : 
      93                 :          4 :         eap->init = eap_otp_init;
      94                 :          4 :         eap->deinit = eap_otp_deinit;
      95                 :          4 :         eap->process = eap_otp_process;
      96                 :            : 
      97                 :          4 :         ret = eap_peer_method_register(eap);
      98         [ -  + ]:          4 :         if (ret)
      99                 :          0 :                 eap_peer_method_free(eap);
     100                 :          4 :         return ret;
     101                 :            : }

Generated by: LCOV version 1.9