diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-01-14 22:10:11 +0100 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-01-14 22:10:11 +0100 |
commit | be0fee19cd01821dcb67cf2bca633b4e2b711bbf (patch) | |
tree | 21cb338a7c0d9fce772790d81984fcfe611c4d16 /src/reclaim | |
parent | f2df460f3320dcd3eaba1caa9ee084673c7cfec7 (diff) | |
download | gnunet-be0fee19cd01821dcb67cf2bca633b4e2b711bbf.tar.gz gnunet-be0fee19cd01821dcb67cf2bca633b4e2b711bbf.zip |
-fix
Diffstat (limited to 'src/reclaim')
-rw-r--r-- | src/reclaim/Makefile.am | 3 | ||||
-rw-r--r-- | src/reclaim/did.h | 49 | ||||
-rw-r--r-- | src/reclaim/did_misc.c | 70 | ||||
-rw-r--r-- | src/reclaim/gnunet-did.c | 44 |
4 files changed, 130 insertions, 36 deletions
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am index 6b5934a2f..a0150a3b9 100644 --- a/src/reclaim/Makefile.am +++ b/src/reclaim/Makefile.am | |||
@@ -189,7 +189,8 @@ test_reclaim_attribute_LDADD = \ | |||
189 | $(GN_LIBINTL) | 189 | $(GN_LIBINTL) |
190 | 190 | ||
191 | gnunet_did_SOURCES = \ | 191 | gnunet_did_SOURCES = \ |
192 | gnunet-did.c | 192 | gnunet-did.c \ |
193 | did_misc.c | ||
193 | gnunet_did_LDADD = \ | 194 | gnunet_did_LDADD = \ |
194 | $(top_builddir)/src/util/libgnunetutil.la \ | 195 | $(top_builddir)/src/util/libgnunetutil.la \ |
195 | $(top_builddir)/src/gns/libgnunetgns.la \ | 196 | $(top_builddir)/src/gns/libgnunetgns.la \ |
diff --git a/src/reclaim/did.h b/src/reclaim/did.h new file mode 100644 index 000000000..054bd29e4 --- /dev/null +++ b/src/reclaim/did.h | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2012-2022 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 | #ifndef RECLAIM_DID_H | ||
22 | #define RECLAIM_DID_H | ||
23 | |||
24 | #define GNUNET_RECLAIM_DID_METHOD_PREFIX "did:reclaim:" | ||
25 | |||
26 | /** | ||
27 | * Create a DID string from an ego in the format | ||
28 | * did:reclaim:<pubkey> | ||
29 | * | ||
30 | * @param ego the Ego to use | ||
31 | * @return the DID string | ||
32 | */ | ||
33 | char* | ||
34 | DID_ego_to_did (struct GNUNET_IDENTITY_Ego *ego); | ||
35 | |||
36 | |||
37 | /** | ||
38 | * Extract the public key from a DID | ||
39 | * in the format did:reclaim:<pubkey> | ||
40 | * | ||
41 | * @param did the DID parse | ||
42 | * @param pk where to store the public key | ||
43 | * @return GNUNET_OK if successful | ||
44 | */ | ||
45 | enum GNUNET_GenericReturnValue | ||
46 | DID_public_key_from_did (const char* did, | ||
47 | struct GNUNET_IDENTITY_PublicKey *pk); | ||
48 | |||
49 | #endif | ||
diff --git a/src/reclaim/did_misc.c b/src/reclaim/did_misc.c new file mode 100644 index 000000000..44b72a69f --- /dev/null +++ b/src/reclaim/did_misc.c | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2012-2022 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 | * @author Martin Schanzenbach | ||
23 | * @file src/reclaim/did_misc.c | ||
24 | * @brief Helper functions for DIDs | ||
25 | * | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_identity_service.h" | ||
30 | #include "jansson.h" | ||
31 | #include "did.h" | ||
32 | |||
33 | char* | ||
34 | DID_ego_to_did (struct GNUNET_IDENTITY_Ego *ego) | ||
35 | { | ||
36 | struct GNUNET_IDENTITY_PublicKey pkey; // Get Public key | ||
37 | char *pkey_str; | ||
38 | char *did_str; | ||
39 | size_t pkey_len; | ||
40 | |||
41 | GNUNET_IDENTITY_ego_get_public_key (ego, &pkey); | ||
42 | |||
43 | pkey_str = GNUNET_IDENTITY_public_key_to_string (&pkey); | ||
44 | GNUNET_asprintf (&did_str, "%s%s", | ||
45 | GNUNET_RECLAIM_DID_METHOD_PREFIX, | ||
46 | pkey_str); | ||
47 | |||
48 | GNUNET_free (pkey_str); | ||
49 | return did_str; | ||
50 | } | ||
51 | |||
52 | enum GNUNET_GenericReturnValue | ||
53 | DID_public_key_from_did (const char* did, | ||
54 | struct GNUNET_IDENTITY_PublicKey *pk) | ||
55 | { | ||
56 | /* FIXME-MSC: I suggest introducing a | ||
57 | * #define MAX_DID_LENGTH <something> | ||
58 | * here and use it for parsing | ||
59 | */ | ||
60 | char pkey_str[59]; | ||
61 | |||
62 | if ((1 != (sscanf (did, GNUNET_RECLAIM_DID_METHOD_PREFIX"%58s", pkey_str))) || | ||
63 | (GNUNET_OK != GNUNET_IDENTITY_public_key_from_string (pkey_str, pk))) | ||
64 | { | ||
65 | return GNUNET_SYSERR; | ||
66 | } | ||
67 | return GNUNET_OK; | ||
68 | } | ||
69 | |||
70 | |||
diff --git a/src/reclaim/gnunet-did.c b/src/reclaim/gnunet-did.c index 2ebef7601..4c5704d44 100644 --- a/src/reclaim/gnunet-did.c +++ b/src/reclaim/gnunet-did.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2012-2021 GNUnet e.V. | 3 | Copyright (C) 2012-2022 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -39,8 +39,8 @@ | |||
39 | #include "gnunet_gns_service.h" | 39 | #include "gnunet_gns_service.h" |
40 | #include "gnunet_gnsrecord_lib.h" | 40 | #include "gnunet_gnsrecord_lib.h" |
41 | #include "jansson.h" | 41 | #include "jansson.h" |
42 | #include "did.h" | ||
42 | 43 | ||
43 | #define GNUNET_DID_METHOD_RECLAIM_PREFIX "did:reclaim:" | ||
44 | #define GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME "1d" | 44 | #define GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME "1d" |
45 | 45 | ||
46 | /** | 46 | /** |
@@ -146,25 +146,6 @@ cleanup (void *cls) | |||
146 | GNUNET_SCHEDULER_shutdown (); | 146 | GNUNET_SCHEDULER_shutdown (); |
147 | } | 147 | } |
148 | 148 | ||
149 | char* | ||
150 | ego_to_did (struct GNUNET_IDENTITY_Ego *ego) | ||
151 | { | ||
152 | struct GNUNET_IDENTITY_PublicKey pkey; // Get Public key | ||
153 | char *pkey_str; | ||
154 | char *did_str; | ||
155 | size_t pkey_len; | ||
156 | |||
157 | GNUNET_IDENTITY_ego_get_public_key (ego, &pkey); | ||
158 | |||
159 | pkey_str = GNUNET_IDENTITY_public_key_to_string (&pkey); | ||
160 | GNUNET_asprintf (&did_str, "%s%s", | ||
161 | GNUNET_DID_METHOD_RECLAIM_PREFIX, | ||
162 | pkey_str); | ||
163 | |||
164 | free (pkey_str); | ||
165 | return did_str; | ||
166 | } | ||
167 | |||
168 | /** | 149 | /** |
169 | * @brief Callback for ego loockup of get_did_for_ego() | 150 | * @brief Callback for ego loockup of get_did_for_ego() |
170 | * | 151 | * |
@@ -183,7 +164,7 @@ get_did_for_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
183 | ret = 1; | 164 | ret = 1; |
184 | return; | 165 | return; |
185 | } | 166 | } |
186 | did_str = ego_to_did (ego); | 167 | did_str = DID_ego_to_did (ego); |
187 | 168 | ||
188 | printf ("%s\n", did_str); | 169 | printf ("%s\n", did_str); |
189 | 170 | ||
@@ -223,16 +204,9 @@ get_did_for_ego () | |||
223 | static void | 204 | static void |
224 | get_pkey_from_attr_did (struct GNUNET_IDENTITY_PublicKey *pkey) | 205 | get_pkey_from_attr_did (struct GNUNET_IDENTITY_PublicKey *pkey) |
225 | { | 206 | { |
226 | /* FIXME-MSC: I suggest introducing a | 207 | if (GNUNET_OK != DID_public_key_from_did (did, pkey)) |
227 | * #define MAX_DID_LENGTH <something> | ||
228 | * here and use it for parsing | ||
229 | */ | ||
230 | char pkey_str[59]; | ||
231 | |||
232 | if ((1 != (sscanf (did, GNUNET_DID_METHOD_RECLAIM_PREFIX"%58s", pkey_str))) || | ||
233 | (GNUNET_OK != GNUNET_IDENTITY_public_key_from_string (pkey_str, pkey))) | ||
234 | { | 208 | { |
235 | fprintf (stderr, _("Invalid DID `%s'\n"), pkey_str); | 209 | fprintf (stderr, _("Invalid DID `%s'\n"), did); |
236 | GNUNET_SCHEDULER_add_now (cleanup, NULL); | 210 | GNUNET_SCHEDULER_add_now (cleanup, NULL); |
237 | ret = 1; | 211 | ret = 1; |
238 | return; | 212 | return; |
@@ -274,7 +248,7 @@ print_did_document ( | |||
274 | printf ("DID Document is not a TXT record\n"); | 248 | printf ("DID Document is not a TXT record\n"); |
275 | } | 249 | } |
276 | 250 | ||
277 | GNUNET_SCHEDULER_add_now (cleanup, NULL); | 251 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); |
278 | ret = 0; | 252 | ret = 0; |
279 | return; | 253 | return; |
280 | } | 254 | } |
@@ -354,7 +328,7 @@ remove_did_document_namestore_cb (void *cls, int32_t success, const char *emgs) | |||
354 | printf ("%s\n", emgs); | 328 | printf ("%s\n", emgs); |
355 | } | 329 | } |
356 | 330 | ||
357 | GNUNET_SCHEDULER_add_now (cleanup, NULL); | 331 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); |
358 | ret = 0; | 332 | ret = 0; |
359 | return; | 333 | return; |
360 | } | 334 | } |
@@ -798,7 +772,7 @@ process_dids (void *cls, struct GNUNET_IDENTITY_Ego *ego, | |||
798 | } | 772 | } |
799 | if (1 == show_all) | 773 | if (1 == show_all) |
800 | { | 774 | { |
801 | did_str = ego_to_did (ego); | 775 | did_str = DID_ego_to_did (ego); |
802 | printf ("%s\n", did_str); | 776 | printf ("%s\n", did_str); |
803 | GNUNET_free (did_str); | 777 | GNUNET_free (did_str); |
804 | return; | 778 | return; |
@@ -807,7 +781,7 @@ process_dids (void *cls, struct GNUNET_IDENTITY_Ego *ego, | |||
807 | { | 781 | { |
808 | if (0 == strncmp (name, egoname, strlen (egoname))) | 782 | if (0 == strncmp (name, egoname, strlen (egoname))) |
809 | { | 783 | { |
810 | did_str = ego_to_did (ego); | 784 | did_str = DID_ego_to_did (ego); |
811 | printf ("%s\n", did_str); | 785 | printf ("%s\n", did_str); |
812 | GNUNET_free (did_str); | 786 | GNUNET_free (did_str); |
813 | return; | 787 | return; |