diff options
author | Florian Dold <florian.dold@gmail.com> | 2013-04-27 11:04:29 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2013-04-27 11:04:29 +0000 |
commit | 00196642a7a8e400a054bd0a9c3b35b24be87a78 (patch) | |
tree | 7733d2a156a8468019ec7dc52e5fc36ec0a21c03 | |
parent | d0dd9f2c530ae5df86fb4180b3107892d34031ed (diff) | |
download | gnunet-00196642a7a8e400a054bd0a9c3b35b24be87a78.tar.gz gnunet-00196642a7a8e400a054bd0a9c3b35b24be87a78.zip |
implemented GNUNET_CRYPTO_get_host_identity
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 13 | ||||
-rw-r--r-- | src/util/crypto_ecc.c | 39 |
2 files changed, 52 insertions, 0 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index bfb514247..a3c4e999f 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -1327,6 +1327,19 @@ GNUNET_CRYPTO_ecc_setup_hostkey (const char *cfg_name); | |||
1327 | 1327 | ||
1328 | 1328 | ||
1329 | /** | 1329 | /** |
1330 | * Retrieve the identity of the host's peer. | ||
1331 | * | ||
1332 | * @param cfg configuration to use | ||
1333 | * @param dst pointer to where to write the peer identity | ||
1334 | * @return GNUNET_OK on success, GNUNET_SYSERR if the identity | ||
1335 | * could not be retrieved | ||
1336 | */ | ||
1337 | int | ||
1338 | GNUNET_CRYPTO_get_host_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
1339 | struct GNUNET_PeerIdentity *dst); | ||
1340 | |||
1341 | |||
1342 | /** | ||
1330 | * Derive key material from a public and a private ECC key. | 1343 | * Derive key material from a public and a private ECC key. |
1331 | * | 1344 | * |
1332 | * @param key private key to use for the ECDH (x) | 1345 | * @param key private key to use for the ECDH (x) |
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index 041d35297..0563c8677 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c | |||
@@ -918,6 +918,45 @@ GNUNET_CRYPTO_ecc_setup_key (const char *cfg_name) | |||
918 | 918 | ||
919 | 919 | ||
920 | /** | 920 | /** |
921 | * Retrieve the identity of the host's peer. | ||
922 | * | ||
923 | * @param cfg configuration to use | ||
924 | * @param dst pointer to where to write the peer identity | ||
925 | * @return GNUNET_OK on success, GNUNET_SYSERR if the identity | ||
926 | * could not be retrieved | ||
927 | */ | ||
928 | int | ||
929 | GNUNET_CRYPTO_get_host_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
930 | struct GNUNET_PeerIdentity *dst) | ||
931 | { | ||
932 | struct GNUNET_CRYPTO_EccPrivateKey *my_private_key; | ||
933 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key; | ||
934 | char *keyfile; | ||
935 | |||
936 | if (GNUNET_OK != | ||
937 | GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", "PRIVATE_KEY", | ||
938 | &keyfile)) | ||
939 | { | ||
940 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
941 | _("Lacking key configuration settings.\n")); | ||
942 | return GNUNET_SYSERR; | ||
943 | } | ||
944 | if (NULL == (my_private_key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile))) | ||
945 | { | ||
946 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
947 | _("Could not access hostkey file `%s'.\n"), keyfile); | ||
948 | GNUNET_free (keyfile); | ||
949 | return GNUNET_SYSERR; | ||
950 | } | ||
951 | GNUNET_free (keyfile); | ||
952 | GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key); | ||
953 | GNUNET_CRYPTO_ecc_key_free (my_private_key); | ||
954 | GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &dst->hashPubKey); | ||
955 | return GNUNET_OK; | ||
956 | } | ||
957 | |||
958 | |||
959 | /** | ||
921 | * Convert the data specified in the given purpose argument to an | 960 | * Convert the data specified in the given purpose argument to an |
922 | * S-expression suitable for signature operations. | 961 | * S-expression suitable for signature operations. |
923 | * | 962 | * |