]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
ike-cfg: Generalize get_dh_group() method
authorTobias Brunner <tobias@strongswan.org>
Thu, 19 Jul 2018 14:53:01 +0000 (16:53 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 14 May 2019 08:54:45 +0000 (10:54 +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 d99abbced65c886890dfa60dd3df95031872c912..30e01704793b5e550f46a73f8327fb68ec1b3b8c 100644 (file)
@@ -393,23 +393,23 @@ METHOD(ike_cfg_t, select_proposal, proposal_t*,
        return selected;
 }
 
-METHOD(ike_cfg_t, get_dh_group, diffie_hellman_group_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 dh_group = MODP_NONE;
+       uint16_t alg = 0;
 
        enumerator = this->proposals->create_enumerator(this->proposals);
        while (enumerator->enumerate(enumerator, &proposal))
        {
-               if (proposal->get_algorithm(proposal, DIFFIE_HELLMAN_GROUP, &dh_group, NULL))
+               if (proposal->get_algorithm(proposal, type, &alg, NULL))
                {
                        break;
                }
        }
        enumerator->destroy(enumerator);
-       return dh_group;
+       return alg;
 }
 
 METHOD(ike_cfg_t, equals, bool,
@@ -648,7 +648,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_dh_group = _get_dh_group,
+                       .get_algorithm = _get_algorithm,
                        .equals = _equals,
                        .get_ref = _get_ref,
                        .destroy = _destroy,
index 9c697dadca3917b0e9af26089ae5b83ecb018049..920455f9d1fba84b62081f5850aa2259c2e90007 100644 (file)
@@ -231,11 +231,16 @@ struct ike_cfg_t {
        childless_t (*childless)(ike_cfg_t *this);
 
        /**
-        * Get the DH group 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                              dh group to use for initialization
+        * For instance, use with DIFFIE_HELLMAN_GROUP to get the DH group to use
+        * for the IKE_SA initiation.
+        *
+        * @param type                  transform type to look for
+        * @return                              algorithm identifier (0 for none)
         */
-       diffie_hellman_group_t (*get_dh_group)(ike_cfg_t *this);
+       uint16_t (*get_algorithm)(ike_cfg_t *this, transform_type_t type);
 
        /**
         * Check if two IKE configs are equal.
index 023119dd4c754670d2754ba05090a754d722df4c..d17f0f1fd995971fa37c0de5867dbd92e4a6c1d8 100644 (file)
@@ -253,8 +253,9 @@ METHOD(task_t, build_i, status_t,
 
                        message->add_payload(message, &sa_payload->payload_interface);
 
-                       group = this->ike_cfg->get_dh_group(this->ike_cfg);
-                       if (group == MODP_NONE)
+                       group = this->ike_cfg->get_algorithm(this->ike_cfg,
+                                                                                                DIFFIE_HELLMAN_GROUP);
+                       if (!group)
                        {
                                DBG1(DBG_IKE, "DH group selection failed");
                                return FAILED;
index 8d0d863a1a955510de12d11676c920d143b9b25d..2668a6ee54f5d814928fab19bd99c5d8886fc843 100644 (file)
@@ -667,12 +667,14 @@ METHOD(task_t, build_i, status_t,
                        }
                        else
                        {       /* this shouldn't happen, but let's be safe */
-                               this->dh_group = ike_cfg->get_dh_group(ike_cfg);
+                               this->dh_group = ike_cfg->get_algorithm(ike_cfg,
+                                                                                                               DIFFIE_HELLMAN_GROUP);
                        }
                }
                else
                {
-                       this->dh_group = ike_cfg->get_dh_group(ike_cfg);
+                       this->dh_group = ike_cfg->get_algorithm(ike_cfg,
+                                                                                                       DIFFIE_HELLMAN_GROUP);
                }
                this->dh = this->keymat->keymat.create_dh(&this->keymat->keymat,
                                                                                                  this->dh_group);