adding GNUNET_CRYPTO_setup_hostkey to setup a hostkey ahead of time, using this funct...
authorChristian Grothoff <christian@grothoff.org>
Tue, 28 Feb 2012 19:08:20 +0000 (19:08 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 28 Feb 2012 19:08:20 +0000 (19:08 +0000)
src/include/gnunet_crypto_lib.h
src/util/crypto_rsa.c
src/vpn/test_gnunet_vpn.c

index 6e37266a252891526a2b5793e26f2126c9a5270a..63d3ee4184c06ba346330968fb4ea5eaf35f5e00 100644 (file)
@@ -763,6 +763,18 @@ struct GNUNET_CRYPTO_RsaPrivateKey *
 GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename);
 
 
+/**
+ * Setup a hostkey file for a peer given the name of the
+ * configuration file (!).  This function is used so that
+ * at a later point code can be certain that reading a
+ * hostkey is fast (for example in time-dependent testcases).
+ *
+ * @param cfg_name name of the configuration file to use
+ */
+void
+GNUNET_CRYPTO_setup_hostkey (const char *cfg_name);
+
+
 /**
  * Deterministically (!) create a private key using only the
  * given HashCode as input to the PRNG.
index 418fe833ba238b1f6d6e84dd74241d4c14cb77d5..5e3a7762ef98516bbec519154aa8daedc4bcbf7c 100644 (file)
@@ -107,7 +107,9 @@ adjust (unsigned char *buf, size_t size, size_t target)
 }
 
 /**
- * This HostKey implementation uses RSA.
+ * Create a new private key. Caller must free return value.
+ *
+ * @return fresh private key
  */
 struct GNUNET_CRYPTO_RsaPrivateKey *
 GNUNET_CRYPTO_rsa_key_create ()
@@ -132,6 +134,7 @@ GNUNET_CRYPTO_rsa_key_create ()
 
 /**
  * Free memory occupied by hostkey
+ * @param hostkey pointer to the memory to free
  */
 void
 GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
@@ -742,6 +745,34 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
 }
 
 
+/**
+ * Setup a hostkey file for a peer given the name of the
+ * configuration file (!).  This function is used so that
+ * at a later point code can be certain that reading a
+ * hostkey is fast (for example in time-dependent testcases).
+ *
+ * @param cfg_name name of the configuration file to use
+ */
+void
+GNUNET_CRYPTO_setup_hostkey (const char *cfg_name)
+{
+  struct GNUNET_CONFIGURATION_Handle *cfg;
+  struct GNUNET_CRYPTO_RsaPrivateKey *pk;
+  char *fn;
+
+  cfg = GNUNET_CONFIGURATION_create ();
+  (void) GNUNET_CONFIGURATION_load (cfg, cfg_name);
+  if (GNUNET_OK == 
+      GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY", &fn))
+  {
+    pk = GNUNET_CRYPTO_rsa_key_create_from_file (fn);
+    if (NULL != pk)
+      GNUNET_CRYPTO_rsa_key_free (pk);
+  }
+  GNUNET_CONFIGURATION_destroy (cfg);
+}
+
+
 /**
  * Encrypt a block with the public key of another host that uses the
  * same cipher.
index 005c7bd07a2f84294c57cb01335e3d8d5339a924..d6e07e960d3d0d28e2496ab3e5853596a47669f8 100644 (file)
@@ -515,7 +515,7 @@ main (int argc, char *const *argv)
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END
   };
-
+  
   if (0 != ACCESS ("/dev/net/tun", R_OK))
   {
     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
@@ -536,6 +536,7 @@ main (int argc, char *const *argv)
             "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n");
     return 0;
   }
+  GNUNET_CRYPTO_setup_hostkey ("test_gnunet_vpn.conf");
   bin = argv[0];
   if (NULL != strstr (bin, "lt-"))
     bin = strstr (bin, "lt-") + 4;