GNUnet  0.11.x
Data Structures | Macros | Typedefs | Functions | Variables
gnunet-did.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_namestore_service.h"
#include "gnunet_gns_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "jansson.h"
#include "did.h"
Include dependency graph for gnunet-did.c:

Go to the source code of this file.

Data Structures

struct  Event
 A Structure containing a cont and cls. More...
 

Macros

#define GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME   "1d"
 

Typedefs

typedef void(* remove_did_document_callback) (void *cls)
 Signature of a callback function that is called after a did has been removed. More...
 

Functions

static void cleanup (void *cls)
 Disconnect and shutdown. More...
 
static void get_did_for_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
 Callback for ego loockup of get_did_for_ego() More...
 
static void get_did_for_ego ()
 Get the DID for a given EGO. More...
 
static void get_pkey_from_attr_did (struct GNUNET_IDENTITY_PublicKey *pkey)
 Get the public key from did attribute given by the user. More...
 
static void print_did_document (void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 GNS lookup callback. More...
 
static void resolve_did_document ()
 Resolve a DID given by the user. More...
 
static void remove_did_document_namestore_cb (void *cls, int32_t success, const char *emgs)
 Implements the GNUNET_NAMESTORE_ContinuationWithStatus Calls the callback function and cls in the event struct. More...
 
static void remove_did_document_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
 Callback called after the ego has been locked up. More...
 
static void remove_did_document (remove_did_document_callback cont, void *cls)
 Remove a DID Document. More...
 
char * create_did_generate (struct GNUNET_IDENTITY_PublicKey pkey)
 Create a did generate did object. More...
 
static void create_did_store_cb (void *cls, int32_t success, const char *emsg)
 Create a DID. More...
 
static void create_did_store (char *didd_str, struct GNUNET_IDENTITY_Ego *ego)
 Create a did. More...
 
static void create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
 Create a did ego lockup cb. More...
 
static void create_did_document_ego_create_cb (void *cls, const struct GNUNET_IDENTITY_PrivateKey *pk, const char *emsg)
 Create a did document - Create a new identity first. More...
 
static void create_did_document ()
 Create a did document. More...
 
static void replace_did_document_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
 Replace a DID Docuemnt. More...
 
static void replace_did_document_remove_cb (void *cls)
 Replace a DID Document. More...
 
static void replace_did_document ()
 Replace a DID Docuemnt. More...
 
static void post_ego_iteration (void *cls)
 
static void process_dids (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 
int main (int argc, char *const argv[])
 

Variables

static int ret
 return value More...
 
static int replace
 Replace DID Document Flag. More...
 
static int remove_did
 Remove DID Document Flag. More...
 
static int get
 Get DID Documement for DID Flag. More...
 
static int create
 Create DID Document Flag. More...
 
static int show
 Show DID for Ego Flag. More...
 
static int show_all
 Show DID for Ego Flag. More...
 
static char * did
 DID Attribut String. More...
 
static char * didd
 DID Document Attribut String. More...
 
static char * egoname
 Ego Attribut String. More...
 
static char * expire
 DID Document expiration Date Attribut String. More...
 
static struct GNUNET_GNS_Handlegns_handle
 
static struct GNUNET_NAMESTORE_Handlenamestore_handle
 
static struct GNUNET_IDENTITY_Handleidentity_handle
 
static const struct GNUNET_CONFIGURATION_Handlemy_cfg
 
static int ego_exists = 0
 Give ego exists. More...
 

Macro Definition Documentation

◆ GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME

#define GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME   "1d"

Definition at line 44 of file gnunet-did.c.

Typedef Documentation

◆ remove_did_document_callback

typedef void(* remove_did_document_callback) (void *cls)

Signature of a callback function that is called after a did has been removed.

Definition at line 282 of file gnunet-did.c.

Function Documentation

◆ cleanup()

static void cleanup ( void *  cls)
static

Disconnect and shutdown.

Parameters
clsclosure

Definition at line 132 of file gnunet-did.c.

133 {
134  if (NULL != gns_handle)
136  if (NULL != namestore_handle)
138  if (NULL != identity_handle)
140 
141  GNUNET_free (did);
142  GNUNET_free (didd);
145 
147 }
static struct GNUNET_GNS_Handle * gns_handle
Definition: gnunet-did.c:104
static char * egoname
Ego Attribut String.
Definition: gnunet-did.c:94
static char * didd
DID Document Attribut String.
Definition: gnunet-did.c:89
static char * expire
DID Document expiration Date Attribut String.
Definition: gnunet-did.c:99
static struct GNUNET_NAMESTORE_Handle * namestore_handle
Definition: gnunet-did.c:109
static struct GNUNET_IDENTITY_Handle * identity_handle
Definition: gnunet-did.c:114
static char * did
DID Attribut String.
Definition: gnunet-did.c:84
void GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle)
Shutdown connection with the GNS service.
Definition: gns_api.c:290
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:921
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531

References did, didd, egoname, expire, gns_handle, GNUNET_free, GNUNET_GNS_disconnect(), GNUNET_IDENTITY_disconnect(), GNUNET_NAMESTORE_disconnect(), GNUNET_SCHEDULER_shutdown(), identity_handle, and namestore_handle.

Referenced by create_did_document(), create_did_document_ego_create_cb(), create_did_ego_lockup_cb(), create_did_generate(), create_did_store(), create_did_store_cb(), get_did_for_ego(), get_did_for_ego_lookup_cb(), get_pkey_from_attr_did(), post_ego_iteration(), print_did_document(), process_dids(), remove_did_document(), remove_did_document_namestore_cb(), replace_did_document(), resolve_did_document(), and run().

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

◆ get_did_for_ego_lookup_cb()

static void get_did_for_ego_lookup_cb ( void *  cls,
struct GNUNET_IDENTITY_Ego ego 
)
static

Callback for ego loockup of get_did_for_ego()

Parameters
clsclosure
egothe returned ego

Definition at line 156 of file gnunet-did.c.

157 {
158  char *did_str;
159 
160  if (ego == NULL)
161  {
162  printf ("EGO not found\n");
164  ret = 1;
165  return;
166  }
167  did_str = DID_ego_to_did (ego);
168 
169  printf ("%s\n", did_str);
170 
172  ret = 0;
173  return;
174 }
char * DID_ego_to_did(struct GNUNET_IDENTITY_Ego *ego)
Create a DID string from an ego in the format did:reclaim:<pubkey>
Definition: did_misc.c:34
static void cleanup(void *cls)
Disconnect and shutdown.
Definition: gnunet-did.c:132
static int ret
return value
Definition: gnunet-did.c:49
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1296

References cleanup(), DID_ego_to_did(), GNUNET_SCHEDULER_add_now(), and ret.

Referenced by get_did_for_ego().

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

◆ get_did_for_ego()

static void get_did_for_ego ( )
static

Get the DID for a given EGO.

Definition at line 181 of file gnunet-did.c.

182 {
183  if (egoname != NULL)
184  {
186  egoname,
188  NULL);
189  }
190  else {
191  printf ("Set the EGO argument to get the DID for a given EGO\n");
193  ret = 1;
194  return;
195  }
196 }
static const struct GNUNET_CONFIGURATION_Handle * my_cfg
Definition: gnunet-did.c:120
static void get_did_for_ego_lookup_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
Callback for ego loockup of get_did_for_ego()
Definition: gnunet-did.c:156
struct GNUNET_IDENTITY_EgoLookup * GNUNET_IDENTITY_ego_lookup(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, GNUNET_IDENTITY_EgoCallback cb, void *cb_cls)
Lookup an ego by name.

References cleanup(), egoname, get_did_for_ego_lookup_cb(), GNUNET_IDENTITY_ego_lookup(), GNUNET_SCHEDULER_add_now(), my_cfg, and ret.

Here is the call graph for this function:

◆ get_pkey_from_attr_did()

static void get_pkey_from_attr_did ( struct GNUNET_IDENTITY_PublicKey pkey)
static

Get the public key from did attribute given by the user.

Parameters
pkeyplace to write the public key to

Definition at line 205 of file gnunet-did.c.

206 {
208  {
209  fprintf (stderr, _("Invalid DID `%s'\n"), did);
211  ret = 1;
212  return;
213  }
214 }
enum GNUNET_GenericReturnValue DID_public_key_from_did(const char *did, struct GNUNET_IDENTITY_PublicKey *pk)
Extract the public key from a DID in the format did:reclaim:<pubkey>
Definition: did_misc.c:53
static char * pkey
Public key of the zone to look in, in ASCII.
@ GNUNET_OK
Definition: gnunet_common.h:95
#define _(String)
GNU gettext support macro.
Definition: platform.h:177

References _, cleanup(), did, DID_public_key_from_did(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), pkey, and ret.

Referenced by resolve_did_document().

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

◆ print_did_document()

static void print_did_document ( void *  cls,
uint32_t  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)
static

GNS lookup callback.

Prints the DID Document to standard out. Fails if there is more than one DID record.

Parameters
clsclosure
rd_countnumber of records in rd
rdthe records in the reply

Definition at line 225 of file gnunet-did.c.

229 {
230  /*
231  * FIXME-MSC: The user may decide to put other records here.
232  * In general I am fine with the constraint here, but not when
233  * we move it to "@"
234  */
235  if (rd_count != 1)
236  {
237  printf ("An ego should only have one DID Document\n");
239  ret = 1;
240  return;
241  }
242 
243  if (rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT)
244  {
245  printf ("%s\n", (char *) rd[0].data);
246  }
247  else {
248  printf ("DID Document is not a TXT record\n");
249  }
250 
252  ret = 0;
253  return;
254 }
uint32_t data
The data value.
#define GNUNET_DNSPARSER_TYPE_TXT

References cleanup(), data, GNUNET_DNSPARSER_TYPE_TXT, GNUNET_SCHEDULER_add_now(), and ret.

Referenced by resolve_did_document().

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

◆ resolve_did_document()

static void resolve_did_document ( )
static

Resolve a DID given by the user.

Definition at line 260 of file gnunet-did.c.

261 {
263 
264  if (did == NULL)
265  {
266  printf ("Set DID option to resolve DID\n");
268  ret = 1;
269  return;
270  }
271 
273 
276 }
static void get_pkey_from_attr_did(struct GNUNET_IDENTITY_PublicKey *pkey)
Get the public key from did attribute given by the user.
Definition: gnunet-did.c:205
static void print_did_document(void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
GNS lookup callback.
Definition: gnunet-did.c:225
struct GNUNET_GNS_LookupRequest * GNUNET_GNS_lookup(struct GNUNET_GNS_Handle *handle, const char *name, const struct GNUNET_IDENTITY_PublicKey *zone, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS.
Definition: gns_api.c:412
#define GNUNET_GNS_EMPTY_LABEL_AT
String we use to indicate an empty label (top-level entry in the zone).
@ GNUNET_GNS_LO_DEFAULT
Defaults, look in cache, then in DHT.
An identity key as per LSD0001.

References cleanup(), did, get_pkey_from_attr_did(), gns_handle, GNUNET_DNSPARSER_TYPE_TXT, GNUNET_GNS_EMPTY_LABEL_AT, GNUNET_GNS_LO_DEFAULT, GNUNET_GNS_lookup(), GNUNET_SCHEDULER_add_now(), pkey, print_did_document(), and ret.

Referenced by post_ego_iteration().

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

◆ remove_did_document_namestore_cb()

static void remove_did_document_namestore_cb ( void *  cls,
int32_t  success,
const char *  emgs 
)
static

Implements the GNUNET_NAMESTORE_ContinuationWithStatus Calls the callback function and cls in the event struct.

Parameters
clsclosure containing the event struct
success
emgs

Definition at line 304 of file gnunet-did.c.

305 {
306  struct Event *event;
307 
308  if (success != GNUNET_SYSERR)
309  {
310  event = (struct Event *) cls;
311 
312  if (event->cont != NULL)
313  {
314  event->cont (event->cls);
315  free (event);
316  }
317  else {
318  free (event);
320  ret = 0;
321  return;
322  }
323  } else {
324  printf ("Something went wrong when deleting the DID Document\n");
325 
326  if (emgs != NULL)
327  {
328  printf ("%s\n", emgs);
329  }
330 
332  ret = 0;
333  return;
334  }
335 }
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
A Structure containing a cont and cls.
Definition: gnunet-did.c:290
remove_did_document_callback cont
Definition: gnunet-did.c:291
void * cls
Definition: gnunet-did.c:292

References cleanup(), Event::cls, Event::cont, GNUNET_SCHEDULER_add_now(), GNUNET_SYSERR, and ret.

Referenced by remove_did_document_ego_lookup_cb().

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

◆ remove_did_document_ego_lookup_cb()

static void remove_did_document_ego_lookup_cb ( void *  cls,
struct GNUNET_IDENTITY_Ego ego 
)
static

Callback called after the ego has been locked up.

Parameters
clsclosure
egothe ego returned by the identity service

Definition at line 344 of file gnunet-did.c.

345 {
346  const struct GNUNET_IDENTITY_PrivateKey *skey =
348 
350  skey,
352  0,
353  NULL,
355  cls);
356 }
static void remove_did_document_namestore_cb(void *cls, int32_t success, const char *emgs)
Implements the GNUNET_NAMESTORE_ContinuationWithStatus Calls the callback function and cls in the eve...
Definition: gnunet-did.c:304
const struct GNUNET_IDENTITY_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:639
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the namestore.
A private key for an identity as per LSD0001.

References GNUNET_GNS_EMPTY_LABEL_AT, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_NAMESTORE_records_store(), namestore_handle, and remove_did_document_namestore_cb().

Referenced by remove_did_document().

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

◆ remove_did_document()

static void remove_did_document ( remove_did_document_callback  cont,
void *  cls 
)
static

Remove a DID Document.

Definition at line 362 of file gnunet-did.c.

363 {
364  struct Event *event;
365 
366  if (egoname == NULL)
367  {
368  printf ("Remove requieres an ego option\n");
370  ret = 1;
371  return;
372  }
373  else {
374  event = malloc (sizeof(*event));
375  event->cont = cont;
376  event->cls = cls;
377 
379  egoname,
381  (void *) event);
382  }
383 }
static void remove_did_document_ego_lookup_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
Callback called after the ego has been locked up.
Definition: gnunet-did.c:344

