Skip to content

Commit 6627706

Browse files
committed
eap-authenticator: Add support for authentication with PPK
1 parent 18f8249 commit 6627706

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

src/libcharon/sa/ikev2/authenticators/eap_authenticator.c

+48-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2012 Tobias Brunner
2+
* Copyright (C) 2012-2018 Tobias Brunner
33
* Copyright (C) 2006-2009 Martin Willi
44
* HSR Hochschule fuer Technik Rapperswil
55
*
@@ -64,6 +64,16 @@ struct private_eap_authenticator_t {
6464
*/
6565
char reserved[3];
6666

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+
6777
/**
6878
* Current EAP method processing
6979
*/
@@ -444,6 +454,7 @@ static bool verify_auth(private_eap_authenticator_t *this, message_t *message,
444454
chunk_t nonce, chunk_t init)
445455
{
446456
auth_payload_t *auth_payload;
457+
notify_payload_t *notify;
447458
chunk_t auth_data, recv_auth_data;
448459
identification_t *other_id;
449460
auth_cfg_t *auth;
@@ -458,14 +469,26 @@ static bool verify_auth(private_eap_authenticator_t *this, message_t *message,
458469
DBG1(DBG_IKE, "AUTH payload missing");
459470
return FALSE;
460471
}
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+
461485
other_id = this->ike_sa->get_other_id(this->ike_sa);
462486
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,
464488
other_id, this->reserved, &auth_data))
465489
{
466490
return FALSE;
467491
}
468-
recv_auth_data = auth_payload->get_data(auth_payload);
469492
if (!auth_data.len || !chunk_equals_const(auth_data, recv_auth_data))
470493
{
471494
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,
507530
DBG1(DBG_IKE, "authentication of '%Y' (myself) with %N",
508531
my_id, auth_class_names, AUTH_CLASS_EAP);
509532

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,
511534
my_id, this->reserved, &auth_data))
512535
{
513536
return FALSE;
@@ -517,6 +540,18 @@ static bool build_auth(private_eap_authenticator_t *this, message_t *message,
517540
auth_payload->set_data(auth_payload, auth_data);
518541
message->add_payload(message, (payload_t*)auth_payload);
519542
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+
}
520555
return TRUE;
521556
}
522557

@@ -698,6 +733,13 @@ METHOD(authenticator_t, is_mutual, bool,
698733
return TRUE;
699734
}
700735

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+
701743
METHOD(authenticator_t, destroy, void,
702744
private_eap_authenticator_t *this)
703745
{
@@ -723,6 +765,7 @@ eap_authenticator_t *eap_authenticator_create_builder(ike_sa_t *ike_sa,
723765
.authenticator = {
724766
.build = _build_client,
725767
.process = _process_client,
768+
.use_ppk = _use_ppk,
726769
.is_mutual = _is_mutual,
727770
.destroy = _destroy,
728771
},
@@ -753,6 +796,7 @@ eap_authenticator_t *eap_authenticator_create_verifier(ike_sa_t *ike_sa,
753796
.authenticator = {
754797
.build = _build_server,
755798
.process = _process_server,
799+
.use_ppk = _use_ppk,
756800
.is_mutual = _is_mutual,
757801
.destroy = _destroy,
758802
},

0 commit comments

Comments
 (0)