diff options
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 12 | ||||
-rw-r--r-- | src/util/crypto_rsa.c | 33 | ||||
-rw-r--r-- | src/vpn/test_gnunet_vpn.c | 3 |
3 files changed, 46 insertions, 2 deletions
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 | |||
@@ -764,6 +764,18 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename); | |||
764 | 764 | ||
765 | 765 | ||
766 | /** | 766 | /** |
767 | * Setup a hostkey file for a peer given the name of the | ||
768 | * configuration file (!). This function is used so that | ||
769 | * at a later point code can be certain that reading a | ||
770 | * hostkey is fast (for example in time-dependent testcases). | ||
771 | * | ||
772 | * @param cfg_name name of the configuration file to use | ||
773 | */ | ||
774 | void | ||
775 | GNUNET_CRYPTO_setup_hostkey (const char *cfg_name); | ||
776 | |||
777 | |||
778 | /** | ||
767 | * Deterministically (!) create a private key using only the | 779 | * Deterministically (!) create a private key using only the |
768 | * given HashCode as input to the PRNG. | 780 | * given HashCode as input to the PRNG. |
769 | * | 781 | * |
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) | |||
107 | } | 107 | } |
108 | 108 | ||
109 | /** | 109 | /** |
110 | * This HostKey implementation uses RSA. | 110 | * Create a new private key. Caller must free return value. |
111 | * | ||
112 | * @return fresh private key | ||
111 | */ | 113 | */ |
112 | struct GNUNET_CRYPTO_RsaPrivateKey * | 114 | struct GNUNET_CRYPTO_RsaPrivateKey * |
113 | GNUNET_CRYPTO_rsa_key_create () | 115 | GNUNET_CRYPTO_rsa_key_create () |
@@ -132,6 +134,7 @@ GNUNET_CRYPTO_rsa_key_create () | |||
132 | 134 | ||
133 | /** | 135 | /** |
134 | * Free memory occupied by hostkey | 136 | * Free memory occupied by hostkey |
137 | * @param hostkey pointer to the memory to free | ||
135 | */ | 138 | */ |
136 | void | 139 | void |
137 | GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) | 140 | GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) |
@@ -743,6 +746,34 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
743 | 746 | ||
744 | 747 | ||
745 | /** | 748 | /** |
749 | * Setup a hostkey file for a peer given the name of the | ||
750 | * configuration file (!). This function is used so that | ||
751 | * at a later point code can be certain that reading a | ||
752 | * hostkey is fast (for example in time-dependent testcases). | ||
753 | * | ||
754 | * @param cfg_name name of the configuration file to use | ||
755 | */ | ||
756 | void | ||
757 | GNUNET_CRYPTO_setup_hostkey (const char *cfg_name) | ||
758 | { | ||
759 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
760 | struct GNUNET_CRYPTO_RsaPrivateKey *pk; | ||
761 | char *fn; | ||
762 | |||
763 | cfg = GNUNET_CONFIGURATION_create (); | ||
764 | (void) GNUNET_CONFIGURATION_load (cfg, cfg_name); | ||
765 | if (GNUNET_OK == | ||
766 | GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY", &fn)) | ||
767 | { | ||
768 | pk = GNUNET_CRYPTO_rsa_key_create_from_file (fn); | ||
769 | if (NULL != pk) | ||
770 | GNUNET_CRYPTO_rsa_key_free (pk); | ||
771 | } | ||
772 | GNUNET_CONFIGURATION_destroy (cfg); | ||
773 | } | ||
774 | |||
775 | |||
776 | /** | ||
746 | * Encrypt a block with the public key of another host that uses the | 777 | * Encrypt a block with the public key of another host that uses the |
747 | * same cipher. | 778 | * same cipher. |
748 | * | 779 | * |
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) | |||
515 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 515 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
516 | GNUNET_GETOPT_OPTION_END | 516 | GNUNET_GETOPT_OPTION_END |
517 | }; | 517 | }; |
518 | 518 | ||
519 | if (0 != ACCESS ("/dev/net/tun", R_OK)) | 519 | if (0 != ACCESS ("/dev/net/tun", R_OK)) |
520 | { | 520 | { |
521 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | 521 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
@@ -536,6 +536,7 @@ main (int argc, char *const *argv) | |||
536 | "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n"); | 536 | "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n"); |
537 | return 0; | 537 | return 0; |
538 | } | 538 | } |
539 | GNUNET_CRYPTO_setup_hostkey ("test_gnunet_vpn.conf"); | ||
539 | bin = argv[0]; | 540 | bin = argv[0]; |
540 | if (NULL != strstr (bin, "lt-")) | 541 | if (NULL != strstr (bin, "lt-")) |
541 | bin = strstr (bin, "lt-") + 4; | 542 | bin = strstr (bin, "lt-") + 4; |