[or-cvs] Better test messages for onion skin bug

Nick Mathewson nickm at seul.org
Fri Jun 13 21:23:17 UTC 2003


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

Modified Files:
	test.c onion.c 
Log Message:
Better test messages for onion skin bug

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/src/or/test.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- test.c	13 Jun 2003 10:23:42 -0000	1.21
+++ test.c	13 Jun 2003 21:23:14 -0000	1.22
@@ -208,6 +208,12 @@
   data3 = tor_malloc(1024);
   test_assert(data1 && data2 && data3);
 
+  /* Try out RNG. */
+  crypto_seed_rng();
+  crypto_rand(100, data1);
+  crypto_rand(100, data2);
+  test_memneq(data1,data2,100);
+  
   /* Try out identity ciphers. */
   env1 = crypto_new_cipher_env(CRYPTO_CIPHER_IDENTITY);
   test_neq(env1, 0);
@@ -415,7 +421,7 @@
   /* server-side */
   char s_buf[DH_KEY_LEN];
   char s_keys[40];
-
+  
   /* shared */
   crypto_pk_env_t *pk = NULL;
 
@@ -436,12 +442,16 @@
   test_assert(! onion_skin_client_handshake(c_dh, s_buf, c_keys, 40));
   
   crypto_dh_free(c_dh);
-  crypto_free_pk_env(pk);
 
   /* FIXME sometimes (infrequently) the following fails! Why? */
+  if (memcmp(c_keys, s_keys, 40)) {
+    puts("Aiiiie");
+    exit(1);
+  }
   test_memeq(c_keys, s_keys, 40);
   memset(s_buf, 0, 40);
   test_memneq(c_keys, s_buf, 40);
+  crypto_free_pk_env(pk);
 }
 
 /* from main.c */
@@ -584,15 +594,25 @@
   log(LOG_ERR,NULL);         /* make logging quieter */
 
   setup_directory();
+#ifndef DEBUG_ONION_SKINS
   puts("========================== Buffers =========================");
   test_buffers();
   puts("========================== Crypto ==========================");
-  test_crypto_dh();
   test_crypto();
+  test_crypto_dh();
   puts("\n========================= Util ============================");
   test_util();
   puts("\n========================= Onion Skins =====================");
-  test_onion_handshake();
+#endif
+#ifdef DEBUG_ONION_SKINS
+  crypto_seed_rng();
+  while(1) {
+#endif
+    test_onion_handshake();
+#ifdef DEBUG_ONION_SKINS
+    fflush(NULL);
+  }
+#endif
   puts("\n========================= Directory Formats ===============");
   test_dir_format();
   puts("");

Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/src/or/onion.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- onion.c	13 Jun 2003 09:59:32 -0000	1.54
+++ onion.c	13 Jun 2003 21:23:14 -0000	1.55
@@ -418,14 +418,19 @@
   if (crypto_dh_get_public(dh, pubkey+16, dhbytes))
     goto err;
 
-#if 0
-  printf("Client DH sent: %x %x %x ... %x %x %x\n",
-         (int) pubkey[16], (int) pubkey[17], (int) pubkey[18], 
-         (int) pubkey[205], (int) pubkey[206], (int) pubkey[207]);
+#ifdef DEBUG_ONION_SKINS
+#define PA(a,n) \
+  { int _i; for (_i = 0; _i<n; ++_i) printf("%02x ",((int)(a)[_i])&0xFF); }
 
-  printf("Client key sent: %x %x %x ... %x %x %x\n",
-         pubkey[0],pubkey[1],pubkey[2], 
-         pubkey[13],pubkey[14],pubkey[15]);
+  printf("Client: client g^x:");
+  PA(pubkey+16,3);
+  printf("...");
+  PA(pubkey+141,3);
+  puts("");
+
+  printf("Client: client symkey:");
+  PA(pubkey+0,16);
+  puts("");
 #endif
 
   cipher = crypto_create_init_cipher(CRYPTO_CIPHER_3DES, pubkey, iv, 1);
@@ -478,9 +483,10 @@
                                 buf, RSA_NO_PADDING) == -1)
     goto err;
   
-#if 0
-  printf("Client key got: %x %x %x ... %x %x %x\n",
-         buf[0],buf[1],buf[2], buf[13],buf[14],buf[15]);
+#ifdef DEBUG_ONION_SKINS
+  printf("Server: client symkey:");
+  PA(buf+0,16);
+  puts("");
 #endif
 
   cipher = crypto_create_init_cipher(CRYPTO_CIPHER_3DES, buf, iv, 0);
@@ -489,21 +495,37 @@
                             buf+pkbytes))
     goto err;
 
-#if 0
-  printf("Client DH got: %x %x %x ... %x %x %x\n",
-         (int) buf[16], (int) buf[17], (int) buf[18], 
-         (int) buf[205], (int) buf[206], (int) buf[207]);
+#ifdef DEBUG_ONION_SKINS
+  printf("Server: client g^x:");
+  PA(buf+16,3);
+  printf("...");
+  PA(buf+141,3);
+  puts("");
 #endif
   
   dh = crypto_dh_new();
   if (crypto_dh_get_public(dh, handshake_reply_out, DH_KEY_LEN))
     goto err;
 
+#ifdef DEBUG_ONION_SKINS
+  printf("Server: server g^y:");
+  PA(handshake_reply_out+0,3);
+  printf("...");
+  PA(handshake_reply_out+125,3);
+  puts("");
+#endif
+
   if (crypto_dh_compute_secret(dh, buf+16, DH_KEY_LEN, buf))
     goto err;
 
   memcpy(key_out, buf+DH_KEY_LEN-key_out_len, key_out_len);
 
+#ifdef DEBUG_ONION_SKINS
+  printf("Server: keys out:");
+  PA(key_out, key_out_len);
+  puts("");
+#endif
+
   crypto_free_cipher_env(cipher);
   crypto_dh_free(dh);
   return 0;
@@ -532,11 +554,25 @@
   
   memset(key_material, 0, DH_KEY_LEN);
 
+#ifdef DEBUG_ONION_SKINS
+  printf("Client: server g^y:");
+  PA(handshake_reply+0,3);
+  printf("...");
+  PA(handshake_reply+125,3);
+  puts("");
+#endif
+
   if (crypto_dh_compute_secret(handshake_state, handshake_reply, DH_KEY_LEN,
                                key_material))
     return -1;
   
   memcpy(key_out, key_material+DH_KEY_LEN-key_out_len, key_out_len);
+
+#ifdef DEBUG_ONION_SKINS
+  printf("Client: keys out:");
+  PA(key_out, key_out_len);
+  puts("");
+#endif
 
   return 0;
 }



More information about the tor-commits mailing list