GNUnet 0.28.1-dev.4-46-g92a0edb0d
 
Loading...
Searching...
No Matches
pils_api.c File Reference
#include <string.h>
#include <stdint.h>
#include "gnunet_common.h"
#include "gnunet_protocols.h"
#include "gnunet_signatures.h"
#include "gnunet_util_lib.h"
#include "gnunet_hello_uri_lib.h"
#include "gnunet_pils_service.h"
#include "pils.h"
Include dependency graph for pils_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_PILS_Operation
 
struct  GNUNET_PILS_Handle
 A handle for the PILS service. More...
 
struct  GNUNET_PILS_KeyRing
 A simplified handle for using the peer identity key. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "pils-api", __VA_ARGS__)
 

Functions

static void transmit_op (struct GNUNET_PILS_Operation *op)
 Send the request of op to the service, if we are connected.
 
static void flush_ops (struct GNUNET_PILS_Handle *h)
 (Re-)transmit every outstanding request of h.
 
static struct GNUNET_PILS_Operationop_start (struct GNUNET_PILS_Handle *h, struct GNUNET_MessageHeader *req)
 Set up a new operation for h and start transmitting req.
 
static void op_destroy (struct GNUNET_PILS_Operation *op)
 Remove op from its handle and free it.
 
static struct GNUNET_PILS_Operationfind_op (struct GNUNET_PILS_Handle *h, uint32_t rid)
 Find the op that matches the rid.
 
static int check_peer_id (void *cls, const struct PeerIdUpdateMessage *msg)
 Handles sign result.
 
static void derive_private_key (struct GNUNET_PILS_Handle *h)
 Re-derive the private key of the current peer identity of h.
 
static void handle_peer_id (void *cls, const struct PeerIdUpdateMessage *pid_msg)
 Handles peer ids sent from the service.
 
static void handle_sign_result (void *cls, const struct SignResultMessage *msg)
 Handles sign result.
 
static void handle_decaps_result (void *cls, const struct DecapsResultMessage *msg)
 Handles decaps result.
 
static void handle_ecdh_result (void *cls, const struct EcdhResultMessage *msg)
 Handles ecdh result.
 
static void reconnect (void *cls)
 Try again to connect to peer identity lifecycle service.
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 Handles errors with the mq.
 
struct GNUNET_PILS_HandleGNUNET_PILS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_PILS_PidChangeCallback pid_change_cb, void *cls)
 Connect to the PILS service.
 
void GNUNET_PILS_disconnect (struct GNUNET_PILS_Handle *handle)
 Disconnect from the PILS service.
 
struct GNUNET_PILS_OperationGNUNET_PILS_sign_by_peer_identity (struct GNUNET_PILS_Handle *handle, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, GNUNET_PILS_SignResultCallback cb, void *cb_cls)
 Sign data with the peer id.
 
struct GNUNET_PILS_OperationGNUNET_PILS_kem_decaps (struct GNUNET_PILS_Handle *handle, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, GNUNET_PILS_DecapsResultCallback cb, void *cb_cls)
 Decaps an encapsulated key with our private key.
 
struct GNUNET_PILS_OperationGNUNET_PILS_ecdh (struct GNUNET_PILS_Handle *handle, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, GNUNET_PILS_EcdhResultCallback cb, void *cb_cls)
 Derive key material from a ECDH public key and our private key.
 
void GNUNET_PILS_cancel (struct GNUNET_PILS_Operation *op)
 Cancel request.
 
void GNUNET_PILS_derive_pid (size_t seed_key_bytes, const uint8_t seed_key[seed_key_bytes], const struct GNUNET_HashCode *addrs_hash, struct GNUNET_CRYPTO_EddsaPrivateKey *outkey)
 Generate the peer id from the addresses hash and the initial secret key.
 
void GNUNET_PILS_feed_addresses (struct GNUNET_PILS_Handle *handle, const struct GNUNET_HELLO_Builder *builder)
 Feed a set of addresses to pils so that it will generate a new peer id based on the given set of addresses.
 
struct GNUNET_PILS_OperationGNUNET_PILS_sign_hello (struct GNUNET_PILS_Handle *handle, const struct GNUNET_HELLO_Builder *builder, struct GNUNET_TIME_Absolute et, GNUNET_PILS_SignResultCallback cb, void *cb_cls)
 Create HELLO signature.
 
const struct GNUNET_PeerIdentityGNUNET_PILS_get_identity (const struct GNUNET_PILS_Handle *handle)
 Return the current peer identity of a given handle.
 
const struct GNUNET_HashCodeGNUNET_PILS_get_identity_hash (const struct GNUNET_PILS_Handle *handle)
 Return the hash of the current peer identity from a given handle.
 
enum GNUNET_GenericReturnValue GNUNET_PILS_enable_private_key (struct GNUNET_PILS_Handle *handle)
 Enable local access to the private key of the current peer identity.
 
const struct GNUNET_CRYPTO_EddsaPrivateKeyGNUNET_PILS_get_private_key (const struct GNUNET_PILS_Handle *handle)
 Return the private key of the current peer identity.
 
void pid_change_cb (void *cls, const struct GNUNET_HELLO_Parser *parser, const struct GNUNET_HashCode *addr_hash)
 
struct GNUNET_PILS_KeyRingGNUNET_PILS_create_key_ring (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_SCHEDULER_TaskCallback init_cb, void *cls)
 Get the initial secret key for generating the peer id.
 
void GNUNET_PILS_destroy_key_ring (struct GNUNET_PILS_KeyRing *key_ring)
 Destroy a key ring handle and free its memory.
 
const struct GNUNET_CRYPTO_EddsaPrivateKeyGNUNET_PILS_key_ring_get_private_key (const struct GNUNET_PILS_KeyRing *key_ring)
 Return the current private key of a given key ring handle.
 

Detailed Description

Author
ch3

Peer Identity Lifecycle Service; the API for managing Peer Identities

This api gives access to the PILS service.

The service maintains the peer identity. On address change it generates a new identity and informs subscribed components. It also signs data with the identity on request.

Definition in file pils_api.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "pils-api", __VA_ARGS__)

Definition at line 44 of file pils_api.c.

Function Documentation

◆ transmit_op()

static void transmit_op ( struct GNUNET_PILS_Operation op)
static

Send the request of op to the service, if we are connected.

A request that cannot be sent right now stays in op_head and is transmitted by flush_ops() once the connection is (re-)established. Note that this must never call GNUNET_MQ_send() on a NULL mq: that asserts, which would take the caller's service down every time an operation is started while PILS happens to be reconnecting.

Parameters
opoperation whose request to transmit

Definition at line 198 of file pils_api.c.

