27
27
#include "rsn_supp/wpa.h"
28
28
29
29
#include "crypto/crypto.h"
30
+ #include "crypto/sha256.h"
30
31
31
32
#include "utils/ext_password.h"
32
33
#include "tls/tls.h"
@@ -191,6 +192,8 @@ void eap_peer_unregister_methods(void)
191
192
}
192
193
}
193
194
195
+
196
+
194
197
int eap_peer_register_methods (void )
195
198
{
196
199
int ret = 0 ;
@@ -232,6 +235,90 @@ void eap_deinit_prev_method(struct eap_sm *sm, const char *txt)
232
235
sm -> m = NULL ;
233
236
}
234
237
238
+ static int eap_sm_set_scard_pin (struct eap_sm * sm ,
239
+ struct eap_peer_config * conf )
240
+ {
241
+ return -1 ;
242
+ }
243
+
244
+ static int eap_sm_get_scard_identity (struct eap_sm * sm ,
245
+ struct eap_peer_config * conf )
246
+ {
247
+ return -1 ;
248
+ }
249
+
250
+
251
+ /**
252
+ * eap_sm_buildIdentity - Build EAP-Identity/Response for the current network
253
+ * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
254
+ * @id: EAP identifier for the packet
255
+ * @encrypted: Whether the packet is for encrypted tunnel (EAP phase 2)
256
+ * Returns: Pointer to the allocated EAP-Identity/Response packet or %NULL on
257
+ * failure
258
+ *
259
+ * This function allocates and builds an EAP-Identity/Response packet for the
260
+ * current network. The caller is responsible for freeing the returned data.
261
+ */
262
+ struct wpabuf * eap_sm_buildIdentity (struct eap_sm * sm , int id , int encrypted )
263
+ {
264
+ struct eap_peer_config * config = eap_get_config (sm );
265
+ struct wpabuf * resp ;
266
+ const u8 * identity ;
267
+ size_t identity_len ;
268
+
269
+ if (config == NULL ) {
270
+ wpa_printf (MSG_ERROR , "EAP: buildIdentity: configuration "
271
+ "was not available" );
272
+ return NULL ;
273
+ }
274
+
275
+ if (sm -> m && sm -> m -> get_identity &&
276
+ (identity = sm -> m -> get_identity (sm , sm -> eap_method_priv ,
277
+ & identity_len )) != NULL ) {
278
+ wpa_hexdump_ascii (MSG_DEBUG , "EAP: using method re-auth "
279
+ "identity" , identity , identity_len );
280
+ } else if (!encrypted && config -> anonymous_identity ) {
281
+ identity = config -> anonymous_identity ;
282
+ identity_len = config -> anonymous_identity_len ;
283
+ wpa_hexdump_ascii (MSG_DEBUG , "EAP: using anonymous identity" ,
284
+ identity , identity_len );
285
+ } else {
286
+ identity = config -> identity ;
287
+ identity_len = config -> identity_len ;
288
+ wpa_hexdump_ascii (MSG_DEBUG , "EAP: using real identity" ,
289
+ identity , identity_len );
290
+ }
291
+
292
+ if (identity == NULL ) {
293
+ wpa_printf (MSG_ERROR , "EAP: buildIdentity: identity "
294
+ "configuration was not available" );
295
+ if (config -> pcsc ) {
296
+ if (eap_sm_get_scard_identity (sm , config ) < 0 )
297
+ return NULL ;
298
+ identity = config -> identity ;
299
+ identity_len = config -> identity_len ;
300
+ wpa_hexdump_ascii (MSG_DEBUG , "permanent identity from "
301
+ "IMSI" , identity , identity_len );
302
+ } else {
303
+ eap_sm_request_identity (sm );
304
+ return NULL ;
305
+ }
306
+ } else if (config -> pcsc ) {
307
+ if (eap_sm_set_scard_pin (sm , config ) < 0 )
308
+ return NULL ;
309
+ }
310
+
311
+ resp = eap_msg_alloc (EAP_VENDOR_IETF , EAP_TYPE_IDENTITY , identity_len ,
312
+ EAP_CODE_RESPONSE , id );
313
+ if (resp == NULL )
314
+ return NULL ;
315
+
316
+ wpabuf_put_data (resp , identity , identity_len );
317
+
318
+ return resp ;
319
+ }
320
+
321
+
235
322
struct wpabuf * eap_sm_build_identity_resp (struct eap_sm * sm , u8 id , int encrypted )
236
323
{
237
324
const u8 * identity ;
@@ -389,6 +476,10 @@ int eap_peer_config_init(
389
476
sm -> config .new_password_len );
390
477
}
391
478
479
+ if (g_wpa_ttls_phase2_type ) {
480
+ sm -> config .phase2 = g_wpa_ttls_phase2_type ;
481
+ }
482
+
392
483
return 0 ;
393
484
394
485
}
@@ -458,6 +549,65 @@ int eap_peer_blob_init(struct eap_sm *sm)
458
549
return ret ;
459
550
}
460
551
552
+ #if defined(CONFIG_CTRL_IFACE ) || !defined(CONFIG_NO_STDOUT_DEBUG )
553
+ static void eap_sm_request (struct eap_sm * sm , enum wpa_ctrl_req_type field ,
554
+ const char * msg , size_t msglen )
555
+ {
556
+ struct eap_peer_config * config ;
557
+
558
+ if (sm == NULL )
559
+ return ;
560
+ config = eap_get_config (sm );
561
+ if (config == NULL )
562
+ return ;
563
+
564
+ switch (field ) {
565
+ case WPA_CTRL_REQ_EAP_IDENTITY :
566
+ config -> pending_req_identity ++ ;
567
+ break ;
568
+ case WPA_CTRL_REQ_EAP_PASSWORD :
569
+ config -> pending_req_password ++ ;
570
+ break ;
571
+ case WPA_CTRL_REQ_EAP_NEW_PASSWORD :
572
+ config -> pending_req_new_password ++ ;
573
+ break ;
574
+ case WPA_CTRL_REQ_EAP_PIN :
575
+ config -> pending_req_pin ++ ;
576
+ break ;
577
+ case WPA_CTRL_REQ_EAP_PASSPHRASE :
578
+ config -> pending_req_passphrase ++ ;
579
+ break ;
580
+ default :
581
+ return ;
582
+ }
583
+
584
+ }
585
+ #else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
586
+ #define eap_sm_request (sm , type , msg , msglen ) do { } while (0)
587
+ #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
588
+
589
+ const char * eap_sm_get_method_name (struct eap_sm * sm )
590
+ {
591
+ if (sm -> m == NULL )
592
+ return "UNKNOWN" ;
593
+ return sm -> m -> name ;
594
+ }
595
+
596
+
597
+ /**
598
+ * eap_sm_request_identity - Request identity from user (ctrl_iface)
599
+ * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
600
+ *
601
+ * EAP methods can call this function to request identity information for the
602
+ * current network. This is normally called when the identity is not included
603
+ * in the network configuration. The request will be sent to monitor programs
604
+ * through the control interface.
605
+ */
606
+ void eap_sm_request_identity (struct eap_sm * sm )
607
+ {
608
+ eap_sm_request (sm , WPA_CTRL_REQ_EAP_IDENTITY , NULL , 0 );
609
+ }
610
+
461
611
void eap_peer_blob_deinit (struct eap_sm * sm )
462
612
{
463
613
int i ;
@@ -495,6 +645,13 @@ struct eap_peer_config * eap_get_config(struct eap_sm *sm)
495
645
return & sm -> config ;
496
646
}
497
647
648
+
649
+ /**
650
+ * eap_get_config_identity - Get identity from the network configuration
651
+ * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
652
+ * @len: Buffer for the length of the identity
653
+ * Returns: Pointer to the identity or %NULL if not found
654
+ */
498
655
const u8 * eap_get_config_identity (struct eap_sm * sm , size_t * len )
499
656
{
500
657
struct eap_peer_config * config = eap_get_config (sm );
@@ -504,6 +661,13 @@ const u8 * eap_get_config_identity(struct eap_sm *sm, size_t *len)
504
661
return config -> identity ;
505
662
}
506
663
664
+
665
+ /**
666
+ * eap_get_config_password - Get password from the network configuration
667
+ * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
668
+ * @len: Buffer for the length of the password
669
+ * Returns: Pointer to the password or %NULL if not found
670
+ */
507
671
const u8 * eap_get_config_password (struct eap_sm * sm , size_t * len )
508
672
{
509
673
struct eap_peer_config * config = eap_get_config (sm );
@@ -513,6 +677,16 @@ const u8 * eap_get_config_password(struct eap_sm *sm, size_t *len)
513
677
return config -> password ;
514
678
}
515
679
680
+
681
+ /**
682
+ * eap_get_config_password2 - Get password from the network configuration
683
+ * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
684
+ * @len: Buffer for the length of the password
685
+ * @hash: Buffer for returning whether the password is stored as a
686
+ * NtPasswordHash instead of plaintext password; can be %NULL if this
687
+ * information is not needed
688
+ * Returns: Pointer to the password or %NULL if not found
689
+ */
516
690
const u8 * eap_get_config_password2 (struct eap_sm * sm , size_t * len , int * hash )
517
691
{
518
692
struct eap_peer_config * config = eap_get_config (sm );
@@ -525,6 +699,13 @@ const u8 * eap_get_config_password2(struct eap_sm *sm, size_t *len, int *hash)
525
699
return config -> password ;
526
700
}
527
701
702
+
703
+ /**
704
+ * eap_get_config_new_password - Get new password from network configuration
705
+ * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
706
+ * @len: Buffer for the length of the new password
707
+ * Returns: Pointer to the new password or %NULL if not found
708
+ */
528
709
const u8 * eap_get_config_new_password (struct eap_sm * sm , size_t * len )
529
710
{
530
711
struct eap_peer_config * config = eap_get_config (sm );
0 commit comments