GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
hello-uri.c File Reference

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

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

Go to the source code of this file.

Data Structures

struct  PilsHelloSignaturePurpose
 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...
 
struct  GNUNET_HELLO_Parser
 Context for parsing HELLOs. More...
 

Functions

static void hash_addresses (const struct Address *addr_start, struct GNUNET_HashCode *hash)
 
static enum GNUNET_GenericReturnValue verify_hello (const struct GNUNET_HELLO_Parser *parser, struct GNUNET_TIME_Absolute et, const struct GNUNET_CRYPTO_EddsaSignature *sig)
 Verify HELLO signature.
 
static struct GNUNET_HELLO_Parserparser_new (const struct GNUNET_PeerIdentity *pid)
 
struct GNUNET_HELLO_BuilderGNUNET_HELLO_builder_new ()
 Allocate builder.
 
const struct GNUNET_PeerIdentityGNUNET_HELLO_parser_get_id (const struct GNUNET_HELLO_Parser *parser)
 Get the PeerIdentity for this builder.
 
struct GNUNET_HELLO_BuilderGNUNET_HELLO_builder_from_parser (const struct GNUNET_HELLO_Parser *p, struct GNUNET_PeerIdentity *pid)
 Allocate builder from parser.
 
void GNUNET_HELLO_parser_free (struct GNUNET_HELLO_Parser *parser)
 Release resources of a builder.
 
void GNUNET_HELLO_builder_free (struct GNUNET_HELLO_Builder *builder)
 Release resources of a builder.
 
struct GNUNET_HELLO_ParserGNUNET_HELLO_parser_from_msg (const struct GNUNET_MessageHeader *msg)
 Parse msg.
 
static enum GNUNET_GenericReturnValue check_address (const char *address)
 
static int cmp_address (void *cls, struct Address *a, struct Address *b)
 Alphanumeric sorting for addresses.
 
static enum GNUNET_GenericReturnValue parser_add_address (struct GNUNET_HELLO_Parser *parser, const char *address)
 
struct GNUNET_HELLO_ParserGNUNET_HELLO_parser_from_block (const void *block, size_t block_size)
 Parse block.
 
struct GNUNET_HELLO_ParserGNUNET_HELLO_parser_from_block_ (const void *block, size_t block_size, int noverify)
 Parse block.
 
struct GNUNET_TIME_Absolute GNUNET_HELLO_get_expiration_time_from_msg (const struct GNUNET_MessageHeader *msg)
 Get the expiration time for this HELLO.
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_add_address (struct GNUNET_HELLO_Builder *builder, const char *address)
 Add individual address to the builder.
 
struct GNUNET_HELLO_ParserGNUNET_HELLO_parser_from_url (const char *url)
 Parse GNUnet HELLO url.
 
char * GNUNET_HELLO_parser_to_url (const struct GNUNET_HELLO_Parser *parser)
 Generate GNUnet HELLO URI from a parser.
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_parser_to_block (const struct GNUNET_HELLO_Parser *parser, void *block, size_t *block_size)
 Generate DHT block from a parser.
 
struct GNUNET_MQ_EnvelopeGNUNET_HELLO_parser_to_env (const struct GNUNET_HELLO_Parser *parser)
 Generate envelope with GNUnet HELLO message (including peer ID) from a parser.
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_del_address (struct GNUNET_HELLO_Builder *builder, const char *address)
 Remove individual address from the builder.
 
void GNUNET_HELLO_builder_iterate (const struct GNUNET_HELLO_Builder *builder, GNUNET_HELLO_UriCallback uc, void *uc_cls)
 Iterate over URIs in a builder.
 
const struct GNUNET_PeerIdentityGNUNET_HELLO_parser_iterate (const struct GNUNET_HELLO_Parser *parser, GNUNET_HELLO_UriCallback uc, void *uc_cls)
 Iterate over URIs in a parser.
 
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.
 
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.
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_build_url (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig, struct GNUNET_TIME_Absolute expiration, char **result)
 
void GNUNET_HELLO_builder_hash_addresses (const struct GNUNET_HELLO_Builder *builder, struct GNUNET_HashCode *hash)
 Compute hash over addresses in builder.
 