199{
200 struct GNUNET_PILS_Handle *h = op->h;
201
202 if (NULL == h->mq)
203 {
205 "Not connected to PILS, deferring request %u\n",
206 (unsigned int) op->op_id);
207 return;
208 }
210 GNUNET_MQ_msg_copy (op->req));
211}
static struct GNUNET_ARM_Operation * op
Current operation.
Definition gnunet-arm.c:143
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition gnunet-arm.c:98
@ GNUNET_ERROR_TYPE_DEBUG
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition mq.c:582
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition mq.c:337
#define LOG(kind,...)
Definition pils_api.c:44
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition arm_api.c:107
struct GNUNET_ARM_Handle * h
ARM handle.
Definition arm_api.c:55
A handle for the PILS service.
Definition pils_api.c:86

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_msg_copy(), GNUNET_MQ_send(), h, GNUNET_ARM_Operation::h, LOG, GNUNET_ARM_Handle::mq, and op.

Referenced by flush_ops(), GNUNET_PILS_ecdh(), GNUNET_PILS_kem_decaps(), and GNUNET_PILS_sign_by_peer_identity().

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

◆ flush_ops()

static void flush_ops ( struct GNUNET_PILS_Handle h)
static

(Re-)transmit every outstanding request of h.

Called after a successful (re-)connect. The service is stateless with respect to these requests – it computes an answer and forgets them – so a request that was in flight when the connection broke is simply gone, and without this its callback would never run. Sending it again is safe: the operations are pure functions of the request, and a duplicate answer is dropped by find_op().

Parameters
hhandle whose operations to flush

Definition at line 227 of file pils_api.c.

228{
229 for (struct GNUNET_PILS_Operation *op = h->op_head;
230 NULL != op;
231 op = op->next)
232 transmit_op (op);
233}
static void transmit_op(struct GNUNET_PILS_Operation *op)
Send the request of op to the service, if we are connected.
Definition pils_api.c:198
struct GNUNET_ARM_Operation * next
This is a doubly-linked list.
Definition arm_api.c:45

References h, GNUNET_ARM_Operation::next, op, and transmit_op().

Referenced by reconnect().

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

◆ op_start()

static struct GNUNET_PILS_Operation * op_start ( struct GNUNET_PILS_Handle h,
struct GNUNET_MessageHeader req 
)
static

Set up a new operation for h and start transmitting req.

Takes ownership of req.

Parameters
hhandle to the PILS service
reqthe request message, with rid already filled in
Returns
the new operation

Definition at line 246 of file pils_api.c.

248{
250
252 op->h = h;
253 op->req = req;
255 h->op_tail,
256 op);
257 return op;
258}
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_MessageHeader * req
Definition pils_api.c:75

References GNUNET_CONTAINER_DLL_insert, GNUNET_new, h, GNUNET_ARM_Operation::h, op, and GNUNET_PILS_Operation::req.

Referenced by GNUNET_PILS_ecdh(), GNUNET_PILS_kem_decaps(), and GNUNET_PILS_sign_by_peer_identity().

Here is the caller graph for this function:

◆ op_destroy()

static void op_destroy ( struct GNUNET_PILS_Operation op)
static

Remove op from its handle and free it.

Parameters
opoperation to destroy

Definition at line 267 of file pils_api.c.

268{
269 struct GNUNET_PILS_Handle *h = op->h;
270
272 h->op_tail,
273 op);
274 GNUNET_free (op->req);
275 GNUNET_free (op);
276}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_CONTAINER_DLL_remove, GNUNET_free, h, GNUNET_ARM_Operation::h, and op.

Referenced by GNUNET_PILS_cancel(), GNUNET_PILS_disconnect(), handle_decaps_result(), handle_ecdh_result(), and handle_sign_result().

Here is the caller graph for this function:

◆ find_op()

static struct GNUNET_PILS_Operation * find_op ( struct GNUNET_PILS_Handle h,
uint32_t  rid 
)
static

Find the op that matches the rid.

Parameters
hPILS handle
ridid to look up
Returns
NULL if rid was not found

Definition at line 287 of file pils_api.c.

288{
290
291 for (op = h->op_head; op != NULL; op = op->next)
292 if (op->op_id == rid)
293 return op;
295 "Finding request with id %u was unsuccessful\n",
296 rid);
297 return NULL;
298}
@ GNUNET_ERROR_TYPE_WARNING

References GNUNET_ERROR_TYPE_WARNING, h, LOG, GNUNET_ARM_Operation::next, and op.

Referenced by handle_decaps_result(), handle_ecdh_result(), and handle_sign_result().

Here is the caller graph for this function:

◆ check_peer_id()

static int check_peer_id ( void *  cls,
const struct PeerIdUpdateMessage msg 
)
static

Handles sign result.

Parameters
clsclosure - Handle to the PILS service
msgthe message containing the signature

Definition at line 308 of file pils_api.c.

309{
310 size_t msg_size;
311 uint32_t block_bytes;
312 (void) cls;
313
314 msg_size = ntohs (msg->header.size);
315 block_bytes = ntohl (msg->block_len);
316 if (msg_size != sizeof (*msg) + block_bytes)
317 {
319 "The msg_size (%lu) is not %lu (header) + %u (block)\n",
320 msg_size,
321 sizeof (*msg),
322 block_bytes);
323 return GNUNET_SYSERR;
324 }
325 return GNUNET_OK;
326
327}
struct GNUNET_MessageHeader * msg
Definition 005.c:2
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_ERROR

References GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SYSERR, LOG, msg, and GNUNET_MessageHeader::size.

◆ derive_private_key()

static void derive_private_key ( struct GNUNET_PILS_Handle h)
static

Re-derive the private key of the current peer identity of h.

Does nothing unless local key access was enabled with GNUNET_PILS_enable_private_key(). Must be called after peer_id and hash were updated, and before the application's GNUNET_PILS_PidChangeCallback runs, so that a caller which sees an identity always sees the matching private key.

If the derived key does not belong to the peer identity the service announced, our [PEER]/PRIVATE_KEY does not match the one the service uses. Signing with it would produce signatures nobody can verify, so the key is discarded and callers fall back to asking the service.

Parameters
hhandle to update

Definition at line 347 of file pils_api.c.

