diff --git a/src/common/crypto.c b/src/common/crypto.c index 8b2268cf7f..e035cc6676 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -53,6 +53,9 @@ #define RETURN_SSL_OUTCOME(exp) return !(exp) #endif +#define PUBLIC_KEY_OK(k) ((k) && (k)->key && (k)->key->n) +#define PRIVATE_KEY_OK(k) ((k) && (k)->key && (k)->key->p) + struct crypto_pk_env_t { int refs; /* reference counting; so we don't have to copy keys */ @@ -373,6 +376,8 @@ crypto_pk_write_private_key_to_filename(crypto_pk_env_t *env, char *s; int r; + assert(PRIVATE_KEY_OK(env)); + if (!(bio = BIO_new(BIO_s_mem()))) return -1; if (PEM_write_bio_RSAPrivateKey(bio, env->key, NULL,NULL,0,NULL,NULL)