GNUnet  0.19.2
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  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...
 

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...
 
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_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)
 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)
 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)
 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...
 
void GNUNET_HELLO_builder_iterate (const struct GNUNET_HELLO_Builder *builder, struct GNUNET_PeerIdentity *pid, 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...
 

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 215 of file hello-uri.c.

217 {
218  struct GNUNET_HashContext *hc;
219 
221  for (struct Address *a = builder->a_head;
222  NULL != a;
223  a = a->next)
224  {
226  "Hashing over %.*s\n",
227  (int) a->uri_len,
228  a->uri);
230  a->uri,
231  a->uri_len);
232  }
234  hash);
235 
236 }
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
#define GNUNET_log(kind,...)
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
Definition: crypto_hash.c:349
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:365
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
Definition: crypto_hash.c:389
@ GNUNET_ERROR_TYPE_DEBUG
Address of a peer.
Definition: hello-uri.c:157

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().

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 248 of file hello-uri.c.

252 {
253  struct HelloSignaturePurpose hsp = {
254  .purpose.size = htonl (sizeof (hsp)),
255  .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
256  .expiration_time = GNUNET_TIME_absolute_hton (et.abs_time)
257  };
258 
260  &hsp.h_addrs);
262  "Address hash is %s\n",
263  GNUNET_h2s_full (&hsp.h_addrs));
265  &hsp,
266  sig);
267 }
#define GNUNET_SIGNATURE_PURPOSE_HELLO
Signature by which a peer affirms its address.
#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:215
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:50
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition: hello-uri.c:54
struct GNUNET_HashCode h_addrs
Hash over all addresses.
Definition: hello-uri.c:64

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_add_address().

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 248 of file hello-uri.c.

283 {
284  struct HelloSignaturePurpose hsp = {
285  .purpose.size = htonl (sizeof (hsp)),
286  .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
287  .expiration_time = GNUNET_TIME_absolute_hton (et)
288  };
289 
291  &hsp.h_addrs);
292  if (GNUNET_OK !=
294  &hsp,
295  sig,
296  &builder->pid.public_key))
297  {
298  GNUNET_break_op (0);
299  return GNUNET_SYSERR;
300  }
302  return GNUNET_NO;
303  return GNUNET_OK;
304 }
#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

Referenced by GNUNET_HELLO_builder_from_block(), and GNUNET_HELLO_builder_from_url().

Here is the caller graph for this function: