GNUnet debian-0.24.3-23-g589b01d60
gnunet_pils_service.h File Reference
Include dependency graph for gnunet_pils_service.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* GNUNET_PILS_SignResultCallback) (void *cls, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig)
 A handler/callback to be called for signatures. More...
 
typedef void(* GNUNET_PILS_SignAddrResultCallback) (void *cls, void *result, size_t result_size)
 A handler/callback to be called for signatures on addresses. More...
 
typedef void(* GNUNET_PILS_DecapsResultCallback) (void *cls, const struct GNUNET_ShortHashCode *key)
 A handler/callback to be called for decaps. More...
 
typedef void(* GNUNET_PILS_PidChangeCallback) (void *cls, const struct GNUNET_HELLO_Parser *parser, const struct GNUNET_HashCode *hash)
 A handler/callback to be called on the change of the peer id. More...
 

Functions

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. More...
 
void GNUNET_PILS_disconnect (struct GNUNET_PILS_Handle *handle)
 Disconnect from the PILS service. More...
 
struct GNUNET_PILS_OperationGNUNET_PILS_sign_by_peer_identity (struct GNUNET_PILS_Handle *handle, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, GNUNET_PILS_SignResultCallback cb, void *cb_cls)
 Sign data with the peer id. More...
 
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. More...
 
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. More...
 
void GNUNET_HELLO_builder_hash_addresses (const struct GNUNET_HELLO_Builder *builder, struct GNUNET_HashCode *address_hash)
 Hash address in buidler. More...
 
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. More...
 
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. More...
 
void GNUNET_PILS_cancel (struct GNUNET_PILS_Operation *op)
 Cancel request. More...
 

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.

Note: Currently the signatures are actually made in the api. TODO is it fine this way?

Definition in file gnunet_pils_service.h.

Typedef Documentation

◆ GNUNET_PILS_SignResultCallback

typedef void(* GNUNET_PILS_SignResultCallback) (void *cls, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig)

A handler/callback to be called for signatures.

The peer identity may have been changed by PILS in the meantime, so the identity that was used to sign is returned here.

Parameters
clsThe closure given to #GNUNET_PILS_sign
pidthe peer identity that produced the signature
sigthe signature, NULL on error

Definition at line 62 of file gnunet_pils_service.h.

◆ GNUNET_PILS_SignAddrResultCallback

typedef void(* GNUNET_PILS_SignAddrResultCallback) (void *cls, void *result, size_t result_size)

A handler/callback to be called for signatures on addresses.

Parameters
clsThe closure given to #GNUNET_PILS_sign
resultallocated address record
result_sizesize of result

Definition at line 74 of file gnunet_pils_service.h.

◆ GNUNET_PILS_DecapsResultCallback

typedef void(* GNUNET_PILS_DecapsResultCallback) (void *cls, const struct GNUNET_ShortHashCode *key)

A handler/callback to be called for decaps.

Parameters
clsThe closure given to GNUNET_PILS_kem_decaps
keyThe decapsulated key

Definition at line 85 of file gnunet_pils_service.h.

◆ GNUNET_PILS_PidChangeCallback

typedef void(* GNUNET_PILS_PidChangeCallback) (void *cls, const struct GNUNET_HELLO_Parser *parser, const struct GNUNET_HashCode *hash)

A handler/callback to be called on the change of the peer id.

Parameters
clsThe closure given to GNUNET_PILS_connect
parsera parsed HELLO block that represents the new PID
hashThe hash of addresses the peer id is based on. This hash is also returned by #GNUNET_PILS_feed_address.

Definition at line 97 of file gnunet_pils_service.h.

Function Documentation

◆ 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 367 of file pils_api.c.

370{
371 struct GNUNET_PILS_Handle *h;
372
374 h->cfg = cfg;
375 h->pid_change_cb = pid_change_cb;
376 h->pid_change_cb_cls = cls;
377 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
378 reconnect (h);
379 return h;
380}
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
void pid_change_cb(void *cls, const struct GNUNET_HELLO_Parser *hparser, const struct GNUNET_HashCode *addr_hash)
Definition: gnunet-pils.c:64
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
static void reconnect(void *cls)
Try again to connect to peer identity lifecycle service.
Definition: pils_api.c:321
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
A handle for the PILS service.
Definition: pils_api.c:82

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

Referenced by GCH_init(), GSC_KX_init(), 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 390 of file pils_api.c.

391{
393
394 GNUNET_assert (NULL != handle);
396 "Disonnecting from peer identity lifecycle service.\n");
397 if (NULL != handle->reconnect_task)
398 {
399 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
400 handle->reconnect_task = NULL;
401 }
402 if (NULL != handle->mq)
403 {
405 handle->mq = NULL;
406 }
407 LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
408 while (NULL != (op = handle->op_head))
409 {
410 GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op);
411 GNUNET_free (op);
412 }
414}
struct GNUNET_PILS_Operation * op
PILS op.
Definition: gnunet-hello.c:94
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
#define LOG(kind,...)
Definition: pils_api.c:44
struct GNUNET_MQ_Handle * mq
Connection to VPN service.
Definition: vpn_api.c:44

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

Referenced by cleaning_task(), do_shutdown(), GCH_shutdown(), GSC_KX_done(), 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_EccSignaturePurpose purpose,
GNUNET_PILS_SignResultCallback  cb,
void *  cb_cls 
)

Sign data with the peer id.

TODO not sure whether this was the intended design from last meeting - this is currently following the design of GNUNET_CRYPTO_sign_by_peer_identity

In particular we currently transfer the secret key from the service to the api so we can sign in-place and have no ipc-overhead. Is this fine?

Parameters
handlehandle to the PILS service
purposewhat to sign (size, purpose and data) TODO improve wording - look at GNUNET_CRYPTO_eddsa_sign
cbsignature result callback
cb_clsclosure for the cb
Returns
handle to the operation, NULL on error
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 428 of file pils_api.c.

434{
436 struct SignRequestMessage *msg;
437
440 ntohl (purpose->size),
442 op->h = handle;
443 op->sign_cb = cb;
444 op->sign_cb_cls = cb_cls;
445 msg->rid = htonl (handle->op_id_counter++);
446 op->op_id = ntohl (msg->rid);
447 memcpy (&msg[1], purpose, ntohl (purpose->size));
449 handle->op_tail,
450 op);
451 // FIXME resend?
453 op->env = NULL;
454 return op;
455}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
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:305
#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:61
#define GNUNET_MESSAGE_TYPE_PILS_SIGN_REQUEST
The client requests data to be signed with the peer identity.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
struct GNUNET_PILS_Handle * h
Definition: pils_api.c:56
GNUNET_PILS_SignResultCallback sign_cb
Definition: pils_api.c:65
struct GNUNET_MQ_Envelope * env
Definition: pils_api.c:71
Message to request a signature from PILS.
Definition: pils.h:213

References GNUNET_PILS_Operation::env, GNUNET_CONTAINER_DLL_insert, GNUNET_MESSAGE_TYPE_PILS_SIGN_REQUEST, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_new, GNUNET_PILS_Operation::h, handle, GNUNET_VPN_Handle::mq, msg, op, GNUNET_PILS_Operation::op_id, GNUNET_PILS_Operation::sign_cb, GNUNET_PILS_Operation::sign_cb_cls, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by forward_dv_learn(), GNUNET_PILS_sign_hello(), handle_validation_challenge(), pils_sign_address(), sign_ephemeral(), start_dv_learn(), 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.

TODO whether it's fine to use the private key in this way needs to be discussed. If not, another key (which has been signed with this id) needs to be used for en-/decapsulating.

Parameters
handlehandle to the PILS service
cthe encapsulated key
cbthe callback to call with the decapsulated key
cb_clscallback closure
Returns
handle to the operation, NULL on error
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 468 of file pils_api.c.

