Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soter: make sure we have the RSA private key before trying to decrypt… #334

Merged
merged 1 commit into from
Nov 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/soter/openssl/soter_asym_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ soter_status_t soter_asym_cipher_decrypt(soter_asym_cipher_t* asym_cipher, const
{
EVP_PKEY *pkey;
RSA *rsa;
const BIGNUM *d = NULL;
int rsa_mod_size;
size_t output_length;

Expand Down Expand Up @@ -243,6 +244,18 @@ soter_status_t soter_asym_cipher_decrypt(soter_asym_cipher_t* asym_cipher, const
return SOTER_INVALID_PARAMETER;
}

/* we can only decrypt, if we have the private key */
/* some versions of OpenSSL just crash, if you send RSA public key to EVP_PKEY_decrypt, so we do checks here */
#if OPENSSL_VERSION_NUMBER < 0x10100000L
d = rsa->d;
#else
RSA_get0_key(rsa, NULL, NULL, &d);
#endif
if (NULL == d)
{
return SOTER_INVALID_PARAMETER;
}

/* Currently we support only OAEP padding for RSA encryption */
/* TODO: should we support "no padding" or PKCS1.5 padding? */
if (!EVP_PKEY_decrypt_init(asym_cipher->pkey_ctx))
Expand Down Expand Up @@ -328,4 +341,4 @@ soter_status_t soter_asym_cipher_destroy(soter_asym_cipher_t* asym_cipher)
{
return status;
}
}
}