1 /*
2 * EAPOL supplicant state machines
3 * Copyright (c) 2004-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 EAPOL_SUPP_SM_H
10 #define EAPOL_SUPP_SM_H
11
12 #include "common/defs.h"
13
14 typedef enum { Unauthorized, Authorized } PortStatus;
15 typedef enum { Auto, ForceUnauthorized, ForceAuthorized } PortControl;
16
17 /**
18 * struct eapol_config - Per network configuration for EAPOL state machines
19 */
20 struct eapol_config {
21 /**
22 * accept_802_1x_keys - Accept IEEE 802.1X (non-WPA) EAPOL-Key frames
23 *
24 * This variable should be set to 1 when using EAPOL state machines
25 * with non-WPA security policy to generate dynamic WEP keys. When
26 * using WPA, this should be set to 0 so that WPA state machine can
27 * process the EAPOL-Key frames.
28 */
29 int accept_802_1x_keys;
30
31 #define EAPOL_REQUIRE_KEY_UNICAST BIT(0)
32 #define EAPOL_REQUIRE_KEY_BROADCAST BIT(1)
33 /**
34 * required_keys - Which EAPOL-Key packets are required
35 *
36 * This variable determines which EAPOL-Key packets are required before
37 * marking connection authenticated. This is a bit field of
38 * EAPOL_REQUIRE_KEY_UNICAST and EAPOL_REQUIRE_KEY_BROADCAST flags.
39 */
40 int required_keys;
41
42 /**
43 * fast_reauth - Whether fast EAP reauthentication is enabled
44 */
45 int fast_reauth;
46
47 /**
48 * workaround - Whether EAP workarounds are enabled
49 */
50 unsigned int workaround;
51
52 /**
53 * eap_disabled - Whether EAP is disabled
54 */
55 int eap_disabled;
56
57 /**
58 * external_sim - Use external processing for SIM/USIM operations
59 */
60 int external_sim;
61
62 #define EAPOL_LOCAL_WPS_IN_USE BIT(0)
63 #define EAPOL_PEER_IS_WPS20_AP BIT(1)
64 /**
65 * wps - Whether this connection is used for WPS
66 */
67 int wps;
68 };
69
70 struct eapol_sm;
71 struct wpa_config_blob;
72
73 enum eapol_supp_result {
74 EAPOL_SUPP_RESULT_FAILURE,
75 EAPOL_SUPP_RESULT_SUCCESS,
76 EAPOL_SUPP_RESULT_EXPECTED_FAILURE
77 };
78
79 /**
80 * struct eapol_ctx - Global (for all networks) EAPOL state machine context
81 */
82 struct eapol_ctx {
83 /**
84 * ctx - Pointer to arbitrary upper level context
85 */
86 void *ctx;
87
88 /**
89 * preauth - IEEE 802.11i/RSN pre-authentication
90 *
91 * This EAPOL state machine is used for IEEE 802.11i/RSN
92 * pre-authentication
93 */
94 int preauth;
95
96 /**
97 * cb - Function to be called when EAPOL negotiation has been completed
98 * @eapol: Pointer to EAPOL state machine data
99 * @result: Whether the authentication was completed successfully
100 * @ctx: Pointer to context data (cb_ctx)
101 *
102 * This optional callback function will be called when the EAPOL
103 * authentication has been completed. This allows the owner of the
104 * EAPOL state machine to process the key and terminate the EAPOL state
105 * machine. Currently, this is used only in RSN pre-authentication.
106 */
107 void (*cb)(struct eapol_sm *eapol, enum eapol_supp_result result,
108 void *ctx);
109
110 /**
111 * cb_ctx - Callback context for cb()
112 */
113 void *cb_ctx;
114
115 /**
116 * msg_ctx - Callback context for wpa_msg() calls
117 */
118 void *msg_ctx;
119
120 /**
121 * scard_ctx - Callback context for PC/SC scard_*() function calls
122 *
123 * This context can be updated with eapol_sm_register_scard_ctx().
124 */
125 void *scard_ctx;
126
127 /**
128 * eapol_send_ctx - Callback context for eapol_send() calls
129 */
130 void *eapol_send_ctx;
131
132 /**
133 * eapol_done_cb - Function to be called at successful completion
134 * @ctx: Callback context (ctx)
135 *
136 * This function is called at the successful completion of EAPOL
137 * authentication. If dynamic WEP keys are used, this is called only
138 * after all the expected keys have been received.
139 */
140 void (*eapol_done_cb)(void *ctx);
141
142 /**
143 * eapol_send - Send EAPOL packets
144 * @ctx: Callback context (eapol_send_ctx)
145 * @type: EAPOL type (IEEE802_1X_TYPE_*)
146 * @buf: Pointer to EAPOL payload
147 * @len: Length of the EAPOL payload
148 * Returns: 0 on success, -1 on failure
149 */
150 int (*eapol_send)(void *ctx, int type, const u8 *buf, size_t len);
151
152 /**
153 * set_wep_key - Configure WEP keys
154 * @ctx: Callback context (ctx)
155 * @unicast: Non-zero = unicast, 0 = multicast/broadcast key
156 * @keyidx: Key index (0..3)
157 * @key: WEP key
158 * @keylen: Length of the WEP key
159 * Returns: 0 on success, -1 on failure
160 */
161 int (*set_wep_key)(void *ctx, int unicast, int keyidx,
162 const u8 *key, size_t keylen);
163
164 /**
165 * set_config_blob - Set or add a named configuration blob
166 * @ctx: Callback context (ctx)
167 * @blob: New value for the blob
168 *
169 * Adds a new configuration blob or replaces the current value of an
170 * existing blob.
171 */
172 void (*set_config_blob)(void *ctx, struct wpa_config_blob *blob);
173
174 /**
175 * get_config_blob - Get a named configuration blob
176 * @ctx: Callback context (ctx)
177 * @name: Name of the blob
178 * Returns: Pointer to blob data or %NULL if not found
179 */
180 const struct wpa_config_blob * (*get_config_blob)(void *ctx,
181 const char *name);
182
183 /**
184 * aborted_cached - Notify that cached PMK attempt was aborted
185 * @ctx: Callback context (ctx)
186 */
187 void (*aborted_cached)(void *ctx);
188
189 /**
190 * opensc_engine_path - Path to the OpenSSL engine for opensc
191 *
192 * This is an OpenSSL specific configuration option for loading OpenSC
193 * engine (engine_opensc.so); if %NULL, this engine is not loaded.
194 */
195 const char *opensc_engine_path;
196
197 /**
198 * pkcs11_engine_path - Path to the OpenSSL engine for PKCS#11
199 *
200 * This is an OpenSSL specific configuration option for loading PKCS#11
201 * engine (engine_pkcs11.so); if %NULL, this engine is not loaded.
202 */
203 const char *pkcs11_engine_path;
204
205 /**
206 * pkcs11_module_path - Path to the OpenSSL OpenSC/PKCS#11 module
207 *
208 * This is an OpenSSL specific configuration option for configuring
209 * path to OpenSC/PKCS#11 engine (opensc-pkcs11.so); if %NULL, this
210 * module is not loaded.
211 */
212 const char *pkcs11_module_path;
213
214 /**
215 * openssl_ciphers - OpenSSL cipher string
216 *
217 * This is an OpenSSL specific configuration option for configuring the
218 * default ciphers. If not set, "DEFAULT:!EXP:!LOW" is used as the
219 * default.
220 */
221 const char *openssl_ciphers;
222
223 /**
224 * wps - WPS context data
225 *
226 * This is only used by EAP-WSC and can be left %NULL if not available.
227 */
228 struct wps_context *wps;
229
230 /**
231 * eap_param_needed - Notify that EAP parameter is needed
232 * @ctx: Callback context (ctx)
233 * @field: Field indicator (e.g., WPA_CTRL_REQ_EAP_IDENTITY)
234 * @txt: User readable text describing the required parameter
235 */
236 void (*eap_param_needed)(void *ctx, enum wpa_ctrl_req_type field,
237 const char *txt);
238
239 /**
240 * port_cb - Set port authorized/unauthorized callback (optional)
241 * @ctx: Callback context (ctx)
242 * @authorized: Whether the supplicant port is now in authorized state
243 */
244 void (*port_cb)(void *ctx, int authorized);
245
246 /**
247 * cert_cb - Notification of a peer certificate
248 * @ctx: Callback context (ctx)
249 * @depth: Depth in certificate chain (0 = server)
250 * @subject: Subject of the peer certificate
251 * @altsubject: Select fields from AltSubject of the peer certificate
252 * @num_altsubject: Number of altsubject values
253 * @cert_hash: SHA-256 hash of the certificate
254 * @cert: Peer certificate
255 */
256 void (*cert_cb)(void *ctx, int depth, const char *subject,
257 const char *altsubject[], int num_altsubject,
258 const char *cert_hash, const struct wpabuf *cert);
259
260 /**
261 * cert_in_cb - Include server certificates in callback
262 */
263 int cert_in_cb;
264
265 /**
266 * status_cb - Notification of a change in EAP status
267 * @ctx: Callback context (ctx)
268 * @status: Step in the process of EAP authentication
269 * @parameter: Step-specific parameter, e.g., EAP method name
270 */
271 void (*status_cb)(void *ctx, const char *status,
272 const char *parameter);
273
274 #ifdef CONFIG_EAP_PROXY
275 /**
276 * eap_proxy_cb - Callback signifying any updates from eap_proxy
277 * @ctx: eapol_ctx from eap_peer_sm_init() call
278 */
279 void (*eap_proxy_cb)(void *ctx);
280 #endif /* CONFIG_EAP_PROXY */
281
282 /**
283 * set_anon_id - Set or add anonymous identity
284 * @ctx: eapol_ctx from eap_peer_sm_init() call
285 * @id: Anonymous identity (e.g., EAP-SIM pseudonym)
286 * @len: Length of anonymous identity in octets
287 */
288 void (*set_anon_id)(void *ctx, const u8 *id, size_t len);
289 };
290
291
292 struct eap_peer_config;
293 struct ext_password_data;
294
295 #ifdef IEEE8021X_EAPOL
296 struct eapol_sm *eapol_sm_init(struct eapol_ctx *ctx);
297 void eapol_sm_deinit(struct eapol_sm *sm);
298 void eapol_sm_step(struct eapol_sm *sm);
299 int eapol_sm_get_status(struct eapol_sm *sm, char *buf, size_t buflen,
300 int verbose);
301 int eapol_sm_get_mib(struct eapol_sm *sm, char *buf, size_t buflen);
302 void eapol_sm_configure(struct eapol_sm *sm, int heldPeriod, int authPeriod,
303 int startPeriod, int maxStart);
304 int eapol_sm_rx_eapol(struct eapol_sm *sm, const u8 *src, const u8 *buf,
305 size_t len);
306 void eapol_sm_notify_tx_eapol_key(struct eapol_sm *sm);
307 void eapol_sm_notify_portEnabled(struct eapol_sm *sm, Boolean enabled);
308 void eapol_sm_notify_portValid(struct eapol_sm *sm, Boolean valid);
309 void eapol_sm_notify_eap_success(struct eapol_sm *sm, Boolean success);
310 void eapol_sm_notify_eap_fail(struct eapol_sm *sm, Boolean fail);
311 void eapol_sm_notify_config(struct eapol_sm *sm,
312 struct eap_peer_config *config,
313 const struct eapol_config *conf);
314 int eapol_sm_get_key(struct eapol_sm *sm, u8 *key, size_t len);
315 const u8 * eapol_sm_get_session_id(struct eapol_sm *sm, size_t *len);
316 void eapol_sm_notify_logoff(struct eapol_sm *sm, Boolean logoff);
317 void eapol_sm_notify_cached(struct eapol_sm *sm);
318 void eapol_sm_notify_pmkid_attempt(struct eapol_sm *sm);
319 void eapol_sm_register_scard_ctx(struct eapol_sm *sm, void *ctx);
320 void eapol_sm_notify_portControl(struct eapol_sm *sm, PortControl portControl);
321 void eapol_sm_notify_ctrl_attached(struct eapol_sm *sm);
322 void eapol_sm_notify_ctrl_response(struct eapol_sm *sm);
323 void eapol_sm_request_reauth(struct eapol_sm *sm);
324 void eapol_sm_notify_lower_layer_success(struct eapol_sm *sm, int in_eapol_sm);
325 void eapol_sm_invalidate_cached_session(struct eapol_sm *sm);
326 const char * eapol_sm_get_method_name(struct eapol_sm *sm);
327 void eapol_sm_set_ext_pw_ctx(struct eapol_sm *sm,
328 struct ext_password_data *ext);
329 int eapol_sm_failed(struct eapol_sm *sm);
330 void eapol_sm_erp_flush(struct eapol_sm *sm);
331 int eapol_sm_get_eap_proxy_imsi(struct eapol_sm *sm, char *imsi, size_t *len);
332 #else /* IEEE8021X_EAPOL */
eapol_sm_init(struct eapol_ctx * ctx)333 static inline struct eapol_sm *eapol_sm_init(struct eapol_ctx *ctx)
334 {
335 free(ctx);
336 return (struct eapol_sm *) 1;
337 }
eapol_sm_deinit(struct eapol_sm * sm)338 static inline void eapol_sm_deinit(struct eapol_sm *sm)
339 {
340 }
eapol_sm_step(struct eapol_sm * sm)341 static inline void eapol_sm_step(struct eapol_sm *sm)
342 {
343 }
eapol_sm_get_status(struct eapol_sm * sm,char * buf,size_t buflen,int verbose)344 static inline int eapol_sm_get_status(struct eapol_sm *sm, char *buf,
345 size_t buflen, int verbose)
346 {
347 return 0;
348 }
eapol_sm_get_mib(struct eapol_sm * sm,char * buf,size_t buflen)349 static inline int eapol_sm_get_mib(struct eapol_sm *sm, char *buf,
350 size_t buflen)
351 {
352 return 0;
353 }
eapol_sm_configure(struct eapol_sm * sm,int heldPeriod,int authPeriod,int startPeriod,int maxStart)354 static inline void eapol_sm_configure(struct eapol_sm *sm, int heldPeriod,
355 int authPeriod, int startPeriod,
356 int maxStart)
357 {
358 }
eapol_sm_rx_eapol(struct eapol_sm * sm,const u8 * src,const u8 * buf,size_t len)359 static inline int eapol_sm_rx_eapol(struct eapol_sm *sm, const u8 *src,
360 const u8 *buf, size_t len)
361 {
362 return 0;
363 }
eapol_sm_notify_tx_eapol_key(struct eapol_sm * sm)364 static inline void eapol_sm_notify_tx_eapol_key(struct eapol_sm *sm)
365 {
366 }
eapol_sm_notify_portEnabled(struct eapol_sm * sm,Boolean enabled)367 static inline void eapol_sm_notify_portEnabled(struct eapol_sm *sm,
368 Boolean enabled)
369 {
370 }
eapol_sm_notify_portValid(struct eapol_sm * sm,Boolean valid)371 static inline void eapol_sm_notify_portValid(struct eapol_sm *sm,
372 Boolean valid)
373 {
374 }
eapol_sm_notify_eap_success(struct eapol_sm * sm,Boolean success)375 static inline void eapol_sm_notify_eap_success(struct eapol_sm *sm,
376 Boolean success)
377 {
378 }
eapol_sm_notify_eap_fail(struct eapol_sm * sm,Boolean fail)379 static inline void eapol_sm_notify_eap_fail(struct eapol_sm *sm, Boolean fail)
380 {
381 }
eapol_sm_notify_config(struct eapol_sm * sm,struct eap_peer_config * config,struct eapol_config * conf)382 static inline void eapol_sm_notify_config(struct eapol_sm *sm,
383 struct eap_peer_config *config,
384 struct eapol_config *conf)
385 {
386 }
eapol_sm_get_key(struct eapol_sm * sm,u8 * key,size_t len)387 static inline int eapol_sm_get_key(struct eapol_sm *sm, u8 *key, size_t len)
388 {
389 return -1;
390 }
391 static inline const u8 *
eapol_sm_get_session_id(struct eapol_sm * sm,size_t * len)392 eapol_sm_get_session_id(struct eapol_sm *sm, size_t *len)
393 {
394 return NULL;
395 }
eapol_sm_notify_logoff(struct eapol_sm * sm,Boolean logoff)396 static inline void eapol_sm_notify_logoff(struct eapol_sm *sm, Boolean logoff)
397 {
398 }
eapol_sm_notify_cached(struct eapol_sm * sm)399 static inline void eapol_sm_notify_cached(struct eapol_sm *sm)
400 {
401 }
eapol_sm_notify_pmkid_attempt(struct eapol_sm * sm)402 static inline void eapol_sm_notify_pmkid_attempt(struct eapol_sm *sm)
403 {
404 }
405 #define eapol_sm_register_scard_ctx(sm, ctx) do { } while (0)
eapol_sm_notify_portControl(struct eapol_sm * sm,PortControl portControl)406 static inline void eapol_sm_notify_portControl(struct eapol_sm *sm,
407 PortControl portControl)
408 {
409 }
eapol_sm_notify_ctrl_attached(struct eapol_sm * sm)410 static inline void eapol_sm_notify_ctrl_attached(struct eapol_sm *sm)
411 {
412 }
eapol_sm_notify_ctrl_response(struct eapol_sm * sm)413 static inline void eapol_sm_notify_ctrl_response(struct eapol_sm *sm)
414 {
415 }
eapol_sm_request_reauth(struct eapol_sm * sm)416 static inline void eapol_sm_request_reauth(struct eapol_sm *sm)
417 {
418 }
eapol_sm_notify_lower_layer_success(struct eapol_sm * sm,int in_eapol_sm)419 static inline void eapol_sm_notify_lower_layer_success(struct eapol_sm *sm,
420 int in_eapol_sm)
421 {
422 }
eapol_sm_invalidate_cached_session(struct eapol_sm * sm)423 static inline void eapol_sm_invalidate_cached_session(struct eapol_sm *sm)
424 {
425 }
eapol_sm_get_method_name(struct eapol_sm * sm)426 static inline const char * eapol_sm_get_method_name(struct eapol_sm *sm)
427 {
428 return NULL;
429 }
eapol_sm_set_ext_pw_ctx(struct eapol_sm * sm,struct ext_password_data * ext)430 static inline void eapol_sm_set_ext_pw_ctx(struct eapol_sm *sm,
431 struct ext_password_data *ext)
432 {
433 }
eapol_sm_failed(struct eapol_sm * sm)434 static inline int eapol_sm_failed(struct eapol_sm *sm)
435 {
436 return 0;
437 }
eapol_sm_erp_flush(struct eapol_sm * sm)438 static inline void eapol_sm_erp_flush(struct eapol_sm *sm)
439 {
440 }
441 #endif /* IEEE8021X_EAPOL */
442
443 #endif /* EAPOL_SUPP_SM_H */
444