472{
474 struct DecapsMessage *msg;
475
478 msg->c = *c;
479 op->h = handle;
480 op->decaps_cb = cb;
481 op->decaps_cb_cls = cb_cls;
482 msg->rid = htonl (handle->op_id_counter++);
483 op->op_id = ntohl (msg->rid);
485 handle->op_tail,
486 op);
487 // FIXME resend?
489 op->env = NULL;
490 return op;
491}
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:76
#define GNUNET_MESSAGE_TYPE_PILS_KEM_DECAPS
Decaps request.
Message to request a decapsulation from PILS.
Definition: pils.h:143
struct GNUNET_CRYPTO_HpkeEncapsulation c
Encapsulation to decapsulate.
Definition: pils.h:152
GNUNET_PILS_DecapsResultCallback decaps_cb
Definition: pils_api.c:59

References DecapsMessage::c, GNUNET_PILS_Operation::decaps_cb, GNUNET_PILS_Operation::decaps_cb_cls, GNUNET_PILS_Operation::env, GNUNET_CONTAINER_DLL_insert, GNUNET_MESSAGE_TYPE_PILS_KEM_DECAPS, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_new, GNUNET_PILS_Operation::h, handle, GNUNET_VPN_Handle::mq, msg, op, and GNUNET_PILS_Operation::op_id.

Referenced by handle_dv_box(), handle_initiator_hello(), and handle_responder_hello().

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 542 of file pils_api.c.

544{
546 struct GNUNET_MQ_Envelope *env;
547 size_t block_bytes;
548
550 // TODO check whether the new hash and the 'current' hash are the same -
551 // nothing to do in that case (directly return the peer id?)
553 block_bytes,
555 msg->block_len = htonl (block_bytes);
557 builder,
558 NULL,
559 NULL,
561 (char*) &msg[1]);
563}
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:1244
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:1312
#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:123

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_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 coutner to the initial secret key to the above PRF.

Definition at line 507 of file pils_api.c.

511{
512 struct GNUNET_ShortHashCode prk;
513
521 addrs_hash,
522 sizeof *addrs_hash,
523 seed_key,
524 seed_key_bytes));
533 sizeof *outkey,
534 &prk,
535 "gnunet-pils-ephemeral-peer-key",
536 strlen ("gnunet-pils-ephemeral-peer-key"),
537 NULL, 0);
538}
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.
Definition: crypto_hkdf.c:224
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_expand(void *result, size_t out_len, const struct GNUNET_ShortHashCode *prk,...)
HKDF-Expand using SHA256.
Definition: crypto_hkdf.c:156
@ GNUNET_OK
A 256-bit hashcode.

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

Referenced by 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_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
handlehande 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 576 of file pils_api.c.

581{
582 struct PilsHelloSignaturePurpose hsp = {
583 .purpose.size = htonl (sizeof (hsp)),
584 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
585 .expiration_time = GNUNET_TIME_absolute_hton (et)
586 };
588 &hsp.h_addrs);
590 "Address hash is %s\n",
591 GNUNET_h2s_full (&hsp.h_addrs));
593 &hsp.purpose,
594 cb,
595 cb_cls);
596}
#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:1134
#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:640
struct GNUNET_PILS_Operation * GNUNET_PILS_sign_by_peer_identity(struct GNUNET_PILS_Handle *handle, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, GNUNET_PILS_SignResultCallback cb, void *cb_cls)
Sign data with the peer id.
Definition: pils_api.c:428
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 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_EccSignaturePurpose::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_cancel()

void GNUNET_PILS_cancel ( struct GNUNET_PILS_Operation op)

Cancel request.

Parameters
opcancel PILS operation

Definition at line 495 of file pils_api.c.

496{
497 struct GNUNET_PILS_Handle *h = op->h;
498
499 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
500 if (NULL != op->env)
502 GNUNET_free (op);
503}
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:285

References GNUNET_PILS_Operation::env, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_discard(), h, GNUNET_PILS_Operation::h, and op.

Referenced by do_shutdown(), GCH_shutdown(), GSC_KX_done(), and shutdown_task().

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