aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_rsa.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-28 19:08:20 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-28 19:08:20 +0000
commit8225f4ac99dcf5b02258d10b88e9fb32543e8a7f (patch)
tree5e91a73278a9a82cb859bd1e5c74b795381d15e0 /src/util/crypto_rsa.c
parent1a9c0bd3293015faa8c2e9d552706227ea2cf170 (diff)
adding GNUNET_CRYPTO_setup_hostkey to setup a hostkey ahead of time, using this function in the VPN testcases to avoid timeouts in cases where creating a hostkey just takes too long --- such as on our UltraSprac
Diffstat (limited to 'src/util/crypto_rsa.c')
-rw-r--r--src/util/crypto_rsa.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c
index 418fe833ba..5e3a7762ef 100644
--- a/src/util/crypto_rsa.c
+++ b/src/util/crypto_rsa.c
@@ -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)
@@ -743,6 +746,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.
*