aboutsummaryrefslogtreecommitdiff
path: root/src/lib/hello/hello-uri.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/hello/hello-uri.c')
-rw-r--r--src/lib/hello/hello-uri.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/lib/hello/hello-uri.c b/src/lib/hello/hello-uri.c
index 25f8948fe..4d0cb4ee0 100644
--- a/src/lib/hello/hello-uri.c
+++ b/src/lib/hello/hello-uri.c
@@ -44,6 +44,27 @@
44GNUNET_NETWORK_STRUCT_BEGIN 44GNUNET_NETWORK_STRUCT_BEGIN
45 45
46/** 46/**
47 * Binary block we sign when we sign an address.
48 */
49struct SignedAddress
50{
51 /**
52 * Purpose must be #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS
53 */
54 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
55
56 /**
57 * When was the address generated.
58 */
59 struct GNUNET_TIME_AbsoluteNBO mono_time;
60
61 /**
62 * Hash of the address.
63 */
64 struct GNUNET_HashCode addr_hash GNUNET_PACKED;
65};
66
67/**
47 * Message signed as part of a HELLO block/URL. 68 * Message signed as part of a HELLO block/URL.
48 */ 69 */
49struct HelloSignaturePurpose 70struct HelloSignaturePurpose
@@ -962,3 +983,63 @@ GNUNET_HELLO_dht_msg_to_block (const struct GNUNET_MessageHeader *hello,
962 } 983 }
963 return ret; 984 return ret;
964} 985}
986
987
988/**
989 * Given an address as a string, extract the prefix that identifies
990 * the communicator offering transmissions to that address.
991 *
992 * @param address a peer's address
993 * @return NULL if the address is mal-formed, otherwise the prefix
994 */
995char *
996GNUNET_HELLO_address_to_prefix (const char *address)
997{
998 const char *dash;
999
1000 dash = strchr (address, '-');
1001 if (NULL == dash)
1002 return NULL;
1003 return GNUNET_strndup (address, dash - address);
1004}
1005
1006
1007/**
1008 * Build address record by signing raw information with private key.
1009 *
1010 * @param address text address at @a communicator to sign
1011 * @param nt network type of @a address
1012 * @param mono_time monotonic time at which @a address was valid
1013 * @param private_key signing key to use
1014 * @param[out] result where to write address record (allocated)
1015 * @param[out] result_size set to size of @a result
1016 */
1017void
1018GNUNET_HELLO_sign_address (
1019 const char *address,
1020 enum GNUNET_NetworkType nt,
1021 struct GNUNET_TIME_Absolute mono_time,
1022 const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key,
1023 void **result,
1024 size_t *result_size)
1025{
1026 struct SignedAddress sa;
1027 struct GNUNET_CRYPTO_EddsaSignature sig;
1028 char *sig_str;
1029
1030 sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS);
1031 sa.purpose.size = htonl (sizeof(sa));
1032 sa.mono_time = GNUNET_TIME_absolute_hton (mono_time);
1033 GNUNET_CRYPTO_hash (address, strlen (address), &sa.addr_hash);
1034 GNUNET_CRYPTO_eddsa_sign (private_key, &sa, &sig);
1035 sig_str = NULL;
1036 (void) GNUNET_STRINGS_base64_encode (&sig, sizeof(sig), &sig_str);
1037 *result_size =
1038 1 + GNUNET_asprintf ((char **) result,
1039 "%s;%llu;%u;%s",
1040 sig_str,
1041 (unsigned long long) mono_time.abs_value_us,
1042 (unsigned int) nt,
1043 address);
1044 GNUNET_free (sig_str);
1045}