[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 65/70: -m DID lib; added check for existing DID document
From: |
gnunet |
Subject: |
[gnunet] 65/70: -m DID lib; added check for existing DID document |
Date: |
Wed, 31 Aug 2022 18:00:59 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
commit 3b4032ef5138bf630d830218a0f29c9032cc35d4
Author: Tristan Schwieren <tristan.schwieren@tum.de>
AuthorDate: Fri Jul 8 12:25:45 2022 +0200
-m DID lib; added check for existing DID document
---
src/reclaim/did_core.c | 128 ++++++++++++++++++++++++++++++++++-------------
src/reclaim/gnunet-did.c | 5 +-
2 files changed, 98 insertions(+), 35 deletions(-)
diff --git a/src/reclaim/did_core.c b/src/reclaim/did_core.c
index f43b7e7eb..645ba0cd4 100644
--- a/src/reclaim/did_core.c
+++ b/src/reclaim/did_core.c
@@ -24,12 +24,7 @@
* @author Tristan Schwieren
*/
-// DO: Expiration time missing in create
-// Add Expiration TIME to json DID document
-
-// TODO: Check if ego already has a DID document in create
-// TODO: Store DID document as compact JSON in GNS but resolve it with newlines
-
+// TODO: DID documents do not have an expiration date. Still we add one
// TODO: Store DID document with empty label and own type (maybe DID-Document
or JSON??)
#include "did_core.h"
@@ -87,7 +82,7 @@ DID_resolve_gns_lookup_cb (
* 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.
*
- * @param did DID that is
resolved000G055PGJ4RJSS4G8HWCP86AWF1C6TF2DW2K3BW05HHRKSJG38NT2Z3JGe
+ * @param did DID that is resolve
*/
enum GNUNET_GenericReturnValue
DID_resolve (const char *did,
@@ -141,6 +136,84 @@ DID_create_did_store_cb (void *cls,
}
}
+struct DID_create_namestore_lookup_closure
+{
+ const char *did_document;
+ struct GNUNET_TIME_Relative expire_time;
+ struct GNUNET_NAMESTORE_Handle *namestore_handle;
+ DID_action_callback *cont;
+ void *cls;
+};
+
+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)
+{
+ struct GNUNET_GNSRECORD_Data record_data;
+ struct GNUNET_IDENTITY_PublicKey pkey;
+
+ const char *did_document
+ = ((struct DID_create_namestore_lookup_closure *) cls)->did_document;
+
+ const struct GNUNET_TIME_Relative expire_time
+ = ((struct DID_create_namestore_lookup_closure *) cls)->expire_time;
+
+ struct GNUNET_NAMESTORE_Handle *namestore_handle
+ = ((struct DID_create_namestore_lookup_closure *) cls)->namestore_handle;
+
+ DID_action_callback *cont
+ = ((struct DID_create_namestore_lookup_closure *) cls)->cont;
+
+ void *cls1
+ = ((struct DID_create_namestore_lookup_closure *) cls)->cls;
+
+ if (rd_count > 0)
+ {
+ printf ("Ego already has a DID Document. Abort.\n");
+ cont (GNUNET_NO, cls1);
+ return;
+ }
+ else {
+ // Get public key
+ GNUNET_IDENTITY_key_get_public (zone, &pkey);
+
+ // No DID Document is given a default one is created
+ if (did_document != NULL)
+ printf (
+ "DID Docuement is read from \"DID-document\" argument
(EXPERIMENTAL)\n");
+ else
+ did_document = DID_pkey_to_did_document (&pkey);
+
+ // Create record
+ record_data.data = did_document;
+ record_data.expiration_time = expire_time.rel_value_us;
+ record_data.data_size = strlen (did_document) + 1;
+ record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"),
+ record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
+
+ // Create closure for record store callback
+ struct DID_action_return *cls2 = malloc (sizeof(struct DID_action_return));
+ cls2->cb = cont;
+ cls2->cls = cls1;
+
+ // Store record
+ GNUNET_NAMESTORE_records_store (namestore_handle,
+ zone,
+ DID_DOCUMENT_LABEL,
+ 1, // FIXME what if
GNUNET_GNS_EMPTY_LABEL_AT has records
+ &record_data,
+ &DID_create_did_store_cb,
+ (void *) cls2);
+
+ free(cls);
+ }
+
+}
+
/**
* @brief Creates a DID and saves DID Document in Namestore.
*
@@ -162,8 +235,6 @@ DID_create (const struct GNUNET_IDENTITY_Ego *ego,
void *cls)
{
struct GNUNET_IDENTITY_PublicKey pkey;
- // struct GNUNET_TIME_Relative expire_time;
- struct GNUNET_GNSRECORD_Data record_data;
// Ego, namestore_handle and cont must be set
if ((ego == NULL) || (namestore_handle == NULL) || (cont == NULL))
@@ -178,33 +249,22 @@ DID_create (const struct GNUNET_IDENTITY_Ego *ego,
return GNUNET_NO;
}
- // No DID Document is given a default one is created
- if (did_document != NULL)
- printf (
- "DID Docuement is read from \"DID-document\" argument (EXPERIMENTAL)\n");
- else
- did_document = DID_pkey_to_did_document (&pkey);
-
- // Create record
- record_data.data = did_document;
- record_data.expiration_time = expire_time->rel_value_us;
- record_data.data_size = strlen (did_document) + 1;
- record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"),
- record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
-
- // Create closure for record store callback
- struct DID_action_return *cls2 = malloc (sizeof(struct DID_action_return));
- cls2->cb = cont;
+ struct DID_create_namestore_lookup_closure *cls2
+ = malloc (sizeof(struct DID_create_namestore_lookup_closure));
+ cls2->did_document = did_document;
+ cls2->expire_time = (*expire_time);
+ cls2->namestore_handle = namestore_handle;
+ cls2->cont = cont;
cls2->cls = cls;
- // Store record
- GNUNET_NAMESTORE_records_store (namestore_handle,
- GNUNET_IDENTITY_ego_get_private_key (ego),
- DID_DOCUMENT_LABEL,
- 1, // FIXME what if
GNUNET_GNS_EMPTY_LABEL_AT has records
- &record_data,
- &DID_create_did_store_cb,
- (void *) cls2);
+ // Check if ego already has a DID Document
+ GNUNET_NAMESTORE_records_lookup (namestore_handle,
+ GNUNET_IDENTITY_ego_get_private_key (ego),
+ DID_DOCUMENT_LABEL,
+ NULL,
+ NULL,
+ DID_create_namestore_lookup_cb,
+ (void *) cls2);
return GNUNET_OK;
}
diff --git a/src/reclaim/gnunet-did.c b/src/reclaim/gnunet-did.c
index fb9a8e9a1..c0f81c3e2 100644
--- a/src/reclaim/gnunet-did.c
+++ b/src/reclaim/gnunet-did.c
@@ -446,7 +446,10 @@ create_did_ego_lockup_cb (void *cls, struct
GNUNET_IDENTITY_Ego *ego)
strcpy (cls, did);
// TODO: Add DID_document argument
- if (GNUNET_OK != DID_create (ego, NULL, &expire_relative, namestore_handle,
+ if (GNUNET_OK != DID_create (ego,
+ NULL,
+ &expire_relative,
+ namestore_handle,
create_did_cb,
cls))
{
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet] 31/70: - did not working create, (continued)
- [gnunet] 31/70: - did not working create, gnunet, 2022/08/31
- [gnunet] 46/70: -code review, gnunet, 2022/08/31
- [gnunet] 53/70: - more tests, gnunet, 2022/08/31
- [gnunet] 61/70: - non working DID lib create func, gnunet, 2022/08/31
- [gnunet] 57/70: - changed did_core header, gnunet, 2022/08/31
- [gnunet] 59/70: - DID resolve using DID lib, gnunet, 2022/08/31
- [gnunet] 67/70: - DID lib; formatting, gnunet, 2022/08/31
- [gnunet] 51/70: - trying to make did_helper a lib, gnunet, 2022/08/31
- [gnunet] 64/70: - didlib; use expire value, gnunet, 2022/08/31
- [gnunet] 69/70: - added gitignores, gnunet, 2022/08/31
- [gnunet] 65/70: -m DID lib; added check for existing DID document,
gnunet <=
- [gnunet] 22/70: -did mulitbase key and assert method for VCs, gnunet, 2022/08/31
- [gnunet] 25/70: -forgot the .c..., gnunet, 2022/08/31