1
1
/*
2
- * Copyright (C) 2012 Tobias Brunner
2
+ * Copyright (C) 2012-2018 Tobias Brunner
3
3
* Copyright (C) 2006-2009 Martin Willi
4
4
* HSR Hochschule fuer Technik Rapperswil
5
5
*
@@ -64,6 +64,16 @@ struct private_eap_authenticator_t {
64
64
*/
65
65
char reserved [3 ];
66
66
67
+ /**
68
+ * PPK to use
69
+ */
70
+ chunk_t ppk ;
71
+
72
+ /**
73
+ * Add a NO_PPK_AUTH notify
74
+ */
75
+ bool no_ppk_auth ;
76
+
67
77
/**
68
78
* Current EAP method processing
69
79
*/
@@ -444,6 +454,7 @@ static bool verify_auth(private_eap_authenticator_t *this, message_t *message,
444
454
chunk_t nonce , chunk_t init )
445
455
{
446
456
auth_payload_t * auth_payload ;
457
+ notify_payload_t * notify ;
447
458
chunk_t auth_data , recv_auth_data ;
448
459
identification_t * other_id ;
449
460
auth_cfg_t * auth ;
@@ -458,14 +469,26 @@ static bool verify_auth(private_eap_authenticator_t *this, message_t *message,
458
469
DBG1 (DBG_IKE , "AUTH payload missing" );
459
470
return FALSE;
460
471
}
472
+ recv_auth_data = auth_payload -> get_data (auth_payload );
473
+
474
+ if (this -> ike_sa -> supports_extension (this -> ike_sa , EXT_PPK ) &&
475
+ !this -> ppk .ptr )
476
+ { /* look for a NO_PPK_AUTH notify if we have no PPK */
477
+ notify = message -> get_notify (message , NO_PPK_AUTH );
478
+ if (notify )
479
+ {
480
+ DBG1 (DBG_IKE , "no PPK available, using NO_PPK_AUTH notify" );
481
+ recv_auth_data = notify -> get_notification_data (notify );
482
+ }
483
+ }
484
+
461
485
other_id = this -> ike_sa -> get_other_id (this -> ike_sa );
462
486
keymat = (keymat_v2_t * )this -> ike_sa -> get_keymat (this -> ike_sa );
463
- if (!keymat -> get_psk_sig (keymat , TRUE, init , nonce , this -> msk , chunk_empty ,
487
+ if (!keymat -> get_psk_sig (keymat , TRUE, init , nonce , this -> msk , this -> ppk ,
464
488
other_id , this -> reserved , & auth_data ))
465
489
{
466
490
return FALSE;
467
491
}
468
- recv_auth_data = auth_payload -> get_data (auth_payload );
469
492
if (!auth_data .len || !chunk_equals_const (auth_data , recv_auth_data ))
470
493
{
471
494
DBG1 (DBG_IKE , "verification of AUTH payload with%s EAP MSK failed" ,
@@ -507,7 +530,7 @@ static bool build_auth(private_eap_authenticator_t *this, message_t *message,
507
530
DBG1 (DBG_IKE , "authentication of '%Y' (myself) with %N" ,
508
531
my_id , auth_class_names , AUTH_CLASS_EAP );
509
532
510
- if (!keymat -> get_psk_sig (keymat , FALSE, init , nonce , this -> msk , chunk_empty ,
533
+ if (!keymat -> get_psk_sig (keymat , FALSE, init , nonce , this -> msk , this -> ppk ,
511
534
my_id , this -> reserved , & auth_data ))
512
535
{
513
536
return FALSE;
@@ -517,6 +540,18 @@ static bool build_auth(private_eap_authenticator_t *this, message_t *message,
517
540
auth_payload -> set_data (auth_payload , auth_data );
518
541
message -> add_payload (message , (payload_t * )auth_payload );
519
542
chunk_free (& auth_data );
543
+
544
+ if (this -> no_ppk_auth )
545
+ {
546
+ if (!keymat -> get_psk_sig (keymat , FALSE, init , nonce , this -> msk ,
547
+ chunk_empty , my_id , this -> reserved , & auth_data ))
548
+ {
549
+ DBG1 (DBG_IKE , "failed adding NO_PPK_AUTH notify" );
550
+ return FALSE;
551
+ }
552
+ message -> add_notify (message , FALSE, NO_PPK_AUTH , auth_data );
553
+ chunk_free (& auth_data );
554
+ }
520
555
return TRUE;
521
556
}
522
557
@@ -698,6 +733,13 @@ METHOD(authenticator_t, is_mutual, bool,
698
733
return TRUE;
699
734
}
700
735
736
+ METHOD (authenticator_t , use_ppk , void ,
737
+ private_eap_authenticator_t * this , chunk_t ppk , bool no_ppk_auth )
738
+ {
739
+ this -> ppk = ppk ;
740
+ this -> no_ppk_auth = no_ppk_auth ;
741
+ }
742
+
701
743
METHOD (authenticator_t , destroy , void ,
702
744
private_eap_authenticator_t * this )
703
745
{
@@ -723,6 +765,7 @@ eap_authenticator_t *eap_authenticator_create_builder(ike_sa_t *ike_sa,
723
765
.authenticator = {
724
766
.build = _build_client ,
725
767
.process = _process_client ,
768
+ .use_ppk = _use_ppk ,
726
769
.is_mutual = _is_mutual ,
727
770
.destroy = _destroy ,
728
771
},
@@ -753,6 +796,7 @@ eap_authenticator_t *eap_authenticator_create_verifier(ike_sa_t *ike_sa,
753
796
.authenticator = {
754
797
.build = _build_server ,
755
798
.process = _process_server ,
799
+ .use_ppk = _use_ppk ,
756
800
.is_mutual = _is_mutual ,
757
801
.destroy = _destroy ,
758
802
},
0 commit comments