Skip to content

Commit

Permalink
do a bit more error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
jjhoughton committed Jul 7, 2019
1 parent 9ed5dc5 commit ec99d71
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ x509_cert_pub_key (napi_env env, napi_callback_info info)
return NULL;
}

if (public_key->n == NULL || public_key->e == NULL)
{
napi_throw_error (env, NULL, "One or more required values in the "
"public key is null");
RSA_free (public_key);
EVP_PKEY_free (evp_pubkey);
X509_free (x509);
BIO_free (bio);
free (buf);
return NULL;
}

n_hex = BN_bn2hex (public_key->n);
e_hex = BN_bn2hex (public_key->e);

Expand Down Expand Up @@ -189,6 +201,19 @@ rsa_priv_key (napi_env env, napi_callback_info info)
return NULL;
}

if (private_key->n == NULL || private_key->e == NULL ||
private_key->d == NULL || private_key->p == NULL ||
private_key->q == NULL || private_key->dmp1 == NULL ||
private_key->dmq1 == NULL || private_key->iqmp == NULL)
{
napi_throw_error (env, NULL, "One or more required values in the "
"private key is null");
RSA_free (private_key);
BIO_free (bio);
free (buf);
return NULL;
}

n_hex = BN_bn2hex (private_key->n);
e_hex = BN_bn2hex (private_key->e);
d_hex = BN_bn2hex (private_key->d);
Expand Down

0 comments on commit ec99d71

Please sign in to comment.