From 001cd08b2eeef9ac43b63fb1e69b4947eca85b21 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 11 Sep 2003 23:26:31 +0000 Subject: Fix bugs in certificate generation and SSL context creation. Both seem to work now. svn:r447 --- src/common/tortls.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/common/tortls.c b/src/common/tortls.c index 1017cb27f..1f943ebb8 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -35,6 +35,7 @@ struct tor_tls_st { /* global tls context, keep it here because nobody else needs to touch it */ static tor_tls_context *global_tls_context=NULL; +static int tls_library_is_initialized = 0; #define _TOR_TLS_SYSCALL -6 #define _TOR_TLS_ZERORETURN -5 @@ -64,6 +65,14 @@ tor_tls_get_error(tor_tls *tls, int r, int extra) } } +static void +tor_tls_init() { + if (!tls_library_is_initialized) { + SSL_library_init(); + tls_library_is_initialized = 1; + } +} + static int always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx) { @@ -87,6 +96,8 @@ tor_tls_write_certificate(char *certfile, crypto_pk_env_t *rsa, char *nickname) int nid; int r; + tor_tls_init(); + start_time = time(NULL); assert(rsa); @@ -101,10 +112,10 @@ tor_tls_write_certificate(char *certfile, crypto_pk_env_t *rsa, char *nickname) if (!(name = X509_NAME_new())) goto error; - if ((nid = OBJ_txt2nid("organizationName")) != NID_undef) goto error; + if ((nid = OBJ_txt2nid("organizationName")) == NID_undef) goto error; if (!(X509_NAME_add_entry_by_NID(name, nid, MBSTRING_ASC, "TOR", -1, -1, 0))) goto error; - if ((nid = OBJ_txt2nid("commonName")) != NID_undef) goto error; + if ((nid = OBJ_txt2nid("commonName")) == NID_undef) goto error; if (!(X509_NAME_add_entry_by_NID(name, nid, MBSTRING_ASC, nickname, -1, -1, 0))) goto error; @@ -172,6 +183,8 @@ tor_tls_context_new(char *certfile, crypto_pk_env_t *rsa, int isServer) assert((certfile && rsa) || (!certfile && !rsa)); + tor_tls_init(); + result = tor_malloc(sizeof(tor_tls_context)); result->ctx = NULL; #ifdef EVERYONE_HAS_AES -- cgit v1.2.3