aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Schwieren <tristan.schwieren@tum.de>2021-12-03 11:22:13 +0100
committerTristan Schwieren <tristan.schwieren@tum.de>2021-12-03 11:22:13 +0100
commit2944a813c543c01aa0c0666212694f079798dfc1 (patch)
tree2ae108aeaf4c4f80704446ccc9801dc1ac752cc7
parent3395a5af880820a16c0295d61cd8c174ead4e646 (diff)
downloadgnunet-2944a813c543c01aa0c0666212694f079798dfc1.tar.gz
gnunet-2944a813c543c01aa0c0666212694f079798dfc1.zip
- did not working create
-rw-r--r--src/did/gnunet-did.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/src/did/gnunet-did.c b/src/did/gnunet-did.c
index aaebc2ee7..891d71ce3 100644
--- a/src/did/gnunet-did.c
+++ b/src/did/gnunet-did.c
@@ -27,6 +27,7 @@
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_namestore_service.h" 28#include "gnunet_namestore_service.h"
29#include "gnunet_gns_service.h" 29#include "gnunet_gns_service.h"
30#include "gnunet_gnsrecord_lib.h"
30#include "jansson.h" 31#include "jansson.h"
31 32
32/** 33/**
@@ -37,17 +38,22 @@ static int ret;
37/** 38/**
38 * Attribute Add 39 * Attribute Add
39 */ 40 */
40static char *attr_add; 41static int attr_add;
41 42
42/** 43/**
43 * Attribute remove 44 * Attribute remove
44 */ 45 */
45static int *attr_remove; 46static int attr_remove;
46 47
47/** 48/**
48 * Attibute get 49 * Attibute get
49 */ 50 */
50static int *attr_get; 51static int attr_get;
52
53/**
54 * Attribute create
55 */
56static int attr_create;
51 57
52/** 58/**
53 * Attribute did 59 * Attribute did
@@ -59,14 +65,10 @@ static char *attr_did;
59 */ 65 */
60static char *attr_ego; 66static char *attr_ego;
61 67
62/**
63 * Attribute create
64 */
65static char *attr_create;
66 68
67static struct GNUNET_GNS_Handle *gns_handle; 69static struct GNUNET_GNS_Handle *gns_handle;
68static struct GNUNET_NAMESTORE_Handle *namestore_handle; 70static struct GNUNET_NAMESTORE_Handle *namestore_handle;
69static struct GNUNET_CONFIGURATRION_Handle *my_cfg; 71const static struct GNUNET_CONFIGURATRION_Handle * my_cfg;
70 72
71// TODO 73// TODO
72// static void get_did_for_ego(); 74// static void get_did_for_ego();
@@ -131,7 +133,7 @@ print_did_document(
131 return; 133 return;
132 } 134 }
133 135
134 printf("%s\n", rd[0].data); 136 printf("%s\n", (char *) rd[0].data);
135 137
136 GNUNET_SCHEDULER_add_now(cleanup, NULL); 138 GNUNET_SCHEDULER_add_now(cleanup, NULL);
137 ret = 0; 139 ret = 0;
@@ -234,6 +236,7 @@ remove_did_document()
234 * @brief Create ad did store DID in Namestore cb 236 * @brief Create ad did store DID in Namestore cb
235 * 237 *
236 */ 238 */
239static void
237create_did_store_cb(void *cls, int32_t success, const char *emsg){ 240create_did_store_cb(void *cls, int32_t success, const char *emsg){
238 free(cls); 241 free(cls);
239 242
@@ -252,15 +255,16 @@ create_did_store_cb(void *cls, int32_t success, const char *emsg){
252static void 255static void
253create_did_ego_lockup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego) 256create_did_ego_lockup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego)
254{ 257{
255 const struct GNUNET_IDENTITY_PublicKey pkey; // Get Public key 258 struct GNUNET_IDENTITY_PublicKey pkey; // Get Public key
256 GNUNET_IDENTITY_ego_get_public_key(ego, &pkey); 259 GNUNET_IDENTITY_ego_get_public_key(ego, &pkey);
260 //
257 261
258 //const ssize_t pkey_len = GNUNET_IDENTITY_key_get_length(&pkey); // Get length of public key 262 //const ssize_t pkey_len = GNUNET_IDENTITY_key_get_length(&pkey); // Get length of public key
259 const char * pkey_str = GNUNET_IDENTITY_public_key_to_string(&pkey); // Convert public key to string 263 const char * pkey_str = GNUNET_IDENTITY_public_key_to_string(&pkey); // Convert public key to string
260 const char did_str[71]; // 58 + 12 + 1= 71 264 char did_str[71]; // 58 + 12 + 1= 71
261 const char pkey_multibase_str[60]; // 58 + 1 + 1 = 60 265 char pkey_multibase_str[60]; // 58 + 1 + 1 = 60
262 sprintf(&did_str, "did:reclaim:%s", pkey_str); // Convert the public key to a DID str 266 sprintf(did_str, "did:reclaim:%s", pkey_str); // Convert the public key to a DID str
263 sprintf(&pkey_multibase_str, "V%s", pkey_str); // Convert the public key to MultiBase data format 267 sprintf(pkey_multibase_str, "V%s", pkey_str); // Convert the public key to MultiBase data format
264 268
265 // Create DID Document 269 // Create DID Document
266 json_t * did_json = json_string(did_str); 270 json_t * did_json = json_string(did_str);
@@ -287,8 +291,8 @@ create_did_ego_lockup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego)
287 json_object_set(didd, "authentication", auth_json); 291 json_object_set(didd, "authentication", auth_json);
288 292
289 // Encode DID Document as JSON string 293 // Encode DID Document as JSON string
290 const size_t didd_str_size = json_dumpb(didd, NULL, 0, JSON_INDENT(2)); 294 void * didd_str = (void *) json_dumps(didd, JSON_INDENT(2));
291 if(didd_str_size == 0) 295 if(didd_str == NULL)
292 { 296 {
293 printf("DID Document could not be encoded"); 297 printf("DID Document could not be encoded");
294 GNUNET_SCHEDULER_add_now(&cleanup, NULL); 298 GNUNET_SCHEDULER_add_now(&cleanup, NULL);
@@ -296,27 +300,23 @@ create_did_ego_lockup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego)
296 return; 300 return;
297 } 301 }
298 302
299 char * didd_str = malloc(didd_str_size);
300 json_dumpb(didd, didd_str, didd_str_size, JSON_INDENT(2));
301
302 // Print DID Docuement to stdout 303 // Print DID Docuement to stdout
303 printf("%s\n", didd_str); 304 printf("%s\n", (char *) didd_str);
304 305
305 // Save DID Document to GNS 306 // Save DID Document to GNS
306 const struct GNUNET_IDENTITY_PrivateKey * skey = GNUNET_IDENTITY_ego_get_private_key(ego); 307 const struct GNUNET_IDENTITY_PrivateKey * skey = GNUNET_IDENTITY_ego_get_private_key(ego);
307 const struct GNUNET_GNSRECORD_Data * record_data = { 308 const struct GNUNET_GNSRECORD_Data record_data = {
308 didd_str, 309 didd_str,
309 86400000000, // =1d TODO: Set to user preference 310 (uint64_t) 86400000000, // =1d TODO: Set to user preference
310 didd_str_size, 311 strlen(didd_str),
311 GNUNET_GNSRECORD_typename_to_number("TXT"), 312 GNUNET_GNSRECORD_typename_to_number("TXT"),
312 0 313 0
313 }; 314 };
314 const unsigned int didd_str_count;
315 GNUNET_NAMESTORE_records_store( namestore_handle, 315 GNUNET_NAMESTORE_records_store( namestore_handle,
316 skey, 316 skey,
317 "didd", 317 "didd",
318 1, 318 1,
319 record_data, 319 &record_data,
320 &create_did_store_cb, 320 &create_did_store_cb,
321 didd_str); 321 didd_str);
322} 322}
@@ -381,7 +381,7 @@ run (void *cls,
381 return; 381 return;
382 } 382 }
383 383
384 if (NULL != attr_add) { 384 if (1 == attr_add) {
385 add_did_document(); 385 add_did_document();
386 } else if (1 == attr_get) { 386 } else if (1 == attr_get) {
387 resolve_did_document(); 387 resolve_did_document();
@@ -406,6 +406,10 @@ main (int argc, char *const argv[])
406 "create", 406 "create",
407 gettext_noop ("Create a DID Document and display its DID"), 407 gettext_noop ("Create a DID Document and display its DID"),
408 &attr_create), 408 &attr_create),
409 GNUNET_GETOPT_option_flag ('a',
410 "add",
411 gettext_noop ("Add a DID Document and display its DID"),
412 &attr_add),
409 GNUNET_GETOPT_option_flag ('g', 413 GNUNET_GETOPT_option_flag ('g',
410 "get", 414 "get",
411 gettext_noop ("Get the DID Document associated with the given DID"), 415 gettext_noop ("Get the DID Document associated with the given DID"),