GNUnet debian-0.24.3-23-g589b01d60
gnunet-service-pils.c File Reference

peer identity lifecycle service More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_protocols.h"
#include "gnunet_signatures.h"
#include "gnunet_pils_service.h"
#include "pils.h"
Include dependency graph for gnunet-service-pils.c:

Go to the source code of this file.

Data Structures

struct  P_Client
 Data structure for each client connected to the CORE service. More...
 

Macros

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

Functions

static void load_ikm ()
 Get the initial secret key for generating the peer id. More...
 
static void print_uri (void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
 
static void do_generate_pid (const struct GNUNET_HELLO_Parser *parser)
 Generate the peer id from the addresses hash and the initial secret key. More...
 
static int check_feed_addresses (void *cls, const struct FeedAddressesMessage *msg)
 Checker for feed messages. More...
 
static void handle_feed_addresses (void *cls, const struct FeedAddressesMessage *message)
 Handler for feed addresses message from client. More...
 
static void handle_decaps (void *cls, const struct DecapsMessage *message)
 Handler for decaps request message from client. More...
 
static int check_sign (void *cls, const struct SignRequestMessage *msg)
 Handler for sign request message from client. More...
 
static void handle_sign (void *cls, const struct SignRequestMessage *message)
 Handler for sign request message from client. More...
 
static void shutdown_task (void *cls)
 Task run during shutdown. More...
 
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
 Set up the service. More...
 
static void * client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)
 Callback called when a client connects to the service. More...
 
static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)
 Callback called when a client disconnected from the service. More...
 
 GNUNET_SERVICE_MAIN (GNUNET_OS_project_data_gnunet(), "pils", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(feed_addresses, GNUNET_MESSAGE_TYPE_PILS_FEED_ADDRESSES, struct FeedAddressesMessage, NULL), GNUNET_MQ_hd_fixed_size(decaps, GNUNET_MESSAGE_TYPE_PILS_KEM_DECAPS, struct DecapsMessage, NULL), GNUNET_MQ_hd_var_size(sign, GNUNET_MESSAGE_TYPE_PILS_SIGN_REQUEST, struct SignRequestMessage, NULL), GNUNET_MQ_handler_end())
 Define "main" method using service macro. More...
 

Variables

static const struct GNUNET_CONFIGURATION_Handlecfg
 Handle to our current configuration. More...
 
static struct GNUNET_SCHEDULER_Taskgenerate_pid_task
 Task to schedule the generation of the peer id. More...
 
struct GNUNET_HashCode addresses_hash
 Hash of the canonicalized addresses. More...
 
struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
 The current private key. More...
 
struct GNUNET_CRYPTO_EddsaPublicKey my_public_key
 The current public key. More...
 
static unsigned char ikm [256/8]
 The initial key material for the peer. More...
 
static struct P_Clientclients_head
 Head of the liked list of clients. More...
 
static struct P_Clientclients_tail
 Tail of the liked list of clients. More...
 
static int have_id
 Peer ID was calculated already at least once. More...
 
static struct GNUNET_MQ_Envelopesigned_hello
 Current signed HELLO. More...
 

Detailed Description

peer identity lifecycle service

Author
ch3
Martin Schanzenbach

This 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 gnunet-service-pils.c.

Macro Definition Documentation

◆ LOG

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

Definition at line 41 of file gnunet-service-pils.c.

Function Documentation

◆ load_ikm()

static void load_ikm ( )
static

Get the initial secret key for generating the peer id.

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 optain 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.

Parameters
initialsecret key the memory the initial secret key can be written to.

Definition at line 140 of file gnunet-service-pils.c.

141{
142 char *keyfile;
144
145 if (GNUNET_OK !=
147 "PEER",
148 "PRIVATE_KEY",
149 &keyfile))
150 {
152 "PEER",
153 "PRIVATE_KEY");
155 return;
156 }
157 if (GNUNET_SYSERR ==
160 &key))
161 {
163 "Failed to setup peer's private key\n");
164 GNUNET_free (keyfile);
166 return;
167 }
168 GNUNET_free (keyfile);
169 GNUNET_assert (sizeof ikm == sizeof key.d);
170 memcpy (ikm, key.d, sizeof ikm);
171}
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned char ikm[256/8]
The initial key material for the peer.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to our current configuration.
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.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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_ERROR
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
Private ECC key encoded for transmission.

References cfg, GNUNET_assert, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CRYPTO_eddsa_key_from_file(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_OK, GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, GNUNET_YES, ikm, and key.

Referenced by run().

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

◆ print_uri()

static void print_uri ( void *  cls,
const struct GNUNET_PeerIdentity pid,
const char *  uri 
)
static

Definition at line 174 of file gnunet-service-pils.c.

177{
179 "%s\n", uri);
180}
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
#define LOG(kind,...)
@ GNUNET_ERROR_TYPE_DEBUG

References GNUNET_ERROR_TYPE_DEBUG, LOG, and uri.

Referenced by do_generate_pid().

Here is the caller graph for this function:

◆ do_generate_pid()

static void do_generate_pid ( const struct GNUNET_HELLO_Parser parser)
static

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

Notify all subscribed clients with the new peer id.

Parameters
clsClosure - unused.

Definition at line 190 of file gnunet-service-pils.c.

191{
193 struct GNUNET_HashCode new_addresses_hash;
194 LOG (GNUNET_ERROR_TYPE_INFO, "Going to generate a new peer id\n");
195 generate_pid_task = NULL;
196
197 if (NULL == parser)
198 {
200 }
201 else
202 {
204 }
206 "Got new address list to derive PID:\n");
209 &new_addresses_hash);
210 /*if (0 == GNUNET_CRYPTO_hash_cmp (&new_addresses_hash,
211 &addresses_hash))
212 {
213 LOG (GNUNET_ERROR_TYPE_DEBUG,
214 "Address hash unchanged at %s, ignoring...\n",
215 GNUNET_h2s (&addresses_hash));
216 GNUNET_HELLO_builder_free (builder);
217 return;
218 }*/
219 addresses_hash = new_addresses_hash;
221 (uint8_t*) ikm,
227 "Successfully generated a new peer id %s - inform clients\n",
229
230 {
231 struct P_Client *client;
232 struct PeerIdUpdateMessage *msg;
234 struct GNUNET_TIME_Absolute et;
235 size_t block_bytes;
237
238 struct PilsHelloSignaturePurpose hsp = {
239 .purpose.size = htonl (sizeof (hsp)),
240 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
241 .expiration_time = GNUNET_TIME_absolute_hton (et)
242 };
246 &hsp.purpose,
247 &sig));
249
251 block_bytes,
253 msg->hash = addresses_hash;
254 msg->block_len = htonl (block_bytes);
256 builder,
258 &sig,
259 et,
260 (char *) &msg[1]);
261 client = clients_head;
262 while (NULL != client)
263 {
265 client = client->next;
266 }
267 }
268}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
static struct GNUNET_MQ_Envelope * signed_hello
Current signed HELLO.
struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
The current private key.
static struct GNUNET_SCHEDULER_Task * generate_pid_task
Task to schedule the generation of the peer id.
struct GNUNET_HashCode addresses_hash
Hash of the canonicalized addresses.
static void print_uri(void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
struct GNUNET_CRYPTO_EddsaPublicKey my_public_key
The current public key.
static struct P_Client * clients_head
Head of the liked list of clients.
static int have_id
Peer ID was calculated already at least once.
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:507
#define GNUNET_SIGNATURE_PURPOSE_HELLO
Signature by which a peer affirms its address.
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
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition: crypto_ecc.c:625
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
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_new()
Allocate builder.
Definition: hello-uri.c:343
void GNUNET_HELLO_builder_iterate(const struct GNUNET_HELLO_Builder *builder, GNUNET_HELLO_UriCallback uc, void *uc_cls)
Iterate over URIs in a builder.
Definition: hello-uri.c:956
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_parser(const struct GNUNET_HELLO_Parser *parser, struct GNUNET_PeerIdentity *pid)
Allocate builder from parser.
Definition: hello-uri.c:360
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_HELLO_ADDRESS_EXPIRATION
For how long are HELLO signatures valid?
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
const char * GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_INFO
void GNUNET_MQ_send_copy(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MQ_Envelope *ev)
Send a copy of a message with the given message queue.
Definition: mq.c:384
#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_PEER_ID
Message passing the new peer id from the service to the client.
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
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:640
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
an ECC signature using EdDSA.
Context for building (or parsing) HELLO URIs.
Definition: hello-uri.c:184
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
Time for absolute times used by GNUnet, in microseconds.
Data structure for each client connected to the CORE service.
struct GNUNET_MQ_Handle * mq
Message queue to talk to client.
struct P_Client * next
Clients are kept in a linked list.
struct GNUNET_SERVICE_Client * client
Handle for the client with the server API.
Message containing the current peer id and the hash from which it was generated.
Definition: pils.h:40
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 addresses_hash, builder, P_Client::client, clients_head, generate_pid_task, GNUNET_assert, GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_eddsa_sign_(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_HELLO_ADDRESS_EXPIRATION, GNUNET_HELLO_builder_from_parser(), GNUNET_HELLO_builder_hash_addresses(), GNUNET_HELLO_builder_iterate(), GNUNET_HELLO_builder_new(), GNUNET_HELLO_builder_to_block(), GNUNET_HELLO_get_builder_to_block_size(), GNUNET_MESSAGE_TYPE_PILS_PEER_ID, GNUNET_MQ_msg_extra, GNUNET_MQ_send_copy(), GNUNET_OK, GNUNET_p2s(), GNUNET_PILS_derive_pid(), GNUNET_SIGNATURE_PURPOSE_HELLO, GNUNET_TIME_absolute_hton(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, PilsHelloSignaturePurpose::h_addrs, have_id, ikm, LOG, P_Client::mq, msg, my_private_key, my_public_key, P_Client::next, warningfilter::parser, print_uri(), PilsHelloSignaturePurpose::purpose, signed_hello, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by handle_feed_addresses(), and run().

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

◆ check_feed_addresses()

static int check_feed_addresses ( void *  cls,
const struct FeedAddressesMessage msg 
)
static

Checker for feed messages.

Parameters
clsclient who sent the message
messagethe message received

Definition at line 279 of file gnunet-service-pils.c.

281{
282 size_t msg_size;
283 uint32_t block_bytes;
284 (void) cls;
285
286 msg_size = ntohs (msg->header.size);
287 block_bytes = ntohl (msg->block_len);
288 if (msg_size != sizeof (*msg) + block_bytes)
289 {
291 "The msg_size (%lu) is not %lu (header) + %u (block)\n",
292 msg_size,
293 sizeof (*msg),
294 block_bytes);
295 return GNUNET_SYSERR;
296 }
297 return GNUNET_OK;
298}
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.

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

◆ handle_feed_addresses()

static void handle_feed_addresses ( void *  cls,
const struct FeedAddressesMessage message 
)
static

Handler for feed addresses message from client.

A client (must be core) sent us the hash of the current set of addresses. This triggers the generation of the new peer id.

Parameters
clsclient who sent the message
messagethe message received

Definition at line 311 of file gnunet-service-pils.c.

313{
314 struct P_Client *client = cls;
316 uint32_t block_bytes;
317
319 "PILS received FEED_ADDRESSES message from client\n");
320
321 /* If there's a peer id generation scheduled, just kill it and generate an id
322 * on the more recent address */
323 block_bytes = ntohl (message->block_len);
325 block_bytes,
326 GNUNET_YES);
328
331}
static void do_generate_pid(const struct GNUNET_HELLO_Parser *parser)
Generate the peer id from the addresses hash and the initial secret key.
void GNUNET_HELLO_parser_free(struct GNUNET_HELLO_Parser *parser)
Release resources of a builder.
Definition: hello-uri.c:379
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_block_(const void *block, size_t block_size, int noverify)
Parse block.
Definition: hello-uri.c:533
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2433
uint32_t block_len
For alignment.
Definition: pils.h:132
Context for parsing HELLOs.
Definition: hello-uri.c:232

References FeedAddressesMessage::block_len, P_Client::client, do_generate_pid(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELLO_parser_free(), GNUNET_HELLO_parser_from_block_(), GNUNET_SERVICE_client_continue(), GNUNET_YES, LOG, and warningfilter::parser.

Here is the call graph for this function:

◆ handle_decaps()

static void handle_decaps ( void *  cls,
const struct DecapsMessage message 
)
static

Handler for decaps request message from client.

Parameters
clsclient who sent the message
messagethe message received

Definition at line 341 of file gnunet-service-pils.c.

343{
344 struct P_Client *client = cls;
345 struct DecapsResultMessage *rmsg;
346 struct GNUNET_MQ_Envelope *env;
348
350 "PILS received KEM_DECAPS message from client\n");
351
353 &message->c,
354 &rmsg->key))
355 {
357 "PILS failed to decapsulate encapsulation received from client\n");
358 memset (&rmsg->key, 0, sizeof (rmsg->key));
359 }
360
361 rmsg->rid = message->rid;
362 GNUNET_MQ_send (client->mq, env);
364}
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_kem_decaps(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *prk)
Decapsulate a key for a private EdDSA key.
Definition: crypto_hpke.c:285
@ GNUNET_ERROR_TYPE_WARNING
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(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:76
#define GNUNET_MESSAGE_TYPE_PILS_DECAPS_RESULT
Decaps result.
uint32_t rid
Request ID.
Definition: pils.h:157
struct GNUNET_CRYPTO_HpkeEncapsulation c
Encapsulation to decapsulate.
Definition: pils.h:152
Message containing the decapsulated key.
Definition: pils.h:164
uint32_t rid
Request ID.
Definition: pils.h:178
struct GNUNET_ShortHashCode key
The decapsulated key.
Definition: pils.h:173

References DecapsMessage::c, P_Client::client, env, GNUNET_CRYPTO_eddsa_kem_decaps(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_MESSAGE_TYPE_PILS_DECAPS_RESULT, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_OK, GNUNET_SERVICE_client_continue(), DecapsResultMessage::key, LOG, P_Client::mq, my_private_key, DecapsMessage::rid, and DecapsResultMessage::rid.

Here is the call graph for this function:

◆ check_sign()

static int check_sign ( void *  cls,
const struct SignRequestMessage msg 
)
static

Handler for sign request message from client.

Parameters
clsclient sending the message
er_msgmessage of type struct EditRecordSetMessage
Returns
GNUNET_OK if er_msg is well-formed

Definition at line 375 of file gnunet-service-pils.c.

376{
378 size_t msg_size;
379 (void) cls;
380
381 msg_size = ntohs (msg->header.size);
382 if (msg_size <= sizeof (*msg) + sizeof (struct
384 {
386 "The msg_size (%lu) is not big enough for msg (%lu) + purpose struct (%lu)\n",
387 msg_size,
388 sizeof (*msg),
389 sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
390 return GNUNET_SYSERR;
391 }
392 purp = (struct GNUNET_CRYPTO_EccSignaturePurpose*) &msg[1];
393 if (msg_size <= sizeof (*msg) + ntohs (purp->size))
394 {
396 "The msg_size (%lu) is not big enough for msg (%lu) + purpose (%u)\n",
397 msg_size,
398 sizeof (*msg),
399 ntohs (purp->size));
400 return GNUNET_SYSERR;
401 }
402 return GNUNET_OK;
403}
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...

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

◆ handle_sign()

static void handle_sign ( void *  cls,
const struct SignRequestMessage message 
)
static

Handler for sign request message from client.

Parameters
clsclient who sent the message
messagethe message received

Definition at line 413 of file gnunet-service-pils.c.

415{
416 struct P_Client *client = cls;
417 struct SignResultMessage *rmsg;
418 struct GNUNET_MQ_Envelope *env;
421
423 "PILS received SIGN message from client\n");
424
425 purp = (struct GNUNET_CRYPTO_EccSignaturePurpose*) &message[1];
427 purp,
428 &rmsg->sig))
429 {
431 "PILS failed to sign message received from client\n");
432 memset (&rmsg->sig, 0, sizeof (rmsg->sig));
433 }
435 "PILS sent SIGN_RESULT message to client %p\n",
436 client->mq);
438 rmsg->rid = message->rid;
439 GNUNET_MQ_send (client->mq, env);
441}
#define GNUNET_MESSAGE_TYPE_PILS_SIGN_RESULT
The service sends the requested signature to the client.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
uint32_t rid
Request ID.
Definition: pils.h:222
Message containing the signature.
Definition: pils.h:185
uint32_t rid
Request ID.
Definition: pils.h:204
struct GNUNET_PeerIdentity peer_id
The peer identity that produces the signature.
Definition: pils.h:194
struct GNUNET_CRYPTO_EddsaSignature sig
The signature.
Definition: pils.h:199

References P_Client::client, env, GNUNET_CRYPTO_eddsa_sign_(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_MESSAGE_TYPE_PILS_SIGN_RESULT, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_OK, GNUNET_SERVICE_client_continue(), LOG, P_Client::mq, my_private_key, my_public_key, SignResultMessage::peer_id, GNUNET_PeerIdentity::public_key, SignResultMessage::rid, SignRequestMessage::rid, and SignResultMessage::sig.

Here is the call graph for this function:

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Task run during shutdown.

Parameters
clsunused

Definition at line 450 of file gnunet-service-pils.c.

451{
452 struct P_Client *c;
453 (void) cls;
454
456 "PILS shutting down\n");
457 c = clients_head;
458 while (NULL != c)
459 {
460 struct P_Client *c_delete = c;
461
462 c = c->next;
464 /* No need to remove from DLL or free here - #client_disconnect_cb(), which
465 * is called by GNUNET_SERVICE_client_drop(), takes care of this. */
466 }
467 if (NULL != signed_hello)
469 cfg = NULL;
470 if (NULL != generate_pid_task)
473}
void GNUNET_CRYPTO_eddsa_key_clear(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
Clear memory that was used to store a private key.
Definition: crypto_ecc.c:447
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2462

References cfg, P_Client::client, clients_head, generate_pid_task, GNUNET_CRYPTO_eddsa_key_clear(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_SCHEDULER_cancel(), GNUNET_SERVICE_client_drop(), LOG, my_private_key, P_Client::next, and signed_hello.

Referenced by run().

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

◆ run()

static void run ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle c,
struct GNUNET_SERVICE_Handle service 
)
static

Set up the service.

Parameters
clsclosure - unused
cconfiguration to use
servicethe initialized service - unused

Definition at line 484 of file gnunet-service-pils.c.

487{
488 cfg = c;
490 "PILS starting\n");
492 load_ikm ();
493 /* Generate an initial peer id from no addresses at all
494 * This is needed for scenarios in which we have only local addresses. */
495 do_generate_pid (NULL);
497}
static void shutdown_task(void *cls)
Task run during shutdown.
static void load_ikm()
Get the initial secret key for generating the peer id.
@ GNUNET_NO
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1339