348{
349 struct GNUNET_PeerIdentity pid;
350
351 if (! h->have_ikm)
352 return;
353 if (NULL == h->private_key)
354 h->private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey);
355 GNUNET_PILS_derive_pid (sizeof (h->initial_key_material),
356 h->initial_key_material,
357 &h->hash,
358 h->private_key);
360 &pid.public_key);
361 if (0 != GNUNET_memcmp (&pid,
362 h->peer_id))
363 {
365 "Locally derived peer identity %s does not match %s announced by the service; check [PEER]/PRIVATE_KEY\n",
366 GNUNET_i2s (&pid),
367 GNUNET_i2s (h->peer_id));
368 GNUNET_CRYPTO_zero_keys (h->private_key,
369 sizeof (*h->private_key));
370 GNUNET_free (h->private_key);
371 h->private_key = NULL;
372 return;
373 }
375 "Derived private key for peer identity %s\n",
376 GNUNET_i2s (h->peer_id));
377}
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition crypto_ecc.c:202
void GNUNET_CRYPTO_zero_keys(void *buffer, size_t length)
Zero out buffer, securely against compiler optimizations.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void GNUNET_PILS_derive_pid(size_t seed_key_bytes, const uint8_t seed_key[seed_key_bytes], const struct GNUNET_HashCode *addrs_hash, struct GNUNET_CRYPTO_EddsaPrivateKey *outkey)
Generate the peer id from the addresses hash and the initial secret key.
Definition pils_api.c:783
Private ECC key encoded for transmission.
The identity of the host (wraps the signing key of the peer).

References GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_zero_keys(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_i2s(), GNUNET_memcmp, GNUNET_new, GNUNET_PILS_derive_pid(), h, LOG, and GNUNET_PeerIdentity::public_key.

Referenced by GNUNET_PILS_enable_private_key(), and handle_peer_id().

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

◆ handle_peer_id()

static void handle_peer_id ( void *  cls,
const struct PeerIdUpdateMessage pid_msg 
)
static

Handles peer ids sent from the service.

Parameters
clsclosure - Handle to the PILS service
pid_msgthe message containing peer id and addresses hash

Definition at line 387 of file pils_api.c.

388{
389 struct GNUNET_PILS_Handle *h = cls;
391 uint32_t block_bytes;
392
393 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
394 block_bytes = ntohl (pid_msg->block_len);
396 block_bytes);
397 if (NULL == parser)
398 {
400 "Error parsing Hello block from PILS!\n");
401 return;
402 }
403
404 if (NULL == h->peer_id)
405 h->peer_id = GNUNET_new (struct GNUNET_PeerIdentity);
406
407 memcpy (&h->hash, &pid_msg->hash, sizeof (struct GNUNET_HashCode));
408 memcpy (h->peer_id, GNUNET_HELLO_parser_get_id (parser),
409 sizeof (struct GNUNET_PeerIdentity));
410 GNUNET_CRYPTO_hash (h->peer_id, sizeof (struct GNUNET_PeerIdentity),
411 &h->peer_hash);
413
414 if (NULL != h->pid_change_cb)
415 {
416 h->pid_change_cb (h->pid_change_cb_cls,
417 parser,
418 &pid_msg->hash);
419 }
421}
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:40
void GNUNET_HELLO_parser_free(struct GNUNET_HELLO_Parser *parser)
Release resources of a builder.
Definition hello-uri.c:380
const struct GNUNET_PeerIdentity * GNUNET_HELLO_parser_get_id(const struct GNUNET_HELLO_Parser *parser)
Get the PeerIdentity for this builder.
Definition hello-uri.c:354
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_block(const void *block, size_t block_size)
Parse block.
Definition hello-uri.c:582
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
static void derive_private_key(struct GNUNET_PILS_Handle *h)
Re-derive the private key of the current peer identity of h.
Definition pils_api.c:347
Context for parsing HELLOs.
Definition hello-uri.c:233
A 512-bit hashcode.
struct GNUNET_HashCode hash
The hash from which the peer id was generated.
Definition pils.h:49
uint32_t block_len
Length of the HELLO block in bytes.
Definition pils.h:54

References PeerIdUpdateMessage::block_len, derive_private_key(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_ERROR, GNUNET_HELLO_parser_free(), GNUNET_HELLO_parser_from_block(), GNUNET_HELLO_parser_get_id(), GNUNET_new, GNUNET_TIME_UNIT_ZERO, h, PeerIdUpdateMessage::hash, and LOG.

Here is the call graph for this function:

◆ handle_sign_result()

static void handle_sign_result ( void *  cls,
const struct SignResultMessage msg 
)
static

Handles sign result.

Parameters
clsclosure - Handle to the PILS service
msgthe message containing the signature

Definition at line 431 of file pils_api.c.

432{
433 struct GNUNET_PILS_Handle *h = cls;
435
436 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
437 op = find_op (h, ntohl (msg->rid));
438
440 "Received SIGN_RESULT message from service\n");
441
442 if (NULL == op)
443 {
445 "Didn't find the operation corresponding to id %u\n",
446 ntohl (msg->rid));
447 return;
448 }
449 if (NULL != op->sign_cb)
450 {
451 // FIXME maybe return NULL of key is 0ed
452 // as this indicates an error
453 op->sign_cb (op->cb_cls,
454 &msg->peer_id,
455 &msg->sig);
456 }
457 op_destroy (op);
458}
static void op_destroy(struct GNUNET_PILS_Operation *op)
Remove op from its handle and free it.
Definition pils_api.c:267
static struct GNUNET_PILS_Operation * find_op(struct GNUNET_PILS_Handle *h, uint32_t rid)
Find the op that matches the rid.
Definition pils_api.c:287

References find_op(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_TIME_UNIT_ZERO, h, LOG, msg, op, and op_destroy().

Here is the call graph for this function:

◆ handle_decaps_result()

static void handle_decaps_result ( void *  cls,
const struct DecapsResultMessage msg 
)
static

Handles decaps result.

Parameters
clsclosure - Handle to the PILS service
msgthe message containing the decapsulation result

Definition at line 468 of file pils_api.c.

469{
470 struct GNUNET_PILS_Handle *h = cls;
472
474 "Received KEM_DECAPS result from service!\n");
475
476 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
477 op = find_op (h, ntohl (msg->rid));
478
479 if (NULL == op)
480 {
482 "Didn't find the operation corresponding to id %u\n",
483 ntohl (msg->rid));
484 return;
485 }
486 if (NULL != op->decaps_cb)
487 {
488 // FIXME maybe return NULL of key is 0ed
489 // as this indicates an error
490 op->decaps_cb (op->cb_cls,
491 &msg->key);
492 }
493 op_destroy (op);
494}

References find_op(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_TIME_UNIT_ZERO, h, LOG, msg, op, and op_destroy().

Here is the call graph for this function:

◆ handle_ecdh_result()

static void handle_ecdh_result ( void *  cls,
const struct EcdhResultMessage msg 
)
static

Handles ecdh result.

Parameters
clsclosure - Handle to the PILS service
msgthe message containing the ecdh result

Definition at line 504 of file pils_api.c.

505{
506 struct GNUNET_PILS_Handle *h = cls;
508
510 "Received ECDH result from service!\n");
511
512 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
513 op = find_op (h, ntohl (msg->rid));
514
515 if (NULL == op)
516 {
518 "Didn't find the operation corresponding to id %u\n",
519 ntohl (msg->rid));
520 return;
521 }
522 if (NULL != op->ecdh_cb)
523 op->ecdh_cb (op->cb_cls,
524 &msg->key);
525 op_destroy (op);
526}

References find_op(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_TIME_UNIT_ZERO, h, LOG, msg, op, and op_destroy().

Here is the call graph for this function:

◆ reconnect()

static void reconnect ( void *  cls)
static

Try again to connect to peer identity lifecycle service.

Parameters
clsthe struct GNUNET_PILS_Handle *

Definition at line 574 of file pils_api.c.

575{
576 struct GNUNET_PILS_Handle *h = cls;
580 struct PeerIdUpdateMessage,
581 h),
582 GNUNET_MQ_hd_fixed_size (decaps_result,
584 struct DecapsResultMessage,
585 h),
586 GNUNET_MQ_hd_fixed_size (ecdh_result,
588 struct EcdhResultMessage,
589 h),
590 GNUNET_MQ_hd_fixed_size (sign_result,
592 struct SignResultMessage,
593 h),
595 };
596
597 h->reconnect_task = NULL;
599 "Connecting to peer identity lifecycle service.\n");
600 GNUNET_assert (NULL == h->mq);
602 "pils",
603 handlers,
605 h);
606 if (NULL == h->mq)
607 {
609 "Failed to connect.\n");
610 {
612 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
613 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
614 }
615 return;
616 }
618 "Connection to service successful!\n");
619 flush_ops (h);
620}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition 003.c:1
static char * peer_id
Option –peer.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition client.c:1182
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_PILS_ECDH_RESULT
Ecdh result.
#define GNUNET_MESSAGE_TYPE_PILS_DECAPS_RESULT
Decaps result.
#define GNUNET_MESSAGE_TYPE_PILS_PEER_ID
Message passing the new peer id from the service to the client.
#define GNUNET_MESSAGE_TYPE_PILS_SIGN_RESULT
The service sends the requested signature to the client.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1283
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Handles errors with the mq.
Definition pils_api.c:546
static void flush_ops(struct GNUNET_PILS_Handle *h)
(Re-)transmit every outstanding request of h.
Definition pils_api.c:227
static void reconnect(void)
Adjust exponential back-off and reconnect to the service.
Message containing the decapsulated key.
Definition pils.h:163
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition arm_api.c:112
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Definition arm_api.c:147
Message handler for a specific message type.
Message containing the current peer id and the hash from which it was generated.
Definition pils.h:40
Message containing the signature.
Definition pils.h:220

References GNUNET_ARM_Handle::cfg, flush_ops(), GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_MESSAGE_TYPE_PILS_DECAPS_RESULT, GNUNET_MESSAGE_TYPE_PILS_ECDH_RESULT, GNUNET_MESSAGE_TYPE_PILS_PEER_ID, GNUNET_MESSAGE_TYPE_PILS_SIGN_RESULT, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, h, handlers, LOG, GNUNET_ARM_Handle::mq, mq_error_handler(), peer_id, reconnect(), and GNUNET_ARM_Handle::reconnect_task.

Here is the call graph for this function:

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Handles errors with the mq.

Schedules the reconnect task and updates the reconnect delay.

Parameters
clsclosure - handle to PILS
errorerror type indicating the kind of problem with mq

Definition at line 546 of file pils_api.c.

547{
548 struct GNUNET_PILS_Handle *h = cls;
549 (void) error;
550
551 // TODO logging
553 "Connection to pils service failed!\n");
555 h->mq = NULL;
556 /* NOTE: @e op_head is deliberately left alone. The requests in it died
557 with the connection, but their callers are still waiting for the
558 callbacks -- #flush_ops() re-sends them once we are back. Dropping
559 them here silently (as this used to do) leaves e.g. CORE holding a
560 half-finished handshake and a TRANSPORT flow control credit it never
561 returns. */
563 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
564 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
565}
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition mq.c:732

References GNUNET_ERROR_TYPE_WARNING, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, h, LOG, GNUNET_ARM_Handle::mq, reconnect(), and GNUNET_ARM_Handle::reconnect_task.

Referenced by reconnect().

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

◆ GNUNET_PILS_connect()

struct GNUNET_PILS_Handle * GNUNET_PILS_connect ( const struct GNUNET_CONFIGURATION_Handle cfg,
GNUNET_PILS_PidChangeCallback  pid_change_cb,
void *  cls 
)

Connect to the PILS service.

Parameters
cfgconfiguration to use
pid_change_cbhandler/callback called once the peer id changes
clsclosure for pid_change_cb
Returns
Handle to the PILS service

Definition at line 624 of file pils_api.c.

627{
628 struct GNUNET_PILS_Handle *h;
629
631 h->cfg = cfg;
632 h->pid_change_cb = pid_change_cb;
633 h->pid_change_cb_cls = cls;
634 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
635 reconnect (h);
636 return h;
637}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
void pid_change_cb(void *cls, const struct GNUNET_HELLO_Parser *parser, const struct GNUNET_HashCode *addr_hash)
Definition pils_api.c:952

References cfg, GNUNET_ARM_Handle::cfg, GNUNET_new, GNUNET_TIME_UNIT_ZERO, h, pid_change_cb(), and reconnect().

Referenced by advertise_dns_exit(), create_service(), DHTU_gnunet_init(), GCH_init(), GNUNET_PILS_create_key_ring(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), GSC_KX_init(), main_init(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), and run().

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

◆ GNUNET_PILS_disconnect()

void GNUNET_PILS_disconnect ( struct GNUNET_PILS_Handle handle)

Disconnect from the PILS service.

Parameters
handlehandle to the PILS service (was returned by GNUNET_PILS_connect)

Definition at line 647 of file pils_api.c.

648{
650
651 GNUNET_assert (NULL != handle);
653 "Disonnecting from peer identity lifecycle service.\n");
654 if (NULL != handle->reconnect_task)
655 {
656 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
657 handle->reconnect_task = NULL;
658 }
659 if (NULL != handle->mq)
660 {
662 handle->mq = NULL;
663 }
664 LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
665 while (NULL != (op = handle->op_head))
666 op_destroy (op);
667 if (handle->peer_id)
668 GNUNET_free (handle->peer_id);
669 if (NULL != handle->private_key)
670 {
671 GNUNET_CRYPTO_zero_keys (handle->private_key,
672 sizeof (*handle->private_key));
673 GNUNET_free (handle->private_key);
674 }
675 GNUNET_CRYPTO_zero_keys (handle->initial_key_material,
676 sizeof (handle->initial_key_material));
678}
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition gnunet-vpn.c:35
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
struct GNUNET_MQ_Handle * mq
Connection to VPN service.
Definition vpn_api.c:44

References GNUNET_assert, GNUNET_CRYPTO_zero_keys(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), handle, LOG, GNUNET_VPN_Handle::mq, op, and op_destroy().

