44#define LOG(kind, ...) GNUNET_log_from (kind, "pils-api", __VA_ARGS__)
205 "Not connected to PILS, deferring request %u\n",
206 (
unsigned int)
op->op_id);
292 if (
op->op_id == rid)
295 "Finding request with id %u was unsuccessful\n",
311 uint32_t block_bytes;
314 msg_size = ntohs (
msg->header.
size);
315 block_bytes = ntohl (
msg->block_len);
316 if (msg_size !=
sizeof (*
msg) + block_bytes)
319 "The msg_size (%lu) is not %lu (header) + %u (block)\n",
353 if (NULL ==
h->private_key)
356 h->initial_key_material,
365 "Locally derived peer identity %s does not match %s announced by the service; check [PEER]/PRIVATE_KEY\n",
369 sizeof (*
h->private_key));
371 h->private_key = NULL;
375 "Derived private key for peer identity %s\n",
391 uint32_t block_bytes;
394 block_bytes = ntohl (pid_msg->
block_len);
400 "Error parsing Hello block from PILS!\n");
404 if (NULL ==
h->peer_id)
414 if (NULL !=
h->pid_change_cb)
416 h->pid_change_cb (
h->pid_change_cb_cls,
440 "Received SIGN_RESULT message from service\n");
445 "Didn't find the operation corresponding to id %u\n",
449 if (NULL !=
op->sign_cb)
453 op->sign_cb (
op->cb_cls,
474 "Received KEM_DECAPS result from service!\n");
482 "Didn't find the operation corresponding to id %u\n",
486 if (NULL !=
op->decaps_cb)
490 op->decaps_cb (
op->cb_cls,
510 "Received ECDH result from service!\n");
518 "Didn't find the operation corresponding to id %u\n",
522 if (NULL !=
op->ecdh_cb)
523 op->ecdh_cb (
op->cb_cls,
553 "Connection to pils service failed!\n");
599 "Connecting to peer identity lifecycle service.\n");
609 "Failed to connect.\n");
618 "Connection to service successful!\n");
633 h->pid_change_cb_cls = cls;
653 "Disonnecting from peer identity lifecycle service.\n");
654 if (NULL !=
handle->reconnect_task)
657 handle->reconnect_task = NULL;
665 while (NULL != (
op =
handle->op_head))
669 if (NULL !=
handle->private_key)
672 sizeof (*
handle->private_key));
676 sizeof (
handle->initial_key_material));
701 size_t plen = ntohl (purpose->
size);
706 msg->header.
size = htons (
sizeof (*
msg) + plen);
707 msg->rid = htonl (
handle->op_id_counter++);
708 memcpy (&
msg[1], purpose, plen);
712 op->op_id = ntohl (
msg->rid);
740 msg->rid = htonl (
handle->op_id_counter++);
744 op->op_id = ntohl (
msg->rid);
765 msg->rid = htonl (
handle->op_id_counter++);
769 op->op_id = ntohl (
msg->rid);
784 const uint8_t
seed_key[seed_key_bytes],
830 msg->block_len = htonl (block_bytes);
865 "Address hash is %s\n",
888 if (NULL ==
handle->peer_id)
891 return &
handle->peer_hash;
921 "Failed to load the peer's private key from `%s'\n",
928 memcpy (
handle->initial_key_material,
930 sizeof (
handle->initial_key_material));
936 if (NULL !=
handle->peer_id)
947 return handle->private_key;
964 "Got PID to derive from `%s':\n",
1037 "Failed to setup peer's private key\n");
struct GNUNET_MQ_MessageHandlers handlers[]
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
static struct GNUNET_ARM_Operation * op
Current operation.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static char * peer_id
Option –peer.
static struct GNUNET_PILS_KeyRing * key_ring
For PILS.
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
struct GNUNET_HashCode key
The key used in the DHT.
static uint8_t seed_key[256/8]
static struct GNUNET_CRYPTO_EddsaPublicKey pub
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
Helper library for handling HELLO URIs.
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.
void(* GNUNET_PILS_DecapsResultCallback)(void *cls, const struct GNUNET_ShortHashCode *key)
A handler/callback to be called for decaps.
void(* GNUNET_PILS_EcdhResultCallback)(void *cls, const struct GNUNET_HashCode *key)
A handler/callback to be called for ecdh.
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.
Constants for network protocols.
#define GNUNET_SIGNATURE_PURPOSE_HELLO
Signature by which a peer affirms its address.
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.
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.
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.
void GNUNET_CRYPTO_zero_keys(void *buffer, size_t length)
Zero out buffer, securely against compiler optimizations.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
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.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
#define GNUNET_CRYPTO_hkdf_expand(result, out_len, prk,...)
HKDF-Expand using SHA256.
void GNUNET_HELLO_parser_free(struct GNUNET_HELLO_Parser *parser)
Release resources of 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 *outbuf)
Generate DHT block from a builder.
size_t GNUNET_HELLO_get_builder_to_block_size(const struct GNUNET_HELLO_Builder *builder)
Get projected block size for builder.
const struct GNUNET_PeerIdentity * GNUNET_HELLO_parser_get_id(const struct GNUNET_HELLO_Parser *parser)
Get the PeerIdentity for this builder.
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_block(const void *block, size_t block_size)
Parse block.
void GNUNET_HELLO_builder_hash_addresses(const struct GNUNET_HELLO_Builder *builder, struct GNUNET_HashCode *hash)
Compute hash over addresses in builder.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
#define GNUNET_CRYPTO_kdf_arg_string(d)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_UNUSED
gcc-ism to document unused arguments
GNUNET_GenericReturnValue
Named constants for return values.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#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_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
#define GNUNET_MESSAGE_TYPE_PILS_ECDH_RESULT
Ecdh result.
#define GNUNET_MESSAGE_TYPE_PILS_SIGN_REQUEST
The client requests data to be signed with the peer identity.
#define GNUNET_MESSAGE_TYPE_PILS_ECDH
Ecdh request.
#define GNUNET_MESSAGE_TYPE_PILS_KEM_DECAPS
Decaps request.
#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.
#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.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
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.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
Common type definitions for the peer identity lifecycle service and API.
void pid_change_cb(void *cls, const struct GNUNET_HELLO_Parser *parser, const struct GNUNET_HashCode *addr_hash)
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.
static void op_destroy(struct GNUNET_PILS_Operation *op)
Remove op from its handle and free it.
static void transmit_op(struct GNUNET_PILS_Operation *op)
Send the request of op to the service, if we are connected.
static void handle_peer_id(void *cls, const struct PeerIdUpdateMessage *pid_msg)
Handles peer ids sent from the service.
static struct GNUNET_PILS_Operation * find_op(struct GNUNET_PILS_Handle *h, uint32_t rid)
Find the op that matches the rid.
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.
void GNUNET_PILS_disconnect(struct GNUNET_PILS_Handle *handle)
Disconnect from the PILS service.
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.
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.
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.
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.
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.
void GNUNET_PILS_cancel(struct GNUNET_PILS_Operation *op)
Cancel request.
static void handle_sign_result(void *cls, const struct SignResultMessage *msg)
Handles sign result.
static void handle_ecdh_result(void *cls, const struct EcdhResultMessage *msg)
Handles ecdh result.
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.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Handles errors with the mq.
static void flush_ops(struct GNUNET_PILS_Handle *h)
(Re-)transmit every outstanding request of h.
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.
static void handle_decaps_result(void *cls, const struct DecapsResultMessage *msg)
Handles decaps result.
void GNUNET_PILS_destroy_key_ring(struct GNUNET_PILS_KeyRing *key_ring)
Destroy a key ring handle and free its memory.
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
static void derive_private_key(struct GNUNET_PILS_Handle *h)
Re-derive the private key of the current peer identity of h.
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.
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.
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 addr...
static int check_peer_id(void *cls, const struct PeerIdUpdateMessage *msg)
Handles sign result.
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.
static int initialized
Have we been initialized?
static void reconnect(void)
Adjust exponential back-off and reconnect to the service.
Message to request a decapsulation from PILS.
struct GNUNET_CRYPTO_HpkeEncapsulation c
Encapsulation to decapsulate.
Message containing the decapsulated key.
Message requesting a signature on data with the current peer id.
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
struct GNUNET_ARM_Operation * next
This is a doubly-linked list.
struct GNUNET_ARM_Handle * h
ARM handle.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Private ECC key encoded for transmission.
HPKE DHKEM encapsulation (X25519) See RFC 9180.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
Context for building (or parsing) HELLO URIs.
Context for parsing HELLOs.
Handle to a message queue.
Message handler for a specific message type.
A handle for the PILS service.
struct GNUNET_PILS_Operation * op_head
DLL.
const struct GNUNET_CONFIGURATION_Handle * cfg
struct GNUNET_HashCode peer_hash
uint32_t op_id_counter
Op ID counter.
struct GNUNET_SCHEDULER_Task * reconnect_task
struct GNUNET_CRYPTO_EddsaPrivateKey * private_key
struct GNUNET_TIME_Relative reconnect_delay
struct GNUNET_PILS_Operation * op_tail
DLL.
struct GNUNET_HashCode hash
GNUNET_PILS_PidChangeCallback pid_change_cb
struct GNUNET_PeerIdentity * peer_id
struct GNUNET_MQ_Handle * mq
unsigned char initial_key_material[256/8]
A simplified handle for using the peer identity key.
struct GNUNET_CRYPTO_EddsaPrivateKey * private_key
Private key.
GNUNET_SCHEDULER_TaskCallback init_cb
Initial callback.
struct GNUNET_HashCode hash
Hash of peer identity.
struct GNUNET_PeerIdentity identity
Peer identity.
unsigned char initial_key_material[256/8]
Initial key material.
void * cls
Closure for initial callback.
struct GNUNET_PILS_Handle * pils
PILS handle.
struct GNUNET_PILS_Operation * next
struct GNUNET_PILS_Handle * h
GNUNET_PILS_SignResultCallback sign_cb
GNUNET_PILS_EcdhResultCallback ecdh_cb
struct GNUNET_MessageHeader * req
GNUNET_PILS_DecapsResultCallback decaps_cb
struct GNUNET_PILS_Operation * prev
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Entry in list of pending tasks.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
struct GNUNET_MQ_Handle * mq
Connection to VPN service.
Message containing the current peer id and the hash from which it was generated.
struct GNUNET_HashCode hash
The hash from which the peer id was generated.
uint32_t block_len
Length of the HELLO block in bytes.
Message signed as part of a HELLO block/URL.
struct GNUNET_HashCode h_addrs
Hash over all addresses.
struct GNUNET_CRYPTO_SignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_HELLO.
Message to request a signature from PILS.
Message containing the signature.
static void init_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity)