[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 62/70: - refactored DID create
From: |
gnunet |
Subject: |
[gnunet] 62/70: - refactored DID create |
Date: |
Wed, 31 Aug 2022 18:00:56 +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 2c8ab6b923a99e5a97cfca0185f1d300cb774f08
Author: Tristan Schwieren <tristan.schwieren@tum.de>
AuthorDate: Fri Jul 1 14:41:41 2022 +0200
- refactored DID create
---
src/reclaim/did_core.c | 122 ++++++++++++++++++++---------------------------
src/reclaim/did_core.h | 9 +---
src/reclaim/gnunet-did.c | 54 ++++++++-------------
3 files changed, 76 insertions(+), 109 deletions(-)
diff --git a/src/reclaim/did_core.c b/src/reclaim/did_core.c
index dea1c82c3..2d0a3c525 100644
--- a/src/reclaim/did_core.c
+++ b/src/reclaim/did_core.c
@@ -32,9 +32,20 @@
#define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME "1d"
static DID_resolve_callback *resolve_cb;
-static DID_action_callback *action_cb;
static void *closure;
+struct DID_resolve_return
+{
+ DID_resolve_callback *cb;
+ void *cls;
+};
+
+struct DID_action_return
+{
+ DID_action_callback *cb;
+ void *cls;
+};
+
// ------------------------------------------------ //
// -------------------- Resolve ------------------- //
// ------------------------------------------------ //
@@ -117,72 +128,23 @@ DID_create_did_store_cb (void *cls,
int32_t success,
const char *emsg)
{
+ DID_action_callback *cb = ((struct DID_action_return *) cls)->cb;
+ void *cls2 = ((struct DID_action_return *) cls)->cls;
+ free (cls);
+
if (GNUNET_OK == success)
{
- // TEST
- struct GNUNET_IDENTITY_PublicKey *pkey_test;
- GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) closure,
- pkey_test);
- printf ("pkey1: %s\n", GNUNET_IDENTITY_public_key_to_string (pkey_test));
-
- printf ("cls3: %s\n", (char *) closure);
- action_cb (GNUNET_OK, closure);
+ cb (GNUNET_OK, (void *) cls2);
}
else
{
printf ("%s\n", emsg);
- action_cb (GNUNET_NO, closure);
- }
-}
-
-/**
- * @brief Store DID Document in Namestore
- *
- * @param didd_str String endoced DID Docuement
- * @param ego Identity whos DID Document is stored
- */
-static enum GNUNET_GenericReturnValue
-DID_create_did_store (struct GNUNET_NAMESTORE_Handle *namestore_handle,
- char *didd_str, struct GNUNET_IDENTITY_Ego *ego)
-{
-
- struct GNUNET_TIME_Relative expire_time;
- struct GNUNET_GNSRECORD_Data record_data;
- const struct GNUNET_IDENTITY_PrivateKey *skey;
-
- if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (
- DID_DOCUMENT_DEFAULT_EXPIRATION_TIME, &expire_time))
- {
- printf ("Failed to read given expiration time\n");
- return GNUNET_NO;
+ cb (GNUNET_NO, (void *) cls2);
}
-
- record_data.data = didd_str;
- record_data.expiration_time = expire_time.rel_value_us;
- record_data.data_size = strlen (didd_str) + 1;
- record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"),
- record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
-
- skey = GNUNET_IDENTITY_ego_get_private_key (ego);
-
- // TEST
- struct GNUNET_IDENTITY_PublicKey *pkey_test;
- GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) closure,
- pkey_test);
- printf ("pkey1: %s\n", GNUNET_IDENTITY_public_key_to_string (pkey_test));
-
- GNUNET_NAMESTORE_records_store (namestore_handle,
- skey,
- DID_DOCUMENT_LABEL,
- 1, // FIXME what if
GNUNET_GNS_EMPTY_LABEL_AT has records
- &record_data,
- &DID_create_did_store_cb,
- NULL);
-
- return GNUNET_OK;
}
// TODO: Expiration time missing
+// TODO: Check if ego already has a DID document
/**
* @brief Creates a DID and saves DID Document in Namestore.
@@ -199,37 +161,59 @@ DID_create_did_store (struct GNUNET_NAMESTORE_Handle
*namestore_handle,
enum GNUNET_GenericReturnValue
DID_create (const struct GNUNET_IDENTITY_Ego *ego,
const char *did_document,
- const struct GNUNET_CONFIGURATION_Handle *cfg_handle,
- struct GNUNET_IDENTITY_Handle *identity_handle,
struct GNUNET_NAMESTORE_Handle *namestore_handle,
DID_action_callback *cont,
void *cls)
{
struct GNUNET_IDENTITY_PublicKey pkey;
+ struct GNUNET_TIME_Relative expire_time;
+ struct GNUNET_GNSRECORD_Data record_data;
- GNUNET_IDENTITY_ego_get_public_key (ego, &pkey);
+ // Check if ego has EdDSA key
+ GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) ego,
+ &pkey);
if (ntohl (pkey.type) != GNUNET_GNSRECORD_TYPE_EDKEY)
{
- printf ("The EGO has to have an EDDSA key pair\n");
+ printf ("The EGO has to have an EdDSA key pair\n");
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);
+ // TODO: Get the expiration time as argument
+ if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (
+ DID_DOCUMENT_DEFAULT_EXPIRATION_TIME, &expire_time))
+ {
+ printf ("Failed to read given expiration time\n");
+ return GNUNET_NO;
+ }
+
+ // 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;
- // TEST
- struct GNUNET_IDENTITY_PublicKey *pkey_test;
- GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) cls,
- pkey_test);
- printf ("pkey1: %s\n", GNUNET_IDENTITY_public_key_to_string (pkey_test));
+ // Create closure for record store callback
+ struct DID_action_return *cls2 = malloc (sizeof(struct DID_action_return));
+ cls2->cb = cont;
+ cls2->cls = cls;
- action_cb = cont;
- closure = 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);
- return DID_create_did_store (namestore_handle, did_document, ego);
+ return GNUNET_OK;
}
diff --git a/src/reclaim/did_core.h b/src/reclaim/did_core.h
index 8b4837e59..6cde18342 100644
--- a/src/reclaim/did_core.h
+++ b/src/reclaim/did_core.h
@@ -29,6 +29,7 @@
#include "gnunet_namestore_service.h"
#include "gnunet_gns_service.h"
#include "gnunet_gnsrecord_lib.h"
+#include "gnunet_identity_service.h"
#include "did_helper.h"
#include "jansson.h"
@@ -96,12 +97,8 @@ DID_remove (const struct GNUNET_IDENTITY_Ego *ego,
* @brief Creates a DID and saves DID Document in Namestore.
*
* @param ego ego for which the DID should be created.
- * If ego==NULL a new ego is created
* @param did_document did_document that should be saved in namestore.
- * If ego==NULL did_document can also be NULL.
- * Default DID document is created.
- * @param cfg_handle pointer to configuration handle
- * @param identity_handle pointer to identity handle. Can be NULL if ego!=NULL
+ * If did_document==NULL -> Default DID document is created.
* @param namestore_handle
* @param cont callback function
* @param cls closure
@@ -109,8 +106,6 @@ DID_remove (const struct GNUNET_IDENTITY_Ego *ego,
enum GNUNET_GenericReturnValue
DID_create (const struct GNUNET_IDENTITY_Ego *ego,
const char *did_document,
- const struct GNUNET_CONFIGURATION_Handle *cfg_handle,
- struct GNUNET_IDENTITY_Handle *identity_handle,
struct GNUNET_NAMESTORE_Handle *namestore_handle,
DID_action_callback *cont,
void *cls);
diff --git a/src/reclaim/gnunet-did.c b/src/reclaim/gnunet-did.c
index 18b171486..c865e8295 100644
--- a/src/reclaim/gnunet-did.c
+++ b/src/reclaim/gnunet-did.c
@@ -354,27 +354,29 @@ remove_did_document (remove_did_document_callback cont,
void *cls)
}
}
-static void create_did ();
+// Needed because create_did_ego_lookup_cb() and
+// create_did_ego_create_cb() can call each other
+static void create_did_ego_lockup_cb ();
/**
* @brief Create a DID(-Document). Called after DID has been created
+ * Prints status and the DID.
*
*/
static void
create_did_cb (enum GNUNET_GenericReturnValue status, void *cls)
{
- struct GNUNET_IDENTITY_Ego *ego;
- // char *did;
-
if (GNUNET_OK == status)
{
- printf ("DID has been created\n");
- // ego = (struct GNUNET_IDENTITY_Ego *) cls;
- // did = DID_identity_to_did(ego);
- printf ("cls4: %s\n", (char *) cls);
+ printf ("DID has been created.\n%s\n", (char *) cls);
+ free (cls);
+ ret = 0;
}
else
- printf ("An error occured while creating the DID\n"), ret = 1;
+ {
+ printf ("An error occured while creating the DID\n");
+ ret = 1;
+ }
GNUNET_SCHEDULER_add_now (&cleanup, NULL);
return;
@@ -396,27 +398,23 @@ create_did_ego_create_cb (void *cls,
return;
}
- create_did ();
+ GNUNET_IDENTITY_ego_lookup (my_cfg,
+ egoname,
+ &create_did_ego_lockup_cb,
+ NULL);
}
/**
* @brief Create a DID(-Document). Called after ego lookup
*
- * @param cls
- * @param ego
*/
static void
create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
{
- // struct GNUNET_IDENTITY_Ego *ego_test;
- struct GNUNET_IDENTITY_PublicKey *pkey_test;
- printf("test3\n");
-
if (ego == NULL)
{
// If Ego was not found. Create new one first
printf ("Ego was not found. Creating new one.\n");
-
GNUNET_IDENTITY_create (identity_handle,
egoname,
NULL,
@@ -426,20 +424,10 @@ create_did_ego_lockup_cb (void *cls, struct
GNUNET_IDENTITY_Ego *ego)
}
else
{
- printf("test1\n");
- cls = (void *) ego;
-
- // TEST
- // ego_test = (struct GNUNET_IDENTITY_Ego *) cls;
- GNUNET_IDENTITY_ego_get_public_key (ego, pkey_test);
- printf ("pkey1: %s\n", GNUNET_IDENTITY_public_key_to_string (pkey_test));
- printf("test4\n");
-
- // TODO: Check if ego already has a DID document
- // DO a resolve
-
- DID_create (ego, NULL, my_cfg, identity_handle, namestore_handle,
- create_did_cb, cls);
+ char *did = DID_identity_to_did (ego);
+ void *cls = malloc (strlen (did) + 1);
+ strcpy (cls, did);
+ DID_create (ego, NULL, namestore_handle, create_did_cb, cls);
}
}
@@ -450,6 +438,7 @@ create_did_ego_lockup_cb (void *cls, struct
GNUNET_IDENTITY_Ego *ego)
static void
create_did ()
{
+ // Expire has to be set
if (expire == NULL)
{
printf (
@@ -459,6 +448,7 @@ create_did ()
return;
}
+ // Ego name to be set
if (egoname == NULL)
{
printf ("Set the Ego argument to create a new DID(-Document)\n");
@@ -466,8 +456,6 @@ create_did ()
ret = 1;
return;
}
-
- printf("test2\n");
GNUNET_IDENTITY_ego_lookup (my_cfg,
egoname,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet] 34/70: -proper license header, (continued)
- [gnunet] 34/70: -proper license header, gnunet, 2022/08/31
- [gnunet] 28/70: - Not working did remove, gnunet, 2022/08/31
- [gnunet] 37/70: -did not working remove, gnunet, 2022/08/31
- [gnunet] 40/70: -did not working key check, gnunet, 2022/08/31
- [gnunet] 48/70: - started DID refactor, gnunet, 2022/08/31
- [gnunet] 41/70: -did key check, gnunet, 2022/08/31
- [gnunet] 56/70: -header DID core, gnunet, 2022/08/31
- [gnunet] 58/70: - missing lib bug, gnunet, 2022/08/31
- [gnunet] 70/70: -fixup merge, gnunet, 2022/08/31
- [gnunet] 52/70: - working did lib and 1. test for did helper, gnunet, 2022/08/31
- [gnunet] 62/70: - refactored DID create,
gnunet <=
- [gnunet] 49/70: - init did test, gnunet, 2022/08/31
- [gnunet] 42/70: -did mulitbase key and assert method for VCs, gnunet, 2022/08/31
- [gnunet] 18/70: -did working replace, generalized remove, refactor, gnunet, 2022/08/31
- [gnunet] 21/70: -did key check, gnunet, 2022/08/31
- [gnunet] 33/70: -add test for w3c-ed25519-2020, gnunet, 2022/08/31
- [gnunet] 35/70: -test against mb b64, gnunet, 2022/08/31
- [gnunet] 38/70: -did working replace, generalized remove, refactor, gnunet, 2022/08/31
- [gnunet] 39/70: -did expiration time fix, gnunet, 2022/08/31
- [gnunet] 50/70: - not working test, gnunet, 2022/08/31
- [gnunet] 47/70: -move to reclaim, gnunet, 2022/08/31