[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Fix bugs in certificate generation and SSL context creation...



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv10204/src/common

Modified Files:
	tortls.c 
Log Message:
Fix bugs in certificate generation and SSL context creation.  Both seem to work now.

Index: tortls.c
===================================================================
RCS file: /home/or/cvsroot/src/common/tortls.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- tortls.c	11 Sep 2003 21:38:57 -0000	1.7
+++ tortls.c	11 Sep 2003 23:26:31 -0000	1.8
@@ -35,6 +35,7 @@
 
 /* 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 @@
   }
 }
 
+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 @@
   int nid;
   int r;
   
+  tor_tls_init();
+
   start_time = time(NULL);
 
   assert(rsa);
@@ -101,10 +112,10 @@
   
   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;
   
@@ -171,6 +182,8 @@
   tor_tls_context *result;
 
   assert((certfile && rsa) || (!certfile && !rsa));
+
+  tor_tls_init();
 
   result = tor_malloc(sizeof(tor_tls_context));
   result->ctx = NULL;