[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 55/70: - finished DID helper with tests
From: |
gnunet |
Subject: |
[gnunet] 55/70: - finished DID helper with tests |
Date: |
Wed, 31 Aug 2022 18:00:49 +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 45d01b5d9a1ab852677bc5c482980d9f15e20b79
Author: Tristan Schwieren <tristan.schwieren@tum.de>
AuthorDate: Tue Jun 7 15:23:05 2022 +0200
- finished DID helper with tests
---
src/reclaim/Makefile.am | 6 ---
src/reclaim/did_helper.c | 104 ++++++++++++++++++------------------
src/reclaim/did_helper.h | 26 +++++----
src/reclaim/test_did_helper.c | 21 +++++---
src/reclaim/test_w3c_ed25519_2020.c | 69 ------------------------
5 files changed, 78 insertions(+), 148 deletions(-)
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am
index 694ce0598..89c361585 100644
--- a/src/reclaim/Makefile.am
+++ b/src/reclaim/Makefile.am
@@ -214,11 +214,6 @@ gnunet_did_LDADD = \
-ljansson
-test_w3c_ed25519_2020_SOURCES = \
- test_w3c_ed25519_2020.c
-test_w3c_ed25519_2020_LDADD = \
- $(top_builddir)/src/util/libgnunetutil.la
-
test_did_helper_SOURCES = \
test_did_helper.c
test_did_helper_LDADD = \
@@ -237,7 +232,6 @@ check_SCRIPTS = \
check_PROGRAMS = \
test_reclaim_attribute \
- test_w3c_ed25519_2020 \
test_did_helper
if ENABLE_TEST_RUN
diff --git a/src/reclaim/did_helper.c b/src/reclaim/did_helper.c
index 8452c9d34..c579a5cca 100644
--- a/src/reclaim/did_helper.c
+++ b/src/reclaim/did_helper.c
@@ -31,12 +31,8 @@
#include "did_helper.h"
#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
-
+#define STR_INDIR(x) #x
+#define STR(x) STR_INDIR (x)
/**
* @brief Generate a DID for a given GNUNET public key
@@ -119,7 +115,21 @@ GNUNET_DID_key_covert_gnunet_to_multibase_base64 (struct
GNUNET_IDENTITY_PublicKey *
pkey)
{
- return NULL;
+ struct GNUNET_CRYPTO_EddsaPublicKey pubkey = pkey->eddsa_key;
+
+ // This is how to convert out pubkeys to W3c Ed25519-2020 multibase
(base64url no padding)
+ char *pkey_base_64;
+ char *pkey_multibase;
+ char pkx[34];
+
+ pkx[0] = 0xed;
+ pkx[1] = 0x01;
+ memcpy (pkx + 2, &pubkey, sizeof (pubkey));
+ GNUNET_STRINGS_base64url_encode (pkx, sizeof (pkx), &pkey_base_64);
+ GNUNET_asprintf (&pkey_multibase, "u%s", pkey_base_64);
+
+ GNUNET_free (pkey_base_64);
+ return pkey_multibase;
}
/**
@@ -131,28 +141,6 @@ GNUNET_DID_key_covert_gnunet_to_multibase_base64 (struct
char *
GNUNET_DID_pkey_to_did_document (struct GNUNET_IDENTITY_PublicKey *pkey)
{
- char *did_str;
- char *didd_str;
- char *verify_id_str;
- 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);
-
- // GNUNET_asprintf (&pkey_multibase_str, "u%s", b64);
- pkey_multibase_str = "moin";
-
- json_t *didd_json;
-
- did_str = GNUNET_DID_pkey_to_did (pkey);
- GNUNET_asprintf (&verify_id_str, "%s#key-1", did_str);
-
- // sprintf(pkey_multibase_str, "V%s", pkey_str); // Convert the public key
to MultiBase data format
/* FIXME-MSC: This is effectively creating a DID Document default template
for
* the initial document.
@@ -161,35 +149,45 @@ GNUNET_DID_pkey_to_did_document (struct
GNUNET_IDENTITY_PublicKey *pkey)
* GNUNET_DID_document_template_from_identity()
*/
- // 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:[{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",
- "assertionMethod",
- "#key-1");
+ char *did_str;
+ char *verify_id_str;
+ char *pkey_multibase_str;
+ char *didd_str;
+ json_t *didd_json;
+
+ did_str = GNUNET_DID_pkey_to_did (pkey);
+ GNUNET_asprintf (&verify_id_str, "%s#key-1", did_str);
+
+ pkey_multibase_str = GNUNET_DID_key_covert_gnunet_to_multibase_base64 (pkey);
+
+ 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",
+ "assertionMethod",
+ "#key-1");
// Encode DID Document as JSON string
didd_str = json_dumps (didd_json, JSON_INDENT (2));
// Free
- // GNUNET_free (pkey_multibase_str);
- // GNUNET_free (b64);
+ GNUNET_free (did_str);
+ GNUNET_free (verify_id_str);
+ GNUNET_free (pkey_multibase_str);
json_decref (didd_json);
return didd_str;
diff --git a/src/reclaim/did_helper.h b/src/reclaim/did_helper.h
index 2eb3ed8bd..11bab0354 100644
--- a/src/reclaim/did_helper.h
+++ b/src/reclaim/did_helper.h
@@ -24,9 +24,6 @@
* @author Tristan Schwieren
*/
-#define STR_INDIR(x) #x
-#define STR(x) STR_INDIR(x)
-
#define GNUNET_DID_METHOD_PREFIX "did:reclaim:"
#define MAX_DID_SPECIFIC_IDENTIFIER_LENGTH 59
@@ -34,16 +31,16 @@
* @brief Return a DID for a given GNUNET public key
*/
char *
-GNUNET_DID_pkey_to_did(struct GNUNET_IDENTITY_PublicKey *pkey);
+GNUNET_DID_pkey_to_did (struct GNUNET_IDENTITY_PublicKey *pkey);
/**
* @brief Generate a DID for a given gnunet EGO
- *
- * @param ego
+ *
+ * @param ego
* @return char * Returns the DID. Caller must free
*/
char *
-GNUNET_DID_identity_to_did(struct GNUNET_IDENTITY_Ego *ego);
+GNUNET_DID_identity_to_did (struct GNUNET_IDENTITY_Ego *ego);
/**
* @brief Return the public key of a DID
@@ -51,17 +48,18 @@ GNUNET_DID_identity_to_did(struct GNUNET_IDENTITY_Ego *ego);
int
GNUNET_DID_did_to_pkey (char *did, struct GNUNET_IDENTITY_PublicKey *pkey);
-/**
- * @brief Convert a base 64 encoded public key to a GNUNET key
- */
-struct GNUNET_IDENTITY_PublicKey *
-GNUNET_DID_key_covert_multibase_base64_to_gnunet(char *);
+// /**
+// * @brief Convert a base 64 encoded public key to a GNUNET key
+// */
+// struct GNUNET_IDENTITY_PublicKey *
+// GNUNET_DID_key_covert_multibase_base64_to_gnunet(char *);
/**
* @brief Convert GNUNET key to a base 64 encoded public key
*/
char *
-GNUNET_DID_key_covert_gnunet_to_multibase_base64(struct
GNUNET_IDENTITY_PublicKey *);
+GNUNET_DID_key_covert_gnunet_to_multibase_base64 (struct
+ GNUNET_IDENTITY_PublicKey *);
/**
* @brief Generate the default DID document for a GNUNET public key
@@ -73,4 +71,4 @@ GNUNET_DID_pkey_to_did_document (struct
GNUNET_IDENTITY_PublicKey *pkey);
* @brief Generate the default DID document for a GNUNET ego
*/
char *
-GNUNET_DID_identity_to_did_document(struct GNUNET_IDENTITY_Ego *ego);
\ No newline at end of file
+GNUNET_DID_identity_to_did_document (struct GNUNET_IDENTITY_Ego *ego);
\ No newline at end of file
diff --git a/src/reclaim/test_did_helper.c b/src/reclaim/test_did_helper.c
index 563b94e78..c514f17b2 100644
--- a/src/reclaim/test_did_helper.c
+++ b/src/reclaim/test_did_helper.c
@@ -43,8 +43,11 @@ static const char test_skey_bytes[32] = {
static const char *test_did =
"did:reclaim:000G0509BYD1MPAXVSTNV0KRD1JAT0YZMPJFQNM869B66S72PSF17K4Y8G";
+static const char *test_multibase_key =
+ "u7QEJX5oaWV3edV2CeGhkrQPfpaT71ogyVmNk4rZeE8yeRA";
+
static const char *test_did_document_format_str =
- "{\"@context\":[\"https://www.w3.org/ns/did/v1\", \
+ "{\"@context\":[\"https://www.w3.org/ns/did/v1\",\
\"https://w3id.org/security/suites/ed25519-2020/v1\"],\
\"id\":\"%s\",\
\"verificationMethod\":[{\
@@ -55,8 +58,6 @@ static const char *test_did_document_format_str =
\"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;
@@ -81,11 +82,18 @@ test_GNUNET_DID_did_to_pkey ()
test_pkey.eddsa_key.q_y) == 0);
}
-void
-test_GNUNET_DID_key_covert_multibase_base64_to_gnunet ();
+// void
+// test_GNUNET_DID_key_covert_multibase_base64_to_gnunet ();
void
-test_GNUNET_DID_key_covert_gnunet_to_multibase_base64 ();
+test_GNUNET_DID_key_covert_gnunet_to_multibase_base64 ()
+{
+ char *multibase_key;
+ multibase_key = GNUNET_DID_key_covert_gnunet_to_multibase_base64
(&test_pkey);
+ printf ("%s\n", multibase_key);
+
+ GNUNET_assert (strcmp (test_multibase_key, multibase_key) == 0);
+}
void
test_GNUNET_DID_pkey_to_did_document ()
@@ -119,5 +127,6 @@ main ()
test_GNUNET_DID_pkey_to_did ();
test_GNUNET_DID_did_to_pkey ();
test_GNUNET_DID_pkey_to_did_document ();
+ test_GNUNET_DID_key_covert_gnunet_to_multibase_base64 ();
return 0;
}
\ No newline at end of file
diff --git a/src/reclaim/test_w3c_ed25519_2020.c
b/src/reclaim/test_w3c_ed25519_2020.c
deleted file mode 100644
index e2534e6ab..000000000
--- a/src/reclaim/test_w3c_ed25519_2020.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2012-2021 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-
-/**
- * @file src/did/test_w3c_ed25519_2020.c
- * @brief Testcases for the w3c Ed25519 formats for SSIs
https://w3c-ccg.github.io/lds-ed25519-2020
- * @author Martin Schanzenbach
- */
-
-#include "platform.h"
-#include "gnunet_crypto_lib.h"
-#include "gnunet_strings_lib.h"
-
-static char test_privkey[32] = {
- 0x9b, 0x93, 0x7b, 0x81, 0x32, 0x2d, 0x81, 0x6c,
- 0xfa, 0xb9, 0xd5, 0xa3, 0xba, 0xac, 0xc9, 0xb2,
- 0xa5, 0xfe, 0xbe, 0x4b, 0x14, 0x9f, 0x12, 0x6b,
- 0x36, 0x30, 0xf9, 0x3a, 0x29, 0x52, 0x70, 0x17
-};
-
-static char *targetPublicKeyMultibase =
"u7QEJX5oaWV3edV2CeGhkrQPfpaT71ogyVmNk4rZeE8yeRA";
-
-int
-main ()
-{
- struct GNUNET_CRYPTO_EddsaPrivateKey privkey;
- struct GNUNET_CRYPTO_EddsaPublicKey pubkey;
-
- memcpy (&privkey, test_privkey, sizeof (privkey));
- GNUNET_CRYPTO_eddsa_key_get_public (&privkey, &pubkey);
-
- //This is how to convert out pubkeys to W3c Ed25519-2020 multibase
(base64url no padding)
- char *b64;
- char pkx[34];
- pkx[0] = 0xed;
- pkx[1] = 0x01;
- memcpy (pkx+2, &pubkey, sizeof (pubkey));
- GNUNET_STRINGS_base64url_encode (pkx,
- sizeof (pkx),
- &b64);
- printf ("u%s\n%s\n", b64, targetPublicKeyMultibase);
- // FIXME convert pubkey to target
- char *res;
- GNUNET_asprintf (&res, "u%s", b64);
- GNUNET_assert (0 == strcmp (res,
- targetPublicKeyMultibase));
-
- GNUNET_free (b64);
- GNUNET_free (res);
- return 0;
-}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet] 38/70: -did working replace, generalized remove, refactor, (continued)
- [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
- [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 <=
- [gnunet] 60/70: - started with DID lib create func, gnunet, 2022/08/31
- [gnunet] 54/70: - default did document test without multibase, gnunet, 2022/08/31
- [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