]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
keymat_v2: Proper cleanup if derive_ike_keys() is called multiple times
authorTobias Brunner <tobias@strongswan.org>
Thu, 28 Jun 2018 13:33:35 +0000 (15:33 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 14 May 2019 08:53:14 +0000 (10:53 +0200)
src/libcharon/sa/ikev2/keymat_v2.c

index 93eaee6f415326d8980c2f42a3a87847568fb946..56cf00dafab24961fad24002ac033ecacc194506 100644 (file)
@@ -332,6 +332,7 @@ METHOD(keymat_v2_t, derive_ike_keys, bool,
                return FALSE;
        }
        this->prf_alg = alg;
+       DESTROY_IF(this->prf);
        this->prf = lib->crypto->create_prf(lib->crypto, alg);
        if (this->prf == NULL)
        {
@@ -425,6 +426,7 @@ METHOD(keymat_v2_t, derive_ike_keys, bool,
 
        /* SK_d is used for generating CHILD_SA key mat => store for later use */
        key_size = this->prf->get_key_size(this->prf);
+       chunk_clear(&this->skd);
        if (!prf_plus->allocate_bytes(prf_plus, key_size, &this->skd))
        {
                goto failure;
@@ -438,6 +440,9 @@ METHOD(keymat_v2_t, derive_ike_keys, bool,
                goto failure;
        }
 
+       DESTROY_IF(this->aead_in);
+       DESTROY_IF(this->aead_out);
+
        if (encryption_algorithm_is_aead(alg))
        {
                if (!derive_ike_aead(this, alg, key_size, prf_plus))
@@ -460,6 +465,9 @@ METHOD(keymat_v2_t, derive_ike_keys, bool,
                }
        }
 
+       chunk_clear(&this->skp_build);
+       chunk_clear(&this->skp_verify);
+
        /* SK_pi/SK_pr used for authentication => stored for later */
        key_size = this->prf->get_key_size(this->prf);
        if (!prf_plus->allocate_bytes(prf_plus, key_size, &key))