References cfg, do_generate_pid(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_SCHEDULER_add_shutdown(), have_id, load_ikm(), LOG, and shutdown_task().

Here is the call graph for this function:

◆ client_connect_cb()

static void * client_connect_cb ( void *  cls,
struct GNUNET_SERVICE_Client c,
struct GNUNET_MQ_Handle mq 
)
static

Callback called when a client connects to the service.

This stores the client in a DLL. If we have a peer id, send it immediately to the api/client.

Parameters
clsclosure for the service - unused
cthe new client that connected to the service
mqthe message queue used to send messages to the client
Returns
the P_Client as closure to handlers and disconnect

Definition at line 512 of file gnunet-service-pils.c.

515{
516 struct P_Client *client;
517 (void) cls;
518
519 LOG (GNUNET_ERROR_TYPE_DEBUG, "A client `%p' connected\n",
520 mq);
521 client = GNUNET_new (struct P_Client);
522 client->client = c;
523 client->mq = mq;
526 client);
527 if (GNUNET_YES == have_id)
528 {
530 }
531 return client;
532}
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
static struct P_Client * clients_tail
Tail of the liked list of clients.
#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_MQ_Handle * mq
Message queue for the client.
Definition: service.c:273

References P_Client::client, clients_head, clients_tail, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_send_copy(), GNUNET_new, GNUNET_YES, have_id, LOG, mq, GNUNET_SERVICE_Client::mq, and signed_hello.

Here is the call graph for this function:

◆ client_disconnect_cb()