Referenced by cleaning_task(), cleanup(), cleanup_task(), destroy_service(), DHTU_gnunet_done(), do_shutdown(), do_shutdown(), do_shutdown(), do_shutdown(), do_shutdown(), do_shutdown(), do_shutdown(), GCH_shutdown(), GNUNET_PILS_destroy_key_ring(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop(), GSC_KX_done(), run(), shutdown_task(), shutdown_task(), shutdown_task(), shutdown_task(), shutdown_task(), shutdown_task(), and shutdown_task().

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

◆ GNUNET_PILS_sign_by_peer_identity()

struct GNUNET_PILS_Operation * GNUNET_PILS_sign_by_peer_identity ( struct GNUNET_PILS_Handle handle,
const struct GNUNET_CRYPTO_SignaturePurpose purpose,
GNUNET_PILS_SignResultCallback  cb,
void *  cb_cls 
)

Sign data with the peer id.

Parameters
handlehandle to the PILS service
purposewhat to sign (size, purpose and data)
cbcallback to call once the signature is ready
cb_clsclosure to cb
Returns
handle to the operation, NULL on error

Definition at line 692 of file pils_api.c.

698{
700 struct SignRequestMessage *msg;
701 size_t plen = ntohl (purpose->size);
702
703 GNUNET_assert (sizeof (*msg) + plen <= UINT16_MAX);
704 msg = GNUNET_malloc (sizeof (*msg) + plen);
706 msg->header.size = htons (sizeof (*msg) + plen);
707 msg->rid = htonl (handle->op_id_counter++);
708 memcpy (&msg[1], purpose, plen);
709 op = op_start (handle, &msg->header);
710 op->sign_cb = cb;
711 op->cb_cls = cb_cls;
712 op->op_id = ntohl (msg->rid);
713 transmit_op (op);
714 return op;
715}
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_MESSAGE_TYPE_PILS_SIGN_REQUEST
The client requests data to be signed with the peer identity.
static struct GNUNET_PILS_Operation * op_start(struct GNUNET_PILS_Handle *h, struct GNUNET_MessageHeader *req)
Set up a new operation for h and start transmitting req.
Definition pils_api.c:246
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
Message to request a signature from PILS.
Definition pils.h:248

References GNUNET_assert, GNUNET_malloc, GNUNET_MESSAGE_TYPE_PILS_SIGN_REQUEST, handle, msg, op, op_start(), GNUNET_MessageHeader::size, GNUNET_CRYPTO_SignaturePurpose::size, transmit_op(), and GNUNET_MessageHeader::type.

Referenced by do_dht_put(), GDS_helper_sign_path(), GNUNET_PILS_sign_hello(), regex_iterator(), send_create(), sign_message_by_peer(), and transmit_task_cb().

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

◆ GNUNET_PILS_kem_decaps()

struct GNUNET_PILS_Operation * GNUNET_PILS_kem_decaps ( struct GNUNET_PILS_Handle handle,
const struct GNUNET_CRYPTO_HpkeEncapsulation c,
GNUNET_PILS_DecapsResultCallback  cb,
void *  cb_cls 
)

Decaps an encapsulated key with our private key.

Parameters
handlehandle to the PILS service
cthe encapsulated key
prkwhere to write the key material HKDF-Extract(c||aX)=HKDF-Extract(c||x(aG))
Returns
handle to the operation, NULL on error

Definition at line 728 of file pils_api.c.

732{
734 struct DecapsMessage *msg;
735
736 msg = GNUNET_new (struct DecapsMessage);
738 msg->header.size = htons (sizeof (*msg));
739 msg->c = *c;
740 msg->rid = htonl (handle->op_id_counter++);
741 op = op_start (handle, &msg->header);
742 op->decaps_cb = cb;
743 op->cb_cls = cb_cls;
744 op->op_id = ntohl (msg->rid);
745 transmit_op (op);
746 return op;
747}
#define GNUNET_MESSAGE_TYPE_PILS_KEM_DECAPS
Decaps request.
Message to request a decapsulation from PILS.
Definition pils.h:142
struct GNUNET_CRYPTO_HpkeEncapsulation c
Encapsulation to decapsulate.
Definition pils.h:151

References DecapsMessage::c, GNUNET_MESSAGE_TYPE_PILS_KEM_DECAPS, GNUNET_new, handle, msg, op, op_start(), GNUNET_MessageHeader::size, transmit_op(), and GNUNET_MessageHeader::type.

Here is the call graph for this function:

◆ GNUNET_PILS_ecdh()

struct GNUNET_PILS_Operation * GNUNET_PILS_ecdh ( struct GNUNET_PILS_Handle handle,
const struct GNUNET_CRYPTO_EcdhePublicKey pub,
GNUNET_PILS_EcdhResultCallback  cb,
void *  cb_cls 
)

Derive key material from a ECDH public key and our private key.

Parameters
handlehandle to the PILS service
pubthe public key
cbthe callback to call with the derived key material
cb_clscallback closure
Returns
handle to the operation, NULL on error

Definition at line 751 of file pils_api.c.

755{
757 struct EcdhMessage *msg;
758
759 GNUNET_assert ((handle) && (pub));
760
761 msg = GNUNET_new (struct EcdhMessage);
762 msg->header.type = htons (GNUNET_MESSAGE_TYPE_PILS_ECDH);
763 msg->header.size = htons (sizeof (*msg));
764 msg->pub = *pub;
765 msg->rid = htonl (handle->op_id_counter++);
766 op = op_start (handle, &msg->header);
767 op->ecdh_cb = cb;
768 op->cb_cls = cb_cls;
769 op->op_id = ntohl (msg->rid);
770 transmit_op (op);
771 return op;
772}
static struct GNUNET_CRYPTO_EddsaPublicKey pub
#define GNUNET_MESSAGE_TYPE_PILS_ECDH
Ecdh request.

References GNUNET_assert, GNUNET_MESSAGE_TYPE_PILS_ECDH, GNUNET_new, handle, msg, op, op_start(), pub, GNUNET_MessageHeader::size, transmit_op(), and GNUNET_MessageHeader::type.

Referenced by GCT_handle_kx(), and GCT_handle_kx_auth().

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

◆ GNUNET_PILS_cancel()

void GNUNET_PILS_cancel ( struct GNUNET_PILS_Operation op)

Cancel request.

Parameters
opcancel PILS operation

Definition at line 776 of file pils_api.c.

777{
778 op_destroy (op);
779}

References op, and op_destroy().

Referenced by cancel_address_store(), cleanup(), cleanup_helper_operation(), destroy_tunnel(), do_dht_put(), do_initial_dht_put(), do_shutdown(), GCC_destroy(), GCH_shutdown(), GCT_handle_kx(), GCT_handle_kx_auth(), iterate_cancel_signature(), regex_iterator(), send_create(), shutdown_task(), and shutdown_task().

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

◆ GNUNET_PILS_derive_pid()

void GNUNET_PILS_derive_pid ( size_t  seed_key_bytes,
const uint8_t  seed_key[seed_key_bytes],
const struct GNUNET_HashCode addrs_hash,
struct GNUNET_CRYPTO_EddsaPrivateKey outkey 
)

Generate the peer id from the addresses hash and the initial secret key.

Parameters
seed_key_byteslength of the seed key in bytes
seed_keythe initial secret key
addrs_hashthe address to use for derivation
[out]outkeythe (private) peer identity key

Since we should have initial keying material of good quality here, this is effectively a PRF called on the address hash with a uniform random key.

We now expand the PRK to the key size we actually require. FIXME: IF we want to use elligator, we need to find a private key that can actually be used as such. For that, we may want to add a counter to the initial secret key to the above PRF.

Definition at line 783 of file pils_api.c.

787{
788 struct GNUNET_ShortHashCode prk;
789
797 addrs_hash,
798 sizeof *addrs_hash,
799 seed_key,
800 seed_key_bytes));
809 outkey,
810 sizeof *outkey,
811 &prk,
812 GNUNET_CRYPTO_kdf_arg_string ("gnunet-pils-ephemeral-peer-key"));
813}
static uint8_t seed_key[256/8]
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_extract(struct GNUNET_ShortHashCode *prk, const void *salt, size_t salt_len, const void *ikm, size_t ikm_len)
HKDF-Extract using SHA256.
#define GNUNET_CRYPTO_hkdf_expand(result, out_len, prk,...)
HKDF-Expand using SHA256.
#define GNUNET_CRYPTO_kdf_arg_string(d)
A 256-bit hashcode.

