GNUnet  0.19.5
did_core.c File Reference

Core functionality for DID. More...

#include "platform.h"
#include "did_core.h"
Include dependency graph for did_core.c:

Go to the source code of this file.

Data Structures

struct  DID_resolve_return
 
struct  DID_action_return
 
struct  DID_create_namestore_lookup_closure
 

Functions

static void DID_resolve_gns_lookup_cb (void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 GNS lookup callback. More...
 
enum GNUNET_GenericReturnValue DID_resolve (const char *did, struct GNUNET_GNS_Handle *gns_handle, DID_resolve_callback *cont, void *cls)
 Resolve a DID. More...
 
static void DID_create_did_store_cb (void *cls, enum GNUNET_ErrorCode ec)
 
static void DID_create_namestore_lookup_cb (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 
enum GNUNET_GenericReturnValue DID_create (const struct GNUNET_IDENTITY_Ego *ego, const char *did_document, const struct GNUNET_TIME_Relative *expire_time, struct GNUNET_NAMESTORE_Handle *namestore_handle, DID_action_callback *cont, void *cls)
 Creates a DID and saves DID Document in Namestore. More...
 

Detailed Description

Core functionality for DID.

Author
Tristan Schwieren

Definition in file did_core.c.

Function Documentation

◆ DID_resolve_gns_lookup_cb()

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

GNS lookup callback.

Calls the given callback function and gives it the DID Document. 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 59 of file did_core.c.

63 {
64  char *did_document;
65  DID_resolve_callback *cb = ((struct DID_resolve_return *) cls)->cb;
66  void *cls_did_resolve_cb = ((struct DID_resolve_return *) cls)->cls;
67  free (cls);
68 
69  for (int i = 0; i < rd_count; i++) {
70  if (rd[i].record_type != GNUNET_GNSRECORD_TYPE_DID_DOCUMENT)
71  continue;
72  did_document = (char *) rd[i].data;
73  cb (GNUNET_OK, did_document, cls_did_resolve_cb);
74  return;
75  }
76  cb (GNUNET_NO, "DID Document is not a DID_DOCUMENT record\n",
77  cls_did_resolve_cb);
78 }
#define GNUNET_GNSRECORD_TYPE_DID_DOCUMENT
Record type to store DID Documents.
void DID_resolve_callback(enum GNUNET_GenericReturnValue status, char *did_document, void *cls)
Signature of a callback function that is called after a did has been resolved.
Definition: did_core.h:50
uint32_t data
The data value.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
@ GNUNET_OK
@ GNUNET_NO
DID_resolve_callback * cb
Definition: did_core.c:35

◆ DID_resolve()

enum GNUNET_GenericReturnValue DID_resolve ( const char *  did,
struct GNUNET_GNS_Handle gns_handle,
DID_resolve_callback cont,
void *  cls 
)

Resolve a DID.

Calls the given callback function with the resolved DID Document and the given closure. If the did can not be resolved did_document is NULL.

Parameters
didDID that is resolve

Definition at line 59 of file did_core.c.

92 {
94 
95  // did, gns_handle and cont must me set
96  if ((did == NULL) || (gns_handle == NULL) || (cont == NULL))
97  return GNUNET_NO;
98 
99  if (GNUNET_OK != DID_did_to_pkey (did, &pkey))
100  return GNUNET_NO;
101 
102  // Create closure for lookup callback
103  struct DID_resolve_return *cls_gns_lookup_cb
104  = malloc (sizeof(struct DID_resolve_return));
105  cls_gns_lookup_cb->cb = cont;
106  cls_gns_lookup_cb->cls = cls;
107 
110  &pkey,
114  cls_gns_lookup_cb);
115 
116  return GNUNET_OK;
117 }
static void DID_resolve_gns_lookup_cb(void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
GNS lookup callback.
Definition: did_core.c:59
#define DID_DOCUMENT_LABEL
Definition: did_core.h:37
enum GNUNET_GenericReturnValue DID_did_to_pkey(const char *did, struct GNUNET_IDENTITY_PublicKey *pkey)
Return the public key of a DID.
Definition: did_helper.c:79
static struct GNUNET_GNS_Handle * gns_handle
Handle to the GNS service.
uint32_t did
This has a different ID for each parameter, see PRISM_DID_* constants.
static char * pkey
Public key of the zone to look in, in ASCII.
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:422
@ GNUNET_GNS_LO_DEFAULT
Defaults, look in cache, then in DHT.
An identity key as per LSD0001.

References DID_resolve_return::cb, DID_resolve_return::cls, data, GNUNET_GNSRECORD_TYPE_DID_DOCUMENT, GNUNET_NO, GNUNET_OK, rd, and rd_count.

Referenced by resolve_did().

Here is the caller graph for this function:

◆ DID_create_did_store_cb()

static void DID_create_did_store_cb ( void *  cls,
enum GNUNET_ErrorCode  ec 
)
static

Definition at line 124 of file did_core.c.

126 {
127  DID_action_callback *cb = ((struct DID_action_return *) cls)->cb;
128  void *cls_did_create_cb = ((struct DID_action_return *) cls)->cls;
129  free (cls);
130 
131  if (GNUNET_EC_NONE == ec)
132  {
133  cb (GNUNET_OK, (void *) cls_did_create_cb);
134  }
135  else
136  {
137  // TODO: Log emsg. Not writing it to STDOUT
138  printf ("%s\n", GNUNET_ErrorCode_get_hint (ec));
139  cb (GNUNET_NO, (void *) cls_did_create_cb);
140  }
141 }
const char * GNUNET_ErrorCode_get_hint(enum GNUNET_ErrorCode ec)
Returns a hint for a given error code.
@ GNUNET_EC_NONE
No error (success).
void DID_action_callback(enum GNUNET_GenericReturnValue status, void *cls)
Signature of a callback function that is called after a did has been removed status = 0 if action was...
Definition: did_core.h:61
DID_action_callback * cb
Definition: did_core.c:41

References DID_resolve_return::cb, DID_action_return::cb, DID_action_return::cls, GNUNET_EC_NONE, GNUNET_ErrorCode_get_hint(), GNUNET_NO, and GNUNET_OK.

Referenced by DID_create().

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

◆ DID_create_namestore_lookup_cb()

static void DID_create_namestore_lookup_cb ( void *  cls,
const struct GNUNET_IDENTITY_PrivateKey zone,
const char *  label,
unsigned int  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Definition at line 152 of file did_core.c.

158 {
159  struct GNUNET_GNSRECORD_Data record_data;
161 
162  const char *did_document
163  = ((struct DID_create_namestore_lookup_closure *) cls)->did_document;
164 
165  const struct GNUNET_TIME_Relative expire_time
166  = ((struct DID_create_namestore_lookup_closure *) cls)->expire_time;
167 
169  = ((struct DID_create_namestore_lookup_closure *) cls)->namestore_handle;
170 
171  struct DID_action_return *cls_record_store_cb
172  = ((struct DID_create_namestore_lookup_closure *) cls)->ret;
173 
174  free (cls);
175 
176  if (rd_count > 0)
177  {
178  printf ("Ego already has a DID Document. Abort.\n");
179  cls_record_store_cb->cb (GNUNET_NO, cls_record_store_cb->cls);
180  }
181  else {
182  // Get public key
184 
185  // If no DID Document is given a default one is created
186  if (did_document != NULL)
187  printf (
188  "DID Docuement is read from \"DID-document\" argument (EXPERIMENTAL)\n");
189  else
191 
192  // Create record
193  record_data.data = did_document;
194  record_data.expiration_time = expire_time.rel_value_us;
195  record_data.data_size = strlen (did_document) + 1;
196  record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"),
197  record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
198 
199  // Store record
201  zone,
203  1, // FIXME what if GNUNET_GNS_EMPTY_LABEL_AT has records
204  &record_data,
206  (void *) cls_record_store_cb);
207  }
208 }
static void DID_create_did_store_cb(void *cls, enum GNUNET_ErrorCode ec)
Definition: did_core.c:124
char * DID_pkey_to_did_document(struct GNUNET_IDENTITY_PublicKey *pkey)
Create a did generate did object.
Definition: did_helper.c:138
static struct GNUNET_NAMESTORE_Handle * namestore_handle
Definition: gnunet-did.c:111
static char * zone
Name of the zone being managed.
@ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
uint32_t GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
Convert a type name (e.g.
Definition: gnsrecord.c:200
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.
Definition: identity_api.c:179
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.
struct GNUNET_TIME_Relative expire_time
Definition: did_core.c:146
Connection to the NAMESTORE service.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.

◆ DID_create()

enum GNUNET_GenericReturnValue DID_create ( const struct GNUNET_IDENTITY_Ego ego,
const char *  did_document,
const struct GNUNET_TIME_Relative expire_time,
struct GNUNET_NAMESTORE_Handle namestore_handle,
DID_action_callback cont,
void *  cls 
)

Creates a DID and saves DID Document in Namestore.

Parameters
egoego for which the DID should be created.
did_documentdid_document that should be saved in namestore. If did_document==NULL -> Default DID document is created.
namestore_handle
contcallback function
clsclosure

Definition at line 152 of file did_core.c.

227 {
229 
230  // Ego, namestore_handle and cont must be set
231  if ((ego == NULL) || (namestore_handle == NULL) || (cont == NULL))
232  return GNUNET_NO;
233 
234  // Check if ego has EdDSA key
236  &pkey);
237  if (ntohl (pkey.type) != GNUNET_GNSRECORD_TYPE_EDKEY)
238  {
239  printf ("The EGO has to have an EdDSA key pair\n");
240  return GNUNET_NO;
241  }
242 
243  struct DID_action_return *ret
244  = malloc (sizeof(struct DID_action_return));
245  ret->cb = cont;
246  ret->cls = cls;
247 
248  struct DID_create_namestore_lookup_closure *cls_name_store_lookup_cb
249  = malloc (sizeof(struct DID_create_namestore_lookup_closure));
250  cls_name_store_lookup_cb->did_document = did_document;
251  cls_name_store_lookup_cb->expire_time = (*expire_time);
252  cls_name_store_lookup_cb->namestore_handle = namestore_handle;
253  cls_name_store_lookup_cb->ret = ret;
254 
255  // Check if ego already has a DID Document
259  NULL,
260  NULL,
262  (void *) cls_name_store_lookup_cb);
263 
264  return GNUNET_OK;
265 }
#define GNUNET_GNSRECORD_TYPE_EDKEY
GNS zone delegation (EDKEY)
static void DID_create_namestore_lookup_cb(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Definition: did_core.c:152
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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:560
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:573
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
Lookup an item in the namestore.
struct GNUNET_NAMESTORE_Handle * namestore_handle
Definition: did_core.c:147
struct DID_action_return * ret
Definition: did_core.c:148
Handle for an ego.
Definition: identity.h:37

References DID_action_return::cb, DID_action_return::cls, GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, DID_create_did_store_cb(), DID_create_namestore_lookup_closure::did_document, DID_DOCUMENT_LABEL, DID_pkey_to_did_document(), GNUNET_GNSRECORD_Data::expiration_time, DID_create_namestore_lookup_closure::expire_time, GNUNET_GNSRECORD_Data::flags, GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_GNSRECORD_typename_to_number(), GNUNET_IDENTITY_key_get_public(), GNUNET_NAMESTORE_records_store(), GNUNET_NO, namestore_handle, pkey, rd_count, GNUNET_GNSRECORD_Data::record_type, GNUNET_TIME_Relative::rel_value_us, and zone.

Referenced by create_did_ego_lockup_cb().

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