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

openssl 3.0: dont use deprecated functions #43

Merged
merged 1 commit into from
Nov 9, 2023
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
30 changes: 19 additions & 11 deletions src/crypto-openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void crypto_ctx_free(crypto_ctx *ctx)
}
}

static int password_cb(char *buf, int size, int rwflag, void *userdata)
static int password_cb(char *buf __attribute__((unused)), int size __attribute__((unused)),
int rwflag __attribute__((unused)), void *userdata __attribute__((unused)))
{
/* Dummy callback to ensure openssl doesn't prompt for a password */
return 0;
Expand Down Expand Up @@ -247,9 +248,9 @@ unsigned char *crypto_decrypt_signature(crypto_ctx *ctx,
{
X509 *x509;
EVP_PKEY *pkey = NULL;
RSA *rsa;
EVP_PKEY_CTX *pctx = NULL;
unsigned char *hash = NULL;
int tmp_len = -1, ossl_pad;
int ossl_pad;

*out_len = 0;

Expand All @@ -272,14 +273,15 @@ unsigned char *crypto_decrypt_signature(crypto_ctx *ctx,
return NULL;
}

rsa = EVP_PKEY_get1_RSA(pkey);
if (rsa == NULL) {
pctx = EVP_PKEY_CTX_new(pkey, NULL);
if (!pctx || EVP_PKEY_verify_recover_init(pctx) <= 0) {
ERR_print_errors_fp (stderr);
crypto_error_set(error, 1, 0, "error getting public key RSA");
crypto_error_set(error, 1, 0, "error creating public key context");
goto out;
}

hash = calloc(1, RSA_size(rsa));
*out_len = EVP_PKEY_size(pkey);
hash = calloc(1, *out_len);
if (!hash) {
crypto_error_set(error, 1, 0, "not enough memory to decrypt signature");
goto out;
Expand All @@ -297,19 +299,25 @@ unsigned char *crypto_decrypt_signature(crypto_ctx *ctx,
goto out;
}

tmp_len = RSA_public_decrypt(sig_len, sig_data, hash, rsa, ossl_pad);
if (tmp_len > 0) {
*out_len = (size_t) tmp_len;
} else {
if (EVP_PKEY_CTX_set_rsa_padding(pctx, ossl_pad) <= 0) {
ERR_print_errors_fp (stderr);
crypto_error_set(error, 1, 0, "failed to set rsa padding");
goto out;
}

if (EVP_PKEY_verify_recover(pctx, hash, out_len, sig_data, sig_len) <= 0) {
ERR_print_errors_fp (stderr);
crypto_error_set(error, 1, 0, "could not decrypt signature");
free(hash);
hash = NULL;
*out_len = 0;
}

out:
if (pkey)
EVP_PKEY_free(pkey);
if (pctx)
EVP_PKEY_CTX_free(pctx);
return hash;
}