]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
ike-cfg: Generalize get_ke_method() method
authorTobias Brunner <tobias@strongswan.org>
Thu, 19 Jul 2018 14:53:01 +0000 (16:53 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 29 Jun 2022 08:28:50 +0000 (10:28 +0200)
src/libcharon/config/ike_cfg.c
src/libcharon/config/ike_cfg.h
src/libcharon/sa/ikev1/tasks/aggressive_mode.c
src/libcharon/sa/ikev2/tasks/ike_init.c

index cb60e7ffdf58d156cc4d86be2eb043f6ac6be204..792f8022a6c1856f1c1632464a832a7495d6960d 100644 (file)
@@ -348,24 +348,23 @@ METHOD(ike_cfg_t, select_proposal, proposal_t*,
        return proposal_select(this->proposals, proposals, flags);
 }
 
-METHOD(ike_cfg_t, get_ke_method, key_exchange_method_t,
-       private_ike_cfg_t *this)
+METHOD(ike_cfg_t, get_algorithm, uint16_t,
+       private_ike_cfg_t *this, transform_type_t type)
 {
        enumerator_t *enumerator;
        proposal_t *proposal;
-       uint16_t method = KE_NONE;
+       uint16_t alg = 0;
 
        enumerator = this->proposals->create_enumerator(this->proposals);
        while (enumerator->enumerate(enumerator, &proposal))
        {
-               if (proposal->get_algorithm(proposal, KEY_EXCHANGE_METHOD, &method,
-                                                                       NULL))
+               if (proposal->get_algorithm(proposal, type, &alg, NULL))
                {
                        break;
                }
        }
        enumerator->destroy(enumerator);
-       return method;
+       return alg;
 }
 
 METHOD(ike_cfg_t, equals, bool,
@@ -604,7 +603,7 @@ ike_cfg_t *ike_cfg_create(ike_cfg_create_t *data)
                        .get_proposals = _get_proposals,
                        .select_proposal = _select_proposal,
                        .has_proposal = _has_proposal,
-                       .get_ke_method = _get_ke_method,
+                       .get_algorithm = _get_algorithm,
                        .equals = _equals,
                        .get_ref = _get_ref,
                        .destroy = _destroy,
index d7cc094dd764ba5056a447178a89cde74fd65c8b..0b4fe356f42129db18f865425d35c933a2b21c37 100644 (file)
@@ -35,7 +35,6 @@ typedef struct ike_cfg_create_t ike_cfg_create_t;
 #include <collections/linked_list.h>
 #include <utils/identification.h>
 #include <crypto/proposal/proposal.h>
-#include <crypto/key_exchange.h>
 
 /**
  * IKE version.
@@ -231,11 +230,16 @@ struct ike_cfg_t {
        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.
index b65ee98a3890e61d1e2ed12dbff2c8c321b9fa8f..0184cb55ea8a5e189d9737ae0f367b7595ed2641 100644 (file)
@@ -252,8 +252,9 @@ METHOD(task_t, build_i, status_t,
 
                        message->add_payload(message, &sa_payload->payload_interface);
 
-                       group = this->ike_cfg->get_ke_method(this->ike_cfg);
-                       if (group == KE_NONE)
+                       group = this->ike_cfg->get_algorithm(this->ike_cfg,
+                                                                                                KEY_EXCHANGE_METHOD);
+                       if (!group)
                        {
                                DBG1(DBG_IKE, "DH group selection failed");
                                return FAILED;
index c9241f7abefc2b7cb58017c4f6700047f98098a3..98185f576e797418510cc44ee378435570f72d44 100644 (file)
@@ -674,12 +674,14 @@ METHOD(task_t, build_i, status_t,
                        }
                        else
                        {       /* 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
                {
-                       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_group);