References GNUNET_assert, GNUNET_CRYPTO_hkdf_expand, GNUNET_CRYPTO_hkdf_extract(), GNUNET_CRYPTO_kdf_arg_string, GNUNET_OK, and seed_key.

Referenced by derive_private_key(), do_generate_pid(), pid_change_cb(), and run().

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

◆ GNUNET_PILS_feed_addresses()

void GNUNET_PILS_feed_addresses ( struct GNUNET_PILS_Handle handle,
const struct GNUNET_HELLO_Builder addresses_builder 
)

Feed a set of addresses to pils so that it will generate a new peer id based on the given set of addresses.

THIS IS ONLY TO BE CALLED FROM CORE!

The address representation will be canonicalized/sorted by pils before the new peer id is generated.

Parameters
handlethe handle to the PILS service
addresses_builderaddresses to feed as builder

Definition at line 817 of file pils_api.c.

819{
821 struct GNUNET_MQ_Envelope *env;
822 size_t block_bytes;
823
825 // TODO check whether the new hash and the 'current' hash are the same -
826 // nothing to do in that case (directly return the peer id?)
828 block_bytes,
830 msg->block_len = htonl (block_bytes);
832 builder,
833 NULL,
834 NULL,
836 (char*) &msg[1]);
838}
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
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 *outbuf)
Generate DHT block from a builder.
Definition hello-uri.c:1322
size_t GNUNET_HELLO_get_builder_to_block_size(const struct GNUNET_HELLO_Builder *builder)
Get projected block size for builder.
Definition hello-uri.c:1390
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MESSAGE_TYPE_PILS_FEED_ADDRESSES
The client (core) provides new addresses to the service, so the service can generate the new peer id.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition time.c:316
Message requesting a signature on data with the current peer id.
Definition pils.h:122

References builder, env, GNUNET_HELLO_builder_to_block(), GNUNET_HELLO_get_builder_to_block_size(), GNUNET_MESSAGE_TYPE_PILS_FEED_ADDRESSES, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_ZERO, handle, GNUNET_VPN_Handle::mq, and msg.

Referenced by feed_addresses_to_pils().

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

◆ GNUNET_PILS_sign_hello()

struct GNUNET_PILS_Operation * GNUNET_PILS_sign_hello ( struct GNUNET_PILS_Handle handle,
const struct GNUNET_HELLO_Builder builder,
struct GNUNET_TIME_Absolute  et,
GNUNET_PILS_SignResultCallback  cb,
void *  cb_cls 
)

Create HELLO signature.

Parameters
handlehandle to the pils service
builderthe builder to use
etexpiration time to sign
cbcallback to call with the signature
cb_clsclosure to cb

Definition at line 851 of file pils_api.c.

856{
857 struct PilsHelloSignaturePurpose hsp = {
858 .purpose.size = htonl (sizeof (hsp)),
859 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
860 .expiration_time = GNUNET_TIME_absolute_hton (et)
861 };
863 &hsp.h_addrs);
865 "Address hash is %s\n",
866 GNUNET_h2s_full (&hsp.h_addrs));
868 &hsp.purpose,
869 cb,
870 cb_cls);
871}
#define GNUNET_SIGNATURE_PURPOSE_HELLO
Signature by which a peer affirms its address.
void GNUNET_HELLO_builder_hash_addresses(const struct GNUNET_HELLO_Builder *builder, struct GNUNET_HashCode *hash)
Compute hash over addresses in builder.
Definition hello-uri.c:1211
#define GNUNET_log(kind,...)
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:636
struct GNUNET_PILS_Operation * GNUNET_PILS_sign_by_peer_identity(struct GNUNET_PILS_Handle *handle, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, GNUNET_PILS_SignResultCallback cb, void *cb_cls)
Sign data with the peer id.
Definition pils_api.c:692
Message signed as part of a HELLO block/URL.
Definition hello-uri.c:51
struct GNUNET_HashCode h_addrs
Hash over all addresses.
Definition hello-uri.c:65
struct GNUNET_CRYPTO_SignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition hello-uri.c:55

References builder, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s_full(), GNUNET_HELLO_builder_hash_addresses(), GNUNET_log, GNUNET_PILS_sign_by_peer_identity(), GNUNET_SIGNATURE_PURPOSE_HELLO, GNUNET_TIME_absolute_hton(), PilsHelloSignaturePurpose::h_addrs, handle, PilsHelloSignaturePurpose::purpose, and GNUNET_CRYPTO_SignaturePurpose::size.

Referenced by peerstore_store_own_cb(), and pid_changed_cb().

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

◆ GNUNET_PILS_get_identity()

const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity ( const struct GNUNET_PILS_Handle handle)

Return the current peer identity of a given handle.

Parameters
handlehandle to the pils service
Returns
Peer identity or NULL on failure

Definition at line 875 of file pils_api.c.

876{
878
879 return handle->peer_id;
880}

References GNUNET_assert, and handle.

