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