From 8225f4ac99dcf5b02258d10b88e9fb32543e8a7f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 28 Feb 2012 19:08:20 +0000 Subject: 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 --- src/include/gnunet_crypto_lib.h | 12 ++++++++++++ src/util/crypto_rsa.c | 33 ++++++++++++++++++++++++++++++++- src/vpn/test_gnunet_vpn.c | 3 ++- 3 files changed, 46 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 6e37266a2..63d3ee418 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -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. diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index 418fe833b..5e3a7762e 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) @@ -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. diff --git a/src/vpn/test_gnunet_vpn.c b/src/vpn/test_gnunet_vpn.c index 005c7bd07..d6e07e960 100644 --- a/src/vpn/test_gnunet_vpn.c +++ b/src/vpn/test_gnunet_vpn.c @@ -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; -- cgit v1.2.3