aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTristan Schwieren <tristan.schwieren@tum.de>2021-12-30 14:57:36 +0100
committerTristan Schwieren <tristan.schwieren@tum.de>2021-12-30 14:57:36 +0100
commit071a403a01239008807053282f134502b9c2d4c3 (patch)
tree96a719fe0c497cc621794c8e1cff74d69ed0fbf2 /src
parentfd620976c140d5df43cf174a54a9f88c4808cad3 (diff)
downloadgnunet-071a403a01239008807053282f134502b9c2d4c3.tar.gz
gnunet-071a403a01239008807053282f134502b9c2d4c3.zip
-w3cvc init
Diffstat (limited to 'src')
-rw-r--r--src/did/test_w3c_ed25519_2020.c69
-rw-r--r--src/include/gnunet_reclaim_lib.h7
-rw-r--r--src/reclaim/Makefile.am15
-rw-r--r--src/reclaim/plugin_reclaim_w3c_verifiable_credential.c372
4 files changed, 461 insertions, 2 deletions
diff --git a/src/did/test_w3c_ed25519_2020.c b/src/did/test_w3c_ed25519_2020.c
new file mode 100644
index 000000000..e2534e6ab
--- /dev/null
+++ b/src/did/test_w3c_ed25519_2020.c
@@ -0,0 +1,69 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21
22/**
23 * @file src/did/test_w3c_ed25519_2020.c
24 * @brief Testcases for the w3c Ed25519 formats for SSIs https://w3c-ccg.github.io/lds-ed25519-2020
25 * @author Martin Schanzenbach
26 */
27
28#include "platform.h"
29#include "gnunet_crypto_lib.h"
30#include "gnunet_strings_lib.h"
31
32static char test_privkey[32] = {
33 0x9b, 0x93, 0x7b, 0x81, 0x32, 0x2d, 0x81, 0x6c,
34 0xfa, 0xb9, 0xd5, 0xa3, 0xba, 0xac, 0xc9, 0xb2,
35 0xa5, 0xfe, 0xbe, 0x4b, 0x14, 0x9f, 0x12, 0x6b,
36 0x36, 0x30, 0xf9, 0x3a, 0x29, 0x52, 0x70, 0x17
37};
38
39static char *targetPublicKeyMultibase = "u7QEJX5oaWV3edV2CeGhkrQPfpaT71ogyVmNk4rZeE8yeRA";
40
41int
42main ()
43{
44 struct GNUNET_CRYPTO_EddsaPrivateKey privkey;
45 struct GNUNET_CRYPTO_EddsaPublicKey pubkey;
46
47 memcpy (&privkey, test_privkey, sizeof (privkey));
48 GNUNET_CRYPTO_eddsa_key_get_public (&privkey, &pubkey);
49
50 //This is how to convert out pubkeys to W3c Ed25519-2020 multibase (base64url no padding)
51 char *b64;
52 char pkx[34];
53 pkx[0] = 0xed;
54 pkx[1] = 0x01;
55 memcpy (pkx+2, &pubkey, sizeof (pubkey));
56 GNUNET_STRINGS_base64url_encode (pkx,
57 sizeof (pkx),
58 &b64);
59 printf ("u%s\n%s\n", b64, targetPublicKeyMultibase);
60 // FIXME convert pubkey to target
61 char *res;
62 GNUNET_asprintf (&res, "u%s", b64);
63 GNUNET_assert (0 == strcmp (res,
64 targetPublicKeyMultibase));
65
66 GNUNET_free (b64);
67 GNUNET_free (res);
68 return 0;
69}
diff --git a/src/include/gnunet_reclaim_lib.h b/src/include/gnunet_reclaim_lib.h
index bbf1c3ad3..8e0e19f01 100644
--- a/src/include/gnunet_reclaim_lib.h
+++ b/src/include/gnunet_reclaim_lib.h
@@ -65,7 +65,12 @@ enum GNUNET_RECLAIM_CredentialType {
65 /** 65 /**
66 * libpabc credential 66 * libpabc credential
67 */ 67 */
68 GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC = 2 68 GNUNET_RECLAIM_CREDENTIAL_TYPE_PABC = 2,
69
70 /**
71 * verifiable credential
72 */
73 GNUNET_RECLAIM_W3C_VERFIIABLE_CREDENTIAL_TYPE = 3
69}; 74};
70 75
71/** 76/**
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am
index 350d77d4b..911a95134 100644
--- a/src/reclaim/Makefile.am
+++ b/src/reclaim/Makefile.am
@@ -14,7 +14,8 @@ REST_PLUGIN = \
14 libgnunet_plugin_rest_reclaim.la 14 libgnunet_plugin_rest_reclaim.la
15 15
16CREDENTIAL_PLUGIN = \ 16CREDENTIAL_PLUGIN = \
17 libgnunet_plugin_reclaim_credential_jwt.la 17 libgnunet_plugin_reclaim_credential_jwt.la \
18 libgnunet_plugin_reclaim_w3c_verifiable_credential.la
18 19
19if HAVE_PABC 20if HAVE_PABC
20 CREDENTIAL_PLUGIN += libgnunet_plugin_reclaim_credential_pabc.la 21 CREDENTIAL_PLUGIN += libgnunet_plugin_reclaim_credential_pabc.la
@@ -171,6 +172,18 @@ libgnunet_plugin_reclaim_credential_jwt_la_LIBADD = \
171libgnunet_plugin_reclaim_credential_jwt_la_LDFLAGS = \ 172libgnunet_plugin_reclaim_credential_jwt_la_LDFLAGS = \
172 $(GN_PLUGIN_LDFLAGS) 173 $(GN_PLUGIN_LDFLAGS)
173 174
175
176libgnunet_plugin_reclaim_w3c_verifiable_credential_la_SOURCES = \
177 plugin_reclaim_w3c_verifiable_credential.c
178libgnunet_plugin_reclaim_w3c_verifiable_credential_la_LIBADD = \
179 $(top_builddir)/src/util/libgnunetutil.la \
180 libgnunetreclaim.la \
181 -ljansson\
182 $(LTLIBINTL)
183libgnunet_plugin_reclaim_w3c_verifiable_credential_la_LDFLAGS = \
184 $(GN_PLUGIN_LDFLAGS)
185
186
174gnunet_reclaim_SOURCES = \ 187gnunet_reclaim_SOURCES = \
175 gnunet-reclaim.c 188 gnunet-reclaim.c
176gnunet_reclaim_LDADD = \ 189gnunet_reclaim_LDADD = \
diff --git a/src/reclaim/plugin_reclaim_w3c_verifiable_credential.c b/src/reclaim/plugin_reclaim_w3c_verifiable_credential.c
new file mode 100644
index 000000000..7902b2084
--- /dev/null
+++ b/src/reclaim/plugin_reclaim_w3c_verifiable_credential.c
@@ -0,0 +1,372 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2013, 2014, 2016 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file reclaim/plugin_reclaim_w3c_verfiable_credential.c
23 * @brief reclaim-w3c-verifiable-credential-plugin attribute plugin to provide the API for
24 * W3C credentials.
25 * @author Tristan Schwieren
26 */
27
28#include "platform.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_reclaim_plugin.h"
31#include <inttypes.h>
32#include <jansson.h>
33
34/**
35 * Convert the 'value' of an verifiable credential to a string.
36 *
37 * @param cls closure
38 * @param type type of the credential
39 * @param data value in binary encoding
40 * @param data_size number of bytes in @a data
41 * @return NULL on error, otherwise human-readable representation of the value
42 */
43static char *
44w3cvc_value_to_string (void *cls,
45 uint32_t type,
46 const void *data,
47 size_t data_size)
48{
49 switch (type)
50 {
51 case GNUNET_RECLAIM_W3C_VERFIIABLE_CREDENTIAL_TYPE:
52 return GNUNET_strndup (data, data_size);
53 //return "A super cool verifiable credential\n";
54 default:
55 return NULL;
56 }
57}
58
59
60/**
61 * Convert human-readable version of a 'value' of an credential to the binary
62 * representation.
63 *
64 * @param cls closure
65 * @param type type of the credential
66 * @param s human-readable string
67 * @param data set to value in binary encoding (will be allocated)
68 * @param data_size set to number of bytes in @a data
69 * @return #GNUNET_OK on success
70 */
71static int
72w3cvc_string_to_value (void *cls,
73 uint32_t type,
74 const char *s,
75 void **data,
76 size_t *data_size)
77{
78 if (NULL == s)
79 return GNUNET_SYSERR;
80
81 switch (type)
82 {
83 case GNUNET_RECLAIM_W3C_VERFIIABLE_CREDENTIAL_TYPE:
84 *data = GNUNET_strdup (s);
85 *data_size = strlen (s) + 1;
86 return GNUNET_OK;
87
88 default:
89 return GNUNET_SYSERR;
90 }
91}
92
93
94/**
95 * Mapping of credential type numbers to human-readable
96 * credential type names.
97 */
98static struct
99{
100 const char *name;
101 uint32_t number;
102} w3cvc_cred_name_map[] = { { "W3CVC", GNUNET_RECLAIM_W3C_VERFIIABLE_CREDENTIAL_TYPE},
103 { NULL, UINT32_MAX } };
104
105/**
106 * Convert a type name to the corresponding number.
107 *
108 * @param cls closure, unused
109 * @param w3cvc_typename name to convert
110 * @return corresponding number, UINT32_MAX on error
111 */
112static uint32_t
113w3cvc_typename_to_number (void *cls, const char *w3cvc_typename)
114{
115 unsigned int i;
116
117 i = 0;
118 while ((NULL != w3cvc_cred_name_map[i].name) &&
119 (0 != strcasecmp (w3cvc_typename, w3cvc_cred_name_map[i].name)))
120 i++;
121 return w3cvc_cred_name_map[i].number;
122}
123
124
125/**
126 * Convert a type number to the corresponding type string (e.g. 1 to "A")
127 *
128 * @param cls closure, unused
129 * @param type number of a type to convert
130 * @return corresponding typestring, NULL on error
131 */
132static const char *
133w3cvc_number_to_typename (void *cls, uint32_t type)
134{
135 unsigned int i;
136
137 i = 0;
138 while ((NULL != w3cvc_cred_name_map[i].name) && (type !=
139 w3cvc_cred_name_map[i].
140 number))
141 i++;
142 return w3cvc_cred_name_map[i].name;
143}
144
145
146/**
147 * Parse a W3C Verifiable Credential and return the respective claim value as Attribute
148 *
149 * @param cls the plugin
150 * @param cred the W3C Verifiable credential
151 * @return a GNUNET_RECLAIM_Attribute, containing the new value
152 */
153struct GNUNET_RECLAIM_AttributeList *
154w3cvc_parse_attributes (void *cls,
155 const char *data,
156 size_t data_size)
157{
158 struct GNUNET_RECLAIM_AttributeList *attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
159
160 GNUNET_RECLAIM_attribute_list_add (attrs,
161 "astring",
162 NULL,
163 GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING,
164 data,
165 strlen(data));
166
167 return attrs;
168}
169
170
171/**
172 * Parse a W3C verifiable credential and return the respective claim value as Attribute
173 *
174 * @param cls the plugin
175 * @param cred the w3cvc credential
176 * @return a GNUNET_RECLAIM_Attribute, containing the new value
177 */
178struct GNUNET_RECLAIM_AttributeList *
179w3cvc_parse_attributes_c (void *cls,
180 const struct GNUNET_RECLAIM_Credential *cred)
181{
182 if (cred->type != GNUNET_RECLAIM_W3C_VERFIIABLE_CREDENTIAL_TYPE)
183 return NULL;
184 return w3cvc_parse_attributes (cls, cred->data, cred->data_size);
185}
186
187
188/**
189 * Parse a W3C verifiable presentation and return the respective claim value as Attribute
190 *
191 * @param cls the plugin
192 * @param cred the w3cvc credential
193 * @return a GNUNET_RECLAIM_Attribute, containing the new value
194 */
195struct GNUNET_RECLAIM_AttributeList *
196w3cvc_parse_attributes_p (void *cls,
197 const struct GNUNET_RECLAIM_Presentation *cred)
198{
199 if (cred->type != GNUNET_RECLAIM_W3C_VERFIIABLE_CREDENTIAL_TYPE)
200 return NULL;
201 return w3cvc_parse_attributes (cls, cred->data, cred->data_size);
202}
203
204
205/**
206 * Parse a VC and return the issuer
207 *
208 * @param cls the plugin
209 * @param cred the verifiable credential
210 * @return a string, containing the isser
211 */
212char *
213w3cvc_get_issuer (void *cls,
214 const char *data,
215 size_t data_size)
216{
217 return "some cool boi";
218}
219
220
221/**
222 * Parse a Verifiable Credential and return the issuer
223 *
224 * @param cls the plugin
225 * @param cred the verifiable credential
226 * @return a string, containing the isser
227 */
228char *
229w3cvc_get_issuer_c (void *cls,
230 const struct GNUNET_RECLAIM_Credential *cred)
231{
232 if (GNUNET_RECLAIM_W3C_VERFIIABLE_CREDENTIAL_TYPE != cred->type)
233 return NULL;
234 return w3cvc_get_issuer (cls, cred->data, cred->data_size);
235}
236
237
238/**
239 * Parse a Verifiable Credential and return the issuer
240 *
241 * @param cls the plugin
242 * @param cred the w3cvc credential
243 * @return a string, containing the isser
244 */
245char *
246w3cvc_get_issuer_p (void *cls,
247 const struct GNUNET_RECLAIM_Presentation *cred)
248{
249 if (GNUNET_RECLAIM_W3C_VERFIIABLE_CREDENTIAL_TYPE != cred->type)
250 return NULL;
251 return w3cvc_get_issuer (cls, cred->data, cred->data_size);
252}
253
254
255/**
256 * Parse a Verifiable Credential and return the expiration
257 *
258 * @param cls the plugin
259 * @param cred the w3cvc credential
260 * @return a string, containing the expiration
261 */
262enum GNUNET_GenericReturnValue
263w3cvc_get_expiration (void *cls,
264 const char *data,
265 size_t data_size,
266 struct GNUNET_TIME_Absolute *exp)
267{
268 exp->abs_value_us = UINT64_MAX;
269 return GNUNET_OK;
270}
271
272
273/**
274 * Parse a Verifiable Credential and return the expiration
275 *
276 * @param cls the plugin
277 * @param cred the w3cvc credential
278 * @return the expirati
279 */
280enum GNUNET_GenericReturnValue
281w3cvc_get_expiration_c (void *cls,
282 const struct GNUNET_RECLAIM_Credential *cred,
283 struct GNUNET_TIME_Absolute *exp)
284{
285 if (GNUNET_RECLAIM_W3C_VERFIIABLE_CREDENTIAL_TYPE != cred->type)
286 return GNUNET_NO;
287 return w3cvc_get_expiration (cls, cred->data, cred->data_size, exp);
288}
289
290
291/**
292 * Parse a verifiable credential and return the expiration
293 *
294 * @param cls the plugin
295 * @param cred the w3cvc credential
296 * @return a string, containing the isser
297 */
298enum GNUNET_GenericReturnValue
299w3cvc_get_expiration_p (void *cls,
300 const struct GNUNET_RECLAIM_Presentation *cred,
301 struct GNUNET_TIME_Absolute *exp)
302{
303 if (GNUNET_RECLAIM_W3C_VERFIIABLE_CREDENTIAL_TYPE != cred->type)
304 return GNUNET_NO;
305 return w3cvc_get_expiration (cls, cred->data, cred->data_size, exp);
306}
307
308
309enum GNUNET_GenericReturnValue
310w3cvc_create_presentation (void *cls,
311 const struct GNUNET_RECLAIM_Credential *cred,
312 const struct GNUNET_RECLAIM_AttributeList *attrs,
313 struct GNUNET_RECLAIM_Presentation **presentation)
314{
315 if (GNUNET_RECLAIM_W3C_VERFIIABLE_CREDENTIAL_TYPE != cred->type)
316 return GNUNET_NO;
317 *presentation = GNUNET_RECLAIM_presentation_new (
318 GNUNET_RECLAIM_W3C_VERFIIABLE_CREDENTIAL_TYPE,
319 cred->data,
320 cred->data_size);
321 return GNUNET_OK;
322}
323
324
325/**
326 * Entry point for the plugin.
327 *
328 * @param cls NULL
329 * @return the exported block API
330 */
331void *
332libgnunet_plugin_reclaim_credential_w3cvc_init (void *cls)
333{
334 struct GNUNET_RECLAIM_CredentialPluginFunctions *api;
335
336 api = GNUNET_new (struct GNUNET_RECLAIM_CredentialPluginFunctions);
337 api->value_to_string = &w3cvc_value_to_string;
338 api->string_to_value = &w3cvc_string_to_value;
339 api->typename_to_number = &w3cvc_typename_to_number;
340 api->number_to_typename = &w3cvc_number_to_typename;
341 api->get_attributes = &w3cvc_parse_attributes_c;
342 api->get_issuer = &w3cvc_get_issuer_c;
343 api->get_expiration = &w3cvc_get_expiration_c;
344 api->value_to_string_p = &w3cvc_value_to_string;
345 api->string_to_value_p = &w3cvc_string_to_value;
346 api->typename_to_number_p = &w3cvc_typename_to_number;
347 api->number_to_typename_p = &w3cvc_number_to_typename;
348 api->get_attributes_p = &w3cvc_parse_attributes_p;
349 api->get_issuer_p = &w3cvc_get_issuer_p;
350 api->get_expiration_p = &w3cvc_get_expiration_p;
351 api->create_presentation = &w3cvc_create_presentation;
352 return api;
353}
354
355
356/**
357 * Exit point from the plugin.
358 *
359 * @param cls the return value from #libgnunet_plugin_block_test_init()
360 * @return NULL
361 */
362void *
363libgnunet_plugin_reclaim_credential_w3cvc_done (void *cls)
364{
365 struct GNUNET_RECLAIM_CredentialPluginFunctions *api = cls;
366
367 GNUNET_free (api);
368 return NULL;
369}
370
371
372/* end of plugin_reclaim_w3c_verifiable_credential_type.c */