[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 54/70: - default did document test without multibase
From: |
gnunet |
Subject: |
[gnunet] 54/70: - default did document test without multibase |
Date: |
Wed, 31 Aug 2022 18:00:48 +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 5ca196a44d74fd8f9af5f3d7ec8cf33ce7aaaa6c
Author: Tristan Schwieren <tristan.schwieren@tum.de>
AuthorDate: Tue Jun 7 12:20:27 2022 +0200
- default did document test without multibase
---
src/reclaim/Makefile.am | 3 ++-
src/reclaim/did_helper.c | 44 ++++++++++++++++++++-----------------
src/reclaim/did_helper.h | 6 -----
src/reclaim/test_did_helper.c | 51 +++++++++++++++++++++++++++++++++----------
4 files changed, 65 insertions(+), 39 deletions(-)
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am
index 3f3419722..694ce0598 100644
--- a/src/reclaim/Makefile.am
+++ b/src/reclaim/Makefile.am
@@ -227,7 +227,8 @@ test_did_helper_LDADD = \
$(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
$(top_builddir)/src/identity/libgnunetidentity.la \
$(top_builddir)/src/namestore/libgnunetnamestore.la \
- libgnunetdid.la
+ libgnunetdid.la \
+ -ljansson
check_SCRIPTS = \
test_reclaim_attribute.sh \
diff --git a/src/reclaim/did_helper.c b/src/reclaim/did_helper.c
index 707cee85e..8452c9d34 100644
--- a/src/reclaim/did_helper.c
+++ b/src/reclaim/did_helper.c
@@ -32,6 +32,12 @@
#include "jansson.h"
+// TODO: GNUNET_DID_key_covert_multibase_base64_to_gnunet
+// TODO: GNUNET_DID_key_covert_gnunet_to_multibase_base64
+
+// TODO: GNUNET_DID_pkey_to_did_document
+
+
/**
* @brief Generate a DID for a given GNUNET public key
*
@@ -55,7 +61,8 @@ GNUNET_DID_pkey_to_did (struct GNUNET_IDENTITY_PublicKey
*pkey)
}
/**
- * @brief Generate a DID for a given gnunet EGO
+ * @brief Generate a DID for a given gnunet EGO.
+ * Wrapper around GNUNET_DID_pkey_to_did
*
* @param ego
* @return char* Returns the DID. Caller must free
@@ -95,15 +102,6 @@ GNUNET_DID_did_to_pkey (char *did, struct
GNUNET_IDENTITY_PublicKey *pkey)
return 0;
}
-/**
- * @brief Return the GNUNET EGO of a DID
- */
-struct GNUNET_IDENTITY_Ego *
-GNUNET_DID_did_to_identity (char *did)
-{
- return NULL;
-}
-
/**
* @brief Convert a base 64 encoded public key to a GNUNET key
*/
@@ -139,14 +137,15 @@ GNUNET_DID_pkey_to_did_document (struct
GNUNET_IDENTITY_PublicKey *pkey)
char *pkey_multibase_str;
/* FIXME-MSC: This screams for a GNUNET_DID_identity_key_to_string() */
- char *b64;
- char pkx[34];
- pkx[0] = 0xed;
- pkx[1] = 0x01;
- memcpy (pkx + 2, &(pkey->eddsa_key), sizeof(pkey->eddsa_key));
- GNUNET_STRINGS_base64_encode (pkx, sizeof(pkx), &b64);
+ // char *b64;
+ // char pkx[34];
+ // pkx[0] = 0xed;
+ // pkx[1] = 0x01;
+ // memcpy (pkx + 2, &(pkey->eddsa_key), sizeof(pkey->eddsa_key));
+ // GNUNET_STRINGS_base64_encode (pkx, sizeof(pkx), &b64);
- GNUNET_asprintf (&pkey_multibase_str, "u%s", b64);
+ // GNUNET_asprintf (&pkey_multibase_str, "u%s", b64);
+ pkey_multibase_str = "moin";
json_t *didd_json;
@@ -165,16 +164,20 @@ GNUNET_DID_pkey_to_did_document (struct
GNUNET_IDENTITY_PublicKey *pkey)
// Add a relative DID URL to reference a verifiation method
// https://www.w3.org/TR/did-core/#relative-did-urls`
- didd_json = json_pack ("{s:[ss], s:s, s:[{ssss}], s:[s], s:[s]",
+ didd_json = json_pack ("{s:[ss], s:s, s:[{s:s, s:s, s:s, s:s}], s:[s],
s:[s]}",
"@context",
"https://www.w3.org/ns/did/v1",
"https://w3id.org/security/suites/ed25519-2020/v1",
"id",
did_str,
"verificationMethod",
+ "id",
verify_id_str,
+ "type",
"Ed25519VerificationKey2020",
+ "controller",
did_str,
+ "publicKeyMultibase",
pkey_multibase_str,
"authentication",
"#key-1",
@@ -185,8 +188,8 @@ GNUNET_DID_pkey_to_did_document (struct
GNUNET_IDENTITY_PublicKey *pkey)
didd_str = json_dumps (didd_json, JSON_INDENT (2));
// Free
- GNUNET_free (pkey_multibase_str);
- GNUNET_free (b64);
+ // GNUNET_free (pkey_multibase_str);
+ // GNUNET_free (b64);
json_decref (didd_json);
return didd_str;
@@ -194,6 +197,7 @@ GNUNET_DID_pkey_to_did_document (struct
GNUNET_IDENTITY_PublicKey *pkey)
/**
* @brief Generate the default DID document for a GNUNET ego
+ * Wrapper around GNUNET_DID_pkey_to_did_document
*/
char *
GNUNET_DID_identity_to_did_document (struct GNUNET_IDENTITY_Ego *ego)
diff --git a/src/reclaim/did_helper.h b/src/reclaim/did_helper.h
index 98b385b4c..2eb3ed8bd 100644
--- a/src/reclaim/did_helper.h
+++ b/src/reclaim/did_helper.h
@@ -51,12 +51,6 @@ GNUNET_DID_identity_to_did(struct GNUNET_IDENTITY_Ego *ego);
int
GNUNET_DID_did_to_pkey (char *did, struct GNUNET_IDENTITY_PublicKey *pkey);
-/**
- * @brief Return the GNUNET EGO of a DID
- */
-struct GNUNET_IDENTITY_Ego *
-GNUNET_DID_did_to_identity(char *did);
-
/**
* @brief Convert a base 64 encoded public key to a GNUNET key
*/
diff --git a/src/reclaim/test_did_helper.c b/src/reclaim/test_did_helper.c
index 8e895d031..563b94e78 100644
--- a/src/reclaim/test_did_helper.c
+++ b/src/reclaim/test_did_helper.c
@@ -30,6 +30,7 @@
#include "gnunet_gns_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "did_helper.h"
+#include "jansson.h"
static const char test_skey_bytes[32] = {
0x9b, 0x93, 0x7b, 0x81, 0x32, 0x2d, 0x81, 0x6c,
@@ -39,29 +40,45 @@ static const char test_skey_bytes[32] = {
};
// TODO: Create a did manual from private key / independet of implementation
-static char *test_did =
+static const char *test_did =
"did:reclaim:000G0509BYD1MPAXVSTNV0KRD1JAT0YZMPJFQNM869B66S72PSF17K4Y8G";
+static const char *test_did_document_format_str =
+ "{\"@context\":[\"https://www.w3.org/ns/did/v1\", \
+ \"https://w3id.org/security/suites/ed25519-2020/v1\"],\
+ \"id\":\"%s\",\
+ \"verificationMethod\":[{\
+ \"id\":\"%s#key-1\",\
+ \"type\":\"Ed25519VerificationKey2020\",\
+ \"controller\":\"%s\",\
+ \"publicKeyMultibase\":\"%s\"}],\
+ \"authentication\":[\"#key-1\"],\
+ \"assertionMethod\":[\"#key-1\"]}";
+
+static const char *test_multibase_key = "moin";
+
static struct GNUNET_IDENTITY_PrivateKey test_skey;
static struct GNUNET_IDENTITY_PublicKey test_pkey;
+static struct json_t *test_did_document;
+static char *test_did_document_str;
void
test_GNUNET_DID_pkey_to_did ()
{
char *str_did;
str_did = GNUNET_DID_pkey_to_did (&test_pkey);
- GNUNET_assert (strcmp (test_did, str_did) == 0);
+ GNUNET_assert (strcmp ((char *) test_did, str_did) == 0);
}
void
test_GNUNET_DID_did_to_pkey ()
{
struct GNUNET_IDENTITY_PublicKey pkey;
- GNUNET_DID_did_to_pkey (test_did, &pkey);
+ GNUNET_DID_did_to_pkey ((char *) test_did, &pkey);
GNUNET_assert (test_pkey.type = pkey.type);
- GNUNET_assert (0 == strcmp (pkey.eddsa_key.q_y,
- test_pkey.eddsa_key.q_y));
+ GNUNET_assert (strcmp (pkey.eddsa_key.q_y,
+ test_pkey.eddsa_key.q_y) == 0);
}
void
@@ -73,21 +90,31 @@ test_GNUNET_DID_key_covert_gnunet_to_multibase_base64 ();
void
test_GNUNET_DID_pkey_to_did_document ()
{
- char *did_document = GNUNET_DID_pkey_to_did_document (&test_pkey);
- printf("%s\n", did_document);
-
- GNUNET_assert(0 == 0);
+ struct json_t *did_document;
+ char *did_document_str = GNUNET_DID_pkey_to_did_document (&test_pkey);
+ did_document = json_loads (did_document_str, JSON_DECODE_ANY, NULL);
+ GNUNET_assert (json_equal (test_did_document, did_document) == 1);
}
int
main ()
{
- // Setup
+ // Setup key
test_skey.type = htonl (GNUNET_IDENTITY_TYPE_EDDSA);
- memcpy (&(test_skey.eddsa_key), test_skey_bytes, sizeof(struct
-
GNUNET_CRYPTO_EddsaPrivateKey));
+ memcpy (&(test_skey.eddsa_key),
+ test_skey_bytes,
+ sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey));
GNUNET_IDENTITY_key_get_public (&test_skey, &test_pkey);
+ // Setup did document
+ GNUNET_asprintf (&test_did_document_str,
+ test_did_document_format_str,
+ test_did,
+ test_did,
+ test_did,
+ test_multibase_key);
+ test_did_document = json_loads (test_did_document_str, JSON_DECODE_ANY,
NULL);
+
// Do tests
test_GNUNET_DID_pkey_to_did ();
test_GNUNET_DID_did_to_pkey ();
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet] 50/70: - not working test, (continued)
- [gnunet] 50/70: - not working test, gnunet, 2022/08/31
- [gnunet] 47/70: -move to reclaim, gnunet, 2022/08/31
- [gnunet] 44/70: -add comments, gnunet, 2022/08/31
- [gnunet] 43/70: -mergefix, gnunet, 2022/08/31
- [gnunet] 36/70: -did not working remove abstraction, gnunet, 2022/08/31
- [gnunet] 45/70: fix bugs, gnunet, 2022/08/31
- [gnunet] 66/70: - DID lib; renamed vars and moved a free, gnunet, 2022/08/31
- [gnunet] 63/70: - remove static variable from did_core, gnunet, 2022/08/31
- [gnunet] 55/70: - finished DID helper with tests, gnunet, 2022/08/31
- [gnunet] 60/70: - started with DID lib create func, gnunet, 2022/08/31
- [gnunet] 54/70: - default did document test without multibase,
gnunet <=
- [gnunet] 68/70: - DID lib; simplify closure, gnunet, 2022/08/31
- [gnunet] 30/70: -DID refactor, uncrustify, not working didd create, gnunet, 2022/08/31
- [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