diff options
author | Tristan Schwieren <tristan.schwieren@tum.de> | 2022-06-28 15:33:43 +0200 |
---|---|---|
committer | Tristan Schwieren <tristan.schwieren@tum.de> | 2022-06-28 15:33:43 +0200 |
commit | ec36e49c337b336ed46b1e7d3f26aafce2be008b (patch) | |
tree | 1365c8e2f5976a9d44c629e37227afa53598fb27 /src/reclaim | |
parent | 47e7cc4fd4c9341926f0cd4aca2b38e9cd5aba7e (diff) | |
download | gnunet-ec36e49c337b336ed46b1e7d3f26aafce2be008b.tar.gz gnunet-ec36e49c337b336ed46b1e7d3f26aafce2be008b.zip |
- DID resolve using DID lib
Diffstat (limited to 'src/reclaim')
-rw-r--r-- | src/reclaim/did_core.c | 9 | ||||
-rw-r--r-- | src/reclaim/gnunet-did.c | 94 |
2 files changed, 25 insertions, 78 deletions
diff --git a/src/reclaim/did_core.c b/src/reclaim/did_core.c index d6ee33f93..5cecc2972 100644 --- a/src/reclaim/did_core.c +++ b/src/reclaim/did_core.c | |||
@@ -27,6 +27,9 @@ | |||
27 | 27 | ||
28 | #include "did_core.h" | 28 | #include "did_core.h" |
29 | 29 | ||
30 | // #define DID_DOCUMENT_LABEL GNUNET_GNS_EMPTY_LABEL_AT | ||
31 | #define DID_DOCUMENT_LABEL "didd" | ||
32 | |||
30 | static DID_resolve_callback *resolve_cb; | 33 | static DID_resolve_callback *resolve_cb; |
31 | static DID_action_callback *action_cb; | 34 | static DID_action_callback *action_cb; |
32 | static void *closure; | 35 | static void *closure; |
@@ -60,7 +63,7 @@ DID_resolve_gns_lookup_cb ( | |||
60 | if (rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT) | 63 | if (rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT) |
61 | { | 64 | { |
62 | didd = (char *) rd[0].data; | 65 | didd = (char *) rd[0].data; |
63 | resolve_cb (GNUNET_NO, didd, closure); | 66 | resolve_cb (GNUNET_OK, didd, closure); |
64 | } | 67 | } |
65 | else | 68 | else |
66 | resolve_cb (GNUNET_NO, "DID Document is not a TXT record\n", closure); | 69 | resolve_cb (GNUNET_NO, "DID Document is not a TXT record\n", closure); |
@@ -93,7 +96,9 @@ DID_resolve (const char *did, | |||
93 | if (GNUNET_OK != DID_did_to_pkey (did, &pkey)) | 96 | if (GNUNET_OK != DID_did_to_pkey (did, &pkey)) |
94 | return GNUNET_NO; | 97 | return GNUNET_NO; |
95 | 98 | ||
96 | GNUNET_GNS_lookup (gns_handle, GNUNET_GNS_EMPTY_LABEL_AT, &pkey, | 99 | GNUNET_GNS_lookup (gns_handle, DID_DOCUMENT_LABEL, &pkey, |
97 | GNUNET_DNSPARSER_TYPE_TXT, | 100 | GNUNET_DNSPARSER_TYPE_TXT, |
98 | GNUNET_GNS_LO_DEFAULT, &DID_resolve_gns_lookup_cb, NULL); | 101 | GNUNET_GNS_LO_DEFAULT, &DID_resolve_gns_lookup_cb, NULL); |
102 | |||
103 | return GNUNET_OK; | ||
99 | } \ No newline at end of file | 104 | } \ No newline at end of file |
diff --git a/src/reclaim/gnunet-did.c b/src/reclaim/gnunet-did.c index 2ba12e8eb..3629c22f8 100644 --- a/src/reclaim/gnunet-did.c +++ b/src/reclaim/gnunet-did.c | |||
@@ -147,7 +147,6 @@ cleanup (void *cls) | |||
147 | GNUNET_SCHEDULER_shutdown (); | 147 | GNUNET_SCHEDULER_shutdown (); |
148 | } | 148 | } |
149 | 149 | ||
150 | |||
151 | /** | 150 | /** |
152 | * @brief Callback for ego loockup of get_did_for_ego() | 151 | * @brief Callback for ego loockup of get_did_for_ego() |
153 | * | 152 | * |
@@ -197,73 +196,16 @@ get_did_for_ego () | |||
197 | } | 196 | } |
198 | } | 197 | } |
199 | 198 | ||
200 | |||
201 | /** | ||
202 | * @brief Get the public key from did attribute given by the user | ||
203 | * | ||
204 | * @param pkey place to write the public key to | ||
205 | */ | ||
206 | static void | ||
207 | get_pkey_from_attr_did (struct GNUNET_IDENTITY_PublicKey *pkey) | ||
208 | { | ||
209 | /* FIXME-MSC: I suggest introducing a | ||
210 | * #define MAX_DID_LENGTH <something> | ||
211 | * here and use it for parsing | ||
212 | */ | ||
213 | char pkey_str[59]; | ||
214 | |||
215 | if ((1 != (sscanf (did, GNUNET_DID_METHOD_PREFIX "%58s", pkey_str))) || | ||
216 | (GNUNET_OK != GNUNET_IDENTITY_public_key_from_string (pkey_str, pkey))) | ||
217 | { | ||
218 | fprintf (stderr, _ ("Invalid DID `%s'\n"), pkey_str); | ||
219 | GNUNET_SCHEDULER_add_now (cleanup, NULL); | ||
220 | ret = 1; | ||
221 | return; | ||
222 | } | ||
223 | } | ||
224 | |||
225 | /** | 199 | /** |
226 | * @brief GNS lookup callback. Prints the DID Document to standard out. | 200 | * @brief Resolve DID callback. Prints the DID Document to standard out. |
227 | * Fails if there is more than one DID record. | 201 | * Prints error message if resolve fails |
228 | * | 202 | * |
229 | * @param cls closure | 203 | * @param cls closure |
230 | * @param rd_count number of records in @a rd | 204 | * @param rd_count number of records in @a rd |
231 | * @param rd the records in the reply | 205 | * @param rd the records in the reply |
232 | */ | 206 | */ |
233 | static void | 207 | static void |
234 | print_did_document ( | 208 | print_did_document( |
235 | void *cls, | ||
236 | uint32_t rd_count, | ||
237 | const struct GNUNET_GNSRECORD_Data *rd) | ||
238 | { | ||
239 | /* | ||
240 | * FIXME-MSC: The user may decide to put other records here. | ||
241 | * In general I am fine with the constraint here, but not when | ||
242 | * we move it to "@" | ||
243 | */ | ||
244 | if (rd_count != 1) | ||
245 | { | ||
246 | printf ("An ego should only have one DID Document\n"); | ||
247 | GNUNET_SCHEDULER_add_now (cleanup, NULL); | ||
248 | ret = 1; | ||
249 | return; | ||
250 | } | ||
251 | |||
252 | if (rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT) | ||
253 | { | ||
254 | printf ("%s\n", (char *) rd[0].data); | ||
255 | } | ||
256 | else { | ||
257 | printf ("DID Document is not a TXT record\n"); | ||
258 | } | ||
259 | |||
260 | GNUNET_SCHEDULER_add_now (cleanup, NULL); | ||
261 | ret = 0; | ||
262 | return; | ||
263 | } | ||
264 | |||
265 | static void | ||
266 | print_did_document2( | ||
267 | enum GNUNET_GenericReturnValue status, | 209 | enum GNUNET_GenericReturnValue status, |
268 | char *did_document, | 210 | char *did_document, |
269 | void *cls | 211 | void *cls |
@@ -285,23 +227,23 @@ print_did_document2( | |||
285 | static void | 227 | static void |
286 | resolve_did_document () | 228 | resolve_did_document () |
287 | { | 229 | { |
288 | // struct GNUNET_IDENTITY_PublicKey pkey; | 230 | struct GNUNET_IDENTITY_PublicKey pkey; |
289 | |||
290 | // if (did == NULL) | ||
291 | // { | ||
292 | // printf ("Set DID option to resolve DID\n"); | ||
293 | // GNUNET_SCHEDULER_add_now (cleanup, NULL); | ||
294 | // ret = 1; | ||
295 | // return; | ||
296 | // } | ||
297 | |||
298 | // get_pkey_from_attr_did (&pkey); | ||
299 | 231 | ||
300 | // GNUNET_GNS_lookup (gns_handle, GNUNET_GNS_EMPTY_LABEL_AT, &pkey, | 232 | if (did == NULL) |
301 | // GNUNET_DNSPARSER_TYPE_TXT, | 233 | { |
302 | // GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL); | 234 | printf ("Set DID option to resolve DID\n"); |
235 | GNUNET_SCHEDULER_add_now (cleanup, NULL); | ||
236 | ret = 1; | ||
237 | return; | ||
238 | } | ||
303 | 239 | ||
304 | DID_resolve(did, gns_handle, print_did_document2, NULL); | 240 | if (GNUNET_OK != DID_resolve(did, gns_handle, print_did_document, NULL)) |
241 | { | ||
242 | printf("An error occured while resoling the DID\n"); | ||
243 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | ||
244 | ret = 0; | ||
245 | return; | ||
246 | } | ||
305 | } | 247 | } |
306 | 248 | ||
307 | 249 | ||