diffie-hellman: Add a bool return value to set_other_public_value()

This commit is contained in:
Martin Willi
2015-03-23 17:54:03 +01:00
parent 42431690e0
commit a777155ffe
19 changed files with 123 additions and 55 deletions
+5 -1
View File
@@ -745,7 +745,11 @@ METHOD(phase1_t, get_nonce_ke, bool,
return FALSE;
}
this->dh_value = chunk_clone(ke_payload->get_key_exchange_data(ke_payload));
this->dh->set_other_public_value(this->dh, this->dh_value);
if (!this->dh->set_other_public_value(this->dh, this->dh_value))
{
DBG1(DBG_IKE, "unable to apply received KE value");
return FALSE;
}
nonce_payload = (nonce_payload_t*)message->get_payload(message, PLV1_NONCE);
if (!nonce_payload)
+6 -2
View File
@@ -493,8 +493,12 @@ static bool get_ke(private_quick_mode_t *this, message_t *message)
DBG1(DBG_IKE, "KE payload missing");
return FALSE;
}
this->dh->set_other_public_value(this->dh,
ke_payload->get_key_exchange_data(ke_payload));
if (this->dh->set_other_public_value(this->dh,
ke_payload->get_key_exchange_data(ke_payload)))
{
DBG1(DBG_IKE, "unable to apply received KE value");
return FALSE;
}
return TRUE;
}
+22 -2
View File
@@ -104,6 +104,11 @@ struct private_child_create_t {
*/
diffie_hellman_t *dh;
/**
* Applying DH public value failed?
*/
bool dh_failed;
/**
* group used for DH exchange
*/
@@ -893,7 +898,7 @@ static void process_payloads(private_child_create_t *this, message_t *message)
}
if (this->dh)
{
this->dh->set_other_public_value(this->dh,
this->dh_failed = !this->dh->set_other_public_value(this->dh,
ke_payload->get_key_exchange_data(ke_payload));
}
break;
@@ -1185,12 +1190,19 @@ METHOD(task_t, build_r, status_t,
case IKE_SA_INIT:
return get_nonce(message, &this->my_nonce);
case CREATE_CHILD_SA:
if (generate_nonce(this) != SUCCESS)
if (generate_nonce(this) != SUCCESS )
{
message->add_notify(message, FALSE, NO_PROPOSAL_CHOSEN,
chunk_empty);
return SUCCESS;
}
if (this->dh_failed)
{
DBG1(DBG_IKE, "applying DH public value failed");
message->add_notify(message, FALSE, NO_PROPOSAL_CHOSEN,
chunk_empty);
return SUCCESS;
}
no_dh = FALSE;
break;
case IKE_AUTH:
@@ -1480,6 +1492,13 @@ METHOD(task_t, process_i, status_t,
return delete_failed_sa(this);
}
if (this->dh_failed)
{
DBG1(DBG_IKE, "applying DH public value failed");
handle_child_sa_failure(this, message);
return delete_failed_sa(this);
}
if (select_and_install(this, no_dh, ike_auth) == SUCCESS)
{
if (!this->rekey)
@@ -1557,6 +1576,7 @@ METHOD(task_t, migrate, void,
DESTROY_IF(this->child_sa);
DESTROY_IF(this->proposal);
DESTROY_IF(this->dh);
this->dh_failed = FALSE;
if (this->proposals)
{
this->proposals->destroy_offset(this->proposals, offsetof(proposal_t, destroy));
+20 -1
View File
@@ -69,6 +69,11 @@ struct private_ike_init_t {
*/
diffie_hellman_t *dh;
/**
* Applying DH public value failed?
*/
bool dh_failed;
/**
* Keymat derivation (from IKE_SA)
*/
@@ -384,7 +389,7 @@ static void process_payloads(private_ike_init_t *this, message_t *message)
}
if (this->dh)
{
this->dh->set_other_public_value(this->dh,
this->dh_failed = !this->dh->set_other_public_value(this->dh,
ke_payload->get_key_exchange_data(ke_payload));
}
}
@@ -576,6 +581,13 @@ METHOD(task_t, build_r, status_t,
return FAILED;
}
if (this->dh_failed)
{
DBG1(DBG_IKE, "applying DH public value failed");
message->add_notify(message, TRUE, NO_PROPOSAL_CHOSEN, chunk_empty);
return FAILED;
}
if (!derive_keys(this, this->other_nonce, this->my_nonce))
{
DBG1(DBG_IKE, "key derivation failed");
@@ -701,6 +713,12 @@ METHOD(task_t, process_i, status_t,
return FAILED;
}
if (this->dh_failed)
{
DBG1(DBG_IKE, "applying DH public value failed");
return FAILED;
}
if (!derive_keys(this, this->my_nonce, this->other_nonce))
{
DBG1(DBG_IKE, "key derivation failed");
@@ -724,6 +742,7 @@ METHOD(task_t, migrate, void,
this->ike_sa = ike_sa;
this->keymat = (keymat_v2_t*)ike_sa->get_keymat(ike_sa);
this->proposal = NULL;
this->dh_failed = FALSE;
if (this->dh && this->dh->get_dh_group(this->dh) != this->dh_group)
{ /* reset DH value only if group changed (INVALID_KE_PAYLOAD) */
this->dh->destroy(this->dh);