eap_tls_common.h 3.8 KB

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