eap_gtc.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * EAP peer method: EAP-GTC (RFC 3748)
  3. * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "includes.h"
  15. #include "common.h"
  16. #include "eap_i.h"
  17. struct eap_gtc_data {
  18. int prefix;
  19. };
  20. static void * eap_gtc_init(struct eap_sm *sm)
  21. {
  22. struct eap_gtc_data *data;
  23. data = os_zalloc(sizeof(*data));
  24. if (data == NULL)
  25. return NULL;
  26. if (sm->m && sm->m->vendor == EAP_VENDOR_IETF &&
  27. sm->m->method == EAP_TYPE_FAST) {
  28. wpa_printf(MSG_DEBUG, "EAP-GTC: EAP-FAST tunnel - use prefix "
  29. "with challenge/response");
  30. data->prefix = 1;
  31. }
  32. return data;
  33. }
  34. static void eap_gtc_deinit(struct eap_sm *sm, void *priv)
  35. {
  36. struct eap_gtc_data *data = priv;
  37. os_free(data);
  38. }
  39. static struct wpabuf * eap_gtc_process(struct eap_sm *sm, void *priv,
  40. struct eap_method_ret *ret,
  41. const struct wpabuf *reqData)
  42. {
  43. struct eap_gtc_data *data = priv;
  44. struct wpabuf *resp;
  45. const u8 *pos, *password, *identity;
  46. size_t password_len, identity_len, len, plen;
  47. int otp;
  48. u8 id;
  49. pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_GTC, reqData, &len);
  50. if (pos == NULL) {
  51. ret->ignore = TRUE;
  52. return NULL;
  53. }
  54. id = eap_get_id(reqData);
  55. wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-GTC: Request message", pos, len);
  56. if (data->prefix &&
  57. (len < 10 || os_memcmp(pos, "CHALLENGE=", 10) != 0)) {
  58. wpa_printf(MSG_DEBUG, "EAP-GTC: Challenge did not start with "
  59. "expected prefix");
  60. /* Send an empty response in order to allow tunneled
  61. * acknowledgement of the failure. This will also cover the
  62. * error case which seems to use EAP-MSCHAPv2 like error
  63. * reporting with EAP-GTC inside EAP-FAST tunnel. */
  64. resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_GTC,
  65. 0, EAP_CODE_RESPONSE, id);
  66. return resp;
  67. }
  68. password = eap_get_config_otp(sm, &password_len);
  69. if (password)
  70. otp = 1;
  71. else {
  72. password = eap_get_config_password(sm, &password_len);
  73. otp = 0;
  74. }
  75. if (password == NULL) {
  76. wpa_printf(MSG_INFO, "EAP-GTC: Password not configured");
  77. eap_sm_request_otp(sm, (const char *) pos, len);
  78. ret->ignore = TRUE;
  79. return NULL;
  80. }
  81. ret->ignore = FALSE;
  82. ret->methodState = data->prefix ? METHOD_MAY_CONT : METHOD_DONE;
  83. ret->decision = DECISION_COND_SUCC;
  84. ret->allowNotifications = FALSE;
  85. plen = password_len;
  86. identity = eap_get_config_identity(sm, &identity_len);
  87. if (identity == NULL)
  88. return NULL;
  89. if (data->prefix)
  90. plen += 9 + identity_len + 1;
  91. resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_GTC, plen,
  92. EAP_CODE_RESPONSE, id);
  93. if (resp == NULL)
  94. return NULL;
  95. if (data->prefix) {
  96. wpabuf_put_data(resp, "RESPONSE=", 9);
  97. wpabuf_put_data(resp, identity, identity_len);
  98. wpabuf_put_u8(resp, '\0');
  99. }
  100. wpabuf_put_data(resp, password, password_len);
  101. wpa_hexdump_ascii_key(MSG_MSGDUMP, "EAP-GTC: Response",
  102. wpabuf_head_u8(resp) + sizeof(struct eap_hdr) +
  103. 1, plen);
  104. if (otp) {
  105. wpa_printf(MSG_DEBUG, "EAP-GTC: Forgetting used password");
  106. eap_clear_config_otp(sm);
  107. }
  108. return resp;
  109. }
  110. int eap_peer_gtc_register(void)
  111. {
  112. struct eap_method *eap;
  113. int ret;
  114. eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
  115. EAP_VENDOR_IETF, EAP_TYPE_GTC, "GTC");
  116. if (eap == NULL)
  117. return -1;
  118. eap->init = eap_gtc_init;
  119. eap->deinit = eap_gtc_deinit;
  120. eap->process = eap_gtc_process;
  121. ret = eap_peer_method_register(eap);
  122. if (ret)
  123. eap_peer_method_free(eap);
  124. return ret;
  125. }