struct GNUNET_MQ_EnvelopeGNUNET_HELLO_builder_to_env (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *hello_sig, struct GNUNET_TIME_Absolute expiration_time)
 Generate envelope with GNUnet HELLO message (including peer ID) from a builder.
 
struct GNUNET_MessageHeaderGNUNET_HELLO_parser_to_dht_hello_msg (const struct GNUNET_HELLO_Parser *parser)
 Generate DHT HELLO message from a parser.
 
struct GNUNET_MessageHeaderGNUNET_HELLO_builder_to_dht_hello_msg (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *hello_sig, struct GNUNET_TIME_Absolute expiration_time)
 Generate DHT HELLO message (without peer ID) from a builder.
 
void GNUNET_HELLO_builder_to_block (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig, struct GNUNET_TIME_Absolute expiration_time, char *block)
 Generate DHT block from a builder.
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_to_url2 (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig, struct GNUNET_TIME_Absolute validity, char **result)
 Generate GNUnet HELLO URI from a builder.
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_to_url (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig, char **result)
 Generate GNUnet HELLO URI from a builder.
 
size_t GNUNET_HELLO_get_builder_to_block_size (const struct GNUNET_HELLO_Builder *builder)
 Get projected block size for builder.
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_address_list_cmp (const struct GNUNET_HELLO_Builder *abuilder, const struct GNUNET_HELLO_Builder *bbuilder)
 Compare address lists of two builders.
 

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 Address addr_start,
struct GNUNET_HashCode hash 
)
static

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

268{
269 struct GNUNET_HashContext *hc;
270
272
273#if HELLO_DETERMINISTIC_PID_DERIVATION
274 for (const struct Address *a = addr_start;
275 NULL != a;
276 a = a->next)
277 {
279 "Hashing over %.*s\n",
280 (int) a->uri_len,
281 a->uri);
283 a->uri,
284 a->uri_len);
285 }
286#endif
288 hash);
289
290}
#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.
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
@ GNUNET_ERROR_TYPE_DEBUG
Address of a peer.
Definition hello-uri.c:157
struct Address * next
Kept in a DLL.
Definition hello-uri.c:161

References GNUNET_CRYPTO_hash_context_finish(), GNUNET_CRYPTO_hash_context_read(), GNUNET_CRYPTO_hash_context_start(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and Address::next.

Referenced by GNUNET_HELLO_builder_hash_addresses(), and verify_hello().

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_Parser parser,
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 303 of file hello-uri.c.

306{
307 struct PilsHelloSignaturePurpose hsp = {
308 .purpose.size = htonl (sizeof (hsp)),
309 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
310 .expiration_time = GNUNET_TIME_absolute_hton (et)
311 };
312
313 hash_addresses (parser->a_head,
314 &hsp.h_addrs);
315 if (GNUNET_OK !=
317 &hsp,
318 sig,
319 &parser->pid.public_key))
320 {
322 "HELLO signature invalid, rejecting.\n");
323 return GNUNET_SYSERR;
324 }
326 return GNUNET_NO;
327 return GNUNET_OK;
328}
#define GNUNET_SIGNATURE_PURPOSE_HELLO
Signature by which a peer affirms its address.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:640
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
static void hash_addresses(const struct Address *addr_start, struct GNUNET_HashCode *hash)
Definition hello-uri.c:266
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
Message signed as part of a HELLO block/URL.
Definition hello-uri.c:50
struct GNUNET_HashCode h_addrs
Hash over all addresses.
Definition hello-uri.c:64
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition hello-uri.c:54

References GNUNET_CRYPTO_eddsa_verify, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_HELLO, GNUNET_SYSERR, GNUNET_TIME_absolute_hton(), GNUNET_TIME_absolute_is_past(), PilsHelloSignaturePurpose::h_addrs, hash_addresses(), PilsHelloSignaturePurpose::purpose, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by GNUNET_HELLO_dht_msg_to_block(), GNUNET_HELLO_parser_from_block_(), and GNUNET_HELLO_parser_from_url().

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

◆ parser_new()