static void client_disconnect_cb ( void *  cls,
struct GNUNET_SERVICE_Client c,
void *  internal_cls 
)
static

Callback called when a client disconnected from the service.

Remove the client from the DLL

Parameters
clsclosure for the service
cthe client that disconnected
internal_clsshould be equal to c

Definition at line 545 of file gnunet-service-pils.c.

548{
549 struct P_Client *client_iter;
550 (void) cls;
551
552 client_iter = clients_head;
553 while (NULL != client_iter)
554 {
555 struct P_Client *client_next = client_iter->next;
556
557 if (client_iter->client == c)
558 {
561 client_iter);
562 GNUNET_free (client_iter);
563 }
564 client_iter = client_next;
565 }
566}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.

References P_Client::client, clients_head, clients_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_free, and P_Client::next.

◆ GNUNET_SERVICE_MAIN()

GNUNET_SERVICE_MAIN ( GNUNET_OS_project_data_gnunet()  ,
"pils"  ,
GNUNET_SERVICE_OPTION_NONE  ,
run,
client_connect_cb,
client_disconnect_cb,
NULL  ,
GNUNET_MQ_hd_var_size(feed_addresses, GNUNET_MESSAGE_TYPE_PILS_FEED_ADDRESSES, struct FeedAddressesMessage, NULL)  ,
GNUNET_MQ_hd_fixed_size(decaps, GNUNET_MESSAGE_TYPE_PILS_KEM_DECAPS, struct DecapsMessage, NULL)  ,
GNUNET_MQ_hd_var_size(sign, GNUNET_MESSAGE_TYPE_PILS_SIGN_REQUEST, struct SignRequestMessage, NULL)  ,
GNUNET_MQ_handler_end()   
)

Define "main" method using service macro.

Variable Documentation

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Handle to our current configuration.

Definition at line 46 of file gnunet-service-pils.c.

Referenced by load_ikm(), run(), and shutdown_task().

◆ generate_pid_task

struct GNUNET_SCHEDULER_Task* generate_pid_task
static

Task to schedule the generation of the peer id.

Definition at line 52 of file gnunet-service-pils.c.

Referenced by do_generate_pid(), and shutdown_task().

◆ addresses_hash

struct GNUNET_HashCode addresses_hash

Hash of the canonicalized addresses.

This is computed by the api, passed to the service as representation of the addresses. From it the service generates the peer id. It is also passed back to the api alongside the peer id to connect the peer id to the addresses it was based upon.

Definition at line 61 of file gnunet-service-pils.c.

Referenced by do_generate_pid().

◆ my_private_key

struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key

The current private key.

Own private key.

Definition at line 67 of file gnunet-service-pils.c.

Referenced by do_generate_pid(), handle_decaps(), handle_sign(), and shutdown_task().

◆ my_public_key

struct GNUNET_CRYPTO_EddsaPublicKey my_public_key

The current public key.

Definition at line 73 of file gnunet-service-pils.c.

Referenced by do_generate_pid(), GNUNET_FS_uri_loc_create(), and handle_sign().

◆ ikm

unsigned char ikm[256/8]
static

The initial key material for the peer.

Definition at line 78 of file gnunet-service-pils.c.

Referenced by checkvec(), do_generate_pid(), labeled_extract(), load_ikm(), output_vectors(), and pid_change_cb().

◆ clients_head

struct P_Client* clients_head
static

Head of the liked list of clients.

Definition at line 110 of file gnunet-service-pils.c.

Referenced by client_connect_cb(), client_disconnect_cb(), do_generate_pid(), and shutdown_task().

◆ clients_tail

struct P_Client* clients_tail
static

Tail of the liked list of clients.

Definition at line 116 of file gnunet-service-pils.c.

Referenced by client_connect_cb(), and client_disconnect_cb().

◆ have_id

int have_id
static

Peer ID was calculated already at least once.

Definition at line 122 of file gnunet-service-pils.c.

Referenced by client_connect_cb(), do_generate_pid(), and run().

◆ signed_hello

struct GNUNET_MQ_Envelope* signed_hello
static

Current signed HELLO.

Definition at line 127 of file gnunet-service-pils.c.

Referenced by client_connect_cb(), do_generate_pid(), and shutdown_task().