eap_otp.c
Go to the documentation of this file.
00001 /*
00002  * EAP peer method: EAP-OTP (RFC 3748)
00003  * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  */
00014 
00015 #include "includes.h"
00016 
00017 #include "common.h"
00018 #include "eap_i.h"
00019 
00020 
00021 static void * eap_otp_init(struct eap_sm *sm)
00022 {
00023         /* No need for private data. However, must return non-NULL to indicate
00024          * success. */
00025         return (void *) 1;
00026 }
00027 
00028 
00029 static void eap_otp_deinit(struct eap_sm *sm, void *priv)
00030 {
00031 }
00032 
00033 
00034 static struct wpabuf * eap_otp_process(struct eap_sm *sm, void *priv,
00035                                        struct eap_method_ret *ret,
00036                                        const struct wpabuf *reqData)
00037 {
00038         struct wpabuf *resp;
00039         const u8 *pos, *password;
00040         size_t password_len, len;
00041         int otp;
00042 
00043         pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_OTP, reqData, &len);
00044         if (pos == NULL) {
00045                 ret->ignore = TRUE;
00046                 return NULL;
00047         }
00048         wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-OTP: Request message",
00049                           pos, len);
00050 
00051         password = eap_get_config_otp(sm, &password_len);
00052         if (password)
00053                 otp = 1;
00054         else {
00055                 password = eap_get_config_password(sm, &password_len);
00056                 otp = 0;
00057         }
00058 
00059         if (password == NULL) {
00060                 wpa_printf(MSG_INFO, "EAP-OTP: Password not configured");
00061                 eap_sm_request_otp(sm, (const char *) pos, len);
00062                 ret->ignore = TRUE;
00063                 return NULL;
00064         }
00065 
00066         ret->ignore = FALSE;
00067 
00068         ret->methodState = METHOD_DONE;
00069         ret->decision = DECISION_COND_SUCC;
00070         ret->allowNotifications = FALSE;
00071 
00072         resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_OTP, password_len,
00073                              EAP_CODE_RESPONSE, eap_get_id(reqData));
00074         if (resp == NULL)
00075                 return NULL;
00076         wpabuf_put_data(resp, password, password_len);
00077         wpa_hexdump_ascii_key(MSG_MSGDUMP, "EAP-OTP: Response",
00078                               password, password_len);
00079 
00080         if (otp) {
00081                 wpa_printf(MSG_DEBUG, "EAP-OTP: Forgetting used password");
00082                 eap_clear_config_otp(sm);
00083         }
00084 
00085         return resp;
00086 }
00087 
00088 
00089 int eap_peer_otp_register(void)
00090 {
00091         struct eap_method *eap;
00092         int ret;
00093 
00094         eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
00095                                     EAP_VENDOR_IETF, EAP_TYPE_OTP, "OTP");
00096         if (eap == NULL)
00097                 return -1;
00098 
00099         eap->init = eap_otp_init;
00100         eap->deinit = eap_otp_deinit;
00101         eap->process = eap_otp_process;
00102 
00103         ret = eap_peer_method_register(eap);
00104         if (ret)
00105                 eap_peer_method_free(eap);
00106         return ret;
00107 }


wpa_supplicant_node
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:33:20