diff options
-rw-r--r-- | src/did/Makefile.am | 1 | ||||
-rw-r--r-- | src/did/gnunet-did.c | 273 |
2 files changed, 213 insertions, 61 deletions
diff --git a/src/did/Makefile.am b/src/did/Makefile.am index dcdf7aa79..3f5e3f34b 100644 --- a/src/did/Makefile.am +++ b/src/did/Makefile.am | |||
@@ -16,6 +16,7 @@ gnunet_did_SOURCES = \ | |||
16 | gnunet_did_LDADD = \ | 16 | gnunet_did_LDADD = \ |
17 | $(top_builddir)/src/util/libgnunetutil.la \ | 17 | $(top_builddir)/src/util/libgnunetutil.la \ |
18 | $(top_builddir)/src/gns/libgnunetgns.la \ | 18 | $(top_builddir)/src/gns/libgnunetgns.la \ |
19 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
19 | $(top_builddir)/src/identity/libgnunetidentity.la \ | 20 | $(top_builddir)/src/identity/libgnunetidentity.la \ |
20 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | 21 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
21 | -ljansson | 22 | -ljansson |
diff --git a/src/did/gnunet-did.c b/src/did/gnunet-did.c index 891d71ce3..1967334ee 100644 --- a/src/did/gnunet-did.c +++ b/src/did/gnunet-did.c | |||
@@ -56,40 +56,100 @@ static int attr_get; | |||
56 | static int attr_create; | 56 | static int attr_create; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Attribute show | ||
60 | */ | ||
61 | static int attr_show; | ||
62 | |||
63 | /** | ||
59 | * Attribute did | 64 | * Attribute did |
60 | */ | 65 | */ |
61 | static char *attr_did; | 66 | static char *attr_did; |
62 | 67 | ||
63 | /** | 68 | /** |
64 | * Attribute did | 69 | * Attribute ego |
65 | */ | 70 | */ |
66 | static char *attr_ego; | 71 | static char *attr_ego; |
67 | 72 | ||
73 | /** | ||
74 | * Attribute name | ||
75 | */ | ||
76 | static char *attr_name; | ||
68 | 77 | ||
69 | static struct GNUNET_GNS_Handle *gns_handle; | 78 | static struct GNUNET_GNS_Handle * gns_handle; |
70 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | 79 | static struct GNUNET_NAMESTORE_Handle * namestore_handle; |
71 | const static struct GNUNET_CONFIGURATRION_Handle * my_cfg; | 80 | static struct GNUNET_IDENTITY_Handle * identity_handle; |
81 | const static struct GNUNET_CONFIGURATION_Handle * my_cfg; | ||
72 | 82 | ||
73 | // TODO | 83 | // TODO |
74 | // static void get_did_for_ego(); | ||
75 | // static void replace_did_document(); - use remove_did_document and add_did_document | 84 | // static void replace_did_document(); - use remove_did_document and add_did_document |
85 | // eddsa only | ||
86 | // welche properties? | ||
87 | // cleans? | ||
76 | 88 | ||
77 | // Add a data DID Document type | 89 | // Add a data DID Document type |
78 | 90 | ||
79 | // Should the module only store and retrieve a DID document or also generate and cofigure it? | ||
80 | // static void generate_did_document(); | ||
81 | |||
82 | /** | 91 | /** |
83 | * @brief Disconnect and shutdown | 92 | * @brief Disconnect and shutdown |
84 | * @param cls closure | 93 | * @param cls closure |
85 | */ | 94 | */ |
86 | static void | 95 | static void |
87 | cleanup(void * cls){ | 96 | cleanup(void * cls) |
97 | { | ||
88 | GNUNET_GNS_disconnect(gns_handle); | 98 | GNUNET_GNS_disconnect(gns_handle); |
89 | GNUNET_NAMESTORE_disconnect(namestore_handle); | 99 | GNUNET_NAMESTORE_disconnect(namestore_handle); |
100 | GNUNET_IDENTITY_disconnect(identity_handle); | ||
90 | GNUNET_SCHEDULER_shutdown(); | 101 | GNUNET_SCHEDULER_shutdown(); |
91 | } | 102 | } |
92 | 103 | ||
104 | /** | ||
105 | * @brief Callback for ego loockup of get_did_for_ego() | ||
106 | * | ||
107 | * @param cls closure | ||
108 | * @param ego the returned ego | ||
109 | */ | ||
110 | static void | ||
111 | get_did_for_ego_lookup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego) | ||
112 | { | ||
113 | if(ego == NULL) { | ||
114 | printf("EGO not found\n"); | ||
115 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | ||
116 | ret = 1; | ||
117 | return; | ||
118 | } | ||
119 | |||
120 | struct GNUNET_IDENTITY_PublicKey pkey; // Get Public key | ||
121 | GNUNET_IDENTITY_ego_get_public_key(ego, &pkey); | ||
122 | |||
123 | const char * pkey_str = GNUNET_IDENTITY_public_key_to_string(&pkey); // Convert public key to string | ||
124 | char did_str[71]; // 58 + 12 + 1= 71 | ||
125 | sprintf(did_str, "did:reclaim:%s", pkey_str); // Convert the public key to a DID str | ||
126 | |||
127 | printf("%s\n", did_str); | ||
128 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | ||
129 | ret = 0; | ||
130 | return; | ||
131 | } | ||
132 | |||
133 | /** | ||
134 | * @brief Get the DID for a given EGO | ||
135 | * | ||
136 | */ | ||
137 | static void | ||
138 | get_did_for_ego() | ||
139 | { | ||
140 | if(attr_ego != NULL){ | ||
141 | GNUNET_IDENTITY_ego_lookup(my_cfg, | ||
142 | attr_ego, | ||
143 | &get_did_for_ego_lookup_cb, | ||
144 | NULL); | ||
145 | } else { | ||
146 | printf("Set the EGO argument to get the DID for a given EGO\n"); | ||
147 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | ||
148 | ret = 1; | ||
149 | return; | ||
150 | } | ||
151 | } | ||
152 | |||
93 | 153 | ||
94 | /** | 154 | /** |
95 | * @brief Get the public key from did attribute given by the user | 155 | * @brief Get the public key from did attribute given by the user |
@@ -125,10 +185,12 @@ print_did_document( | |||
125 | uint32_t rd_count, | 185 | uint32_t rd_count, |
126 | const struct GNUNET_GNSRECORD_Data *rd) | 186 | const struct GNUNET_GNSRECORD_Data *rd) |
127 | { | 187 | { |
188 | printf("Going to print did\n"); | ||
128 | // TODO: Remove "store.sock" at the end of print | 189 | // TODO: Remove "store.sock" at the end of print |
129 | if (rd_count != 1) | 190 | if (rd_count != 1) |
130 | { | 191 | { |
131 | printf("An ego should only have one DID Document"); | 192 | printf("An ego should only have one DID Document"); |
193 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | ||
132 | ret = 1; | 194 | ret = 1; |
133 | return; | 195 | return; |
134 | } | 196 | } |
@@ -148,12 +210,16 @@ resolve_did_document() | |||
148 | { | 210 | { |
149 | if (attr_did == NULL) { | 211 | if (attr_did == NULL) { |
150 | printf("Set DID option to resolve DID\n"); | 212 | printf("Set DID option to resolve DID\n"); |
213 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | ||
214 | ret = 1; | ||
215 | return; | ||
151 | } | 216 | } |
152 | 217 | ||
153 | struct GNUNET_IDENTITY_PublicKey pkey; | 218 | struct GNUNET_IDENTITY_PublicKey pkey; |
154 | get_pkey_from_attr_did(&pkey); | 219 | get_pkey_from_attr_did(&pkey); |
155 | 220 | ||
156 | // TODO: Check the type of returned records | 221 | // TODO: Check the type of returned records |
222 | printf("Start GNS lockup\n"); | ||
157 | GNUNET_GNS_lookup(gns_handle, "didd", &pkey, GNUNET_DNSPARSER_TYPE_TXT, GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL); | 223 | GNUNET_GNS_lookup(gns_handle, "didd", &pkey, GNUNET_DNSPARSER_TYPE_TXT, GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL); |
158 | } | 224 | } |
159 | 225 | ||
@@ -203,13 +269,8 @@ remove_did_ego_lookup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego){ | |||
203 | static void | 269 | static void |
204 | remove_did_document() | 270 | remove_did_document() |
205 | { | 271 | { |
206 | if(attr_did == NULL && attr_ego == NULL) { | 272 | if(attr_ego == NULL) { |
207 | printf("Remove requieres an ego or did option\n"); | 273 | printf("Remove requieres an ego option\n"); |
208 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | ||
209 | ret = 1; | ||
210 | return; | ||
211 | } else if(attr_did != NULL && attr_ego != NULL) { | ||
212 | printf("Only set one of the EGO or DID options\n"); | ||
213 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | 274 | GNUNET_SCHEDULER_add_now(cleanup, NULL); |
214 | ret = 1; | 275 | ret = 1; |
215 | return; | 276 | return; |
@@ -218,48 +279,24 @@ remove_did_document() | |||
218 | attr_ego, | 279 | attr_ego, |
219 | &remove_did_ego_lookup_cb, | 280 | &remove_did_ego_lookup_cb, |
220 | NULL); | 281 | NULL); |
221 | } else if (attr_did != NULL) { | 282 | } else { |
222 | // TODO: Use did->pkey->ego->skey to remove did document | 283 | printf("Something during the remove went wrong. Make sure you set the options correct\n"); |
223 | // struct GNUNET_IDENTITY_PublicKey pkey; | ||
224 | // get_pkey_from_attr_did(&pkey); | ||
225 | printf("Remove by DID not supported\n"); | ||
226 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | 284 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); |
227 | ret = 1; | 285 | ret = 1; |
228 | return; | 286 | return; |
229 | } else { | ||
230 | printf("Something during the remove went wrong. Make sure you set the options correct\n"); | ||
231 | } | 287 | } |
232 | } | 288 | } |
233 | 289 | ||
234 | 290 | ||
235 | /** | 291 | /** |
236 | * @brief Create ad did store DID in Namestore cb | 292 | * @brief Create a did generate did object |
237 | * | ||
238 | */ | ||
239 | static void | ||
240 | create_did_store_cb(void *cls, int32_t success, const char *emsg){ | ||
241 | free(cls); | ||
242 | |||
243 | printf("DID Document has been stored to namestore"); | ||
244 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | ||
245 | ret = 0; | ||
246 | return; | ||
247 | } | ||
248 | |||
249 | /** | ||
250 | * @brief Create a did ego lockup cb | ||
251 | * | 293 | * |
252 | * @param cls | 294 | * @param pkey |
253 | * @param ego | 295 | * @return void* Return pointer to the DID Document |
254 | */ | 296 | */ |
255 | static void | 297 | char * |
256 | create_did_ego_lockup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego) | 298 | create_did_generate(struct GNUNET_IDENTITY_PublicKey pkey) |
257 | { | 299 | { |
258 | struct GNUNET_IDENTITY_PublicKey pkey; // Get Public key | ||
259 | GNUNET_IDENTITY_ego_get_public_key(ego, &pkey); | ||
260 | // | ||
261 | |||
262 | //const ssize_t pkey_len = GNUNET_IDENTITY_key_get_length(&pkey); // Get length of public key | ||
263 | const char * pkey_str = GNUNET_IDENTITY_public_key_to_string(&pkey); // Convert public key to string | 300 | const char * pkey_str = GNUNET_IDENTITY_public_key_to_string(&pkey); // Convert public key to string |
264 | char did_str[71]; // 58 + 12 + 1= 71 | 301 | char did_str[71]; // 58 + 12 + 1= 71 |
265 | char pkey_multibase_str[60]; // 58 + 1 + 1 = 60 | 302 | char pkey_multibase_str[60]; // 58 + 1 + 1 = 60 |
@@ -291,7 +328,7 @@ create_did_ego_lockup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego) | |||
291 | json_object_set(didd, "authentication", auth_json); | 328 | json_object_set(didd, "authentication", auth_json); |
292 | 329 | ||
293 | // Encode DID Document as JSON string | 330 | // Encode DID Document as JSON string |
294 | void * didd_str = (void *) json_dumps(didd, JSON_INDENT(2)); | 331 | char * didd_str = json_dumps(didd, JSON_INDENT(2)); |
295 | if(didd_str == NULL) | 332 | if(didd_str == NULL) |
296 | { | 333 | { |
297 | printf("DID Document could not be encoded"); | 334 | printf("DID Document could not be encoded"); |
@@ -300,40 +337,139 @@ create_did_ego_lockup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego) | |||
300 | return; | 337 | return; |
301 | } | 338 | } |
302 | 339 | ||
303 | // Print DID Docuement to stdout | 340 | // TODO: FREEEEEE |
304 | printf("%s\n", (char *) didd_str); | 341 | |
342 | return didd_str; | ||
343 | } | ||
344 | |||
345 | /** | ||
346 | * @brief Create a DID. Store DID in Namestore cb | ||
347 | * | ||
348 | */ | ||
349 | static void | ||
350 | create_did_store_cb(void *cls, int32_t success, const char *emsg){ | ||
351 | printf("DID Document has been stored to namestore\n"); | ||
352 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | ||
353 | ret = 0; | ||
354 | return; | ||
355 | } | ||
305 | 356 | ||
306 | // Save DID Document to GNS | 357 | /** |
358 | * @brief Create a did. Store DID in Namestore | ||
359 | * | ||
360 | * @param didd_str String endoced DID Docuement | ||
361 | * @param ego Identity whos DID Document is stored | ||
362 | */ | ||
363 | static void | ||
364 | create_did_store(char * didd_str, struct GNUNET_IDENTITY_Ego * ego) | ||
365 | { | ||
307 | const struct GNUNET_IDENTITY_PrivateKey * skey = GNUNET_IDENTITY_ego_get_private_key(ego); | 366 | const struct GNUNET_IDENTITY_PrivateKey * skey = GNUNET_IDENTITY_ego_get_private_key(ego); |
308 | const struct GNUNET_GNSRECORD_Data record_data = { | 367 | const struct GNUNET_GNSRECORD_Data record_data = { |
309 | didd_str, | 368 | (void *) didd_str, |
310 | (uint64_t) 86400000000, // =1d TODO: Set to user preference | 369 | (uint64_t) 86400000000, // =1d TODO: Set to user preference |
311 | strlen(didd_str), | 370 | strlen(didd_str), |
312 | GNUNET_GNSRECORD_typename_to_number("TXT"), | 371 | GNUNET_GNSRECORD_typename_to_number("TXT"), |
313 | 0 | 372 | 0 |
314 | }; | 373 | }; |
374 | |||
315 | GNUNET_NAMESTORE_records_store( namestore_handle, | 375 | GNUNET_NAMESTORE_records_store( namestore_handle, |
316 | skey, | 376 | skey, |
317 | "didd", | 377 | "didd", |
318 | 1, | 378 | 1, |
319 | &record_data, | 379 | &record_data, |
320 | &create_did_store_cb, | 380 | &create_did_store_cb, |
321 | didd_str); | 381 | NULL); |
322 | } | 382 | } |
323 | 383 | ||
324 | /** | 384 | /** |
325 | * @brief Create a did document object | 385 | * @brief Create a did ego lockup cb |
386 | * | ||
387 | * @param cls | ||
388 | * @param ego | ||
326 | */ | 389 | */ |
327 | static void | 390 | static void |
391 | create_did_ego_lockup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego) | ||
392 | { | ||
393 | if(ego == NULL) | ||
394 | { | ||
395 | printf("EGO not found\n"); | ||
396 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | ||
397 | ret = 1; | ||
398 | return; | ||
399 | } | ||
400 | |||
401 | struct GNUNET_IDENTITY_PublicKey pkey; // Get Public key | ||
402 | GNUNET_IDENTITY_ego_get_public_key(ego, &pkey); | ||
403 | |||
404 | printf("DEBUG: Key type: %d\n", pkey.type); | ||
405 | |||
406 | // check if the key is of right type (EDDSA) | ||
407 | // What does "Defined by the GNS zone type value in NBO" mean? | ||
408 | //if (pkey.type != GNUNET_IDENTITY_TYPE_EDDSA) { | ||
409 | if (false) | ||
410 | { | ||
411 | printf("The EGO has to have an EDDSA key pair\n"); | ||
412 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | ||
413 | ret = 1; | ||
414 | return; | ||
415 | } | ||
416 | |||
417 | // TODO: Check if a an option with a DID Docuement was supplied | ||
418 | |||
419 | // Generate DID Docuement from public key | ||
420 | char * didd_str = create_did_generate(pkey); | ||
421 | |||
422 | // Print DID Docuement to stdout | ||
423 | printf("%s\n", didd_str); | ||
424 | |||
425 | // Store the DID Docuement | ||
426 | create_did_store(didd_str, ego); | ||
427 | |||
428 | // Save DID Document String to GNS | ||
429 | free(didd_str); | ||
430 | } | ||
431 | |||
432 | /** | ||
433 | * @brief Create a did document - Create a new identity first | ||
434 | */ | ||
435 | static void | ||
436 | create_did_document_ego_create_cb(void *cls, | ||
437 | const struct GNUNET_IDENTITY_PrivateKey *pk, | ||
438 | const char *emsg) | ||
439 | { | ||
440 | if (emsg != NULL){ | ||
441 | printf("Something went wrong during the creation of a new identity\n"); | ||
442 | printf("%s\n", emsg); | ||
443 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | ||
444 | ret = 1; | ||
445 | return; | ||
446 | } | ||
447 | |||
448 | const char * ego_name = (char *) cls; | ||
449 | |||
450 | GNUNET_IDENTITY_ego_lookup(my_cfg, | ||
451 | ego_name, | ||
452 | &create_did_ego_lockup_cb, | ||
453 | NULL); | ||
454 | } | ||
455 | |||
456 | static void | ||
328 | create_did_document() | 457 | create_did_document() |
329 | { | 458 | { |
330 | if(attr_ego != NULL){ | 459 | if(attr_name != NULL){ |
460 | GNUNET_IDENTITY_create(identity_handle, | ||
461 | attr_name, | ||
462 | NULL, | ||
463 | GNUNET_IDENTITY_TYPE_EDDSA, | ||
464 | &create_did_document_ego_create_cb, | ||
465 | (void *) attr_name); | ||
466 | } else if (attr_ego != NULL) { | ||
331 | GNUNET_IDENTITY_ego_lookup(my_cfg, | 467 | GNUNET_IDENTITY_ego_lookup(my_cfg, |
332 | attr_ego, | 468 | attr_ego, |
333 | &create_did_ego_lockup_cb, | 469 | &create_did_ego_lockup_cb, |
334 | NULL); | 470 | NULL); |
335 | } else { | 471 | } else { |
336 | printf("Set the EGO argument to create a new DID Document\n"); | 472 | printf("Set the NAME or the EGO argument to create a new DID(-Document)\n"); |
337 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | 473 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); |
338 | ret = 1; | 474 | ret = 1; |
339 | return; | 475 | return; |
@@ -341,7 +477,7 @@ create_did_document() | |||
341 | } | 477 | } |
342 | 478 | ||
343 | 479 | ||
344 | static void | 480 | static void |
345 | add_did_document() | 481 | add_did_document() |
346 | { | 482 | { |
347 | printf("Do nothing\n"); | 483 | printf("Do nothing\n"); |
@@ -356,6 +492,7 @@ run (void *cls, | |||
356 | { | 492 | { |
357 | gns_handle = GNUNET_GNS_connect(c); | 493 | gns_handle = GNUNET_GNS_connect(c); |
358 | namestore_handle = GNUNET_NAMESTORE_connect(c); | 494 | namestore_handle = GNUNET_NAMESTORE_connect(c); |
495 | identity_handle = GNUNET_IDENTITY_connect(c, NULL, NULL); | ||
359 | my_cfg = c; | 496 | my_cfg = c; |
360 | 497 | ||
361 | // check if GNS_handle could connect | 498 | // check if GNS_handle could connect |
@@ -370,10 +507,13 @@ run (void *cls, | |||
370 | return; | 507 | return; |
371 | } | 508 | } |
372 | 509 | ||
373 | // check for more than one argument given | 510 | // check if IDENTITY_handle could connect |
374 | //if (NULL != attr_did && NULL != attr_delete || | 511 | if(identity_handle == NULL) { |
375 | // NULL != attr_did && NULL != attr_add || | 512 | ret = 1; |
376 | // NULL != attr_delete && NULL != attr_add) | 513 | return; |
514 | } | ||
515 | |||
516 | // TODO: Check for more than one argument given | ||
377 | if(false) | 517 | if(false) |
378 | { | 518 | { |
379 | ret = 1; | 519 | ret = 1; |
@@ -389,6 +529,8 @@ run (void *cls, | |||
389 | remove_did_document(); | 529 | remove_did_document(); |
390 | } else if (1 == attr_create) { | 530 | } else if (1 == attr_create) { |
391 | create_did_document(); | 531 | create_did_document(); |
532 | } else if (1 == attr_show) { | ||
533 | get_did_for_ego(); | ||
392 | } else { | 534 | } else { |
393 | // No Argument found | 535 | // No Argument found |
394 | printf("No correct argument combination found. Use gnunet-did -h for help"); | 536 | printf("No correct argument combination found. Use gnunet-did -h for help"); |
@@ -414,6 +556,10 @@ main (int argc, char *const argv[]) | |||
414 | "get", | 556 | "get", |
415 | gettext_noop ("Get the DID Document associated with the given DID"), | 557 | gettext_noop ("Get the DID Document associated with the given DID"), |
416 | &attr_get), | 558 | &attr_get), |
559 | GNUNET_GETOPT_option_flag ('s', | ||
560 | "show", | ||
561 | gettext_noop ("Show the DID for a given ego"), | ||
562 | &attr_show), | ||
417 | GNUNET_GETOPT_option_flag ('r', | 563 | GNUNET_GETOPT_option_flag ('r', |
418 | "remove", | 564 | "remove", |
419 | gettext_noop ("Remove the DID Document with DID from GNUNET"), | 565 | gettext_noop ("Remove the DID Document with DID from GNUNET"), |
@@ -428,6 +574,11 @@ main (int argc, char *const argv[]) | |||
428 | "EGO", | 574 | "EGO", |
429 | gettext_noop ("The EGO to work with"), | 575 | gettext_noop ("The EGO to work with"), |
430 | &attr_ego), | 576 | &attr_ego), |
577 | GNUNET_GETOPT_option_string ('n', | ||
578 | "name", | ||
579 | "NAME", | ||
580 | gettext_noop ("The name of the created EGO"), | ||
581 | &attr_name), | ||
431 | GNUNET_GETOPT_OPTION_END | 582 | GNUNET_GETOPT_OPTION_END |
432 | }; | 583 | }; |
433 | 584 | ||