Check RSA_public_decrypt() length before constructing and comparing a chunk

If decryption fails, it returns -1. chunk_equals() should catch that error,
but be more explicit in error checking.
This commit is contained in:
Martin Willi
2013-04-10 18:10:30 +02:00
committed by Andreas Steffen
parent 97d975b7bb
commit b52771fbb2
@@ -48,8 +48,6 @@ struct private_openssl_rsa_public_key_t {
refcount_t ref;
};
/**
* Verification of an EMPSA PKCS1 signature described in PKCS#1
*/
@@ -67,12 +65,17 @@ static bool verify_emsa_pkcs1_signature(private_openssl_rsa_public_key_t *this,
if (type == NID_undef)
{
chunk_t hash = chunk_alloc(rsa_size);
char *buf;
int len;
hash.len = RSA_public_decrypt(signature.len, signature.ptr, hash.ptr,
this->rsa, RSA_PKCS1_PADDING);
valid = chunk_equals(data, hash);
free(hash.ptr);
buf = malloc(rsa_size);
len = RSA_public_decrypt(signature.len, signature.ptr, buf, this->rsa,
RSA_PKCS1_PADDING);
if (len != -1)
{
valid = chunk_equals(data, chunk_create(buf, len));
}
free(buf);
}
else
{