eap_tls_common.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * EAP peer: EAP-TLS/PEAP/TTLS/FAST common functions
  3. * Copyright (c) 2004-2009, 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. #ifndef EAP_TLS_COMMON_H
  15. #define EAP_TLS_COMMON_H
  16. /**
  17. * struct eap_ssl_data - TLS data for EAP methods
  18. */
  19. struct eap_ssl_data {
  20. /**
  21. * conn - TLS connection context data from tls_connection_init()
  22. */
  23. struct tls_connection *conn;
  24. /**
  25. * tls_out - TLS message to be sent out in fragments
  26. */
  27. struct wpabuf *tls_out;
  28. /**
  29. * tls_out_pos - The current position in the outgoing TLS message
  30. */
  31. size_t tls_out_pos;
  32. /**
  33. * tls_out_limit - Maximum fragment size for outgoing TLS messages
  34. */
  35. size_t tls_out_limit;
  36. /**
  37. * tls_in - Received TLS message buffer for re-assembly
  38. */
  39. struct wpabuf *tls_in;
  40. /**
  41. * tls_in_left - Number of remaining bytes in the incoming TLS message
  42. */
  43. size_t tls_in_left;
  44. /**
  45. * tls_in_total - Total number of bytes in the incoming TLS message
  46. */
  47. size_t tls_in_total;
  48. /**
  49. * phase2 - Whether this TLS connection is used in EAP phase 2 (tunnel)
  50. */
  51. int phase2;
  52. /**
  53. * include_tls_length - Whether the TLS length field is included even
  54. * if the TLS data is not fragmented
  55. */
  56. int include_tls_length;
  57. /**
  58. * tls_ia - Whether TLS/IA is enabled for this TLS connection
  59. */
  60. int tls_ia;
  61. /**
  62. * eap - EAP state machine allocated with eap_peer_sm_init()
  63. */
  64. struct eap_sm *eap;
  65. };
  66. /* EAP TLS Flags */
  67. #define EAP_TLS_FLAGS_LENGTH_INCLUDED 0x80
  68. #define EAP_TLS_FLAGS_MORE_FRAGMENTS 0x40
  69. #define EAP_TLS_FLAGS_START 0x20
  70. #define EAP_TLS_VERSION_MASK 0x07
  71. /* could be up to 128 bytes, but only the first 64 bytes are used */
  72. #define EAP_TLS_KEY_LEN 64
  73. int eap_peer_tls_ssl_init(struct eap_sm *sm, struct eap_ssl_data *data,
  74. struct eap_peer_config *config);
  75. void eap_peer_tls_ssl_deinit(struct eap_sm *sm, struct eap_ssl_data *data);
  76. u8 * eap_peer_tls_derive_key(struct eap_sm *sm, struct eap_ssl_data *data,
  77. const char *label, size_t len);
  78. int eap_peer_tls_process_helper(struct eap_sm *sm, struct eap_ssl_data *data,
  79. EapType eap_type, int peap_version,
  80. u8 id, const u8 *in_data, size_t in_len,
  81. struct wpabuf **out_data);
  82. struct wpabuf * eap_peer_tls_build_ack(u8 id, EapType eap_type,
  83. int peap_version);
  84. int eap_peer_tls_reauth_init(struct eap_sm *sm, struct eap_ssl_data *data);
  85. int eap_peer_tls_status(struct eap_sm *sm, struct eap_ssl_data *data,
  86. char *buf, size_t buflen, int verbose);
  87. const u8 * eap_peer_tls_process_init(struct eap_sm *sm,
  88. struct eap_ssl_data *data,
  89. EapType eap_type,
  90. struct eap_method_ret *ret,
  91. const struct wpabuf *reqData,
  92. size_t *len, u8 *flags);
  93. void eap_peer_tls_reset_input(struct eap_ssl_data *data);
  94. void eap_peer_tls_reset_output(struct eap_ssl_data *data);
  95. int eap_peer_tls_decrypt(struct eap_sm *sm, struct eap_ssl_data *data,
  96. const struct wpabuf *in_data,
  97. struct wpabuf **in_decrypted);
  98. int eap_peer_tls_encrypt(struct eap_sm *sm, struct eap_ssl_data *data,
  99. EapType eap_type, int peap_version, u8 id,
  100. const struct wpabuf *in_data,
  101. struct wpabuf **out_data);
  102. int eap_peer_select_phase2_methods(struct eap_peer_config *config,
  103. const char *prefix,
  104. struct eap_method_type **types,
  105. size_t *num_types);
  106. int eap_peer_tls_phase2_nak(struct eap_method_type *types, size_t num_types,
  107. struct eap_hdr *hdr, struct wpabuf **resp);
  108. #endif /* EAP_TLS_COMMON_H */