GNUnet 0.27.0
 
Loading...
Searching...
No Matches
pils_api.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2024, 2026 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
33#include <string.h>
34#include <stdint.h>
35#include "gnunet_common.h"
36#include "gnunet_protocols.h"
37#include "gnunet_signatures.h"
38#include "gnunet_util_lib.h"
40#include "gnunet_pils_service.h"
41#include "pils.h"
42
43/* Shorthand for Logging */
44#define LOG(kind, ...) GNUNET_log_from (kind, "pils-api", __VA_ARGS__)
45
46
48{
49 // DLL
51
52 // DLL
54
55 // Service handle
57
58 // Decaps callback
60
61 // Ecdh callback
63
64 // Sign callback
66
67 // Decaps callback closure
68 void *cb_cls;
69
70 // Current message to send
72
73 // Op ID
74 uint32_t op_id;
75};
76
77
82{
83 /* The handle to the configuration */
85
86 /* Callback called with the new peer id */
88
89 /* Closure to the #pid_change_cb callback */
91
92 /* Task regularly trying to connect to the service */
94
95 /* Delay until the next reconnect */
97
98 /* Handle to the mq to communicate with the service */
100
101 /* The current peer_id */
103
104 /* The current peer id hash */
106
107 /* The hash from the last set of addresses fed to PILS. */
109
114
119
124
125};
126
127
168
176static struct GNUNET_PILS_Operation *
177find_op (struct GNUNET_PILS_Handle *h, uint32_t rid)
178{
180
181 for (op = h->op_head; op != NULL; op = op->next)
182 if (op->op_id == rid)
183 return op;
185 "Finding request with id %u was unsuccessful\n",
186 rid);
187 return NULL;
188}
189
190
197static int
198check_peer_id (void *cls, const struct PeerIdUpdateMessage *msg)
199{
200 size_t msg_size;
201 uint32_t block_bytes;
202 (void) cls;
203
204 msg_size = ntohs (msg->header.size);
205 block_bytes = ntohl (msg->block_len);
206 if (msg_size != sizeof (*msg) + block_bytes)
207 {
209 "The msg_size (%lu) is not %lu (header) + %u (block)\n",
210 msg_size,
211 sizeof (*msg),
212 block_bytes);
213 return GNUNET_SYSERR;
214 }
215 return GNUNET_OK;
216
217}
218
219
226static void
227handle_peer_id (void *cls, const struct PeerIdUpdateMessage *pid_msg)
228{
229 struct GNUNET_PILS_Handle *h = cls;
230 struct GNUNET_HELLO_Parser *parser;
231 uint32_t block_bytes;
232
233 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
234 block_bytes = ntohl (pid_msg->block_len);
235 parser = GNUNET_HELLO_parser_from_block (&pid_msg[1],
236 block_bytes);
237 if (NULL == parser)
238 {
240 "Error parsing Hello block from PILS!\n");
241 return;
242 }
243
244 if (NULL == h->peer_id)
245 h->peer_id = GNUNET_new (struct GNUNET_PeerIdentity);
246
247 memcpy (&h->hash, &pid_msg->hash, sizeof (struct GNUNET_HashCode));
248 memcpy (h->peer_id, GNUNET_HELLO_parser_get_id (parser),
249 sizeof (struct GNUNET_PeerIdentity));
250 GNUNET_CRYPTO_hash (h->peer_id, sizeof (struct GNUNET_PeerIdentity),
251 &h->peer_hash);
252
253 if (NULL != h->pid_change_cb)
254 {
255 h->pid_change_cb (h->pid_change_cb_cls,
256 parser,
257 &pid_msg->hash);
258 }
260}
261
262
269static void
270handle_sign_result (void *cls, const struct SignResultMessage *msg)
271{
272 struct GNUNET_PILS_Handle *h = cls;
274
275 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
276 op = find_op (h, ntohl (msg->rid));
277
279 "Received SIGN_RESULT message from service\n");
280
281 if (NULL == op)
282 {
284 "Didn't find the operation corresponding to id %u\n",
285 ntohl (msg->rid));
286 return;
287 }
288 if (NULL != op->sign_cb)
289 {
290 // FIXME maybe return NULL of key is 0ed
291 // as this indicates an error
292 op->sign_cb (op->cb_cls,
293 &msg->peer_id,
294 &msg->sig);
295 }
297 h->op_tail,
298 op);
299 GNUNET_free (op);
300}
301
302
309static void
311{
312 struct GNUNET_PILS_Handle *h = cls;
314
316 "Received KEM_DECAPS result from service!\n");
317
318 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
319 op = find_op (h, ntohl (msg->rid));
320
321 if (NULL == op)
322 {
324 "Didn't find the operation corresponding to id %u\n",
325 ntohl (msg->rid));
326 return;
327 }
328 if (NULL != op->decaps_cb)
329 {
330 // FIXME maybe return NULL of key is 0ed
331 // as this indicates an error
332 op->decaps_cb (op->cb_cls,
333 &msg->key);
334 }
336 h->op_tail,
337 op);
338 GNUNET_free (op);
339}
340
341
348static void
349handle_ecdh_result (void *cls, const struct EcdhResultMessage *msg)
350{
351 struct GNUNET_PILS_Handle *h = cls;
353
355 "Received ECDH result from service!\n");
356
357 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
358 op = find_op (h, ntohl (msg->rid));
359
360 if (NULL == op)
361 {
363 "Didn't find the operation corresponding to id %u\n",
364 ntohl (msg->rid));
365 return;
366 }
367 if (NULL != op->ecdh_cb)
368 op->ecdh_cb (op->cb_cls,
369 &msg->key);
371 h->op_tail,
372 op);
373 GNUNET_free (op);
374}
375
376
382static void
383reconnect (void *cls);
384
385
393static void
394mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
395{
396 struct GNUNET_PILS_Handle *h = cls;
397 (void) error;
398
399 // TODO logging
401 "Connection to pils service failed!\n");
403 h->mq = NULL;
405 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
406 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
407}
408
409
415static void
416reconnect (void *cls)
417{
418 struct GNUNET_PILS_Handle *h = cls;
422 struct PeerIdUpdateMessage,
423 h),
424 GNUNET_MQ_hd_fixed_size (decaps_result,
426 struct DecapsResultMessage,
427 h),
428 GNUNET_MQ_hd_fixed_size (ecdh_result,
430 struct EcdhResultMessage,
431 h),
432 GNUNET_MQ_hd_fixed_size (sign_result,
434 struct SignResultMessage,
435 h),
437 };
438
439 h->reconnect_task = NULL;
441 "Connecting to peer identity lifecycle service.\n");
442 GNUNET_assert (NULL == h->mq);
444 "pils",
445 handlers,
447 h);
448 if (NULL == h->mq)
449 {
451 "Failed to connect.\n");
452 {
454 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
455 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
456 }
457 return;
458 }
460 "Connection to service successful!\n");
461}
462
463
464struct GNUNET_PILS_Handle *
467 void *cls)
468{
469 struct GNUNET_PILS_Handle *h;
470
472 h->cfg = cfg;
473 h->pid_change_cb = pid_change_cb;
474 h->pid_change_cb_cls = cls;
475 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
476 reconnect (h);
477 return h;
478}
479
480
487void
489{
491
492 GNUNET_assert (NULL != handle);
494 "Disonnecting from peer identity lifecycle service.\n");
495 if (NULL != handle->reconnect_task)
496 {
497 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
498 handle->reconnect_task = NULL;
499 }
500 if (NULL != handle->mq)
501 {
503 handle->mq = NULL;
504 }
505 LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
506 while (NULL != (op = handle->op_head))
507 {
508 GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op);
509 GNUNET_free (op);
510 }
511 if (handle->peer_id)
512 GNUNET_free (handle->peer_id);
514}
515
516
529 const struct
532 void *cb_cls)
533
534{
536 struct SignRequestMessage *msg;
537
539 op->env = GNUNET_MQ_msg_extra (msg,
540 ntohl (purpose->size),
542 op->h = handle;
543 op->sign_cb = cb;
544 op->cb_cls = cb_cls;
545 msg->rid = htonl (handle->op_id_counter++);
546 op->op_id = ntohl (msg->rid);
547 memcpy (&msg[1], purpose, ntohl (purpose->size));
549 handle->op_tail,
550 op);
551 // FIXME resend?
552 GNUNET_MQ_send (handle->mq, op->env);
553 op->env = NULL;
554 return op;
555}
556
557
569 const struct GNUNET_CRYPTO_HpkeEncapsulation *c,
571 void *cb_cls)
572{
574 struct DecapsMessage *msg;
575
578 msg->c = *c;
579 op->h = handle;
580 op->decaps_cb = cb;
581 op->cb_cls = cb_cls;
582 msg->rid = htonl (handle->op_id_counter++);
583 op->op_id = ntohl (msg->rid);
585 handle->op_tail,
586 op);
587 // FIXME resend?
588 GNUNET_MQ_send (handle->mq, op->env);
589 op->env = NULL;
590 return op;
591}
592
593
596 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
598 void *cb_cls)
599{
601 struct EcdhMessage *msg;
602
603 GNUNET_assert ((handle) && (pub));
604
607 msg->pub = *pub;
608 op->h = handle;
609 op->ecdh_cb = cb;
610 op->cb_cls = cb_cls;
611 msg->rid = htonl (handle->op_id_counter++);
612 op->op_id = ntohl (msg->rid);
614 handle->op_tail,
615 op);
616 GNUNET_MQ_send (handle->mq, op->env);
617 op->env = NULL;
618 return op;
619}
620
621
622void
624{
625 struct GNUNET_PILS_Handle *h = op->h;
626
627 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
628 if (NULL != op->env)
629 GNUNET_MQ_discard (op->env);
630 GNUNET_free (op);
631}
632
633
634void
635GNUNET_PILS_derive_pid (size_t seed_key_bytes,
636 const uint8_t seed_key[seed_key_bytes],
637 const struct GNUNET_HashCode *addrs_hash,
638 struct GNUNET_CRYPTO_EddsaPrivateKey *outkey)
639{
640 struct GNUNET_ShortHashCode prk;
641
649 addrs_hash,
650 sizeof *addrs_hash,
651 seed_key,
652 seed_key_bytes));
661 outkey,
662 sizeof *outkey,
663 &prk,
664 GNUNET_CRYPTO_kdf_arg_string ("gnunet-pils-ephemeral-peer-key"));
665}
666
667
668void
670 const struct GNUNET_HELLO_Builder *builder)
671{
673 struct GNUNET_MQ_Envelope *env;
674 size_t block_bytes;
675
677 // TODO check whether the new hash and the 'current' hash are the same -
678 // nothing to do in that case (directly return the peer id?)
680 block_bytes,
682 msg->block_len = htonl (block_bytes);
684 builder,
685 NULL,
686 NULL,
688 (char*) &msg[1]);
690}
691
692
704 const struct GNUNET_HELLO_Builder *builder,
705 struct GNUNET_TIME_Absolute et,
707 void *cb_cls)
708{
709 struct PilsHelloSignaturePurpose hsp = {
710 .purpose.size = htonl (sizeof (hsp)),
711 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
712 .expiration_time = GNUNET_TIME_absolute_hton (et)
713 };
715 &hsp.h_addrs);
717 "Address hash is %s\n",
718 GNUNET_h2s_full (&hsp.h_addrs));
720 &hsp.purpose,
721 cb,
722 cb_cls);
723}
724
725
726const struct GNUNET_PeerIdentity*
728{
730
731 return handle->peer_id;
732}
733
734
735const struct GNUNET_HashCode*
737{
739
740 if (NULL == handle->peer_id)
741 return NULL;
742
743 return &handle->peer_hash;
744}
745
746
747void
748pid_change_cb (void *cls,
749 GNUNET_UNUSED const struct GNUNET_HELLO_Parser *parser,
750 const struct GNUNET_HashCode *addr_hash)
751{
754
755 GNUNET_assert ((cls) && (addr_hash));
756
757 key_ring = cls;
758
760 "Got PID to derive from `%s':\n",
761 GNUNET_h2s (addr_hash));
762 if (NULL == key_ring->private_key)
763 {
766 }
767 else
769
772 addr_hash,
777 sizeof (key_ring->identity),
778 &(key_ring->hash));
779
780
782 &(key_ring->identity)));
783
784 if (GNUNET_YES != initialized)
785 return;
786
787 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialize key ring\n");
788
789 if (key_ring->init_cb)
791}
792
793
806 void *cls)
807{
808 char *keyfile;
810
812
813 LOG (GNUNET_ERROR_TYPE_DEBUG, "Create key ring!\n");
814
815 if (GNUNET_OK !=
817 "PEER",
818 "PRIVATE_KEY",
819 &keyfile))
820 {
822 "PEER",
823 "PRIVATE_KEY");
824 return NULL;
825 }
826
827 if (GNUNET_SYSERR ==
830 &key))
831 {
833 "Failed to setup peer's private key\n");
834 GNUNET_free (keyfile);
835 return NULL;
836 }
837
838 GNUNET_free (keyfile);
839
842 if (NULL == key_ring)
843 return NULL;
845 key_ring->cls = cls;
846
847 GNUNET_assert (sizeof (key_ring->initial_key_material) == sizeof key.d);
848
850 if (NULL == key_ring->pils)
851 {
853 return NULL;
854 }
855
858
859 return key_ring;
860}
861
862
863void
884
885
894
895
896/* end of pils_api.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition 003.c:1
struct GNUNET_MessageHeader * msg
Definition 005.c:2
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
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
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
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.
Definition gnunet-vpn.c:35
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.
Definition client.c:1060
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.
Definition crypto_ecc.c:201
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.
Definition crypto_hash.c:41
#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.
Definition hello-uri.c:380
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:1280
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:1348
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:560
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:1170
#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.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
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_free(ptr)
Wrapper around free.
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.
Definition mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition mq.c:285
#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_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#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.
Definition mq.c:700
#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.
Definition scheduler.c:986
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.
Definition scheduler.c:1283
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
#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.
Definition time.c:636
#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)
Definition pils_api.c:748
static void handle_peer_id(void *cls, const struct PeerIdUpdateMessage *pid_msg)
Handles peer ids sent from the service.
Definition pils_api.c:227
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:177
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:465
void GNUNET_PILS_disconnect(struct GNUNET_PILS_Handle *handle)
Disconnect from the PILS service.
Definition pils_api.c:488
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.
Definition pils_api.c:736
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:635
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.
Definition pils_api.c:595
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.
Definition pils_api.c:703
void GNUNET_PILS_cancel(struct GNUNET_PILS_Operation *op)
Cancel request.
Definition pils_api.c:623
static void handle_sign_result(void *cls, const struct SignResultMessage *msg)
Handles sign result.
Definition pils_api.c:270
static void handle_ecdh_result(void *cls, const struct EcdhResultMessage *msg)
Handles ecdh result.
Definition pils_api.c:349
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:528
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Handles errors with the mq.
Definition pils_api.c:394
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.
Definition pils_api.c:804
static void handle_decaps_result(void *cls, const struct DecapsResultMessage *msg)
Handles decaps result.
Definition pils_api.c:310
void GNUNET_PILS_destroy_key_ring(struct GNUNET_PILS_KeyRing *key_ring)
Destroy a key ring handle and free its memory.
Definition pils_api.c:864
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:727
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.
Definition pils_api.c:887
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.
Definition pils_api.c:568
#define LOG(kind,...)
Definition pils_api.c:44
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...
Definition pils_api.c:669
static int check_peer_id(void *cls, const struct PeerIdUpdateMessage *msg)
Handles sign result.
Definition pils_api.c:198
static int initialized
Have we been initialized?
Definition plugin.c:57
static void reconnect(void)
Adjust exponential back-off and reconnect to the service.
Message to request a decapsulation from PILS.
Definition pils.h:142
struct GNUNET_CRYPTO_HpkeEncapsulation c
Encapsulation to decapsulate.
Definition pils.h:151
Message containing the decapsulated key.
Definition pils.h:163
Message requesting a signature on data with the current peer id.
Definition pils.h:122
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition arm_api.c:107
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
struct GNUNET_ARM_Operation * next
This is a doubly-linked list.
Definition arm_api.c:45
struct GNUNET_ARM_Handle * h
ARM handle.
Definition arm_api.c:55
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.
Definition hello-uri.c:185
Context for parsing HELLOs.
Definition hello-uri.c:233
A 512-bit hashcode.
Handle to a message queue.
Definition mq.c:87
Message handler for a specific message type.
A handle for the PILS service.
Definition pils_api.c:82
struct GNUNET_PILS_Operation * op_head
DLL.
Definition pils_api.c:113
const struct GNUNET_CONFIGURATION_Handle * cfg
Definition pils_api.c:84
void * pid_change_cb_cls
Definition pils_api.c:90
struct GNUNET_HashCode peer_hash
Definition pils_api.c:105
uint32_t op_id_counter
Op ID counter.
Definition pils_api.c:123
struct GNUNET_SCHEDULER_Task * reconnect_task
Definition pils_api.c:93
struct GNUNET_TIME_Relative reconnect_delay
Definition pils_api.c:96
struct GNUNET_PILS_Operation * op_tail
DLL.
Definition pils_api.c:118
struct GNUNET_HashCode hash
Definition pils_api.c:108
GNUNET_PILS_PidChangeCallback pid_change_cb
Definition pils_api.c:87
struct GNUNET_PeerIdentity * peer_id
Definition pils_api.c:102
struct GNUNET_MQ_Handle * mq
Definition pils_api.c:99
A simplified handle for using the peer identity key.
Definition pils_api.c:132
struct GNUNET_CRYPTO_EddsaPrivateKey * private_key
Private key.
Definition pils_api.c:156
GNUNET_SCHEDULER_TaskCallback init_cb
Initial callback.
Definition pils_api.c:141
struct GNUNET_HashCode hash
Hash of peer identity.
Definition pils_api.c:166
struct GNUNET_PeerIdentity identity
Peer identity.
Definition pils_api.c:161
unsigned char initial_key_material[256/8]
Initial key material.
Definition pils_api.c:151
void * cls
Closure for initial callback.
Definition pils_api.c:146
struct GNUNET_PILS_Handle * pils
PILS handle.
Definition pils_api.c:136
struct GNUNET_PILS_Operation * next
Definition pils_api.c:50
struct GNUNET_PILS_Handle * h
Definition pils_api.c:56
GNUNET_PILS_SignResultCallback sign_cb
Definition pils_api.c:65
GNUNET_PILS_EcdhResultCallback ecdh_cb
Definition pils_api.c:62
GNUNET_PILS_DecapsResultCallback decaps_cb
Definition pils_api.c:59
struct GNUNET_PILS_Operation * prev
Definition pils_api.c:53
struct GNUNET_MQ_Envelope * env
Definition pils_api.c:71
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Entry in list of pending tasks.
Definition scheduler.c:141
A 256-bit hashcode.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_MQ_Handle * mq
Connection to VPN service.
Definition vpn_api.c:44
Message containing the current peer id and the hash from which it was generated.
Definition pils.h:40
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
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
Message to request a signature from PILS.
Definition pils.h:248
Message containing the signature.
Definition pils.h:220
static void init_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity)