diff options
author | Tristan Schwieren <tristan.schwieren@tum.de> | 2021-12-13 17:19:47 +0100 |
---|---|---|
committer | Tristan Schwieren <tristan.schwieren@tum.de> | 2021-12-13 17:19:47 +0100 |
commit | 50ed616a746dc676bc80d23dfba37b02ee529524 (patch) | |
tree | af3ed2bdc1b468e0db4032531226cc3a9b264ea7 | |
parent | 237b03c46da9a47a5e30153faf2abf03e518e33c (diff) | |
parent | 1c895918c6ff4232f3f2ca086c63d57a78f7ddf2 (diff) | |
download | gnunet-50ed616a746dc676bc80d23dfba37b02ee529524.tar.gz gnunet-50ed616a746dc676bc80d23dfba37b02ee529524.zip |
Merge branch 'dev/trizuz/dids' of git+ssh://git.gnunet.org/gnunet into dev/trizuz/dids
-rw-r--r-- | src/did/.gitignore | 2 | ||||
-rw-r--r-- | src/did/Makefile.am | 13 | ||||
-rw-r--r-- | src/did/test_w3c_ed25519_2020.c | 69 |
3 files changed, 84 insertions, 0 deletions
diff --git a/src/did/.gitignore b/src/did/.gitignore new file mode 100644 index 000000000..d47f720ff --- /dev/null +++ b/src/did/.gitignore | |||
@@ -0,0 +1,2 @@ | |||
1 | test_w3c_ed25519_2020 | ||
2 | gnunet-did | ||
diff --git a/src/did/Makefile.am b/src/did/Makefile.am index 21f210dd0..3f5e3f34b 100644 --- a/src/did/Makefile.am +++ b/src/did/Makefile.am | |||
@@ -22,3 +22,16 @@ gnunet_did_LDADD = \ | |||
22 | -ljansson | 22 | -ljansson |
23 | 23 | ||
24 | 24 | ||
25 | check_PROGRAMS = \ | ||
26 | test_w3c_ed25519_2020 | ||
27 | |||
28 | test_w3c_ed25519_2020_SOURCES = \ | ||
29 | test_w3c_ed25519_2020.c | ||
30 | test_w3c_ed25519_2020_LDADD = \ | ||
31 | $(top_builddir)/src/util/libgnunetutil.la | ||
32 | |||
33 | if ENABLE_TEST_RUN | ||
34 | TESTS = $(check_PROGRAMS) | ||
35 | endif | ||
36 | |||
37 | |||
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 | |||
32 | static 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 | |||
39 | static char *targetPublicKeyMultibase = "u7QEJX5oaWV3edV2CeGhkrQPfpaT71ogyVmNk4rZeE8yeRA"; | ||
40 | |||
41 | int | ||
42 | main () | ||
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 | } | ||