GNUnet 0.21.1
hello-uri.c File Reference

helper library for handling URI-based HELLOs More...

#include "platform.h"
#include "gnunet_signatures.h"
#include "gnunet_hello_uri_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_util_lib.h"
Include dependency graph for hello-uri.c:

Go to the source code of this file.

Data Structures

struct  SignedAddress
 Binary block we sign when we sign an address. More...
 
struct  HelloSignaturePurpose
 Message signed as part of a HELLO block/URL. More...
 
struct  HelloUriMessage
 Message used when gossiping HELLOs between peers. More...
 
struct  BlockHeader
 Start of a 'block'. More...
 
struct  DhtHelloMessage
 Message used when a DHT provides its HELLO to direct neighbours. More...
 
struct  Address
 Address of a peer. More...
 
struct  GNUNET_HELLO_Builder
 Context for building (or parsing) HELLO URIs. More...
 
struct  AddressUriMergeResult
 Struct to wrap data to do the merge of to hello uris. More...
 

Functions

static void hash_addresses (const struct GNUNET_HELLO_Builder *builder, struct GNUNET_HashCode *hash)
 Compute hash over addresses in builder. More...
 
static void sign_hello (const struct GNUNET_HELLO_Builder *builder, struct GNUNET_TIME_Timestamp et, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaSignature *sig)
 Create HELLO signature. More...
 
static enum GNUNET_GenericReturnValue verify_hello (const struct GNUNET_HELLO_Builder *builder, struct GNUNET_TIME_Absolute et, const struct GNUNET_CRYPTO_EddsaSignature *sig)
 Verify HELLO signature. More...
 
struct GNUNET_HELLO_BuilderGNUNET_HELLO_builder_new (const struct GNUNET_PeerIdentity *pid)
 Allocate builder. More...
 
const struct GNUNET_PeerIdentityGNUNET_HELLO_builder_get_id (const struct GNUNET_HELLO_Builder *builder)
 Get the PeerIdentity for this builder. More...
 
void GNUNET_HELLO_builder_free (struct GNUNET_HELLO_Builder *builder)
 Release resources of a builder. More...
 
struct GNUNET_HELLO_BuilderGNUNET_HELLO_builder_from_msg (const struct GNUNET_MessageHeader *msg)
 Parse msg into builder. More...
 
struct GNUNET_HELLO_BuilderGNUNET_HELLO_builder_from_block (const void *block, size_t block_size)
 Parse block into builder. More...
 
struct GNUNET_TIME_Absolute GNUNET_HELLO_builder_get_expiration_time (const struct GNUNET_MessageHeader *msg)
 Get the expiration time for this HELLO. More...
 
struct GNUNET_HELLO_BuilderGNUNET_HELLO_builder_from_url (const char *url)
 Parse GNUnet HELLO url into builder. More...
 
struct GNUNET_MQ_EnvelopeGNUNET_HELLO_builder_to_env (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_TIME_Relative expiration_time)
 Generate envelope with GNUnet HELLO message (including peer ID) from a builder. More...
 
struct GNUNET_MessageHeaderGNUNET_HELLO_builder_to_dht_hello_msg (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_TIME_Relative expiration_time)
 Generate DHT HELLO message (without peer ID) from a builder. More...
 
char * GNUNET_HELLO_builder_to_url (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
 Generate GNUnet HELLO URI from a builder. More...
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_to_block (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, void *block, size_t *block_size, struct GNUNET_TIME_Relative expiration_time)
 Generate DHT block from a builder. More...
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_add_address (struct GNUNET_HELLO_Builder *builder, const char *address)
 Add individual address to the builder. More...
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_del_address (struct GNUNET_HELLO_Builder *builder, const char *address)
 Remove individual address from the builder. More...
 
const struct GNUNET_PeerIdentityGNUNET_HELLO_builder_iterate (const struct GNUNET_HELLO_Builder *builder, GNUNET_HELLO_UriCallback uc, void *uc_cls)
 Iterate over URIs in a builder. More...
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_dht_msg_to_block (const struct GNUNET_MessageHeader *hello, const struct GNUNET_PeerIdentity *pid, void **block, size_t *block_size, struct GNUNET_TIME_Absolute *block_expiration)
 Convert a DHT hello message to a HELLO block. More...
 
char * GNUNET_HELLO_address_to_prefix (const char *address)
 Given an address as a string, extract the prefix that identifies the communicator offering transmissions to that address. More...
 
void 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)
 Build address record by signing raw information with private key. More...
 

Detailed Description

helper library for handling URI-based HELLOs

Author
Christian Grothoff

Note:

  • Current API does not support deserializing HELLO of another peer and then serializing it into another format (we always require the private key). Not sure if we need this, but if we do, we need to extend the builder and the API.
  • Current API does not allow overriding the default HELLO expiration time. We may want to add a function that does this to create bootstrap HELLOs shipped with the TGZ.

