summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-04-25 19:21:44 +0000
committerNick Mathewson <nickm@torproject.org>2004-04-25 19:21:44 +0000
commit70bbd0cafabeae9854ba15158f5cc6635b2c0291 (patch)
tree31275cbcd3ed3b47c6fe28b022dde41018a09b93
parent0fca143ea1699ffa68fab34ba329c7b2db2c7bca (diff)
downloadtor-70bbd0cafabeae9854ba15158f5cc6635b2c0291.tar.gz
tor-70bbd0cafabeae9854ba15158f5cc6635b2c0291.zip
Add assert on crypto_pk_write_private_key,and macros to make sure we have real keys
svn:r1694
-rw-r--r--src/common/crypto.c5
1 files changed, 5 insertions, 0 deletions
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)