]> 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)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Mon, 28 Aug 2023 17:36:23 +0000 (19:36 +0200)
src/libcharon/sa/ikev2/keymat_v2.c

index 5b26537c0473aa1046c027755fb488909fbb8653..6fb2065d27520fb64ae92fd40232b1ea785334d7 100644 (file)
@@ -280,6 +280,8 @@ METHOD(keymat_v2_t, derive_ike_keys, bool,
                         ENCRYPTION_ALGORITHM);
                return FALSE;
        }
+       DESTROY_IF(this->aead_in);
+       DESTROY_IF(this->aead_out);
        if (!encryption_algorithm_is_aead(enc_alg))
        {
                if (!proposal->get_algorithm(proposal, INTEGRITY_ALGORITHM, &int_alg,
@@ -412,6 +414,7 @@ METHOD(keymat_v2_t, derive_ike_keys, bool,
        {
                goto failure;
        }
+       chunk_clear(&this->skd);
        chunk_split(keymat, "ammmmaa", key_size, &this->skd, sk_ai.len, &sk_ai,
                                sk_ar.len, &sk_ar, sk_ei.len, &sk_ei, sk_er.len, &sk_er,
                                key_size, &sk_pi, key_size, &sk_pr);
@@ -433,6 +436,8 @@ METHOD(keymat_v2_t, derive_ike_keys, bool,
        /* SK_pi/SK_pr used for authentication => stored for later */
        DBG4(DBG_IKE, "Sk_pi secret %B", &sk_pi);
        DBG4(DBG_IKE, "Sk_pr secret %B", &sk_pr);
+       chunk_clear(&this->skp_build);
+       chunk_clear(&this->skp_verify);
        if (this->initiator)
        {
                this->skp_build = sk_pi;