Skip to content

Commit

Permalink
Prevent crash on malformed subjectPublicKey
Browse files Browse the repository at this point in the history
A malformed subjectPublicKey causes X509_PUBKEY_get0() to return NULL.
Fort wasn't catching this when linked specifically to OpenSSL < 3.

Thanks to Niklas Vogel for reporting this.
  • Loading branch information
ydahhrk committed Aug 6, 2024
1 parent d8e36c5 commit 5689dea
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/object/certificate.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,18 @@ validate_subject_public_key(X509_PUBKEY *pubkey)

#define MODULUS 2048
#define EXPONENT "65537"
EVP_PKEY *pkey;
const RSA *rsa;
const BIGNUM *exp;
char *exp_str;
int modulus;
int error;

rsa = EVP_PKEY_get0_RSA(X509_PUBKEY_get0(pubkey));
pkey = X509_PUBKEY_get0(pubkey);
if (pkey == NULL)
return val_crypto_err("The certificate's Subject Public Key is missing or malformed.");

rsa = EVP_PKEY_get0_RSA(pkey);
if (rsa == NULL)
return val_crypto_err("EVP_PKEY_get0_RSA() returned NULL");

Expand Down

0 comments on commit 5689dea

Please sign in to comment.