Definition in file hello-uri.c.

Function Documentation

◆ hash_addresses()

static void hash_addresses ( const struct GNUNET_HELLO_Builder builder,
struct GNUNET_HashCode hash 
)
static

Compute hash over addresses in builder.

Parameters
builderthe builder to hash addresses of
[out]hashwhere to write the hash

Definition at line 262 of file hello-uri.c.

264{
265 struct GNUNET_HashContext *hc;
266
268 for (struct Address *a = builder->a_head;
269 NULL != a;
270 a = a->next)
271 {
273 "Hashing over %.*s\n",
274 (int) a->uri_len,
275 a->uri);
277 a->uri,
278 a->uri_len);
279 }
281 hash);
282
283}
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
Definition: crypto_hash.c:366
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
Definition: crypto_hash.c:390
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
Definition: crypto_hash.c:350
@ GNUNET_ERROR_TYPE_DEBUG
Address of a peer.
Definition: hello-uri.c:178

References builder, GNUNET_CRYPTO_hash_context_finish(), GNUNET_CRYPTO_hash_context_read(), GNUNET_CRYPTO_hash_context_start(), GNUNET_ERROR_TYPE_DEBUG, and GNUNET_log.

Referenced by sign_hello(), and verify_hello().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sign_hello()

static void sign_hello ( const struct GNUNET_HELLO_Builder builder,
struct GNUNET_TIME_Timestamp  et,
const struct GNUNET_CRYPTO_EddsaPrivateKey priv,
struct GNUNET_CRYPTO_EddsaSignature sig 
)
static

Create HELLO signature.

Parameters
builderthe builder to use
etexpiration time to sign
privkey to sign with
[out]sigwhere to write the signature

Definition at line 295 of file hello-uri.c.

299{
300 struct HelloSignaturePurpose hsp = {
301 .purpose.size = htonl (sizeof (hsp)),
302 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
303 .expiration_time = GNUNET_TIME_absolute_hton (et.abs_time)
304 };
305
307 &hsp.h_addrs);
309 "Address hash is %s\n",
310 GNUNET_h2s_full (&hsp.h_addrs));
312 &hsp,
313 sig);
314}
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:638
static void hash_addresses(const struct GNUNET_HELLO_Builder *builder, struct GNUNET_HashCode *hash)
Compute hash over addresses in builder.
Definition: hello-uri.c:262
#define GNUNET_SIGNATURE_PURPOSE_HELLO
Signature by which a peer affirms its address.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
struct GNUNET_TIME_Absolute abs_time
The actual value.
Message signed as part of a HELLO block/URL.
Definition: hello-uri.c:71
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition: hello-uri.c:75
struct GNUNET_HashCode h_addrs
Hash over all addresses.
Definition: hello-uri.c:85

References GNUNET_TIME_Timestamp::abs_time, builder, GNUNET_CRYPTO_eddsa_sign, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s_full(), GNUNET_log, GNUNET_SIGNATURE_PURPOSE_HELLO, GNUNET_TIME_absolute_hton(), HelloSignaturePurpose::h_addrs, hash_addresses(), HelloSignaturePurpose::purpose, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by GNUNET_HELLO_builder_to_block(), and GNUNET_HELLO_builder_to_url().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_hello()

static enum GNUNET_GenericReturnValue verify_hello ( const struct GNUNET_HELLO_Builder builder,
struct GNUNET_TIME_Absolute  et,
const struct GNUNET_CRYPTO_EddsaSignature sig 
)
static

Verify HELLO signature.

Parameters
builderthe builder to use
etexpiration time to verify
sigsignature to verify
Returns
GNUNET_OK if everything is ok, GNUNET_NO if the HELLO expired, GNUNET_SYSERR if the signature is wrong

Definition at line 327 of file hello-uri.c.

330{
331 struct HelloSignaturePurpose hsp = {
332 .purpose.size = htonl (sizeof (hsp)),
333 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
334 .expiration_time = GNUNET_TIME_absolute_hton (et)
335 };
336
338 &hsp.h_addrs);
339 if (GNUNET_OK !=
341 &hsp,
342 sig,
343 &builder->pid.public_key))
344 {
345 GNUNET_break_op (0);
346 return GNUNET_SYSERR;
347 }
349 return GNUNET_NO;
350 return GNUNET_OK;
351}
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition: time.c:669

References builder, GNUNET_break_op, GNUNET_CRYPTO_eddsa_verify, GNUNET_NO, GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_HELLO, GNUNET_SYSERR, GNUNET_TIME_absolute_hton(), GNUNET_TIME_absolute_is_past(), HelloSignaturePurpose::h_addrs, hash_addresses(), HelloSignaturePurpose::purpose, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by GNUNET_HELLO_builder_from_block(), GNUNET_HELLO_builder_from_url(), and GNUNET_HELLO_dht_msg_to_block().

Here is the call graph for this function:
Here is the caller graph for this function: