From: Tobias Brunner Date: Thu, 28 Jun 2018 13:33:35 +0000 (+0200) Subject: keymat_v2: Proper cleanup if derive_ike_keys() is called multiple times X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff77e96d24383b6629734930353bd7430bc5c7da;p=thirdparty%2Fstrongswan.git keymat_v2: Proper cleanup if derive_ike_keys() is called multiple times --- diff --git a/src/libcharon/sa/ikev2/keymat_v2.c b/src/libcharon/sa/ikev2/keymat_v2.c index 93eaee6f41..56cf00dafa 100644 --- a/src/libcharon/sa/ikev2/keymat_v2.c +++ b/src/libcharon/sa/ikev2/keymat_v2.c @@ -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))