1 /*
2  * hostapd / EAP-TLS/PEAP/TTLS/FAST common functions
3  * Copyright (c) 2004-2008, 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 
15 #ifndef EAP_TLS_COMMON_H
16 #define EAP_TLS_COMMON_H
17 
18 struct eap_ssl_data {
19 	struct tls_connection *conn;
20 
21 	size_t tls_out_limit;
22 
23 	int phase2;
24 
25 	struct eap_sm *eap;
26 
27 	enum { MSG, FRAG_ACK, WAIT_FRAG_ACK } state;
28 	struct wpabuf *in_buf;
29 	struct wpabuf *out_buf;
30 	size_t out_used;
31 	struct wpabuf tmpbuf;
32 };
33 
34 
35 /* EAP TLS Flags */
36 #define EAP_TLS_FLAGS_LENGTH_INCLUDED 0x80
37 #define EAP_TLS_FLAGS_MORE_FRAGMENTS 0x40
38 #define EAP_TLS_FLAGS_START 0x20
39 #define EAP_TLS_VERSION_MASK 0x07
40 
41  /* could be up to 128 bytes, but only the first 64 bytes are used */
42 #define EAP_TLS_KEY_LEN 64
43 
44 
45 int eap_server_tls_ssl_init(struct eap_sm *sm, struct eap_ssl_data *data,
46 			    int verify_peer);
47 void eap_server_tls_ssl_deinit(struct eap_sm *sm, struct eap_ssl_data *data);
48 u8 * eap_server_tls_derive_key(struct eap_sm *sm, struct eap_ssl_data *data,
49 			       char *label, size_t len);
50 struct wpabuf * eap_server_tls_build_msg(struct eap_ssl_data *data,
51 					 int eap_type, int version, u8 id);
52 struct wpabuf * eap_server_tls_build_ack(u8 id, int eap_type, int version);
53 int eap_server_tls_phase1(struct eap_sm *sm, struct eap_ssl_data *data);
54 struct wpabuf * eap_server_tls_encrypt(struct eap_sm *sm,
55 				       struct eap_ssl_data *data,
56 				       const u8 *plain, size_t plain_len);
57 int eap_server_tls_process(struct eap_sm *sm, struct eap_ssl_data *data,
58 			   struct wpabuf *respData, void *priv, int eap_type,
59 			   int (*proc_version)(struct eap_sm *sm, void *priv,
60 					       int peer_version),
61 			   void (*proc_msg)(struct eap_sm *sm, void *priv,
62 					    const struct wpabuf *respData));
63 
64 #endif /* EAP_TLS_COMMON_H */
65