aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/reclaim/Makefile.am3
-rw-r--r--src/reclaim/did_helper.c44
-rw-r--r--src/reclaim/did_helper.h6
-rw-r--r--src/reclaim/test_did_helper.c51
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 = \
227 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 227 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
228 $(top_builddir)/src/identity/libgnunetidentity.la \ 228 $(top_builddir)/src/identity/libgnunetidentity.la \
229 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 229 $(top_builddir)/src/namestore/libgnunetnamestore.la \
230 libgnunetdid.la 230 libgnunetdid.la \
231 -ljansson
231 232
232check_SCRIPTS = \ 233check_SCRIPTS = \
233 test_reclaim_attribute.sh \ 234 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 @@
32#include "jansson.h" 32#include "jansson.h"
33 33
34 34
35// TODO: GNUNET_DID_key_covert_multibase_base64_to_gnunet
36// TODO: GNUNET_DID_key_covert_gnunet_to_multibase_base64
37
38// TODO: GNUNET_DID_pkey_to_did_document
39
40
35/** 41/**
36 * @brief Generate a DID for a given GNUNET public key 42 * @brief Generate a DID for a given GNUNET public key
37 * 43 *
@@ -55,7 +61,8 @@ GNUNET_DID_pkey_to_did (struct GNUNET_IDENTITY_PublicKey *pkey)
55} 61}
56 62
57/** 63/**
58 * @brief Generate a DID for a given gnunet EGO 64 * @brief Generate a DID for a given gnunet EGO.
65 * Wrapper around GNUNET_DID_pkey_to_did
59 * 66 *
60 * @param ego 67 * @param ego
61 * @return char* Returns the DID. Caller must free 68 * @return char* Returns the DID. Caller must free
@@ -96,15 +103,6 @@ GNUNET_DID_did_to_pkey (char *did, struct GNUNET_IDENTITY_PublicKey *pkey)
96} 103}
97 104
98/** 105/**
99 * @brief Return the GNUNET EGO of a DID
100 */
101struct GNUNET_IDENTITY_Ego *
102GNUNET_DID_did_to_identity (char *did)
103{
104 return NULL;
105}
106
107/**
108 * @brief Convert a base 64 encoded public key to a GNUNET key 106 * @brief Convert a base 64 encoded public key to a GNUNET key
109 */ 107 */
110struct GNUNET_IDENTITY_PublicKey * 108struct GNUNET_IDENTITY_PublicKey *
@@ -139,14 +137,15 @@ GNUNET_DID_pkey_to_did_document (struct GNUNET_IDENTITY_PublicKey *pkey)
139 char *pkey_multibase_str; 137 char *pkey_multibase_str;
140 138
141 /* FIXME-MSC: This screams for a GNUNET_DID_identity_key_to_string() */ 139 /* FIXME-MSC: This screams for a GNUNET_DID_identity_key_to_string() */
142 char *b64; 140 // char *b64;
143 char pkx[34]; 141 // char pkx[34];
144 pkx[0] = 0xed; 142 // pkx[0] = 0xed;
145 pkx[1] = 0x01; 143 // pkx[1] = 0x01;
146 memcpy (pkx + 2, &(pkey->eddsa_key), sizeof(pkey->eddsa_key)); 144 // memcpy (pkx + 2, &(pkey->eddsa_key), sizeof(pkey->eddsa_key));
147 GNUNET_STRINGS_base64_encode (pkx, sizeof(pkx), &b64); 145 // GNUNET_STRINGS_base64_encode (pkx, sizeof(pkx), &b64);
148 146
149 GNUNET_asprintf (&pkey_multibase_str, "u%s", b64); 147 // GNUNET_asprintf (&pkey_multibase_str, "u%s", b64);
148 pkey_multibase_str = "moin";
150 149
151 json_t *didd_json; 150 json_t *didd_json;
152 151
@@ -165,16 +164,20 @@ GNUNET_DID_pkey_to_did_document (struct GNUNET_IDENTITY_PublicKey *pkey)
165 // Add a relative DID URL to reference a verifiation method 164 // Add a relative DID URL to reference a verifiation method
166 // https://www.w3.org/TR/did-core/#relative-did-urls` 165 // https://www.w3.org/TR/did-core/#relative-did-urls`
167 166
168 didd_json = json_pack ("{s:[ss], s:s, s:[{ssss}], s:[s], s:[s]", 167 didd_json = json_pack ("{s:[ss], s:s, s:[{s:s, s:s, s:s, s:s}], s:[s], s:[s]}",
169 "@context", 168 "@context",
170 "https://www.w3.org/ns/did/v1", 169 "https://www.w3.org/ns/did/v1",
171 "https://w3id.org/security/suites/ed25519-2020/v1", 170 "https://w3id.org/security/suites/ed25519-2020/v1",
172 "id", 171 "id",
173 did_str, 172 did_str,
174 "verificationMethod", 173 "verificationMethod",
174 "id",
175 verify_id_str, 175 verify_id_str,
176 "type",
176 "Ed25519VerificationKey2020", 177 "Ed25519VerificationKey2020",
178 "controller",
177 did_str, 179 did_str,
180 "publicKeyMultibase",
178 pkey_multibase_str, 181 pkey_multibase_str,
179 "authentication", 182 "authentication",
180 "#key-1", 183 "#key-1",
@@ -185,8 +188,8 @@ GNUNET_DID_pkey_to_did_document (struct GNUNET_IDENTITY_PublicKey *pkey)
185 didd_str = json_dumps (didd_json, JSON_INDENT (2)); 188 didd_str = json_dumps (didd_json, JSON_INDENT (2));
186 189
187 // Free 190 // Free
188 GNUNET_free (pkey_multibase_str); 191 // GNUNET_free (pkey_multibase_str);
189 GNUNET_free (b64); 192 // GNUNET_free (b64);
190 json_decref (didd_json); 193 json_decref (didd_json);
191 194
192 return didd_str; 195 return didd_str;
@@ -194,6 +197,7 @@ GNUNET_DID_pkey_to_did_document (struct GNUNET_IDENTITY_PublicKey *pkey)
194 197
195/** 198/**
196 * @brief Generate the default DID document for a GNUNET ego 199 * @brief Generate the default DID document for a GNUNET ego
200 * Wrapper around GNUNET_DID_pkey_to_did_document
197 */ 201 */
198char * 202char *
199GNUNET_DID_identity_to_did_document (struct GNUNET_IDENTITY_Ego *ego) 203GNUNET_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
@@ -52,12 +52,6 @@ int
52GNUNET_DID_did_to_pkey (char *did, struct GNUNET_IDENTITY_PublicKey *pkey); 52GNUNET_DID_did_to_pkey (char *did, struct GNUNET_IDENTITY_PublicKey *pkey);
53 53
54/** 54/**
55 * @brief Return the GNUNET EGO of a DID
56 */
57struct GNUNET_IDENTITY_Ego *
58GNUNET_DID_did_to_identity(char *did);
59
60/**
61 * @brief Convert a base 64 encoded public key to a GNUNET key 55 * @brief Convert a base 64 encoded public key to a GNUNET key
62 */ 56 */
63struct GNUNET_IDENTITY_PublicKey * 57struct GNUNET_IDENTITY_PublicKey *
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 @@
30#include "gnunet_gns_service.h" 30#include "gnunet_gns_service.h"
31#include "gnunet_gnsrecord_lib.h" 31#include "gnunet_gnsrecord_lib.h"
32#include "did_helper.h" 32#include "did_helper.h"
33#include "jansson.h"
33 34
34static const char test_skey_bytes[32] = { 35static const char test_skey_bytes[32] = {
35 0x9b, 0x93, 0x7b, 0x81, 0x32, 0x2d, 0x81, 0x6c, 36 0x9b, 0x93, 0x7b, 0x81, 0x32, 0x2d, 0x81, 0x6c,
@@ -39,29 +40,45 @@ static const char test_skey_bytes[32] = {
39}; 40};
40 41
41// TODO: Create a did manual from private key / independet of implementation 42// TODO: Create a did manual from private key / independet of implementation
42static char *test_did = 43static const char *test_did =
43 "did:reclaim:000G0509BYD1MPAXVSTNV0KRD1JAT0YZMPJFQNM869B66S72PSF17K4Y8G"; 44 "did:reclaim:000G0509BYD1MPAXVSTNV0KRD1JAT0YZMPJFQNM869B66S72PSF17K4Y8G";
44 45
46static const char *test_did_document_format_str =
47 "{\"@context\":[\"https://www.w3.org/ns/did/v1\", \
48 \"https://w3id.org/security/suites/ed25519-2020/v1\"],\
49 \"id\":\"%s\",\
50 \"verificationMethod\":[{\
51 \"id\":\"%s#key-1\",\
52 \"type\":\"Ed25519VerificationKey2020\",\
53 \"controller\":\"%s\",\
54 \"publicKeyMultibase\":\"%s\"}],\
55 \"authentication\":[\"#key-1\"],\
56 \"assertionMethod\":[\"#key-1\"]}";
57
58static const char *test_multibase_key = "moin";
59
45static struct GNUNET_IDENTITY_PrivateKey test_skey; 60static struct GNUNET_IDENTITY_PrivateKey test_skey;
46static struct GNUNET_IDENTITY_PublicKey test_pkey; 61static struct GNUNET_IDENTITY_PublicKey test_pkey;
62static struct json_t *test_did_document;
63static char *test_did_document_str;
47 64
48void 65void
49test_GNUNET_DID_pkey_to_did () 66test_GNUNET_DID_pkey_to_did ()
50{ 67{
51 char *str_did; 68 char *str_did;
52 str_did = GNUNET_DID_pkey_to_did (&test_pkey); 69 str_did = GNUNET_DID_pkey_to_did (&test_pkey);
53 GNUNET_assert (strcmp (test_did, str_did) == 0); 70 GNUNET_assert (strcmp ((char *) test_did, str_did) == 0);
54} 71}
55 72
56void 73void
57test_GNUNET_DID_did_to_pkey () 74test_GNUNET_DID_did_to_pkey ()
58{ 75{
59 struct GNUNET_IDENTITY_PublicKey pkey; 76 struct GNUNET_IDENTITY_PublicKey pkey;
60 GNUNET_DID_did_to_pkey (test_did, &pkey); 77 GNUNET_DID_did_to_pkey ((char *) test_did, &pkey);
61 78
62 GNUNET_assert (test_pkey.type = pkey.type); 79 GNUNET_assert (test_pkey.type = pkey.type);
63 GNUNET_assert (0 == strcmp (pkey.eddsa_key.q_y, 80 GNUNET_assert (strcmp (pkey.eddsa_key.q_y,
64 test_pkey.eddsa_key.q_y)); 81 test_pkey.eddsa_key.q_y) == 0);
65} 82}
66 83
67void 84void
@@ -73,21 +90,31 @@ test_GNUNET_DID_key_covert_gnunet_to_multibase_base64 ();
73void 90void
74test_GNUNET_DID_pkey_to_did_document () 91test_GNUNET_DID_pkey_to_did_document ()
75{ 92{
76 char *did_document = GNUNET_DID_pkey_to_did_document (&test_pkey); 93 struct json_t *did_document;
77 printf("%s\n", did_document); 94 char *did_document_str = GNUNET_DID_pkey_to_did_document (&test_pkey);
78 95 did_document = json_loads (did_document_str, JSON_DECODE_ANY, NULL);
79 GNUNET_assert(0 == 0); 96 GNUNET_assert (json_equal (test_did_document, did_document) == 1);
80} 97}
81 98
82int 99int
83main () 100main ()
84{ 101{
85 // Setup 102 // Setup key
86 test_skey.type = htonl (GNUNET_IDENTITY_TYPE_EDDSA); 103 test_skey.type = htonl (GNUNET_IDENTITY_TYPE_EDDSA);
87 memcpy (&(test_skey.eddsa_key), test_skey_bytes, sizeof(struct 104 memcpy (&(test_skey.eddsa_key),
88 GNUNET_CRYPTO_EddsaPrivateKey)); 105 test_skey_bytes,
106 sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey));
89 GNUNET_IDENTITY_key_get_public (&test_skey, &test_pkey); 107 GNUNET_IDENTITY_key_get_public (&test_skey, &test_pkey);
90 108
109 // Setup did document
110 GNUNET_asprintf (&test_did_document_str,
111 test_did_document_format_str,
112 test_did,
113 test_did,
114 test_did,
115 test_multibase_key);
116 test_did_document = json_loads (test_did_document_str, JSON_DECODE_ANY, NULL);
117
91 // Do tests 118 // Do tests
92 test_GNUNET_DID_pkey_to_did (); 119 test_GNUNET_DID_pkey_to_did ();
93 test_GNUNET_DID_did_to_pkey (); 120 test_GNUNET_DID_did_to_pkey ();