aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_ecc.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-06-26 17:17:35 +0000
committerChristian Grothoff <christian@grothoff.org>2013-06-26 17:17:35 +0000
commitabc1a0ea19b7dc199b83749d31e32622c7469ded (patch)
tree358bba92baec84a1f9bb28a6328a45390ed1d18b /src/util/crypto_ecc.c
parentbb7b311515f189f38a990892ee11baffb5608ccb (diff)
downloadgnunet-abc1a0ea19b7dc199b83749d31e32622c7469ded.tar.gz
gnunet-abc1a0ea19b7dc199b83749d31e32622c7469ded.zip
-introducing convenience function to load private key of peer
Diffstat (limited to 'src/util/crypto_ecc.c')
-rw-r--r--src/util/crypto_ecc.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index b5a057aed..498de59df 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -890,6 +890,28 @@ GNUNET_CRYPTO_ecc_key_create_start (const char *filename,
890 890
891 891
892/** 892/**
893 * Create a new private key by reading our peer's key from
894 * the file specified in the configuration.
895 *
896 * @return new private key, NULL on error (for example,
897 * permission denied)
898 */
899struct GNUNET_CRYPTO_EccPrivateKey *
900GNUNET_CRYPTO_ecc_key_create_from_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
901{
902 struct GNUNET_CRYPTO_EccPrivateKey *pk;
903 char *fn;
904
905 if (GNUNET_OK !=
906 GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", "PRIVATE_KEY", &fn))
907 return NULL;
908 pk = GNUNET_CRYPTO_ecc_key_create_from_file (fn);
909 GNUNET_free (fn);
910 return pk;
911}
912
913
914/**
893 * Setup a key file for a peer given the name of the 915 * Setup a key file for a peer given the name of the
894 * configuration file (!). This function is used so that 916 * configuration file (!). This function is used so that
895 * at a later point code can be certain that reading a 917 * at a later point code can be certain that reading a
@@ -902,18 +924,12 @@ GNUNET_CRYPTO_ecc_setup_key (const char *cfg_name)
902{ 924{
903 struct GNUNET_CONFIGURATION_Handle *cfg; 925 struct GNUNET_CONFIGURATION_Handle *cfg;
904 struct GNUNET_CRYPTO_EccPrivateKey *pk; 926 struct GNUNET_CRYPTO_EccPrivateKey *pk;
905 char *fn;
906 927
907 cfg = GNUNET_CONFIGURATION_create (); 928 cfg = GNUNET_CONFIGURATION_create ();
908 (void) GNUNET_CONFIGURATION_load (cfg, cfg_name); 929 (void) GNUNET_CONFIGURATION_load (cfg, cfg_name);
909 if (GNUNET_OK == 930 pk = GNUNET_CRYPTO_ecc_key_create_from_configuration (cfg);
910 GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", "PRIVATE_KEY", &fn)) 931 if (NULL != pk)
911 { 932 GNUNET_CRYPTO_ecc_key_free (pk);
912 pk = GNUNET_CRYPTO_ecc_key_create_from_file (fn);
913 if (NULL != pk)
914 GNUNET_CRYPTO_ecc_key_free (pk);
915 GNUNET_free (fn);
916 }
917 GNUNET_CONFIGURATION_destroy (cfg); 933 GNUNET_CONFIGURATION_destroy (cfg);
918} 934}
919 935
@@ -932,24 +948,13 @@ GNUNET_CRYPTO_get_host_identity (const struct GNUNET_CONFIGURATION_Handle *cfg,
932{ 948{
933 struct GNUNET_CRYPTO_EccPrivateKey *my_private_key; 949 struct GNUNET_CRYPTO_EccPrivateKey *my_private_key;
934 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key; 950 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
935 char *keyfile;
936 951
937 if (GNUNET_OK != 952 if (NULL == (my_private_key = GNUNET_CRYPTO_ecc_key_create_from_configuration (cfg)))
938 GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", "PRIVATE_KEY",
939 &keyfile))
940 {
941 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
942 _("Lacking key configuration settings.\n"));
943 return GNUNET_SYSERR;
944 }
945 if (NULL == (my_private_key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile)))
946 { 953 {
947 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 954 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
948 _("Could not access hostkey file `%s'.\n"), keyfile); 955 _("Could not load peer's private key\n"));
949 GNUNET_free (keyfile);
950 return GNUNET_SYSERR; 956 return GNUNET_SYSERR;
951 } 957 }
952 GNUNET_free (keyfile);
953 GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key); 958 GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key);
954 GNUNET_CRYPTO_ecc_key_free (my_private_key); 959 GNUNET_CRYPTO_ecc_key_free (my_private_key);
955 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &dst->hashPubKey); 960 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &dst->hashPubKey);