From 3d2a951fa12546c09809f0a4d7e789ef8e971b03 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 4 May 2019 16:53:00 +0200 Subject: only use mono time in TNG HELLOs --- src/hello/hello-ng.c | 99 ++++++++++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 58 deletions(-) (limited to 'src/hello/hello-ng.c') diff --git a/src/hello/hello-ng.c b/src/hello/hello-ng.c index 2d60b04f3..29ab17f9b 100644 --- a/src/hello/hello-ng.c +++ b/src/hello/hello-ng.c @@ -41,9 +41,9 @@ struct SignedAddress struct GNUNET_CRYPTO_EccSignaturePurpose purpose; /** - * When does the address expire. + * When was the address generated. */ - struct GNUNET_TIME_AbsoluteNBO expiration; + struct GNUNET_TIME_AbsoluteNBO mono_time; /** * Hash of the address. @@ -57,18 +57,19 @@ struct SignedAddress * * @param address text address at @a communicator to sign * @param nt network type of @a address - * @param expiration how long is @a address valid + * @param mono_time monotonic time at which @a address was valid * @param private_key signing key to use * @param result[out] where to write address record (allocated) * @param result_size[out] set to size of @a result */ void -GNUNET_HELLO_sign_address (const char *address, - enum GNUNET_NetworkType nt, - struct GNUNET_TIME_Absolute expiration, - const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key, - void **result, - size_t *result_size) +GNUNET_HELLO_sign_address ( + const char *address, + enum GNUNET_NetworkType nt, + struct GNUNET_TIME_Absolute mono_time, + const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key, + void **result, + size_t *result_size) { struct SignedAddress sa; struct GNUNET_CRYPTO_EddsaSignature sig; @@ -76,24 +77,19 @@ GNUNET_HELLO_sign_address (const char *address, sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); sa.purpose.size = htonl (sizeof (sa)); - sa.expiration = GNUNET_TIME_absolute_hton (expiration); - GNUNET_CRYPTO_hash (address, - strlen (address), - &sa.h_addr); + sa.mono_time = GNUNET_TIME_absolute_hton (mono_time); + GNUNET_CRYPTO_hash (address, strlen (address), &sa.h_addr); GNUNET_assert (GNUNET_YES == - GNUNET_CRYPTO_eddsa_sign (private_key, - &sa.purpose, - &sig)); + GNUNET_CRYPTO_eddsa_sign (private_key, &sa.purpose, &sig)); sig_str = NULL; - (void) GNUNET_STRINGS_base64_encode (&sig, - sizeof (sig), - &sig_str); - *result_size = 1 + GNUNET_asprintf ((char **) result, - "%s;%llu;%u;%s", - sig_str, - (unsigned long long) expiration.abs_value_us, - (unsigned int) nt, - address); + (void) GNUNET_STRINGS_base64_encode (&sig, sizeof (sig), &sig_str); + *result_size = + 1 + GNUNET_asprintf ((char **) result, + "%s;%llu;%u;%s", + sig_str, + (unsigned long long) mono_time.abs_value_us, + (unsigned int) nt, + address); GNUNET_free (sig_str); } @@ -105,15 +101,15 @@ GNUNET_HELLO_sign_address (const char *address, * @param raw_size size of @a raw * @param pid public key to use for signature verification * @param nt[out] set to network type - * @param expiration[out] how long is the address valid + * @param mono_time[out] when was the address generated * @return NULL on error, otherwise the address */ char * GNUNET_HELLO_extract_address (const void *raw, - size_t raw_size, - const struct GNUNET_PeerIdentity *pid, - enum GNUNET_NetworkType *nt, - struct GNUNET_TIME_Absolute *expiration) + size_t raw_size, + const struct GNUNET_PeerIdentity *pid, + enum GNUNET_NetworkType *nt, + struct GNUNET_TIME_Absolute *mono_time) { const struct GNUNET_CRYPTO_EddsaPublicKey *public_key = &pid->public_key; const char *raws = raw; @@ -123,7 +119,7 @@ GNUNET_HELLO_extract_address (const void *raw, const char *sc2; const char *sc3; const char *raw_addr; - struct GNUNET_TIME_Absolute raw_expiration; + struct GNUNET_TIME_Absolute raw_mono_time; struct SignedAddress sa; struct GNUNET_CRYPTO_EddsaSignature *sig; @@ -132,40 +128,30 @@ GNUNET_HELLO_extract_address (const void *raw, GNUNET_break_op (0); return NULL; } - if (NULL == (sc = strchr (raws, - ';'))) + if (NULL == (sc = strchr (raws, ';'))) { GNUNET_break_op (0); return NULL; } - if (NULL == (sc2 = strchr (sc + 1, - ';'))) + if (NULL == (sc2 = strchr (sc + 1, ';'))) { GNUNET_break_op (0); return NULL; } - if (NULL == (sc3 = strchr (sc2 + 1, - ';'))) + if (NULL == (sc3 = strchr (sc2 + 1, ';'))) { GNUNET_break_op (0); return NULL; } - if (1 != sscanf (sc + 1, - "%llu;%u;", - &raw_us, - &raw_nt)) + if (1 != sscanf (sc + 1, "%llu;%u;", &raw_us, &raw_nt)) { GNUNET_break_op (0); return NULL; } - raw_expiration.abs_value_us = raw_us; - if (0 == GNUNET_TIME_absolute_get_remaining (raw_expiration).rel_value_us) - return NULL; /* expired */ + raw_mono_time.abs_value_us = raw_us; sig = NULL; if (sizeof (struct GNUNET_CRYPTO_EddsaSignature) != - GNUNET_STRINGS_base64_decode (raws, - sc - raws, - (void **) &sig)) + GNUNET_STRINGS_base64_decode (raws, sc - raws, (void **) &sig)) { GNUNET_break_op (0); GNUNET_free_non_null (sig); @@ -175,22 +161,20 @@ GNUNET_HELLO_extract_address (const void *raw, sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); sa.purpose.size = htonl (sizeof (sa)); - sa.expiration = GNUNET_TIME_absolute_hton (raw_expiration); - GNUNET_CRYPTO_hash (raw_addr, - strlen (raw_addr), - &sa.h_addr); + sa.mono_time = GNUNET_TIME_absolute_hton (raw_mono_time); + GNUNET_CRYPTO_hash (raw_addr, strlen (raw_addr), &sa.h_addr); if (GNUNET_YES != GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS, - &sa.purpose, - sig, - public_key)) + &sa.purpose, + sig, + public_key)) { GNUNET_break_op (0); GNUNET_free (sig); return NULL; } GNUNET_free (sig); - *expiration = raw_expiration; + *mono_time = raw_mono_time; *nt = (enum GNUNET_NetworkType) raw_nt; return GNUNET_strdup (raw_addr); } @@ -202,7 +186,7 @@ GNUNET_HELLO_extract_address (const void *raw, * * @param address a peer's address * @return NULL if the address is mal-formed, otherwise the prefix - */ + */ char * GNUNET_HELLO_address_to_prefix (const char *address) { @@ -211,6 +195,5 @@ GNUNET_HELLO_address_to_prefix (const char *address) dash = strchr (address, '-'); if (NULL == dash) return NULL; - return GNUNET_strndup (address, - dash - address); + return GNUNET_strndup (address, dash - address); } -- cgit v1.2.3