References cleanup(), Event::cls, Event::cont, egoname, GNUNET_IDENTITY_ego_lookup(), GNUNET_SCHEDULER_add_now(), my_cfg, remove_did_document_ego_lookup_cb(), and ret.

Referenced by post_ego_iteration(), and replace_did_document().

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

◆ create_did_generate()

char* create_did_generate ( struct GNUNET_IDENTITY_PublicKey  pkey)

Create a did generate did object.

Parameters
pkey
Returns
void* Return pointer to the DID Document

Definition at line 393 of file gnunet-did.c.

394 {
395  /* FIXME-MSC: I would prefer constants instead of magic numbers */
396  char *pkey_str; // Convert public key to string
397  char did_str[71]; // 58 + 12 + 1 = 71
398  char *didd_str;
399  char verify_id_str[77]; // did_str len + "#key-1" = 71 + 6 = 77
400  char *pkey_multibase_str;
401 
402  /* FIXME-MSC: This screams for a GNUNET_DID_identity_key_to_string() */
403  char *b64;
404  char pkx[34];
405  pkx[0] = 0xed;
406  pkx[1] = 0x01;
407  memcpy (pkx + 2, &(pkey.eddsa_key), sizeof(pkey.eddsa_key));
408  GNUNET_STRINGS_base64_encode (pkx, sizeof(pkx), &b64);
409 
410  GNUNET_asprintf (&pkey_multibase_str, "u%s", b64);
411 
412  json_t *didd;
413  json_t *did_json;
414  json_t *pkey_multibase_json;
415  json_t *context_json;
416  json_t *context_1_json;
417  json_t *context_2_json;
418  json_t *verify_json;
419  json_t *verify_1_json;
420  json_t *verify_1_type_json;
421  json_t *verify_1_id_json;
422  json_t *verify_relative_ref_json;
423  json_t *auth_json;
424  json_t *assert_json;
425 
426  /* FIXME-MSC: This screams for GNUNET_DID_identity_to_did() */
427  pkey_str = GNUNET_IDENTITY_public_key_to_string (&pkey); // Convert public key to string
428  sprintf (did_str, "did:reclaim:%s", pkey_str); // Convert the public key to a DID str
429  sprintf (verify_id_str, "did:reclaim:%s#key-1", pkey_str); // Convert the public key to a DID str
430 
431  // sprintf(pkey_multibase_str, "V%s", pkey_str); // Convert the public key to MultiBase data format
432 
433  /* FIXME-MSC: This is effectively creating a DID Document default template for
434  * the initial document.
435  * Maybe this can be refactored to generate such a template for an identity?
436  * Even if higher layers add/modify it, there should probably still be a
437  * GNUNET_DID_document_template_from_identity()
438  */
439  // Create Json Strings
440  did_json = json_string (did_str);
441  pkey_multibase_json = json_string (pkey_multibase_str);
442 
443  context_1_json = json_string ("https://www.w3.org/ns/did/v1");
444  context_2_json = json_string (
445  "https://w3id.org/security/suites/ed25519-2020/v1");
446  verify_1_id_json = json_string (verify_id_str);
447  verify_1_type_json = json_string ("Ed25519VerificationKey2020");
448 
449  // Add a relative DID URL to reference a verifiation method
450  // https://www.w3.org/TR/did-core/#relative-did-urls`
451  verify_relative_ref_json = json_string ("#key-1");
452 
453  // Create DID Document
454  didd = json_object ();
455 
456  // Add context
457  context_json = json_array ();
458  json_array_append (context_json, context_1_json);
459  json_array_append (context_json, context_2_json);
460  json_object_set (didd, "@context", context_json);
461 
462  // Add id
463  json_object_set (didd, "id", did_json);
464 
465  // Add verification method
466  verify_json = json_array ();
467  verify_1_json = json_object ();
468  json_object_set (verify_1_json, "id", verify_1_id_json);
469  json_object_set (verify_1_json, "type", verify_1_type_json);
470  json_object_set (verify_1_json, "controller", did_json);
471  json_object_set (verify_1_json, "publicKeyMultiBase", pkey_multibase_json);
472  json_array_append (verify_json, verify_1_json);
473  json_object_set (didd, "verificationMethod", verify_json);
474 
475  // Add authentication method
476  auth_json = json_array ();
477  json_array_append (auth_json, verify_relative_ref_json);
478  json_object_set (didd, "authentication", auth_json);
479 
480  // Add assertion method to issue a Verifiable Credential
481  assert_json = json_array ();
482  json_array_append (assert_json, verify_relative_ref_json);
483  json_object_set (didd, "assertionMethod", assert_json);
484 
485  // Encode DID Document as JSON string
486  didd_str = json_dumps (didd, JSON_INDENT (2));
487  if (didd_str == NULL)
488  {
489  printf ("DID Document could not be encoded");
491  ret = 1;
492  return NULL;
493  }
494 
495  // TODO: MORE FREEEEEEEE
496  /* FIXME-MSC: json_t's are free'd using "json_decref". Also json_t usually
497  * keeps a reference counter. Check jansson docs for how to use it.
498  * Also: Use valgrind to find leaks.
499  */
500  free (pkey_multibase_str);
501  free (b64);
502 
503  free (didd);
504  free (did_json);
505  free (pkey_multibase_json);
506  free (context_json);
507  free (context_1_json);
508  free (context_2_json);
509  free (verify_json);
510  free (verify_1_json);
511  free (verify_1_type_json);
512  free (verify_1_id_json);
513  free (auth_json);
514  free (assert_json);
515  free (verify_relative_ref_json);
516 
517  return didd_str;
518 }
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1598

References cleanup(), didd, GNUNET_asprintf(), GNUNET_IDENTITY_public_key_to_string(), GNUNET_SCHEDULER_add_now(), GNUNET_STRINGS_base64_encode(), pkey, and ret.

Referenced by create_did_ego_lockup_cb().

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

◆ create_did_store_cb()

static void create_did_store_cb ( void *  cls,
int32_t  success,
const char *  emsg 
)
static

Create a DID.

Store DID in Namestore cb

Definition at line 525 of file gnunet-did.c.

526 {
528  ret = 0;
529  return;
530 }

References cleanup(), GNUNET_SCHEDULER_add_now(), and ret.

Referenced by create_did_store().

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

◆ create_did_store()

static void create_did_store ( char *  didd_str,
struct GNUNET_IDENTITY_Ego ego 
)
static

Create a did.

Store DID in Namestore

Parameters
didd_strString endoced DID Docuement
egoIdentity whos DID Document is stored

Definition at line 539 of file gnunet-did.c.

540 {
541 
542  struct GNUNET_TIME_Relative expire_time;
543  struct GNUNET_GNSRECORD_Data record_data;
544  const struct GNUNET_IDENTITY_PrivateKey *skey;
545 
547  expire :
549  &expire_time) == GNUNET_OK)
550  {
551  record_data.data = didd_str;
552  record_data.expiration_time = expire_time.rel_value_us;
553  record_data.data_size = strlen (didd_str) + 1;
554  record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"),
555  record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
556 
558 
560  skey,
562  1, //FIXME what if GNUNET_GNS_EMPTY_LABEL_AT has records
563  &record_data,
565  NULL);
566  }
567  else {
568  printf ("Failed to read given expiration time\n");
570  ret = 1;
571  return;
572  }
573 }
static void create_did_store_cb(void *cls, int32_t success, const char *emsg)
Create a DID.
Definition: gnunet-did.c:525
#define GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME
Definition: gnunet-did.c:44
uint32_t GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
Convert a type name (e.g "AAAA") to the corresponding number.
Definition: gnsrecord.c:217
@ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_relative(const char *fancy_time, struct GNUNET_TIME_Relative *rtime)
Convert a given fancy human-readable time to our internal representation.
Definition: strings.c:261
Time for relative time used by GNUnet, in microseconds.

References cleanup(), create_did_store_cb(), GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, GNUNET_GNSRECORD_Data::expiration_time, expire, GNUNET_GNSRECORD_Data::flags, GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME, GNUNET_GNS_EMPTY_LABEL_AT, GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_GNSRECORD_typename_to_number(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_NAMESTORE_records_store(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_STRINGS_fancy_time_to_relative(), namestore_handle, GNUNET_GNSRECORD_Data::record_type, GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by create_did_ego_lockup_cb(), and replace_did_document_ego_lookup_cb().

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

◆ create_did_ego_lockup_cb()

static void create_did_ego_lockup_cb ( void *  cls,
struct GNUNET_IDENTITY_Ego ego 
)
static

Create a did ego lockup cb.

Parameters
cls
ego

Definition at line 582 of file gnunet-did.c.

583 {
585  char *didd_str;
586 
587  if (ego == NULL)
588  {
589  printf ("EGO not found\n");
591  ret = 1;
592  return;
593  }
594 
596 
597  if (ntohl (pkey.type) != GNUNET_GNSRECORD_TYPE_EDKEY)
598  {
599  printf ("The EGO has to have an EDDSA key pair\n");
601  ret = 1;
602  return;
603  }
604 
605  if (didd != NULL)
606  {
607  printf (
608  "DID Docuement is read from \"did-document\" argument (EXPERIMENTAL)\n");
609  didd_str = strdup (didd);
610  }
611  else {
612  // Generate DID Docuement from public key
613  didd_str = create_did_generate (pkey);
614  }
615 
616  // Print DID Document to stdout
617  printf ("%s\n", didd_str);
618 
619  // Store the DID Document
620  create_did_store (didd_str, ego);
621 
622  // Save DID Document String to GNS
623  free (didd_str);
624 }
#define GNUNET_GNSRECORD_TYPE_EDKEY
Record type for EDKEY zone delegations.
char * create_did_generate(struct GNUNET_IDENTITY_PublicKey pkey)
Create a did generate did object.
Definition: gnunet-did.c:393
static void create_did_store(char *didd_str, struct GNUNET_IDENTITY_Ego *ego)
Create a did.
Definition: gnunet-did.c:539
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.
Definition: identity_api.c:652

References cleanup(), create_did_generate(), create_did_store(), didd, GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_IDENTITY_ego_get_public_key(), GNUNET_SCHEDULER_add_now(), pkey, and ret.

Referenced by create_did_document_ego_create_cb().

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

◆ create_did_document_ego_create_cb()

static void create_did_document_ego_create_cb ( void *  cls,
const struct GNUNET_IDENTITY_PrivateKey pk,
const char *  emsg 
)
static

Create a did document - Create a new identity first.

Definition at line 630 of file gnunet-did.c.

633 {
634 
635  if (emsg != NULL)
636  {
637  printf ("%s\n", emsg);
639  ret = 1;
640  return;
641  }
642 
644  egoname,
646  NULL);
647 }
static void create_did_ego_lockup_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
Create a did ego lockup cb.
Definition: gnunet-did.c:582

References cleanup(), create_did_ego_lockup_cb(), egoname, GNUNET_IDENTITY_ego_lookup(), GNUNET_SCHEDULER_add_now(), my_cfg, and ret.

Referenced by create_did_document().

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

◆ create_did_document()

static void create_did_document ( )
static

Create a did document.

Definition at line 654 of file gnunet-did.c.

655 {
656  if ((egoname != NULL) && (expire != NULL))
657  {
659  egoname,
660  NULL,
663  egoname);
664  }
665  else {
666  printf (
667  "Set the EGO and the Expiration-time argument to create a new DID(-Document)\n");
669  ret = 1;
670  return;
671  }
672 }
static void create_did_document_ego_create_cb(void *cls, const struct GNUNET_IDENTITY_PrivateKey *pk, const char *emsg)
Create a did document - Create a new identity first.
Definition: gnunet-did.c:630
struct GNUNET_IDENTITY_Operation * GNUNET_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.
Definition: identity_api.c:757
@ GNUNET_IDENTITY_TYPE_EDDSA
EDDSA identity.

References cleanup(), create_did_document_ego_create_cb(), egoname, expire, GNUNET_IDENTITY_create(), GNUNET_IDENTITY_TYPE_EDDSA, GNUNET_SCHEDULER_add_now(), identity_handle, and ret.

Referenced by post_ego_iteration().

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

◆ replace_did_document_ego_lookup_cb()

static void replace_did_document_ego_lookup_cb ( void *  cls,
struct GNUNET_IDENTITY_Ego ego 
)
static

Replace a DID Docuemnt.

Callback function after ego lockup

Parameters
cls
ego

Definition at line 682 of file gnunet-did.c.

683 {
684  create_did_store (didd, ego);
685 }

References create_did_store(), and didd.

Referenced by replace_did_document_remove_cb().

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

◆ replace_did_document_remove_cb()

static void replace_did_document_remove_cb ( void *  cls)
static

Replace a DID Document.

Callback functiona after remove

Parameters
cls

Definition at line 693 of file gnunet-did.c.

694 {
696  egoname,
698  NULL);
699 }
static void replace_did_document_ego_lookup_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
Replace a DID Docuemnt.
Definition: gnunet-did.c:682

References egoname, GNUNET_IDENTITY_ego_lookup(), my_cfg, and replace_did_document_ego_lookup_cb().

Referenced by replace_did_document().

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

◆ replace_did_document()

static void replace_did_document ( )
static

Replace a DID Docuemnt.

Definition at line 706 of file gnunet-did.c.

707 {
708  if ((didd != NULL) && (expire != NULL))
709  {
711  }
712  else {
713  printf (
714  "Set the DID Document and expiration time argument to replace the DID Document\n");
716  ret = 1;
717  return;
718  }
719 }
static void replace_did_document_remove_cb(void *cls)
Replace a DID Document.
Definition: gnunet-did.c:693
static void remove_did_document(remove_did_document_callback cont, void *cls)
Remove a DID Document.
Definition: gnunet-did.c:362

References cleanup(), didd, expire, GNUNET_SCHEDULER_add_now(), remove_did_document(), replace_did_document_remove_cb(), and ret.

Referenced by post_ego_iteration().

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

◆ post_ego_iteration()

static void post_ego_iteration ( void *  cls)
static

Definition at line 722 of file gnunet-did.c.

723 {
724  if (1 == replace)
725  {
727  }
728  else if (1 == get)
729  {
731  }
732  else if (1 == remove_did)
733  {
734  remove_did_document (NULL, NULL);
735  }
736  else if (1 == create)
737  {
739  }
740  else {
741  // No Argument found
743  return;
744  }
745 }
static int replace
Replace DID Document Flag.
Definition: gnunet-did.c:54
static void create_did_document()
Create a did document.
Definition: gnunet-did.c:654
static int remove_did
Remove DID Document Flag.
Definition: gnunet-did.c:59
static void resolve_did_document()
Resolve a DID given by the user.
Definition: gnunet-did.c:260
static int get
Get DID Documement for DID Flag.
Definition: gnunet-did.c:64
static int create
Create DID Document Flag.
Definition: gnunet-did.c:69
static void replace_did_document()
Replace a DID Docuemnt.
Definition: gnunet-did.c:706

References cleanup(), create, create_did_document(), get, GNUNET_SCHEDULER_add_now(), remove_did, remove_did_document(), replace, replace_did_document(), and resolve_did_document().

Referenced by process_dids().

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

◆ process_dids()

static void process_dids ( void *  cls,
struct GNUNET_IDENTITY_Ego ego,
void **  ctx,
const char *  name 
)
static

Definition at line 748 of file gnunet-did.c.

750 {
751  char *did_str;
752 
753  if (ego == NULL)
754  {
755  if (1 == ego_exists)
756  {
758  return;
759  }
761  return;
762  }
763  if (NULL == name)
764  return;
765  if ((1 == create) &&
766  (0 == strncmp (name, egoname, strlen (egoname))) &&
767  (1 != ego_exists))
768  {
769  fprintf(stderr, "%s already exists!\n", egoname);
770  ego_exists = 1;
771  return;
772  }
773  if (1 == show_all)
774  {
775  did_str = DID_ego_to_did (ego);
776  printf ("%s\n", did_str);
777  GNUNET_free (did_str);
778  return;
779  }
780  if (1 == show)
781  {
782  if (0 == strncmp (name, egoname, strlen (egoname)))
783  {
784  did_str = DID_ego_to_did (ego);
785  printf ("%s\n", did_str);
786  GNUNET_free (did_str);
787  return;
788  }
789  }
790 }
static int show_all
Show DID for Ego Flag.
Definition: gnunet-did.c:79
static int ego_exists
Give ego exists.
Definition: gnunet-did.c:125
static void post_ego_iteration(void *cls)
Definition: gnunet-did.c:722
static int show
Show DID for Ego Flag.
Definition: gnunet-did.c:74
const char * name

References cleanup(), create, DID_ego_to_did(), ego_exists, egoname, GNUNET_free, GNUNET_SCHEDULER_add_now(), name, post_ego_iteration(), show, and show_all.

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,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle c 
)
static

Definition at line 795 of file gnunet-did.c.

799 {
802  my_cfg = c;
803 
804  // check if GNS_handle could connect
805  if (gns_handle == NULL)
806  {
807  ret = 1;
808  return;
809  }
810 
811  // check if NAMESTORE_handle could connect
812  if (namestore_handle == NULL)
813  {
815  ret = 1;
816  return;
817  }
818 
820  if (identity_handle == NULL)
821  {
823  ret = 1;
824  return;
825  }
826 }
static void process_dids(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
Definition: gnunet-did.c:748
struct GNUNET_GNS_Handle * GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the GNS service.
Definition: gns_api.c:268
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
Definition: identity_api.c:610
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.

References cleanup(), gns_handle, GNUNET_GNS_connect(), GNUNET_IDENTITY_connect(), GNUNET_NAMESTORE_connect(), GNUNET_SCHEDULER_add_now(), identity_handle, my_cfg, namestore_handle, process_dids(), and ret.

Referenced by main().

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

◆ main()

int main ( int  argc,
char *const  argv[] 
)

Definition at line 829 of file gnunet-did.c.

830 {
833  "create",
834  gettext_noop (
835  "Create a DID Document and display its DID"),
836  &create),
838  "get",
839  gettext_noop (
840  "Get the DID Document associated with the given DID"),
841  &get),
843  "show",
844  gettext_noop ("Show the DID for a given ego"),
845  &show),
847  "remove",
848  gettext_noop (
849  "Remove the DID"),
850  &remove_did),
852  "replace",
853  gettext_noop ("Replace the DID Document."),
854  &replace),
856  "--show-all",
857  gettext_noop ("Replace the DID Document."),
858  &show_all),
860  "did",
861  "DID",
862  gettext_noop (
863  "The Decentralized Identity (DID)"),
864  &did),
866  "--did-document",
867  "JSON",
868  gettext_noop (
869  "The DID Document to store in GNUNET"),
870  &didd),
872  "ego",
873  "EGO",
874  gettext_noop ("The name of the EGO"),
875  &egoname),
877  "expiration-time",
878  "TIME",
879  gettext_noop (
880  "The time until the DID Document is going to expire (e.g. 5d)"),
881  &expire),
883  };
884 
885  if (GNUNET_OK != GNUNET_PROGRAM_run (argc,
886  argv,
887  "gnunet-did",
888  _ (
889  "Manage Decentralized Identities (DIDs)"),
890  options,
891  &run,
892  NULL))
893  return 1;
894  else
895  return ret;
896 }
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:69
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Definition: gnunet-did.c:795
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:399
Definition of a command line option.

References _, create, did, didd, egoname, expire, get, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_string(), GNUNET_OK, GNUNET_PROGRAM_run(), options, remove_did, replace, ret, run(), show, and show_all.

Here is the call graph for this function:

Variable Documentation

◆ ret

int ret
static

◆ replace

int replace
static

Replace DID Document Flag.

Definition at line 54 of file gnunet-did.c.

Referenced by main(), post_ego_iteration(), replace_char(), try_ifconfig(), and try_ip().

◆ remove_did

int remove_did
static

Remove DID Document Flag.

Definition at line 59 of file gnunet-did.c.

Referenced by main(), and post_ego_iteration().

◆ get

int get
static

Get DID Documement for DID Flag.

Definition at line 64 of file gnunet-did.c.

Referenced by check_dht_local_get_result_seen(), check_get(), handle_dht_p2p_get(), main(), and post_ego_iteration().

◆ create

int create
static

Create DID Document Flag.

Definition at line 69 of file gnunet-did.c.

Referenced by GCP_get(), GCP_get_tunnel(), GNUNET_SERVER_set_callbacks(), main(), post_ego_iteration(), and process_dids().

◆ show

int show
static

Show DID for Ego Flag.

Definition at line 74 of file gnunet-did.c.

Referenced by main(), and process_dids().

◆ show_all

int show_all
static

Show DID for Ego Flag.

Definition at line 79 of file gnunet-did.c.

Referenced by main(), and process_dids().

◆ did

char* did
static

DID Attribut String.

Definition at line 84 of file gnunet-did.c.

Referenced by cleanup(), get_pkey_from_attr_did(), main(), and resolve_did_document().

◆ didd

char* didd
static

DID Document Attribut String.

Definition at line 89 of file gnunet-did.c.

Referenced by cleanup(), create_did_ego_lockup_cb(), create_did_generate(), main(), replace_did_document(), and replace_did_document_ego_lookup_cb().

◆ egoname

char* egoname
static

◆ expire

char* expire
static

◆ gns_handle

struct GNUNET_GNS_Handle* gns_handle
static

Definition at line 104 of file gnunet-did.c.

Referenced by cleanup(), resolve_did_document(), and run().

◆ namestore_handle

struct GNUNET_NAMESTORE_Handle* namestore_handle
static

Definition at line 109 of file gnunet-did.c.

Referenced by cleanup(), create_did_store(), remove_did_document_ego_lookup_cb(), and run().

◆ identity_handle

struct GNUNET_IDENTITY_Handle* identity_handle
static

Definition at line 114 of file gnunet-did.c.

Referenced by cleanup(), create_did_document(), and run().

◆ my_cfg

const struct GNUNET_CONFIGURATION_Handle* my_cfg
static

◆ ego_exists

int ego_exists = 0
static

Give ego exists.

Definition at line 125 of file gnunet-did.c.

Referenced by process_dids().