Referenced by announce_id(), cb_path_signed(), check_dv_box(), check_dv_learn(), decaps_dv_box_cont(), decrypt_and_check_tc(), dir_ready_cb(), do_initial_dht_put(), do_rekey(), encapsulate_for_dv(), find_proof(), forward_dv_learn(), forward_reply(), GCCH_bind(), GCCH_channel_local_new(), GCPP_try_path_from_dht(), GCT_alice_or_betty(), GDS_CLIENTS_handle_reply(), GDS_NEIGHBOURS_get_id(), GDS_NEIGHBOURS_handle_get(), GDS_NEIGHBOURS_handle_put(), GDS_NEIGHBOURS_handle_reply(), GDS_try_connect(), GDS_u_connect(), get_next_free_ctn(), got_hello(), GSC_CLIENTS_solicit_request(), GSC_complete_initialization_cb(), GSC_KX_start(), GSC_SESSIONS_dequeue_request(), GSF_peer_connect_handler(), handle_backchannel_encapsulation(), handle_client_init(), handle_client_send_request(), handle_communicator_available(), handle_connection_create(), handle_core_connect(), handle_core_disconnect(), handle_dht_local_get(), handle_dht_local_hello_get(), handle_dht_local_put(), handle_dht_p2p_get(), handle_dht_p2p_put(), handle_dht_p2p_result(), handle_dv_box(), handle_dv_learn(), handle_find_my_hello(), handle_hello_for_client(), handle_hello_for_incoming(), handle_p2p_estimate(), handle_port_open(), handle_suggest(), handle_transport_notify_connect(), handshake_monotime_cb(), iface_proc(), inject_rekey(), learn_dv_path(), mq_send(), peerinfo_cb(), pid_change_cb(), pid_change_cb(), pils_id_change_cb(), pils_pid_change_cb(), pils_sign_address(), recv_rx_key_cb(), regex_iterator(), route_message(), run(), send_broken_without_mqm(), send_challenge(), send_create(), send_initiator_hello(), send_msg_with_kx(), setup_flood_message(), setup_in_cipher(), setup_in_cipher_elligator(), sock_read(), sock_read(), start_dv_learn(), store_pi(), tokenized_cb(), transmit_kx(), try_connection_reversal(), try_handle_plaintext(), update_flood_message(), and verify_confirmation().

◆ GNUNET_PILS_get_identity_hash()

const struct GNUNET_HashCode * GNUNET_PILS_get_identity_hash ( const struct GNUNET_PILS_Handle handle)

Return the hash of the current peer identity from a given handle.

Parameters
handlehandle to the pils service
Returns
Peer identity hash or NULL on failure

Definition at line 884 of file pils_api.c.

885{
887
888 if (NULL == handle->peer_id)
889 return NULL;
890
891 return &handle->peer_hash;
892}

References GNUNET_assert, and handle.

Referenced by find_bucket(), GDS_am_closest_peer(), GDS_DATACACHE_handle_put(), GDS_NEIGHBOURS_handle_get(), GDS_NEIGHBOURS_handle_put(), handle_find_my_hello(), handle_initiator_hello(), handle_initiator_hello_cont(), restart_kx(), select_peer(), and send_find_peer_message().

Here is the caller graph for this function:

◆ GNUNET_PILS_enable_private_key()

enum GNUNET_GenericReturnValue GNUNET_PILS_enable_private_key ( struct GNUNET_PILS_Handle handle)

Enable local access to the private key of the current peer identity.

Loads the peer's master key from [PEER]/PRIVATE_KEY (the same file the PILS service itself uses) and derives the private key belonging to the current peer identity from it, re-deriving it whenever the peer identity changes. This lets a caller sign directly with GNUNET_CRYPTO_eddsa_sign() instead of round-tripping through the service with GNUNET_PILS_sign_by_peer_identity(), which is what you want when the signature is needed in the middle of a synchronous operation.

Only call this from components that may hold the peer's private key.

Parameters
handlehandle to the pils service
Returns
GNUNET_OK on success, GNUNET_SYSERR if the key could not be loaded (the handle stays usable, just without local key access)

Definition at line 896 of file pils_api.c.

897{
898 char *keyfile;
900
902 if (handle->have_ikm)
903 return GNUNET_OK; /* already enabled */
904 if (GNUNET_OK !=
906 "PEER",
907 "PRIVATE_KEY",
908 &keyfile))
909 {
911 "PEER",
912 "PRIVATE_KEY");
913 return GNUNET_SYSERR;
914 }
915 if (GNUNET_SYSERR ==
918 &key))
919 {
921 "Failed to load the peer's private key from `%s'\n",
922 keyfile);
923 GNUNET_free (keyfile);
924 return GNUNET_SYSERR;
925 }
926 GNUNET_free (keyfile);
927 GNUNET_assert (sizeof (handle->initial_key_material) == sizeof (key.d));
928 memcpy (handle->initial_key_material,
929 key.d,
930 sizeof (handle->initial_key_material));
932 sizeof (key));
933 handle->have_ikm = true;
934 /* If the service already told us our identity, catch up now so that
935 callers do not have to wait for the next PID change. */
936 if (NULL != handle->peer_id)
938 return GNUNET_OK;
939}
struct GNUNET_HashCode key
The key used in the DHT.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_key_from_file(const char *filename, int do_create, struct GNUNET_CRYPTO_EddsaPrivateKey *pkey)
Create a new private key by reading it from a file.
@ GNUNET_YES
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Definition vpn_api.c:39

