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