GNUnet  0.11.x
Data Structures | Macros | Functions
identity_api.c File Reference

api to interact with the identity service More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_protocols.h"
#include "gnunet_identity_service.h"
#include "identity.h"
Include dependency graph for identity_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_IDENTITY_Operation
 Handle for an operation with the identity service. More...
 
struct  GNUNET_IDENTITY_Handle
 Handle for the service. More...
 

Macros

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

Functions

struct GNUNET_IDENTITY_EgoGNUNET_IDENTITY_ego_get_anonymous ()
 Obtain the ego representing 'anonymous' users. More...
 
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_key_get_public (const struct GNUNET_IDENTITY_PrivateKey *privkey, struct GNUNET_IDENTITY_PublicKey *key)
 Retrieves the public key representation of a private key. More...
 
static int private_key_create (enum GNUNET_IDENTITY_KeyType ktype, struct GNUNET_IDENTITY_PrivateKey *key)
 
static void reconnect (void *cls)
 Try again to connect to the identity service. More...
 
static int free_ego (void *cls, const struct GNUNET_HashCode *key, void *value)
 Free ego from hash map. More...
 
static void reschedule_connect (struct GNUNET_IDENTITY_Handle *h)
 Reschedule a connect attempt to the service. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More...
 
static int check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
 We received a result code from the service. More...
 
static void handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
 We received a result code from the service. More...
 
static int check_identity_update (void *cls, const struct UpdateMessage *um)
 Check validity of identity update message. More...
 
static void handle_identity_update (void *cls, const struct UpdateMessage *um)
 Handle identity update message. More...
 
static int check_identity_set_default (void *cls, const struct SetDefaultMessage *sdm)
 Function called when we receive a set default message from the service. More...
 
static void handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm)
 Type of a function to call when we receive a message from the service. More...
 
struct GNUNET_IDENTITY_HandleGNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
 Connect to the identity service. More...
 
const struct GNUNET_IDENTITY_PrivateKeyGNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego)
 Obtain the ECC key associated with a ego. More...
 
void GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_IDENTITY_PublicKey *pk)
 Get the identifier (public key) of an ego. More...
 
struct GNUNET_IDENTITY_OperationGNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h, const char *service_name, GNUNET_IDENTITY_Callback cb, void *cb_cls)
 Obtain the identity that is currently preferred/default for a service. More...
 
struct GNUNET_IDENTITY_OperationGNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, const char *service_name, struct GNUNET_IDENTITY_Ego *ego, GNUNET_IDENTITY_Continuation cont, void *cont_cls)
 Set the preferred/default identity for a service. More...
 
struct GNUNET_IDENTITY_OperationGNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, const char *name, const struct GNUNET_IDENTITY_PrivateKey *privkey, enum GNUNET_IDENTITY_KeyType ktype, GNUNET_IDENTITY_CreateContinuation cont, void *cont_cls)
 Create a new ego with the given name. More...
 
struct GNUNET_IDENTITY_OperationGNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h, const char *old_name, const char *new_name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
 Renames an existing identity. More...
 
struct GNUNET_IDENTITY_OperationGNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h, const char *name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
 Delete an existing identity. More...
 
void GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op)
 Cancel an identity operation. More...
 
void GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h)
 Disconnect from identity service. More...
 
ssize_t private_key_get_length (const struct GNUNET_IDENTITY_PrivateKey *key)
 
ssize_t GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key)
 Get the compacted length of a GNUNET_IDENTITY_PublicKey. More...
 
ssize_t GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key, const void *buffer, size_t len)
 Reads a GNUNET_IDENTITY_PublicKey from a compact buffer. More...
 
ssize_t GNUNET_IDENTITY_write_key_to_buffer (const struct GNUNET_IDENTITY_PublicKey *key, void *buffer, size_t len)
 Writes a GNUNET_IDENTITY_PublicKey to a compact buffer. More...
 
ssize_t GNUNET_IDENTITY_signature_get_length (const struct GNUNET_IDENTITY_Signature *sig)
 Get the compacted length of a GNUNET_IDENTITY_Signature. More...
 
ssize_t GNUNET_IDENTITY_read_signature_from_buffer (struct GNUNET_IDENTITY_Signature *sig, const void *buffer, size_t len)
 Reads a GNUNET_IDENTITY_Signature from a compact buffer. More...
 
ssize_t GNUNET_IDENTITY_write_signature_to_buffer (const struct GNUNET_IDENTITY_Signature *sig, void *buffer, size_t len)
 Writes a GNUNET_IDENTITY_Signature to a compact buffer. More...
 
int GNUNET_IDENTITY_sign_ (const struct GNUNET_IDENTITY_PrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_IDENTITY_Signature *sig)
 Sign a given block. More...
 
int GNUNET_IDENTITY_signature_verify_ (uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_IDENTITY_Signature *sig, const struct GNUNET_IDENTITY_PublicKey *pub)
 Verify a given signature. More...
 
ssize_t GNUNET_IDENTITY_encrypt (const void *block, size_t size, const struct GNUNET_IDENTITY_PublicKey *pub, struct GNUNET_CRYPTO_EcdhePublicKey *ecc, void *result)
 Encrypt a block with GNUNET_IDENTITY_PublicKey and derives a GNUNET_CRYPTO_EcdhePublicKey which is required for decryption using ecdh to derive a symmetric key. More...
 
ssize_t GNUNET_IDENTITY_decrypt (const void *block, size_t size, const struct GNUNET_IDENTITY_PrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *ecc, void *result)
 Decrypt a given block with GNUNET_IDENTITY_PrivateKey and a given GNUNET_CRYPTO_EcdhePublicKey using ecdh to derive a symmetric key. More...
 
char * GNUNET_IDENTITY_public_key_to_string (const struct GNUNET_IDENTITY_PublicKey *key)
 Creates a (Base32) string representation of the public key. More...
 
char * GNUNET_IDENTITY_private_key_to_string (const struct GNUNET_IDENTITY_PrivateKey *key)
 Creates a (Base32) string representation of the private key. More...
 
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_public_key_from_string (const char *str, struct GNUNET_IDENTITY_PublicKey *key)
 Parses a (Base32) string representation of the public key. More...
 
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_private_key_from_string (const char *str, struct GNUNET_IDENTITY_PrivateKey *key)
 Parses a (Base32) string representation of the private key. More...
 

Detailed Description

api to interact with the identity service

Author
Christian Grothoff

Definition in file identity_api.c.

Macro Definition Documentation

◆ LOG

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

Definition at line 33 of file identity_api.c.

Function Documentation

◆ private_key_create()

static int private_key_create ( enum GNUNET_IDENTITY_KeyType  ktype,
struct GNUNET_IDENTITY_PrivateKey key 
)
static

Definition at line 199 of file identity_api.c.

201 {
202  key->type = htonl (ktype);
203  switch (ktype)
204  {
206  GNUNET_CRYPTO_ecdsa_key_create (&key->ecdsa_key);
207  break;
209  GNUNET_CRYPTO_eddsa_key_create (&key->eddsa_key);
210  break;
211  default:
212  GNUNET_break (0);
213  return GNUNET_SYSERR;
214  }
215  return GNUNET_OK;
216 }
struct GNUNET_HashCode key
The key used in the DHT.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
void GNUNET_CRYPTO_eddsa_key_create(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:461
void GNUNET_CRYPTO_ecdsa_key_create(struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:446
@ GNUNET_IDENTITY_TYPE_ECDSA
The identity type.
@ GNUNET_IDENTITY_TYPE_EDDSA
EDDSA identity.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

References GNUNET_break, GNUNET_CRYPTO_ecdsa_key_create(), GNUNET_CRYPTO_eddsa_key_create(), GNUNET_IDENTITY_TYPE_ECDSA, GNUNET_IDENTITY_TYPE_EDDSA, GNUNET_OK, GNUNET_SYSERR, and key.

Referenced by GNUNET_IDENTITY_create().

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

◆ reconnect()

static void reconnect ( void *  cls)
static

Try again to connect to the identity service.

Parameters
clshandle to the identity service.

Definition at line 559 of file identity_api.c.

560 {
561  struct GNUNET_IDENTITY_Handle *h = cls;
563  GNUNET_MQ_hd_var_size (identity_result_code,
565  struct ResultCodeMessage,
566  h),
567  GNUNET_MQ_hd_var_size (identity_update,
569  struct UpdateMessage,
570  h),
571  GNUNET_MQ_hd_var_size (identity_set_default,
573  struct SetDefaultMessage,
574  h),
576  };
577  struct GNUNET_MQ_Envelope *env;
578  struct GNUNET_MessageHeader *msg;
579 
580  h->reconnect_task = NULL;
582  "Connecting to identity service.\n");
583  GNUNET_assert (NULL == h->mq);
585  "identity",
586  handlers,
588  h);
589  if (NULL == h->mq)
590  return;
591  if (NULL != h->cb)
592  {
593  env = GNUNET_MQ_msg (msg,
595  GNUNET_MQ_send (h->mq,
596  env);
597  }
598 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
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:1064
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
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:355
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_IDENTITY_START
First message send from identity client to service (to subscribe to updates).
#define GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT
Client sets default identity; or service informs about default identity.
#define GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE
Generic response from identity service with success and/or error message.
#define GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE
Update about identity status from service to clients.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
Definition: identity_api.c:315
#define LOG(kind,...)
Definition: identity_api.c:33
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
Handle for the service.
Definition: identity_api.c:96
Message handler for a specific message type.
Header for all communications.
Answer from service to client about last operation; GET_DEFAULT maybe answered with this message on f...
Definition: identity.h:81
Used from service to client as a result to the GET_DEFAULT message, used from client to service to SE...
Definition: identity.h:173
Service informs client about status of a pseudonym.
Definition: identity.h:116

References GNUNET_ARM_Handle::cfg, env, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, GNUNET_MESSAGE_TYPE_IDENTITY_START, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), h, handlers, LOG, GNUNET_ARM_Handle::mq, mq_error_handler(), msg, and GNUNET_ARM_Handle::reconnect_task.

Referenced by GNUNET_IDENTITY_connect(), and reschedule_connect().

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

◆ free_ego()

static int free_ego ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Free ego from hash map.

Parameters
clsidentity service handle
keyunused
valueego to free
Returns
GNUNET_OK (continue to iterate)

Definition at line 237 of file identity_api.c.

240 {
241  struct GNUNET_IDENTITY_Handle *h = cls;
242  struct GNUNET_IDENTITY_Ego *ego = value;
243 
244  if (NULL != h->cb)
245  h->cb (h->cb_cls, ego,
246  &ego->ctx,
247  NULL);
248  GNUNET_free (ego->name);
251  key,
252  value));
253  GNUNET_free (ego);
254  return GNUNET_OK;
255 }
static char * value
Value of the record to add/remove.
@ GNUNET_YES
Definition: gnunet_common.h:97
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
#define GNUNET_free(ptr)
Wrapper around free.
Handle for an ego.
Definition: identity.h:37
void * ctx
Client context associated with this ego.
Definition: identity.h:61
char * name
Current name associated with this ego.
Definition: identity.h:56

References GNUNET_IDENTITY_Ego::ctx, GNUNET_assert, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_free, GNUNET_OK, GNUNET_YES, h, key, GNUNET_IDENTITY_Ego::name, and value.

Referenced by GNUNET_IDENTITY_disconnect(), and reschedule_connect().

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

◆ reschedule_connect()

static void reschedule_connect ( struct GNUNET_IDENTITY_Handle h)
static

Reschedule a connect attempt to the service.

Parameters
htransport service to reconnect

Definition at line 264 of file identity_api.c.

265 {
267 
268  GNUNET_assert (NULL == h->reconnect_task);
269 
270  if (NULL != h->mq)
271  {
273  h->mq = NULL;
274  }
275  while (NULL != (op = h->op_head))
276  {
277  GNUNET_CONTAINER_DLL_remove (h->op_head,
278  h->op_tail,
279  op);
280  if (NULL != op->cont)
281  op->cont (op->cls,
282  "Error in communication with the identity service");
283  else if (NULL != op->cb)
284  op->cb (op->cls, NULL, NULL, NULL);
285  else if (NULL != op->create_cont)
286  op->create_cont (op->cls,
287  NULL,
288  "Failed to communicate with the identity service");
289  GNUNET_free (op);
290  }
292  &free_ego,
293  h);
295  "Scheduling task to reconnect to identity service in %s.\n",
296  GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay,
297  GNUNET_YES));
298  h->reconnect_task =
299  GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
300  &reconnect,
301  h);
302  h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
303 }
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
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:1269
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:557
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static void reconnect(void *cls)
Try again to connect to the identity service.
Definition: identity_api.c:559
static int free_ego(void *cls, const struct GNUNET_HashCode *key, void *value)
Free ego from hash map.
Definition: identity_api.c:237
Handle for an operation with the identity service.
Definition: identity_api.c:40

References free_ego(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, h, LOG, GNUNET_ARM_Handle::mq, op, reconnect(), and GNUNET_ARM_Handle::reconnect_task.

Referenced by handle_identity_result_code(), handle_identity_set_default(), handle_identity_update(), and mq_error_handler().

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

◆ mq_error_handler()

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

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_IDENTITY_Handle *
errorerror code

Definition at line 315 of file identity_api.c.

317 {
318  struct GNUNET_IDENTITY_Handle *h = cls;
319 
321 }
static void reschedule_connect(struct GNUNET_IDENTITY_Handle *h)
Reschedule a connect attempt to the service.
Definition: identity_api.c:264

References h, and reschedule_connect().

Referenced by reconnect().

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

◆ check_identity_result_code()

static int check_identity_result_code ( void *  cls,
const struct ResultCodeMessage rcm 
)
static

We received a result code from the service.

Check the message is well-formed.

Parameters
clsclosure
rcmresult message received
Returns
GNUNET_OK if the message is well-formed

Definition at line 333 of file identity_api.c.

335 {
336  if (sizeof(*rcm) != htons (rcm->header.size))
338  return GNUNET_OK;
339 }
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE.
Definition: identity.h:85

References GNUNET_MQ_check_zero_termination, GNUNET_OK, ResultCodeMessage::header, and GNUNET_MessageHeader::size.

◆ handle_identity_result_code()

static void handle_identity_result_code ( void *  cls,
const struct ResultCodeMessage rcm 
)
static

We received a result code from the service.

Parameters
clsclosure
rcmresult message received

Definition at line 349 of file identity_api.c.

351 {
352  struct GNUNET_IDENTITY_Handle *h = cls;
354  uint16_t size = ntohs (rcm->header.size) - sizeof(*rcm);
355  const char *str = (0 == size) ? NULL : (const char *) &rcm[1];
356 
357  op = h->op_head;
358  if (NULL == op)
359  {
360  GNUNET_break (0);
362  return;
363  }
364  GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
365  if (NULL != op->cont)
366  op->cont (op->cls, str);
367  else if (NULL != op->cb)
368  op->cb (op->cls, NULL, NULL, NULL);
369  else if (NULL != op->create_cont)
370  op->create_cont (op->cls, (NULL == str) ? &op->pk : NULL, str);
371  GNUNET_free (op);
372 }
static unsigned int size
Size of the "table".
Definition: peer.c:67

References GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, h, ResultCodeMessage::header, op, reschedule_connect(), GNUNET_MessageHeader::size, and size.

Here is the call graph for this function:

◆ check_identity_update()

static int check_identity_update ( void *  cls,
const struct UpdateMessage um 
)
static

Check validity of identity update message.

Parameters
clsclosure
ummessage received
Returns
GNUNET_OK if the message is well-formed

Definition at line 383 of file identity_api.c.

385 {
386  uint16_t size = ntohs (um->header.size);
387  uint16_t name_len = ntohs (um->name_len);
388  const char *str = (const char *) &um[1];
389 
390  if ((size != name_len + sizeof(struct UpdateMessage)) ||
391  ((0 != name_len) && ('\0' != str[name_len - 1])))
392  {
393  GNUNET_break (0);
394  return GNUNET_SYSERR;
395  }
396  return GNUNET_OK;
397 }
uint16_t name_len
Number of bytes in ego name string including 0-termination, in NBO; 0 if the ego was deleted.
Definition: identity.h:126
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE.
Definition: identity.h:120

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, UpdateMessage::header, UpdateMessage::name_len, GNUNET_MessageHeader::size, and size.

◆ handle_identity_update()

static void handle_identity_update ( void *  cls,
const struct UpdateMessage um 
)
static

Handle identity update message.

Parameters
clsclosure
ummessage received

Definition at line 407 of file identity_api.c.

409 {
410  struct GNUNET_IDENTITY_Handle *h = cls;
411  uint16_t name_len = ntohs (um->name_len);
412  const char *str = (0 == name_len) ? NULL : (const char *) &um[1];
413  struct GNUNET_HashCode id;
414  struct GNUNET_IDENTITY_Ego *ego;
415 
416  if (GNUNET_YES == ntohs (um->end_of_list))
417  {
418  /* end of initial list of data */
419  if (NULL != h->cb)
420  h->cb (h->cb_cls, NULL, NULL, NULL);
421  return;
422  }
424  sizeof (um->private_key),
425  &id);
427  &id);
428  if (NULL == ego)
429  {
430  /* ego was created */
431  if (NULL == str)
432  {
433  /* deletion of unknown ego? not allowed */
434  GNUNET_break (0);
436  return;
437  }
438  ego = GNUNET_new (struct GNUNET_IDENTITY_Ego);
439  ego->pub_initialized = GNUNET_NO;
440  ego->pk = um->private_key;
441  ego->name = GNUNET_strdup (str);
442  ego->id = id;
445  h->egos,
446  &ego->id,
447  ego,
449  }
450  if (NULL == str)
451  {
452  /* ego was deleted */
455  &ego->id,
456  ego));
457  }
458  else
459  {
460  /* ego changed name */
461  GNUNET_free (ego->name);
462  ego->name = GNUNET_strdup (str);
463  }
464  /* inform application about change */
465  if (NULL != h->cb)
466  h->cb (h->cb_cls,
467  ego,
468  &ego->ctx,
469  str);
470  /* complete deletion */
471  if (NULL == str)
472  {
473  GNUNET_free (ego->name);
474  GNUNET_free (ego);
475  }
476 }
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
@ GNUNET_NO
Definition: gnunet_common.h:94
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
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
A 512-bit hashcode.
bool pub_initialized
Set to true once pub was initialized.
Definition: identity.h:66
struct GNUNET_IDENTITY_PrivateKey pk
The identity key pair.
Definition: identity.h:51
struct GNUNET_HashCode id
Hash of the private key of this ego.
Definition: identity.h:41
struct GNUNET_IDENTITY_PrivateKey private_key
The private key.
Definition: identity.h:136
uint16_t end_of_list
Usually GNUNET_NO, GNUNET_YES to signal end of list.
Definition: identity.h:131

References GNUNET_IDENTITY_Ego::ctx, UpdateMessage::end_of_list, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_new, GNUNET_NO, GNUNET_strdup, GNUNET_YES, h, id, GNUNET_IDENTITY_Ego::id, GNUNET_IDENTITY_Ego::name, UpdateMessage::name_len, GNUNET_IDENTITY_Ego::pk, UpdateMessage::private_key, GNUNET_IDENTITY_Ego::pub_initialized, and reschedule_connect().

Here is the call graph for this function:

◆ check_identity_set_default()

static int check_identity_set_default ( void *  cls,
const struct SetDefaultMessage sdm 
)
static

Function called when we receive a set default message from the service.

Parameters
clsclosure
sdmmessage received
Returns
GNUNET_OK if the message is well-formed

Definition at line 488 of file identity_api.c.

490 {
491  uint16_t size = ntohs (sdm->header.size) - sizeof(*sdm);
492  uint16_t name_len = ntohs (sdm->name_len);
493  const char *str = (const char *) &sdm[1];
494 
495  if ((size != name_len) || ((0 != name_len) && ('\0' != str[name_len - 1])))
496  {
497  GNUNET_break (0);
498  return GNUNET_SYSERR;
499  }
500  GNUNET_break (0 == ntohs (sdm->reserved));
501  return GNUNET_OK;
502 }
uint16_t reserved
Always zero.
Definition: identity.h:187
uint16_t name_len
Number of bytes in service name string including 0-termination, in NBO.
Definition: identity.h:182
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT.
Definition: identity.h:177

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, SetDefaultMessage::header, SetDefaultMessage::name_len, SetDefaultMessage::reserved, GNUNET_MessageHeader::size, and size.

◆ handle_identity_set_default()

static void handle_identity_set_default ( void *  cls,
const struct SetDefaultMessage sdm 
)
static

Type of a function to call when we receive a message from the service.

Parameters
clsclosure
sdmmessage received

Definition at line 513 of file identity_api.c.

515 {
516  struct GNUNET_IDENTITY_Handle *h = cls;
518  struct GNUNET_HashCode id;
519  struct GNUNET_IDENTITY_Ego *ego;
520 
522  sizeof(sdm->private_key),
523  &id);
525  &id);
526  if (NULL == ego)
527  {
528  GNUNET_break (0);
530  return;
531  }
532  op = h->op_head;
533  if (NULL == op)
534  {
535  GNUNET_break (0);
537  return;
538  }
540  "Received SET_DEFAULT message from identity service\n");
541  GNUNET_CONTAINER_DLL_remove (h->op_head,
542  h->op_tail,
543  op);
544  if (NULL != op->cb)
545  op->cb (op->cls,
546  ego,
547  &ego->ctx,
548  ego->name);
549  GNUNET_free (op);
550 }
#define GNUNET_log(kind,...)
struct GNUNET_IDENTITY_PrivateKey private_key
The private key.
Definition: identity.h:192

References GNUNET_IDENTITY_Ego::ctx, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, h, id, GNUNET_IDENTITY_Ego::name, op, SetDefaultMessage::private_key, and reschedule_connect().

Here is the call graph for this function:

◆ private_key_get_length()

ssize_t private_key_get_length ( const struct GNUNET_IDENTITY_PrivateKey key)

Definition at line 958 of file identity_api.c.

959 {
960  switch (ntohl (key->type))
961  {
963  return sizeof (key->type) + sizeof (key->ecdsa_key);
964  break;
966  return sizeof (key->type) + sizeof (key->eddsa_key);
967  break;
968  default:
969  GNUNET_break (0);
970  }
971  return -1;
972 }

References GNUNET_break, GNUNET_IDENTITY_TYPE_ECDSA, GNUNET_IDENTITY_TYPE_EDDSA, and key.

Referenced by GNUNET_IDENTITY_private_key_from_string().

Here is the caller graph for this function: