eap_otp.c 2.2 KB

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