References GNUNET_VPN_Handle::cfg, derive_private_key(), GNUNET_assert, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CRYPTO_eddsa_key_from_file(), GNUNET_CRYPTO_zero_keys(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_config_missing(), GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, handle, key, and LOG.

Referenced by GSC_KX_start(), run(), and run().

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

◆ GNUNET_PILS_get_private_key()

const struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_PILS_get_private_key ( const struct GNUNET_PILS_Handle handle)

Return the private key of the current peer identity.

Requires a preceding successful call to GNUNET_PILS_enable_private_key(). The returned key belongs to the identity GNUNET_PILS_get_identity() reports and stays valid until the peer identity changes, so do not cache it across GNUNET_PILS_PidChangeCallback invocations.

Parameters
handlehandle to the pils service
Returns
the private key, or NULL if local key access was not enabled, no peer identity is known yet, or the loaded key does not match the identity announced by the service

Definition at line 943 of file pils_api.c.

944{
946
947 return handle->private_key;
948}

References GNUNET_assert, and handle.

Referenced by GDS_NEIGHBOURS_handle_put(), GDS_NEIGHBOURS_handle_reply(), handle_dv_box(), handle_initiator_hello(), handle_responder_hello(), and sign_by_my_identity().

Here is the caller graph for this function:

◆ pid_change_cb()

void pid_change_cb ( void *  cls,
const struct GNUNET_HELLO_Parser parser,
const struct GNUNET_HashCode addr_hash 
)

Definition at line 952 of file pils_api.c.

955{
958
959 GNUNET_assert ((cls) && (addr_hash));
960
961 key_ring = cls;
962
964 "Got PID to derive from `%s':\n",
965 GNUNET_h2s (addr_hash));
966 if (NULL == key_ring->private_key)
967 {
970 }
971 else
973
976 addr_hash,
981 sizeof (key_ring->identity),
982 &(key_ring->hash));
983
984
986 &(key_ring->identity)));
987
988 if (GNUNET_YES != initialized)
989 return;
990
991 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialize key ring\n");
992
993 if (key_ring->init_cb)
995}
static struct GNUNET_PILS_KeyRing * key_ring
For PILS.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_NO
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
Definition pils_api.c:875
static int initialized
Have we been initialized?
Definition plugin.c:57
A simplified handle for using the peer identity key.
Definition pils_api.c:149
struct GNUNET_CRYPTO_EddsaPrivateKey * private_key
Private key.
Definition pils_api.c:173
GNUNET_SCHEDULER_TaskCallback init_cb
Initial callback.
Definition pils_api.c:158
struct GNUNET_HashCode hash
Hash of peer identity.
Definition pils_api.c:183
struct GNUNET_PeerIdentity identity
Peer identity.
Definition pils_api.c:178
unsigned char initial_key_material[256/8]
Initial key material.
Definition pils_api.c:168
void * cls
Closure for initial callback.
Definition pils_api.c:163
struct GNUNET_PILS_Handle * pils
PILS handle.
Definition pils_api.c:153
struct GNUNET_CRYPTO_EddsaPublicKey public_key

References GNUNET_PILS_KeyRing::cls, GNUNET_assert, GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcmp, GNUNET_new, GNUNET_NO, GNUNET_PILS_derive_pid(), GNUNET_PILS_get_identity(), GNUNET_YES, GNUNET_PILS_KeyRing::hash, GNUNET_PILS_KeyRing::identity, GNUNET_PILS_KeyRing::init_cb, GNUNET_PILS_KeyRing::initial_key_material, initialized, key_ring, GNUNET_PILS_KeyRing::pils, GNUNET_PILS_KeyRing::private_key, and GNUNET_PeerIdentity::public_key.

Referenced by GNUNET_PILS_connect(), and GNUNET_PILS_create_key_ring().

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

◆ GNUNET_PILS_create_key_ring()

struct GNUNET_PILS_KeyRing * GNUNET_PILS_create_key_ring ( const struct GNUNET_CONFIGURATION_Handle cfg,
GNUNET_SCHEDULER_TaskCallback  init_cb,
void *  cls 
)

Get the initial secret key for generating the peer id.

Create a key ring handle to use the current peer identity key.

This is supposed to be generated at random once in the lifetime of a peer, so all generated peer ids use the same initial secret key to obtain the same peer id per set of addresses.

First check whether there's already a initial secret key. If so: return it. If no initial secret key exists yet, generate at random and store it where it will be found.

Definition at line 1008 of file pils_api.c.

1011{
1012 char *keyfile;
1014
1016
1017 LOG (GNUNET_ERROR_TYPE_DEBUG, "Create key ring!\n");
1018
1019 if (GNUNET_OK !=
1021 "PEER",
1022 "PRIVATE_KEY",
1023 &keyfile))
1024 {
1026 "PEER",
1027 "PRIVATE_KEY");
1028 return NULL;
1029 }
1030
1031 if (GNUNET_SYSERR ==
1033 GNUNET_YES,
1034 &key))
1035 {
1037 "Failed to setup peer's private key\n");
1038 GNUNET_free (keyfile);
1039 return NULL;
1040 }
1041
1042 GNUNET_free (keyfile);
1043
1046 if (NULL == key_ring)
1047 return NULL;
1049 key_ring->cls = cls;
1050
1051 GNUNET_assert (sizeof (key_ring->initial_key_material) == sizeof key.d);
1052
1054 if (NULL == key_ring->pils)
1055 {
1057 return NULL;
1058 }
1059
1060 memcpy (key_ring->initial_key_material, key.d,
1061 sizeof (key_ring->initial_key_material));
1062
1063 return key_ring;
1064}
struct GNUNET_PILS_Handle * GNUNET_PILS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_PILS_PidChangeCallback pid_change_cb, void *cls)
Connect to the PILS service.
Definition pils_api.c:624
static void init_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity)

References cfg, GNUNET_PILS_KeyRing::cls, GNUNET_assert, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CRYPTO_eddsa_key_from_file(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_new, GNUNET_OK, GNUNET_PILS_connect(), GNUNET_SYSERR, GNUNET_YES, init_cb(), GNUNET_PILS_KeyRing::init_cb, GNUNET_PILS_KeyRing::initial_key_material, key, key_ring, LOG, pid_change_cb(), and GNUNET_PILS_KeyRing::pils.

Referenced by run(), and run().

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

◆ GNUNET_PILS_destroy_key_ring()

void GNUNET_PILS_destroy_key_ring ( struct GNUNET_PILS_KeyRing key_ring)

Destroy a key ring handle and free its memory.

Parameters
key_ringkey ring handle

Definition at line 1068 of file pils_api.c.

1069{
1071
1072 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroy key ring!\n");
1073
1074 if (key_ring->pils)
1076
1077 if (key_ring->private_key)
1078 {
1080 sizeof (*(key_ring->private_key)));
1082 }
1083
1085 sizeof (key_ring->initial_key_material));
1087}
void GNUNET_PILS_disconnect(struct GNUNET_PILS_Handle *handle)
Disconnect from the PILS service.
Definition pils_api.c:647

References GNUNET_assert, GNUNET_CRYPTO_zero_keys(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_PILS_disconnect(), GNUNET_PILS_KeyRing::initial_key_material, key_ring, LOG, GNUNET_PILS_KeyRing::pils, and GNUNET_PILS_KeyRing::private_key.

Referenced by do_shutdown(), and do_shutdown().

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

◆ GNUNET_PILS_key_ring_get_private_key()

const struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_PILS_key_ring_get_private_key ( const struct GNUNET_PILS_KeyRing key_ring)

Return the current private key of a given key ring handle.

Parameters
key_ringkey ring handle
Returns
Private key or NULL on failure

Definition at line 1091 of file pils_api.c.

1093{
1095
1096 return key_ring->private_key;
1097}

References GNUNET_assert, key_ring, and GNUNET_PILS_KeyRing::private_key.

Referenced by iface_proc(), inject_rekey(), send_challenge(), send_msg_with_kx(), setup_in_cipher(), setup_in_cipher_elligator(), setup_initial_shared_secret_dec(), setup_shared_secret_dec(), and transmit_kx().

Here is the caller graph for this function: