ike-cfg: Generalize get_ke_method() method

This commit is contained in:
Tobias Brunner 2018-07-19 16:53:01 +02:00 committed by Andreas Steffen
parent 4fa84482e7
commit d30f1a6418
4 changed files with 21 additions and 15 deletions

View File

@ -347,24 +347,23 @@ METHOD(ike_cfg_t, select_proposal, proposal_t*,
return proposal_select(this->proposals, proposals, flags); return proposal_select(this->proposals, proposals, flags);
} }
METHOD(ike_cfg_t, get_ke_method, key_exchange_method_t, METHOD(ike_cfg_t, get_algorithm, uint16_t,
private_ike_cfg_t *this) private_ike_cfg_t *this, transform_type_t type)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
proposal_t *proposal; proposal_t *proposal;
uint16_t method = KE_NONE; uint16_t alg = 0;
enumerator = this->proposals->create_enumerator(this->proposals); enumerator = this->proposals->create_enumerator(this->proposals);
while (enumerator->enumerate(enumerator, &proposal)) while (enumerator->enumerate(enumerator, &proposal))
{ {
if (proposal->get_algorithm(proposal, KEY_EXCHANGE_METHOD, &method, if (proposal->get_algorithm(proposal, type, &alg, NULL))
NULL))
{ {
break; break;
} }
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
return method; return alg;
} }
METHOD(ike_cfg_t, equals, bool, METHOD(ike_cfg_t, equals, bool,
@ -603,7 +602,7 @@ ike_cfg_t *ike_cfg_create(ike_cfg_create_t *data)
.get_proposals = _get_proposals, .get_proposals = _get_proposals,
.select_proposal = _select_proposal, .select_proposal = _select_proposal,
.has_proposal = _has_proposal, .has_proposal = _has_proposal,
.get_ke_method = _get_ke_method, .get_algorithm = _get_algorithm,
.equals = _equals, .equals = _equals,
.get_ref = _get_ref, .get_ref = _get_ref,
.destroy = _destroy, .destroy = _destroy,

View File

@ -34,7 +34,6 @@ typedef struct ike_cfg_create_t ike_cfg_create_t;
#include <collections/linked_list.h> #include <collections/linked_list.h>
#include <utils/identification.h> #include <utils/identification.h>
#include <crypto/proposal/proposal.h> #include <crypto/proposal/proposal.h>
#include <crypto/key_exchange.h>
/** /**
* IKE version. * IKE version.
@ -230,11 +229,16 @@ struct ike_cfg_t {
childless_t (*childless)(ike_cfg_t *this); childless_t (*childless)(ike_cfg_t *this);
/** /**
* Get the key exchange method to use for IKE_SA setup. * Get the first algorithm of a certain transform type that's contained in
* any of the configured proposals.
* *
* @return key exchange method to use for initialization * For instance, use with KEY_EXCHANGE_METHOD to get the KE metho to use
* for the IKE_SA initiation.
*
* @param type transform type to look for
* @return algorithm identifier (0 for none)
*/ */
key_exchange_method_t (*get_ke_method)(ike_cfg_t *this); uint16_t (*get_algorithm)(ike_cfg_t *this, transform_type_t type);
/** /**
* Check if two IKE configs are equal. * Check if two IKE configs are equal.

View File

@ -253,8 +253,9 @@ METHOD(task_t, build_i, status_t,
message->add_payload(message, &sa_payload->payload_interface); message->add_payload(message, &sa_payload->payload_interface);
group = this->ike_cfg->get_ke_method(this->ike_cfg); group = this->ike_cfg->get_algorithm(this->ike_cfg,
if (group == KE_NONE) KEY_EXCHANGE_METHOD);
if (!group)
{ {
DBG1(DBG_IKE, "DH group selection failed"); DBG1(DBG_IKE, "DH group selection failed");
return FAILED; return FAILED;

View File

@ -673,12 +673,14 @@ METHOD(task_t, build_i, status_t,
} }
else else
{ /* this shouldn't happen, but let's be safe */ { /* this shouldn't happen, but let's be safe */
this->dh_group = ike_cfg->get_ke_method(ike_cfg); this->dh_group = ike_cfg->get_algorithm(ike_cfg,
KEY_EXCHANGE_METHOD);
} }
} }
else else
{ {
this->dh_group = ike_cfg->get_ke_method(ike_cfg); this->dh_group = ike_cfg->get_algorithm(ike_cfg,
KEY_EXCHANGE_METHOD);
} }
this->dh = this->keymat->keymat.create_ke(&this->keymat->keymat, this->dh = this->keymat->keymat.create_ke(&this->keymat->keymat,
this->dh_group); this->dh_group);