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