Przeglądaj źródła

Add assert on crypto_pk_write_private_key,and macros to make sure we have real keys

svn:r1694
Nick Mathewson 21 lat temu
rodzic
commit
70bbd0cafa
1 zmienionych plików z 5 dodań i 0 usunięć
  1. 5 0
      src/common/crypto.c

+ 5 - 0
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)