]> git.ipfire.org Git - thirdparty/hostap.git/blob - src/eapol_supp/eapol_supp_sm.h
STA: Allow PTK rekeying without Ext KeyID to be disabled as a workaround
[thirdparty/hostap.git] / src / eapol_supp / eapol_supp_sm.h
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 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 /**
192 * opensc_engine_path - Path to the OpenSSL engine for opensc
193 *
194 * This is an OpenSSL specific configuration option for loading OpenSC
195 * engine (engine_opensc.so); if %NULL, this engine is not loaded.
196 */
197 const char *opensc_engine_path;
198
199 /**
200 * pkcs11_engine_path - Path to the OpenSSL engine for PKCS#11
201 *
202 * This is an OpenSSL specific configuration option for loading PKCS#11
203 * engine (engine_pkcs11.so); if %NULL, this engine is not loaded.
204 */
205 const char *pkcs11_engine_path;
206
207 /**
208 * pkcs11_module_path - Path to the OpenSSL OpenSC/PKCS#11 module
209 *
210 * This is an OpenSSL specific configuration option for configuring
211 * path to OpenSC/PKCS#11 engine (opensc-pkcs11.so); if %NULL, this
212 * module is not loaded.
213 */
214 const char *pkcs11_module_path;
215
216 /**
217 * openssl_ciphers - OpenSSL cipher string
218 *
219 * This is an OpenSSL specific configuration option for configuring the
220 * default ciphers. If not set, "DEFAULT:!EXP:!LOW" is used as the
221 * default.
222 */
223 const char *openssl_ciphers;
224
225 /**
226 * wps - WPS context data
227 *
228 * This is only used by EAP-WSC and can be left %NULL if not available.
229 */
230 struct wps_context *wps;
231
232 /**
233 * eap_param_needed - Notify that EAP parameter is needed
234 * @ctx: Callback context (ctx)
235 * @field: Field indicator (e.g., WPA_CTRL_REQ_EAP_IDENTITY)
236 * @txt: User readable text describing the required parameter
237 */
238 void (*eap_param_needed)(void *ctx, enum wpa_ctrl_req_type field,
239 const char *txt);
240
241 /**
242 * port_cb - Set port authorized/unauthorized callback (optional)
243 * @ctx: Callback context (ctx)
244 * @authorized: Whether the supplicant port is now in authorized state
245 */
246 void (*port_cb)(void *ctx, int authorized);
247
248 /**
249 * cert_cb - Notification of a peer certificate
250 * @ctx: Callback context (ctx)
251 * @cert: Certificate information
252 * @cert_hash: SHA-256 hash of the certificate
253 */
254 void (*cert_cb)(void *ctx, struct tls_cert_data *cert,
255 const char *cert_hash);
256
257 /**
258 * cert_in_cb - Include server certificates in callback
259 */
260 int cert_in_cb;
261
262 /**
263 * status_cb - Notification of a change in EAP status
264 * @ctx: Callback context (ctx)
265 * @status: Step in the process of EAP authentication
266 * @parameter: Step-specific parameter, e.g., EAP method name
267 */
268 void (*status_cb)(void *ctx, const char *status,
269 const char *parameter);
270
271 /**
272 * eap_error_cb - Notification of EAP method error
273 * @ctx: Callback context (ctx)
274 * @error_code: EAP method error code
275 */
276 void (*eap_error_cb)(void *ctx, int error_code);
277
278 #ifdef CONFIG_EAP_PROXY
279 /**
280 * eap_proxy_cb - Callback signifying any updates from eap_proxy
281 * @ctx: eapol_ctx from eap_peer_sm_init() call
282 */
283 void (*eap_proxy_cb)(void *ctx);
284
285 /**
286 * eap_proxy_notify_sim_status - Notification of SIM status change
287 * @ctx: eapol_ctx from eap_peer_sm_init() call
288 * @status: One of enum value from sim_state
289 */
290 void (*eap_proxy_notify_sim_status)(void *ctx,
291 enum eap_proxy_sim_state sim_state);
292 #endif /* CONFIG_EAP_PROXY */
293
294 /**
295 * set_anon_id - Set or add anonymous identity
296 * @ctx: eapol_ctx from eap_peer_sm_init() call
297 * @id: Anonymous identity (e.g., EAP-SIM pseudonym)
298 * @len: Length of anonymous identity in octets
299 */
300 void (*set_anon_id)(void *ctx, const u8 *id, size_t len);
301
302 /**
303 * confirm_auth_cb - Callback confirming if we can install a new PTK
304 * @ctx: eapol_ctx from eap_peer_sm_init() call
305 * Returns: 0 when authentication can continue, -1 when reconnecting
306 *
307 * Automatically triggers a reconnect when not.
308 */
309 int (*confirm_auth_cb)(void *ctx);
310 };
311
312
313 struct eap_peer_config;
314 struct ext_password_data;
315
316 #ifdef IEEE8021X_EAPOL
317 struct eapol_sm *eapol_sm_init(struct eapol_ctx *ctx);
318 void eapol_sm_deinit(struct eapol_sm *sm);
319 void eapol_sm_step(struct eapol_sm *sm);
320 int eapol_sm_get_status(struct eapol_sm *sm, char *buf, size_t buflen,
321 int verbose);
322 int eapol_sm_get_mib(struct eapol_sm *sm, char *buf, size_t buflen);
323 void eapol_sm_configure(struct eapol_sm *sm, int heldPeriod, int authPeriod,
324 int startPeriod, int maxStart);
325 int eapol_sm_rx_eapol(struct eapol_sm *sm, const u8 *src, const u8 *buf,
326 size_t len);
327 void eapol_sm_notify_tx_eapol_key(struct eapol_sm *sm);
328 void eapol_sm_notify_portEnabled(struct eapol_sm *sm, Boolean enabled);
329 void eapol_sm_notify_portValid(struct eapol_sm *sm, Boolean valid);
330 void eapol_sm_notify_eap_success(struct eapol_sm *sm, Boolean success);
331 void eapol_sm_notify_eap_fail(struct eapol_sm *sm, Boolean fail);
332 void eapol_sm_notify_config(struct eapol_sm *sm,
333 struct eap_peer_config *config,
334 const struct eapol_config *conf);
335 int eapol_sm_get_key(struct eapol_sm *sm, u8 *key, size_t len);
336 const u8 * eapol_sm_get_session_id(struct eapol_sm *sm, size_t *len);
337 void eapol_sm_notify_logoff(struct eapol_sm *sm, Boolean logoff);
338 void eapol_sm_notify_cached(struct eapol_sm *sm);
339 void eapol_sm_notify_pmkid_attempt(struct eapol_sm *sm);
340 void eapol_sm_register_scard_ctx(struct eapol_sm *sm, void *ctx);
341 void eapol_sm_notify_portControl(struct eapol_sm *sm, PortControl portControl);
342 void eapol_sm_notify_ctrl_attached(struct eapol_sm *sm);
343 void eapol_sm_notify_ctrl_response(struct eapol_sm *sm);
344 void eapol_sm_request_reauth(struct eapol_sm *sm);
345 void eapol_sm_notify_lower_layer_success(struct eapol_sm *sm, int in_eapol_sm);
346 void eapol_sm_invalidate_cached_session(struct eapol_sm *sm);
347 const char * eapol_sm_get_method_name(struct eapol_sm *sm);
348 void eapol_sm_set_ext_pw_ctx(struct eapol_sm *sm,
349 struct ext_password_data *ext);
350 int eapol_sm_failed(struct eapol_sm *sm);
351 void eapol_sm_erp_flush(struct eapol_sm *sm);
352 struct wpabuf * eapol_sm_build_erp_reauth_start(struct eapol_sm *sm);
353 void eapol_sm_process_erp_finish(struct eapol_sm *sm, const u8 *buf,
354 size_t len);
355 int eapol_sm_get_eap_proxy_imsi(void *ctx, int sim_num, char *imsi,
356 size_t *len);
357 int eapol_sm_update_erp_next_seq_num(struct eapol_sm *sm, u16 next_seq_num);
358 int eapol_sm_get_erp_info(struct eapol_sm *sm, struct eap_peer_config *config,
359 const u8 **username, size_t *username_len,
360 const u8 **realm, size_t *realm_len,
361 u16 *erp_next_seq_num, const u8 **rrk,
362 size_t *rrk_len);
363
364 #else /* IEEE8021X_EAPOL */
365 static inline struct eapol_sm *eapol_sm_init(struct eapol_ctx *ctx)
366 {
367 free(ctx);
368 return (struct eapol_sm *) 1;
369 }
370 static inline void eapol_sm_deinit(struct eapol_sm *sm)
371 {
372 }
373 static inline void eapol_sm_step(struct eapol_sm *sm)
374 {
375 }
376 static inline int eapol_sm_get_status(struct eapol_sm *sm, char *buf,
377 size_t buflen, int verbose)
378 {
379 return 0;
380 }
381 static inline int eapol_sm_get_mib(struct eapol_sm *sm, char *buf,
382 size_t buflen)
383 {
384 return 0;
385 }
386 static inline void eapol_sm_configure(struct eapol_sm *sm, int heldPeriod,
387 int authPeriod, int startPeriod,
388 int maxStart)
389 {
390 }
391 static inline int eapol_sm_rx_eapol(struct eapol_sm *sm, const u8 *src,
392 const u8 *buf, size_t len)
393 {
394 return 0;
395 }
396 static inline void eapol_sm_notify_tx_eapol_key(struct eapol_sm *sm)
397 {
398 }
399 static inline void eapol_sm_notify_portEnabled(struct eapol_sm *sm,
400 Boolean enabled)
401 {
402 }
403 static inline void eapol_sm_notify_portValid(struct eapol_sm *sm,
404 Boolean valid)
405 {
406 }
407 static inline void eapol_sm_notify_eap_success(struct eapol_sm *sm,
408 Boolean success)
409 {
410 }
411 static inline void eapol_sm_notify_eap_fail(struct eapol_sm *sm, Boolean fail)
412 {
413 }
414 static inline void eapol_sm_notify_config(struct eapol_sm *sm,
415 struct eap_peer_config *config,
416 struct eapol_config *conf)
417 {
418 }
419 static inline int eapol_sm_get_key(struct eapol_sm *sm, u8 *key, size_t len)
420 {
421 return -1;
422 }
423 static inline const u8 *
424 eapol_sm_get_session_id(struct eapol_sm *sm, size_t *len)
425 {
426 return NULL;
427 }
428 static inline void eapol_sm_notify_logoff(struct eapol_sm *sm, Boolean logoff)
429 {
430 }
431 static inline void eapol_sm_notify_cached(struct eapol_sm *sm)
432 {
433 }
434 static inline void eapol_sm_notify_pmkid_attempt(struct eapol_sm *sm)
435 {
436 }
437 #define eapol_sm_register_scard_ctx(sm, ctx) do { } while (0)
438 static inline void eapol_sm_notify_portControl(struct eapol_sm *sm,
439 PortControl portControl)
440 {
441 }
442 static inline void eapol_sm_notify_ctrl_attached(struct eapol_sm *sm)
443 {
444 }
445 static inline void eapol_sm_notify_ctrl_response(struct eapol_sm *sm)
446 {
447 }
448 static inline void eapol_sm_request_reauth(struct eapol_sm *sm)
449 {
450 }
451 static inline void eapol_sm_notify_lower_layer_success(struct eapol_sm *sm,
452 int in_eapol_sm)
453 {
454 }
455 static inline void eapol_sm_invalidate_cached_session(struct eapol_sm *sm)
456 {
457 }
458 static inline const char * eapol_sm_get_method_name(struct eapol_sm *sm)
459 {
460 return NULL;
461 }
462 static inline void eapol_sm_set_ext_pw_ctx(struct eapol_sm *sm,
463 struct ext_password_data *ext)
464 {
465 }
466 static inline int eapol_sm_failed(struct eapol_sm *sm)
467 {
468 return 0;
469 }
470 static inline void eapol_sm_erp_flush(struct eapol_sm *sm)
471 {
472 }
473 static inline struct wpabuf *
474 eapol_sm_build_erp_reauth_start(struct eapol_sm *sm)
475 {
476 return NULL;
477 }
478 static inline void eapol_sm_process_erp_finish(struct eapol_sm *sm,
479 const u8 *buf, size_t len)
480 {
481 }
482 static inline int eapol_sm_update_erp_next_seq_num(struct eapol_sm *sm,
483 u16 next_seq_num)
484 {
485 return -1;
486 }
487 static inline int
488 eapol_sm_get_erp_info(struct eapol_sm *sm, struct eap_peer_config *config,
489 const u8 **username, size_t *username_len,
490 const u8 **realm, size_t *realm_len,
491 u16 *erp_next_seq_num, const u8 **rrk, size_t *rrk_len)
492 {
493 return -1;
494 }
495 #endif /* IEEE8021X_EAPOL */
496
497 #endif /* EAPOL_SUPP_SM_H */