GNUnet 0.22.0
hello-uri.c File Reference

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

#include "platform.h"
#include "gnunet_time_lib.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_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...
 
static 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, const struct GNUNET_CRYPTO_EddsaSignature *sig)
 
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...
 
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 277 of file hello-uri.c.

279{
280 struct GNUNET_HashContext *hc;
281
283 for (struct Address *a = builder->a_head;
284 NULL != a;
285 a = a->next)
286 {
288 "Hashing over %.*s\n",
289 (int) a->uri_len,
290 a->uri);
292 a->uri,
293 a->uri_len);
294 }
296 hash);
297
298}
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:179

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

314{
315 struct HelloSignaturePurpose hsp = {
316 .purpose.size = htonl (sizeof (hsp)),
317 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
318 .expiration_time = GNUNET_TIME_absolute_hton (et.abs_time)
319 };
320
322 &hsp.h_addrs);
324 "Address hash is %s\n",
325 GNUNET_h2s_full (&hsp.h_addrs));
327 &hsp,
328 sig);
329}
#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:640
static void hash_addresses(const struct GNUNET_HELLO_Builder *builder, struct GNUNET_HashCode *hash)
Compute hash over addresses in builder.
Definition: hello-uri.c:277
#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:72
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition: hello-uri.c:76
struct GNUNET_HashCode h_addrs
Hash over all addresses.
Definition: hello-uri.c:86

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

345{
346 struct HelloSignaturePurpose hsp = {
347 .purpose.size = htonl (sizeof (hsp)),
348 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
349 .expiration_time = GNUNET_TIME_absolute_hton (et)
350 };
351
353 &hsp.h_addrs);
354 if (GNUNET_OK !=
356 &hsp,
357 sig,
358 &builder->pid.public_key))
359 {
360 GNUNET_break_op (0);
361 return GNUNET_SYSERR;
362 }
364 return GNUNET_NO;
365 return GNUNET_OK;
366}
#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:671

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:

◆ GNUNET_HELLO_builder_to_env_()

static struct GNUNET_MQ_Envelope * GNUNET_HELLO_builder_to_env_ ( const struct GNUNET_HELLO_Builder builder,
const struct GNUNET_CRYPTO_EddsaPrivateKey priv,
struct GNUNET_TIME_Relative  expiration_time,
const struct GNUNET_CRYPTO_EddsaSignature sig 
)
static

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

843{
844 struct GNUNET_MQ_Envelope *env;
845 struct HelloUriMessage *msg;
846 size_t blen;
847
848 if (builder->a_length > UINT16_MAX)
849 {
850 GNUNET_break (0);
851 return NULL;
852 }
853 blen = 0;
856 priv,
857 NULL,
858 &blen,
859 expiration_time));
861 blen,
863 msg->url_counter = htons ((uint16_t) builder->a_length);
866 priv,
867 &msg[1],
868 &blen,
869 expiration_time));
870 return env;
871}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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.
Definition: hello-uri.c:777
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MESSAGE_TYPE_HELLO_URI
Latest HELLO messages used for communicating peer addresses.
Message used when gossiping HELLOs between peers.
Definition: hello-uri.c:94

References builder, env, GNUNET_assert, GNUNET_break, GNUNET_HELLO_builder_to_block(), GNUNET_MESSAGE_TYPE_HELLO_URI, GNUNET_MQ_msg_extra, GNUNET_NO, GNUNET_OK, and msg.

Referenced by GNUNET_HELLO_builder_to_env().

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