eap_gtc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * EAP peer method: EAP-GTC (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. struct eap_gtc_data {
  12. int prefix;
  13. };
  14. static void * eap_gtc_init(struct eap_sm *sm)
  15. {
  16. struct eap_gtc_data *data;
  17. data = os_zalloc(sizeof(*data));
  18. if (data == NULL)
  19. return NULL;
  20. if (sm->m && sm->m->vendor == EAP_VENDOR_IETF &&
  21. sm->m->method == EAP_TYPE_FAST) {
  22. wpa_printf(MSG_DEBUG, "EAP-GTC: EAP-FAST tunnel - use prefix "
  23. "with challenge/response");
  24. data->prefix = 1;
  25. }
  26. return data;
  27. }
  28. static void eap_gtc_deinit(struct eap_sm *sm, void *priv)
  29. {
  30. struct eap_gtc_data *data = priv;
  31. os_free(data);
  32. }
  33. static struct wpabuf * eap_gtc_process(struct eap_sm *sm, void *priv,
  34. struct eap_method_ret *ret,
  35. const struct wpabuf *reqData)
  36. {
  37. struct eap_gtc_data *data = priv;
  38. struct wpabuf *resp;
  39. const u8 *pos, *password, *identity;
  40. size_t password_len, identity_len, len, plen;
  41. int otp;
  42. u8 id;
  43. pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_GTC, reqData, &len);
  44. if (pos == NULL) {
  45. ret->ignore = TRUE;
  46. return NULL;
  47. }
  48. id = eap_get_id(reqData);
  49. wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-GTC: Request message", pos, len);
  50. if (data->prefix &&
  51. (len < 10 || os_memcmp(pos, "CHALLENGE=", 10) != 0)) {
  52. wpa_printf(MSG_DEBUG, "EAP-GTC: Challenge did not start with "
  53. "expected prefix");
  54. /* Send an empty response in order to allow tunneled
  55. * acknowledgement of the failure. This will also cover the
  56. * error case which seems to use EAP-MSCHAPv2 like error
  57. * reporting with EAP-GTC inside EAP-FAST tunnel. */
  58. resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_GTC,
  59. 0, EAP_CODE_RESPONSE, id);
  60. return resp;
  61. }
  62. password = eap_get_config_otp(sm, &password_len);
  63. if (password)
  64. otp = 1;
  65. else {
  66. password = eap_get_config_password(sm, &password_len);
  67. otp = 0;
  68. }
  69. if (password == NULL) {
  70. wpa_printf(MSG_INFO, "EAP-GTC: Password not configured");
  71. eap_sm_request_otp(sm, (const char *) pos, len);
  72. ret->ignore = TRUE;
  73. return NULL;
  74. }
  75. ret->ignore = FALSE;
  76. ret->methodState = data->prefix ? METHOD_MAY_CONT : METHOD_DONE;
  77. ret->decision = DECISION_COND_SUCC;
  78. ret->allowNotifications = FALSE;
  79. plen = password_len;
  80. identity = eap_get_config_identity(sm, &identity_len);
  81. if (identity == NULL)
  82. return NULL;
  83. if (data->prefix)
  84. plen += 9 + identity_len + 1;
  85. resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_GTC, plen,
  86. EAP_CODE_RESPONSE, id);
  87. if (resp == NULL)
  88. return NULL;
  89. if (data->prefix) {
  90. wpabuf_put_data(resp, "RESPONSE=", 9);
  91. wpabuf_put_data(resp, identity, identity_len);
  92. wpabuf_put_u8(resp, '\0');
  93. }
  94. wpabuf_put_data(resp, password, password_len);
  95. wpa_hexdump_ascii_key(MSG_MSGDUMP, "EAP-GTC: Response",
  96. wpabuf_head_u8(resp) + sizeof(struct eap_hdr) +
  97. 1, plen);
  98. if (otp) {
  99. wpa_printf(MSG_DEBUG, "EAP-GTC: Forgetting used password");
  100. eap_clear_config_otp(sm);
  101. }
  102. return resp;
  103. }
  104. int eap_peer_gtc_register(void)
  105. {
  106. struct eap_method *eap;
  107. eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
  108. EAP_VENDOR_IETF, EAP_TYPE_GTC, "GTC");
  109. if (eap == NULL)
  110. return -1;
  111. eap->init = eap_gtc_init;
  112. eap->deinit = eap_gtc_deinit;
  113. eap->process = eap_gtc_process;
  114. return eap_peer_method_register(eap);
  115. }