GNUnet 0.21.1
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_error_codes.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...
 
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 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...
 
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_CRYPTO_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_CRYPTO_PublicKey *pk)
 Get the identifier (public key) of an ego. More...
 
static enum GNUNET_GenericReturnValue private_key_create (enum GNUNET_CRYPTO_KeyType ktype, struct GNUNET_CRYPTO_PrivateKey *key)
 
struct GNUNET_IDENTITY_OperationGNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, const char *name, const struct GNUNET_CRYPTO_PrivateKey *privkey, enum GNUNET_CRYPTO_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...
 

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 34 of file identity_api.c.

Function Documentation

◆ reconnect()

static void reconnect ( void *  cls)
static

Try again to connect to the identity service.

Parameters
clshandle to the identity service.

Definition at line 440 of file identity_api.c.

441{
442 struct GNUNET_IDENTITY_Handle *h = cls;
444 GNUNET_MQ_hd_fixed_size (identity_result_code,
446 struct ResultCodeMessage,
447 h),
448 GNUNET_MQ_hd_var_size (identity_update,
450 struct UpdateMessage,
451 h),
453 };
454 struct GNUNET_MQ_Envelope *env;
456
457 h->reconnect_task = NULL;
459 "Connecting to identity service.\n");
460 GNUNET_assert (NULL == h->mq);
462 "identity",
463 handlers,
465 h);
466 if (NULL == h->mq)
467 return;
468 if (NULL != h->cb)
469 {
473 env);
474 }
475}
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_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
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:1057
#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:304
#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:78
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_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_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:275
#define LOG(kind,...)
Definition: identity_api.c:34
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:97
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
Service informs client about status of a pseudonym.
Definition: identity.h:114

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_START, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, 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 197 of file identity_api.c.

200{
201 struct GNUNET_IDENTITY_Handle *h = cls;
202 struct GNUNET_IDENTITY_Ego *ego = value;
203
204 if (NULL != h->cb)
205 h->cb (h->cb_cls, ego,
206 &ego->ctx,
207 NULL);
208 GNUNET_free (ego->name);
211 key,
212 value));
213 GNUNET_free (ego);
214 return GNUNET_OK;
215}
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
enum GNUNET_GenericReturnValue 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.
@ GNUNET_OK
@ GNUNET_YES
#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 224 of file identity_api.c.

225{
227
228 GNUNET_assert (NULL == h->reconnect_task);
229
230 if (NULL != h->mq)
231 {
233 h->mq = NULL;
234 }
235 while (NULL != (op = h->op_head))
236 {
238 h->op_tail,
239 op);
240 if (NULL != op->cont)
241 op->cont (op->cls,
243 else if (NULL != op->cb)
244 op->cb (op->cls, NULL, NULL, NULL);
245 else if (NULL != op->create_cont)
246 op->create_cont (op->cls,
247 NULL,
249 GNUNET_free (op);
250 }
252 &free_ego,
253 h);
255 "Scheduling task to reconnect to identity service in %s.\n",
257 GNUNET_YES));
259 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
260 &reconnect,
261 h);
262 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
263}
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_MultiHashMapIteratorCallback 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:683
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:1278
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:570
#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:440
static int free_ego(void *cls, const struct GNUNET_HashCode *key, void *value)
Free ego from hash map.
Definition: identity_api.c:197
@ GNUNET_EC_SERVICE_COMMUNICATION_FAILED
Communication with service failed.
Handle for an operation with the identity service.
Definition: identity_api.c:41

References free_ego(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_EC_SERVICE_COMMUNICATION_FAILED, 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_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 275 of file identity_api.c.

277{
278 struct GNUNET_IDENTITY_Handle *h = cls;
279
281}
static void reschedule_connect(struct GNUNET_IDENTITY_Handle *h)
Reschedule a connect attempt to the service.
Definition: identity_api.c:224

References h, and reschedule_connect().

Referenced by reconnect().

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

◆ 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 291 of file identity_api.c.

293{
294 struct GNUNET_IDENTITY_Handle *h = cls;
296 enum GNUNET_ErrorCode ec = ntohl (rcm->result_code);
297
298 op = h->op_head;
299 if (NULL == op)
300 {
301 GNUNET_break (0);
303 return;
304 }
305 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
306 if (NULL != op->cont)
307 op->cont (op->cls, ec);
308 else if (NULL != op->cb)
309 op->cb (op->cls, NULL, NULL, NULL);
310 else if (NULL != op->create_cont)
311 op->create_cont (op->cls, (GNUNET_EC_NONE == ec) ? &op->pk : NULL, ec);
312 GNUNET_free (op);
313}
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
GNUNET_ErrorCode
Taler error codes.
@ GNUNET_EC_NONE
No error (success).
uint32_t result_code
Status code for the last operation, in NBO.
Definition: identity.h:91

References GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_EC_NONE, GNUNET_free, h, op, reschedule_connect(), and ResultCodeMessage::result_code.

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 324 of file identity_api.c.

326{
327 uint16_t size = ntohs (um->header.size);
328 uint16_t name_len = ntohs (um->name_len);
329 const char *str = (const char *) &um[1];
330
331 if ((size < name_len + sizeof(struct UpdateMessage)) ||
332 ((0 != name_len) && ('\0' != str[name_len - 1])))
333 {
334 GNUNET_break (0);
335 return GNUNET_SYSERR;
336 }
337 return GNUNET_OK;
338}
@ GNUNET_SYSERR
static unsigned int size
Size of the "table".
Definition: peer.c:68
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
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:124
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE.
Definition: identity.h:118

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 348 of file identity_api.c.

350{
351 struct GNUNET_IDENTITY_Handle *h = cls;
352 uint16_t name_len = ntohs (um->name_len);
353 const char *str;
354 size_t key_len;
355 size_t kb_read;
356 struct GNUNET_HashCode id;
357 struct GNUNET_IDENTITY_Ego *ego;
358 struct GNUNET_CRYPTO_PrivateKey private_key;
359 const char *tmp;
360
361 if (GNUNET_YES == ntohs (um->end_of_list))
362 {
363 /* end of initial list of data */
364 if (NULL != h->cb)
365 h->cb (h->cb_cls, NULL, NULL, NULL);
366 return;
367 }
368 tmp = (const char*) &um[1];
369 str = (0 == name_len) ? NULL : tmp;
370 memset (&private_key, 0, sizeof (private_key));
371 key_len = ntohs (um->key_len);
374 key_len,
375 &private_key,
376 &kb_read));
378 GNUNET_CRYPTO_hash (&private_key,
380 &id);
382 &id);
383 if (NULL == ego)
384 {
385 /* ego was created */
386 if (NULL == str)
387 {
388 /* deletion of unknown ego? not allowed */
389 GNUNET_break (0);
391 return;
392 }
393 ego = GNUNET_new (struct GNUNET_IDENTITY_Ego);
395 ego->pk = private_key;
396 ego->name = GNUNET_strdup (str);
397 ego->id = id;
400 h->egos,
401 &ego->id,
402 ego,
404 }
405 if (NULL == str)
406 {
407 /* ego was deleted */
410 &ego->id,
411 ego));
412 }
413 else
414 {
415 /* ego changed name */
416 GNUNET_free (ego->name);
417 ego->name = GNUNET_strdup (str);
418 }
419 /* inform application about change */
420 if (NULL != h->cb)
421 h->cb (h->cb_cls,
422 ego,
423 &ego->ctx,
424 str);
425 /* complete deletion */
426 if (NULL == str)
427 {
428 GNUNET_free (ego->name);
429 GNUNET_free (ego);
430 }
431}
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
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
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.
enum GNUNET_GenericReturnValue 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.
@ 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...
ssize_t GNUNET_CRYPTO_private_key_get_length(const struct GNUNET_CRYPTO_PrivateKey *key)
Get the compacted length of a GNUNET_CRYPTO_PrivateKey.
Definition: crypto_pkey.c:47
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_private_key_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_PrivateKey *key, size_t *read)
Reads a GNUNET_CRYPTO_PrivateKey from a compact buffer.
Definition: crypto_pkey.c:146
@ GNUNET_NO
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
A private key for an identity as per LSD0001.
A 512-bit hashcode.
bool pub_initialized
Set to true once pub was initialized.
Definition: identity.h:66
struct GNUNET_CRYPTO_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
uint16_t end_of_list
Usually GNUNET_NO, GNUNET_YES to signal end of list.
Definition: identity.h:129
uint16_t key_len
Key length.
Definition: identity.h:134

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_CRYPTO_private_key_get_length(), GNUNET_CRYPTO_read_private_key_from_buffer(), GNUNET_free, GNUNET_new, GNUNET_NO, GNUNET_strdup, GNUNET_SYSERR, GNUNET_YES, h, id, GNUNET_IDENTITY_Ego::id, UpdateMessage::key_len, GNUNET_IDENTITY_Ego::name, UpdateMessage::name_len, GNUNET_IDENTITY_Ego::pk, GNUNET_IDENTITY_Ego::pub_initialized, and reschedule_connect().

Here is the call graph for this function:

◆ private_key_create()

static enum GNUNET_GenericReturnValue private_key_create ( enum GNUNET_CRYPTO_KeyType  ktype,
struct GNUNET_CRYPTO_PrivateKey key 
)
static

Definition at line 541 of file identity_api.c.

543{
544 key->type = htonl (ktype);
545 switch (ktype)
546 {
549 break;
552 break;
553 default:
554 GNUNET_break (0);
555 return GNUNET_SYSERR;
556 }
557 return GNUNET_OK;
558}
void GNUNET_CRYPTO_eddsa_key_create(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:462
void GNUNET_CRYPTO_ecdsa_key_create(struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:447
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_PUBLIC_KEY_TYPE_ECDSA
The identity type.

References GNUNET_break, GNUNET_CRYPTO_ecdsa_key_create(), GNUNET_CRYPTO_eddsa_key_create(), GNUNET_OK, GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, 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: