xref: /freebsd/contrib/wpa/src/eap_peer/eap_tls_common.h (revision 96190b4fef3b4a0cc3ca0606b0c4e3e69a5e6717)
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 
9 #ifndef EAP_TLS_COMMON_H
10 #define EAP_TLS_COMMON_H
11 
12 /**
13  * struct eap_ssl_data - TLS data for EAP methods
14  */
15 struct eap_ssl_data {
16 	/**
17 	 * conn - TLS connection context data from tls_connection_init()
18 	 */
19 	struct tls_connection *conn;
20 
21 	/**
22 	 * tls_out - TLS message to be sent out in fragments
23 	 */
24 	struct wpabuf *tls_out;
25 
26 	/**
27 	 * tls_out_pos - The current position in the outgoing TLS message
28 	 */
29 	size_t tls_out_pos;
30 
31 	/**
32 	 * tls_out_limit - Maximum fragment size for outgoing TLS messages
33 	 */
34 	size_t tls_out_limit;
35 
36 	/**
37 	 * tls_in - Received TLS message buffer for re-assembly
38 	 */
39 	struct wpabuf *tls_in;
40 
41 	/**
42 	 * tls_in_left - Number of remaining bytes in the incoming TLS message
43 	 */
44 	size_t tls_in_left;
45 
46 	/**
47 	 * tls_in_total - Total number of bytes in the incoming TLS message
48 	 */
49 	size_t tls_in_total;
50 
51 	/**
52 	 * phase2 - Whether this TLS connection is used in EAP phase 2 (tunnel)
53 	 */
54 	int phase2;
55 
56 	/**
57 	 * include_tls_length - Whether the TLS length field is included even
58 	 * if the TLS data is not fragmented
59 	 */
60 	int include_tls_length;
61 
62 	/**
63 	 * eap - EAP state machine allocated with eap_peer_sm_init()
64 	 */
65 	struct eap_sm *eap;
66 
67 	/**
68 	 * ssl_ctx - TLS library context to use for the connection
69 	 */
70 	void *ssl_ctx;
71 
72 	/**
73 	 * eap_type - EAP method used in Phase 1
74 	 * (EAP_TYPE_TLS/PEAP/TTLS/FAST/TEAP)
75 	 */
76 	u8 eap_type;
77 
78 	/**
79 	 * tls_v13 - Whether TLS v1.3 or newer is used
80 	 */
81 	int tls_v13;
82 
83 	/**
84 	 * client_cert_conf: Whether client certificate has been configured
85 	 */
86 	bool client_cert_conf;
87 };
88 
89 
90 /* EAP TLS Flags */
91 #define EAP_TLS_FLAGS_LENGTH_INCLUDED 0x80
92 #define EAP_TLS_FLAGS_MORE_FRAGMENTS 0x40
93 #define EAP_TLS_FLAGS_START 0x20
94 #define EAP_TEAP_FLAGS_OUTER_TLV_LEN 0x10
95 #define EAP_TLS_VERSION_MASK 0x07
96 
97  /* could be up to 128 bytes, but only the first 64 bytes are used */
98 #define EAP_TLS_KEY_LEN 64
99 
100 /* stub type used as a flag for UNAUTH-TLS */
101 #define EAP_UNAUTH_TLS_TYPE 255
102 #define EAP_WFA_UNAUTH_TLS_TYPE 254
103 
104 
105 int eap_peer_tls_ssl_init(struct eap_sm *sm, struct eap_ssl_data *data,
106 			  struct eap_peer_config *config, u8 eap_type);
107 void eap_peer_tls_ssl_deinit(struct eap_sm *sm, struct eap_ssl_data *data);
108 u8 * eap_peer_tls_derive_key(struct eap_sm *sm, struct eap_ssl_data *data,
109 			     const char *label, const u8 *context,
110 			     size_t context_len, size_t len);
111 u8 * eap_peer_tls_derive_session_id(struct eap_sm *sm,
112 				    struct eap_ssl_data *data, u8 eap_type,
113 				    size_t *len);
114 int eap_peer_tls_process_helper(struct eap_sm *sm, struct eap_ssl_data *data,
115 				enum eap_type eap_type, int peap_version,
116 				u8 id, const struct wpabuf *in_data,
117 				struct wpabuf **out_data);
118 struct wpabuf * eap_peer_tls_build_ack(u8 id, enum eap_type eap_type,
119 				       int peap_version);
120 int eap_peer_tls_reauth_init(struct eap_sm *sm, struct eap_ssl_data *data);
121 int eap_peer_tls_status(struct eap_sm *sm, struct eap_ssl_data *data,
122 			char *buf, size_t buflen, int verbose);
123 const u8 * eap_peer_tls_process_init(struct eap_sm *sm,
124 				     struct eap_ssl_data *data,
125 				     enum eap_type eap_type,
126 				     struct eap_method_ret *ret,
127 				     const struct wpabuf *reqData,
128 				     size_t *len, u8 *flags);
129 void eap_peer_tls_reset_input(struct eap_ssl_data *data);
130 void eap_peer_tls_reset_output(struct eap_ssl_data *data);
131 int eap_peer_tls_decrypt(struct eap_sm *sm, struct eap_ssl_data *data,
132 			 const struct wpabuf *in_data,
133 			 struct wpabuf **in_decrypted);
134 int eap_peer_tls_encrypt(struct eap_sm *sm, struct eap_ssl_data *data,
135 			 enum eap_type eap_type, int peap_version, u8 id,
136 			 const struct wpabuf *in_data,
137 			 struct wpabuf **out_data);
138 int eap_peer_select_phase2_methods(struct eap_peer_config *config,
139 				   const char *prefix,
140 				   struct eap_method_type **types,
141 				   size_t *num_types, int use_machine_cred);
142 int eap_peer_tls_phase2_nak(struct eap_method_type *types, size_t num_types,
143 			    struct eap_hdr *hdr, struct wpabuf **resp);
144 
145 #endif /* EAP_TLS_COMMON_H */
146