static struct GNUNET_HELLO_Parser * parser_new ( const struct GNUNET_PeerIdentity pid)
static

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

333{
334 struct GNUNET_HELLO_Parser *p;
335
337 p->pid = *pid;
338 return p;
339}
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition gnunet-uri.c:38
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Context for parsing HELLOs.
Definition hello-uri.c:232
pid_t pid
PID of the process.
Definition os_priority.c:50

References GNUNET_new, p, GNUNET_OS_Process::pid, and pid.

Referenced by GNUNET_HELLO_parser_from_block_(), and GNUNET_HELLO_parser_from_url().

Here is the caller graph for this function:

◆ check_address()

static enum GNUNET_GenericReturnValue check_address ( const char *  address)
static

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

439{
440 const char *e;
441
442 if (NULL == (e = strstr (address,
443 "://")))
444 {
445 GNUNET_break_op (0);
447 "Invalid address `%s'\n",
448 address);
449 return GNUNET_SYSERR;
450 }
451 if (e == address)
452 {
453 GNUNET_break_op (0);
454 return GNUNET_SYSERR;
455 }
456 for (const char *p = address; p != e; p++)
457 if ( (! isalpha ((unsigned char) *p)) &&
458 ('+' != *p) )
459 {
460 GNUNET_break_op (0);
461 return GNUNET_SYSERR;
462 }
463 return GNUNET_OK;
464}
static char * address
GNS address for this phone.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
@ GNUNET_ERROR_TYPE_ERROR

References address, GNUNET_break_op, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, and p.

Referenced by GNUNET_HELLO_builder_add_address(), and parser_add_address().

Here is the caller graph for this function:

◆ cmp_address()

static int cmp_address ( void *  cls,
struct Address a,
struct Address b 
)
static

Alphanumeric sorting for addresses.

Parameters
clsNULL
afirst address
baddress to compare first address with
Returns
result of strcmp on the URI of the addresses

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

478{
479 return strcmp (a->uri, b->uri);
480}
const char * uri
Actual URI, allocated at the end of this struct.
Definition hello-uri.c:171

References Address::uri.

Referenced by GNUNET_HELLO_builder_add_address(), and parser_add_address().

Here is the caller graph for this function:

◆ parser_add_address()

static enum GNUNET_GenericReturnValue parser_add_address ( struct GNUNET_HELLO_Parser parser,
const char *  address 
)
static

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

486{
487 struct Address *a;
489 size_t alen = strlen (address) + 1;
490
492 if (GNUNET_OK != ret)
493 {
495 "Failed to add address to builder\n");
496 return ret;
497 }
498 /* check for duplicates */
499 for (a = parser->a_head;
500 NULL != a;
501 a = a->next)
502 if (0 == strcmp (address,
503 a->uri))
504 return GNUNET_NO;
505 a = GNUNET_malloc (sizeof (struct Address) + alen);
506 a->uri_len = alen;
507 memcpy (&a[1],
508 address,
509 alen);
510 a->uri = (const char *) &a[1];
513 NULL,
514 parser->a_head,
515 parser->a_tail,
516 a);
517 parser->a_length++;
518 return GNUNET_OK;
519}
static int ret
Final status code.
Definition gnunet-arm.c:93
#define GNUNET_CONTAINER_DLL_insert_sorted(TYPE, comparator, comparator_cls, head, tail, element)
Insertion sort of element into DLL from head to tail sorted by comparator.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_malloc(size)
Wrapper around malloc.
static int cmp_address(void *cls, struct Address *a, struct Address *b)
Alphanumeric sorting for addresses.
Definition hello-uri.c:477
static enum GNUNET_GenericReturnValue check_address(const char *address)
Definition hello-uri.c:438
size_t uri_len
Length of uri including 0-terminator.
Definition hello-uri.c:176

References address, check_address(), cmp_address(), GNUNET_CONTAINER_DLL_insert_sorted, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_malloc, GNUNET_NO, GNUNET_OK, Address::next, ret, Address::uri, and Address::uri_len.

Referenced by GNUNET_HELLO_parser_from_block_(), and GNUNET_HELLO_parser_from_url().

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