mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-06 21:58:57 -04:00
added missing free for public keys used in envelop encryption
This commit is contained in:
parent
10230dff6e
commit
55e80871eb
1 changed files with 13 additions and 2 deletions
|
@ -544,11 +544,10 @@ bool GxsSecurity::encrypt(uint8_t *& out, uint32_t &outlen, const uint8_t *in, u
|
||||||
out = NULL ;
|
out = NULL ;
|
||||||
EVP_CIPHER_CTX ctx;
|
EVP_CIPHER_CTX ctx;
|
||||||
EVP_CIPHER_CTX_init(&ctx);
|
EVP_CIPHER_CTX_init(&ctx);
|
||||||
|
std::vector<EVP_PKEY *> public_keys(keys.size(),NULL);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::vector<EVP_PKEY *> public_keys(keys.size(),NULL);
|
|
||||||
|
|
||||||
for(uint32_t i=0;i<keys.size();++i)
|
for(uint32_t i=0;i<keys.size();++i)
|
||||||
{
|
{
|
||||||
RSA *tmpkey = ::extractPublicKey(keys[i]) ;
|
RSA *tmpkey = ::extractPublicKey(keys[i]) ;
|
||||||
|
@ -591,6 +590,11 @@ bool GxsSecurity::encrypt(uint8_t *& out, uint32_t &outlen, const uint8_t *in, u
|
||||||
if(!EVP_SealInit(&ctx, EVP_aes_128_cbc(), ek.data(), eklen.data(), iv, public_keys.data(), keys.size()))
|
if(!EVP_SealInit(&ctx, EVP_aes_128_cbc(), ek.data(), eklen.data(), iv, public_keys.data(), keys.size()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// now we can release the encryption keys
|
||||||
|
for(uint32_t i=0;i<public_keys.size();++i)
|
||||||
|
EVP_PKEY_free(public_keys[i]) ;
|
||||||
|
public_keys.clear() ;
|
||||||
|
|
||||||
int total_ek_size = MULTI_ENCRYPTION_FORMAT_v001_ENCRYPTED_KEY_SIZE * keys.size() ;
|
int total_ek_size = MULTI_ENCRYPTION_FORMAT_v001_ENCRYPTED_KEY_SIZE * keys.size() ;
|
||||||
|
|
||||||
int max_outlen = MULTI_ENCRYPTION_FORMAT_v001_HEADER_SIZE + MULTI_ENCRYPTION_FORMAT_v001_NUMBER_OF_KEYS_SIZE + total_ek_size + EVP_MAX_IV_LENGTH + (inlen + cipher_block_size) ;
|
int max_outlen = MULTI_ENCRYPTION_FORMAT_v001_HEADER_SIZE + MULTI_ENCRYPTION_FORMAT_v001_NUMBER_OF_KEYS_SIZE + total_ek_size + EVP_MAX_IV_LENGTH + (inlen + cipher_block_size) ;
|
||||||
|
@ -670,6 +674,10 @@ bool GxsSecurity::encrypt(uint8_t *& out, uint32_t &outlen, const uint8_t *in, u
|
||||||
if(out) free(out) ;
|
if(out) free(out) ;
|
||||||
out = NULL ;
|
out = NULL ;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<public_keys.size();++i)
|
||||||
|
EVP_PKEY_free(public_keys[i]) ;
|
||||||
|
public_keys.clear() ;
|
||||||
|
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -867,6 +875,9 @@ bool GxsSecurity::decrypt(uint8_t *& out, uint32_t & outlen, const uint8_t *in,
|
||||||
{
|
{
|
||||||
succeed = EVP_OpenInit(&ctx, EVP_aes_128_cbc(),in + encrypted_keys_offset + i*MULTI_ENCRYPTION_FORMAT_v001_ENCRYPTED_KEY_SIZE , MULTI_ENCRYPTION_FORMAT_v001_ENCRYPTED_KEY_SIZE, in+IV_offset, privateKey);
|
succeed = EVP_OpenInit(&ctx, EVP_aes_128_cbc(),in + encrypted_keys_offset + i*MULTI_ENCRYPTION_FORMAT_v001_ENCRYPTED_KEY_SIZE , MULTI_ENCRYPTION_FORMAT_v001_ENCRYPTED_KEY_SIZE, in+IV_offset, privateKey);
|
||||||
|
|
||||||
|
if(!succeed)
|
||||||
|
EVP_CIPHER_CTX_cleanup(&ctx);
|
||||||
|
|
||||||
#ifdef GXS_SECURITY_DEBUG
|
#ifdef GXS_SECURITY_DEBUG
|
||||||
std::cerr << " encrypted key at offset " << encrypted_keys_offset + i*MULTI_ENCRYPTION_FORMAT_v001_ENCRYPTED_KEY_SIZE << ": " << succeed << std::endl;
|
std::cerr << " encrypted key at offset " << encrypted_keys_offset + i*MULTI_ENCRYPTION_FORMAT_v001_ENCRYPTED_KEY_SIZE << ": " << succeed << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue