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

[or-cvs] Make base-64-encoded DER work, including workaround for ugl...



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

Modified Files:
	dirserv.c test.c 
Log Message:
Make base-64-encoded DER work, including workaround for ugly openssl misfeature that makes base64 decoding fail when you strip out the newlines.

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -d -r1.89 -r1.90
--- dirserv.c	6 Oct 2004 13:31:48 -0000	1.89
+++ dirserv.c	7 Oct 2004 03:11:42 -0000	1.90
@@ -557,7 +557,7 @@
   char signature[128];
   char published[33];
   time_t published_on;
-  int i, identity_pkeylen;
+  int i;
   eos = s+maxlen;
 
   if (!descriptor_list)
@@ -565,14 +565,15 @@
 
   if (list_running_servers(&cp))
     return -1;
-#if 0
-  /* PEM-encode the identity key key */
-  if(crypto_pk_write_public_key_to_string(private_key,
-                                        &identity_pkey,&identity_pkeylen)<0) {
+
+  /* ASN.1-encode the public key.  This is a temporary measure; once
+   * everyone is running 0.0.9pre3 or later, we can shift to using a
+   * PEM-encoded key instead.
+   */
+  if(crypto_pk_DER64_encode_public_key(private_key, &identity_pkey)<0) {
     log_fn(LOG_WARN,"write identity_pkey to string failed!");
     return -1;
   }
-#endif
   dirserv_remove_old_servers(ROUTER_MAX_AGE);
   published_on = time(NULL);
   format_iso_time(published, published_on);
@@ -580,8 +581,9 @@
            "signed-directory\n"
            "published %s\n"
            "recommended-software %s\n"
-           "running-routers %s\n\n",
-           published, options.RecommendedVersions, cp);
+           "running-routers %s\n"
+           "opt dir-signing-key %s\n\n",
+           published, options.RecommendedVersions, cp, identity_pkey);
 
   tor_free(cp);
   tor_free(identity_pkey);

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/src/or/test.c,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- test.c	6 Oct 2004 13:31:48 -0000	1.118
+++ test.c	7 Oct 2004 03:11:42 -0000	1.119
@@ -365,6 +365,20 @@
   test_assert(! crypto_pk_write_public_key_to_string(pk1, &cp, &i));
   test_assert(! crypto_pk_read_public_key_from_string(pk2, cp, i));
   test_eq(0, crypto_pk_cmp_keys(pk1, pk2));
+  tor_free(cp);
+
+  /* Check DER encoding */
+  i=crypto_pk_DER64_encode_public_key(pk1, &cp);
+  test_assert(i>0);
+  test_assert(cp);
+  test_assert(!strchr(cp, ' '));
+  test_assert(!strchr(cp, '\n'));
+  test_eq(0, crypto_pk_cmp_keys(pk1, pk1));
+  crypto_free_pk_env(pk2);
+  pk2 = crypto_pk_DER64_decode_public_key(cp);
+  test_assert(pk2);
+  test_eq(0, crypto_pk_cmp_keys(pk1, pk2));
+  tor_free(cp);
 
   test_eq(128, crypto_pk_keysize(pk1));
   test_eq(128, crypto_pk_keysize(pk2));
@@ -1095,6 +1109,7 @@
 //  puts("========================== Buffers =========================");
 //  test_buffers();
   puts("\n========================== Crypto ==========================");
+  // add_stream_log(LOG_DEBUG, LOG_ERR, "<stdout>", stdout);
   test_crypto();
   test_crypto_dh();
   puts("\n========================= Util ============================");
@@ -1105,7 +1120,6 @@
   test_onion();
   test_onion_handshake();
   puts("\n========================= Directory Formats ===============");
-  /* add_stream_log(LOG_DEBUG, LOG_ERR, "<stdout>", stdout); */
   test_dir_format();
   puts("\n========================= Rendezvous functionality ========");
   test_rend_fns();