diff options
author | Tristan Schwieren <tristan.schwieren@tum.de> | 2021-12-02 12:09:24 +0100 |
---|---|---|
committer | Tristan Schwieren <tristan.schwieren@tum.de> | 2021-12-02 12:09:24 +0100 |
commit | 3395a5af880820a16c0295d61cd8c174ead4e646 (patch) | |
tree | 4b81a964d5e6eff29fc080c78e764625ebd8f8ab | |
parent | f1d0f54c06726a8914d95585a462f8a6aa775b7e (diff) | |
download | gnunet-3395a5af880820a16c0295d61cd8c174ead4e646.tar.gz gnunet-3395a5af880820a16c0295d61cd8c174ead4e646.zip |
-DID refactor, uncrustify, not working didd create
-rw-r--r-- | src/did/Makefile.am | 4 | ||||
-rw-r--r-- | src/did/default_did_document.json | 15 | ||||
-rw-r--r-- | src/did/gnunet-did.c | 506 |
3 files changed, 343 insertions, 182 deletions
diff --git a/src/did/Makefile.am b/src/did/Makefile.am index 8fd634769..fe96a4be8 100644 --- a/src/did/Makefile.am +++ b/src/did/Makefile.am | |||
@@ -17,5 +17,7 @@ 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/identity/libgnunetidentity.la \ | 19 | $(top_builddir)/src/identity/libgnunetidentity.la \ |
20 | $(top_builddir)/src/namestore/libgnunetnamestore.la | 20 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
21 | -ljansson | ||
22 | |||
21 | 23 | ||
diff --git a/src/did/default_did_document.json b/src/did/default_did_document.json new file mode 100644 index 000000000..61675a886 --- /dev/null +++ b/src/did/default_did_document.json | |||
@@ -0,0 +1,15 @@ | |||
1 | { | ||
2 | "@context": [ | ||
3 | "https://www.w3.org/ns/did/v1", | ||
4 | "https://w3id.org/security/suites/ed25519-2020/v1" | ||
5 | ], | ||
6 | "id": "did:example:123", | ||
7 | "authentication": [ | ||
8 | { | ||
9 | "id": "did:example:123#z6MkecaLyHuYWkayBDLw5ihndj3T1m6zKTGqau3A51G7RBf3", | ||
10 | "type": "Ed25519VerificationKey2020", | ||
11 | "controller": "did:example:123", | ||
12 | "publicKeyMultibase": "zAKJP3f7BD6W4iWEQ9jwndVTCBq8ua2Utt8EEjJ6Vxsf" | ||
13 | } | ||
14 | ] | ||
15 | } \ No newline at end of file | ||
diff --git a/src/did/gnunet-did.c b/src/did/gnunet-did.c index 7ed004263..aaebc2ee7 100644 --- a/src/did/gnunet-did.c +++ b/src/did/gnunet-did.c | |||
@@ -20,13 +20,14 @@ | |||
20 | /** | 20 | /** |
21 | * @author Tristan Schwieren | 21 | * @author Tristan Schwieren |
22 | * @file src/did/gnunet-did.c | 22 | * @file src/did/gnunet-did.c |
23 | * @brief DID Method Wrapper | 23 | * @brief DID Method Wrapper |
24 | * | 24 | * |
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
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 "jansson.h" | ||
30 | 31 | ||
31 | /** | 32 | /** |
32 | * return value | 33 | * return value |
@@ -34,12 +35,12 @@ | |||
34 | static int ret; | 35 | static int ret; |
35 | 36 | ||
36 | /** | 37 | /** |
37 | * Attribute Add | 38 | * Attribute Add |
38 | */ | 39 | */ |
39 | static char *attr_add; | 40 | static char *attr_add; |
40 | 41 | ||
41 | /** | 42 | /** |
42 | * Attribute remove | 43 | * Attribute remove |
43 | */ | 44 | */ |
44 | static int *attr_remove; | 45 | static int *attr_remove; |
45 | 46 | ||
@@ -58,18 +59,15 @@ static char *attr_did; | |||
58 | */ | 59 | */ |
59 | static char *attr_ego; | 60 | static char *attr_ego; |
60 | 61 | ||
62 | /** | ||
63 | * Attribute create | ||
64 | */ | ||
65 | static char *attr_create; | ||
66 | |||
61 | static struct GNUNET_GNS_Handle *gns_handle; | 67 | static struct GNUNET_GNS_Handle *gns_handle; |
62 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | 68 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; |
63 | static struct GNUNET_CONFIGURATRION_Handle *my_cfg; | 69 | static struct GNUNET_CONFIGURATRION_Handle *my_cfg; |
64 | 70 | ||
65 | static void resolve_did_document(); | ||
66 | static void add_did_document(); | ||
67 | static void get_pkey_from_attr_did(); | ||
68 | static void print_did_document(); | ||
69 | static void remove_did_document(); | ||
70 | static void remove_did_ego_lookup_cb(); | ||
71 | static void remove_did_callback(); | ||
72 | |||
73 | // TODO | 71 | // TODO |
74 | // static void get_did_for_ego(); | 72 | // static void get_did_for_ego(); |
75 | // static void replace_did_document(); - use remove_did_document and add_did_document | 73 | // static void replace_did_document(); - use remove_did_document and add_did_document |
@@ -79,218 +77,364 @@ static void remove_did_callback(); | |||
79 | // Should the module only store and retrieve a DID document or also generate and cofigure it? | 77 | // Should the module only store and retrieve a DID document or also generate and cofigure it? |
80 | // static void generate_did_document(); | 78 | // static void generate_did_document(); |
81 | 79 | ||
82 | static void cleanup(); | 80 | /** |
83 | 81 | * @brief Disconnect and shutdown | |
82 | * @param cls closure | ||
83 | */ | ||
84 | static void | 84 | static void |
85 | run (void *cls, | 85 | cleanup(void * cls){ |
86 | char *const *args, | 86 | GNUNET_GNS_disconnect(gns_handle); |
87 | const char *cfgfile, | 87 | GNUNET_NAMESTORE_disconnect(namestore_handle); |
88 | const struct GNUNET_CONFIGURATION_Handle *c) | 88 | GNUNET_SCHEDULER_shutdown(); |
89 | { | ||
90 | gns_handle = GNUNET_GNS_connect(c); | ||
91 | namestore_handle = GNUNET_NAMESTORE_connect(c); | ||
92 | my_cfg = c; | ||
93 | |||
94 | // check if GNS_handle could connect | ||
95 | if(gns_handle == NULL){ | ||
96 | ret = 1; | ||
97 | return; | ||
98 | } | ||
99 | |||
100 | // check if NAMESTORE_handle could connect | ||
101 | if(namestore_handle == NULL){ | ||
102 | ret = 1; | ||
103 | return; | ||
104 | } | ||
105 | |||
106 | // check for more than one argument given | ||
107 | //if (NULL != attr_did && NULL != attr_delete || | ||
108 | // NULL != attr_did && NULL != attr_add || | ||
109 | // NULL != attr_delete && NULL != attr_add) | ||
110 | if(false) | ||
111 | { | ||
112 | ret = 1; | ||
113 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | ||
114 | return; | ||
115 | } | ||
116 | |||
117 | if (NULL != attr_add) { | ||
118 | add_did_document(); | ||
119 | } else if (1 == attr_get){ | ||
120 | resolve_did_document(); | ||
121 | } else if (1 == attr_remove) { | ||
122 | remove_did_document(); | ||
123 | } else { | ||
124 | // No Argument found | ||
125 | printf("No correct argument combination found. Use gnunet-did -h for help"); | ||
126 | ret = 1; | ||
127 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | ||
128 | return; | ||
129 | } | ||
130 | } | 89 | } |
131 | 90 | ||
132 | int | ||
133 | main (int argc, char *const argv[]) | ||
134 | { | ||
135 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
136 | GNUNET_GETOPT_option_string ('a', | ||
137 | "add", | ||
138 | "VALUE", | ||
139 | gettext_noop ("Add an DID Document"), | ||
140 | &attr_add), | ||
141 | GNUNET_GETOPT_option_flag ('r', | ||
142 | "remove", | ||
143 | gettext_noop ("Remove the DID Document with DID from GNUNET"), | ||
144 | &attr_remove), | ||
145 | GNUNET_GETOPT_option_flag ('g', | ||
146 | "get", | ||
147 | gettext_noop ("Get the DID Document associated with the given DID"), | ||
148 | &attr_get), | ||
149 | GNUNET_GETOPT_option_string ('d', | ||
150 | "did", | ||
151 | "DID", | ||
152 | gettext_noop ("The DID to work with"), | ||
153 | &attr_did), | ||
154 | GNUNET_GETOPT_option_string ('e', | ||
155 | "ego", | ||
156 | "EGO", | ||
157 | gettext_noop ("The EGO to work with"), | ||
158 | &attr_ego), | ||
159 | GNUNET_GETOPT_OPTION_END | ||
160 | }; | ||
161 | 91 | ||
162 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, | 92 | /** |
163 | argv, | 93 | * @brief Get the public key from did attribute given by the user |
164 | "gnunet-did", | 94 | * |
165 | ("did command line tool"), | 95 | * @param pkey place to write the public key to |
166 | options, | 96 | */ |
167 | &run, | 97 | static void |
168 | NULL)) | 98 | get_pkey_from_attr_did(struct GNUNET_IDENTITY_PublicKey * pkey) |
169 | return 1; | 99 | { |
170 | else | 100 | char id_str[59]; |
171 | return ret; | 101 | |
102 | if ((1 != (sscanf (attr_did, "did:reclaim:%58s", id_str))) || | ||
103 | (GNUNET_OK != GNUNET_IDENTITY_public_key_from_string (id_str, pkey))) | ||
104 | { | ||
105 | fprintf (stderr, _ ("Invalid DID `%s'\n"), id_str); | ||
106 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | ||
107 | ret = 1; | ||
108 | return; | ||
109 | } | ||
172 | } | 110 | } |
173 | 111 | ||
174 | 112 | /** | |
113 | * @brief GNS lookup callback. Prints the DID Document to standard out. | ||
114 | * Fails if there is more than one DID record. | ||
115 | * | ||
116 | * @param cls closure | ||
117 | * @param rd_count number of records in @a rd | ||
118 | * @param rd the records in the reply | ||
119 | */ | ||
175 | static void | 120 | static void |
176 | add_did_document(){ | 121 | print_did_document( |
177 | printf("Do nothing\n"); | 122 | void *cls, |
123 | uint32_t rd_count, | ||
124 | const struct GNUNET_GNSRECORD_Data *rd) | ||
125 | { | ||
126 | // TODO: Remove "store.sock" at the end of print | ||
127 | if (rd_count != 1) | ||
128 | { | ||
129 | printf("An ego should only have one DID Document"); | ||
130 | ret = 1; | ||
131 | return; | ||
132 | } | ||
133 | |||
134 | printf("%s\n", rd[0].data); | ||
135 | |||
136 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | ||
137 | ret = 0; | ||
138 | return; | ||
178 | } | 139 | } |
179 | 140 | ||
141 | /** | ||
142 | * @brief Resolve a DID given by the user. | ||
143 | */ | ||
180 | static void | 144 | static void |
181 | resolve_did_document() | 145 | resolve_did_document() |
182 | { | 146 | { |
183 | if (attr_did == NULL){ | 147 | if (attr_did == NULL) { |
184 | printf("Set DID option to resolve DID\n"); | 148 | printf("Set DID option to resolve DID\n"); |
185 | } | 149 | } |
150 | |||
151 | struct GNUNET_IDENTITY_PublicKey pkey; | ||
152 | get_pkey_from_attr_did(&pkey); | ||
153 | |||
154 | // TODO: Check the type of returned records | ||
155 | GNUNET_GNS_lookup(gns_handle, "didd", &pkey, GNUNET_DNSPARSER_TYPE_TXT, GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL); | ||
156 | } | ||
186 | 157 | ||
187 | struct GNUNET_IDENTITY_PublicKey pkey; | ||
188 | get_pkey_from_attr_did(&pkey); | ||
189 | 158 | ||
190 | // TODO: Check the type of returned records | 159 | /** |
191 | GNUNET_GNS_lookup(gns_handle, "didd", &pkey, GNUNET_DNSPARSER_TYPE_TXT, GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL); | 160 | * @brief Callback after the DID has been removed |
161 | */ | ||
162 | static void | ||
163 | remove_did_cb(){ | ||
164 | // Test if record was removed from Namestore | ||
165 | printf("DID Document has been removed\n"); | ||
166 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | ||
167 | ret = 0; | ||
168 | return; | ||
192 | } | 169 | } |
193 | 170 | ||
171 | /** | ||
172 | * @brief Callback called after the ego has been locked up | ||
173 | * | ||
174 | * @param cls closure | ||
175 | * @param ego the ego returned by the identity service | ||
176 | */ | ||
194 | static void | 177 | static void |
195 | get_pkey_from_attr_did(struct GNUNET_IDENTITY_PublicKey * pkey) | 178 | remove_did_ego_lookup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego){ |
179 | const struct GNUNET_IDENTITY_PrivateKey * skey = GNUNET_IDENTITY_ego_get_private_key(ego); | ||
180 | const int emp[0]; | ||
181 | struct GNUNET_GNSRECORD_Data rd = { | ||
182 | .data = &emp, | ||
183 | .expiration_time = 0, | ||
184 | .data_size = 0, | ||
185 | .record_type = 0, | ||
186 | .flags = GNUNET_GNSRECORD_RF_NONE | ||
187 | }; | ||
188 | |||
189 | GNUNET_NAMESTORE_records_store (namestore_handle, | ||
190 | skey, | ||
191 | "didd", | ||
192 | 0, | ||
193 | &rd, | ||
194 | &remove_did_cb, | ||
195 | NULL); | ||
196 | } | ||
197 | |||
198 | /** | ||
199 | * @brief Remove a DID Document | ||
200 | */ | ||
201 | static void | ||
202 | remove_did_document() | ||
196 | { | 203 | { |
197 | char id_str[59]; | 204 | if(attr_did == NULL && attr_ego == NULL) { |
205 | printf("Remove requieres an ego or did option\n"); | ||
206 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | ||
207 | ret = 1; | ||
208 | return; | ||
209 | } else if(attr_did != NULL && attr_ego != NULL) { | ||
210 | printf("Only set one of the EGO or DID options\n"); | ||
211 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | ||
212 | ret = 1; | ||
213 | return; | ||
214 | } else if (attr_ego != NULL) { | ||
215 | GNUNET_IDENTITY_ego_lookup(my_cfg, | ||
216 | attr_ego, | ||
217 | &remove_did_ego_lookup_cb, | ||
218 | NULL); | ||
219 | } else if (attr_did != NULL) { | ||
220 | // TODO: Use did->pkey->ego->skey to remove did document | ||
221 | // struct GNUNET_IDENTITY_PublicKey pkey; | ||
222 | // get_pkey_from_attr_did(&pkey); | ||
223 | printf("Remove by DID not supported\n"); | ||
224 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | ||
225 | ret = 1; | ||
226 | return; | ||
227 | } else { | ||
228 | printf("Something during the remove went wrong. Make sure you set the options correct\n"); | ||
229 | } | ||
230 | } | ||
198 | 231 | ||
199 | if ((1 != (sscanf (attr_did, "did:reclaim:%58s", id_str))) || | 232 | |
200 | (GNUNET_OK != GNUNET_IDENTITY_public_key_from_string (id_str, pkey))) | 233 | /** |
201 | { | 234 | * @brief Create ad did store DID in Namestore cb |
202 | fprintf (stderr, _ ("Invalid DID `%s'\n"), id_str); | 235 | * |
203 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | 236 | */ |
204 | ret = 1; | 237 | create_did_store_cb(void *cls, int32_t success, const char *emsg){ |
205 | return; | 238 | free(cls); |
206 | } | 239 | |
240 | printf("DID Document has been stored to namestore"); | ||
241 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | ||
242 | ret = 0; | ||
243 | return; | ||
207 | } | 244 | } |
208 | 245 | ||
246 | /** | ||
247 | * @brief Create a did ego lockup cb | ||
248 | * | ||
249 | * @param cls | ||
250 | * @param ego | ||
251 | */ | ||
209 | static void | 252 | static void |
210 | print_did_document( | 253 | create_did_ego_lockup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego) |
211 | void *cls, | ||
212 | uint32_t rd_count, | ||
213 | const struct GNUNET_GNSRECORD_Data *rd) | ||
214 | { | 254 | { |
215 | // TODO: Remove "store.sock" at the end of print | 255 | const struct GNUNET_IDENTITY_PublicKey pkey; // Get Public key |
216 | if (rd_count != 1) | 256 | GNUNET_IDENTITY_ego_get_public_key(ego, &pkey); |
257 | |||
258 | //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 | ||
260 | const char did_str[71]; // 58 + 12 + 1= 71 | ||
261 | const 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 | ||
263 | sprintf(&pkey_multibase_str, "V%s", pkey_str); // Convert the public key to MultiBase data format | ||
264 | |||
265 | // Create DID Document | ||
266 | json_t * did_json = json_string(did_str); | ||
267 | json_t * pkey_multibase_json = json_string(pkey_multibase_str); | ||
268 | json_t * context_1_json = json_string("https://www.w3.org/ns/did/v1"); | ||
269 | json_t * context_2_json = json_string("https://w3id.org/security/suites/ed25519-2020/v1"); | ||
270 | json_t * auth_type_json = json_string("Ed25519VerificationKey2020"); | ||
271 | |||
272 | json_t * context_json = json_array(); | ||
273 | json_array_append(context_json, context_1_json); | ||
274 | json_array_append(context_json, context_2_json); | ||
275 | |||
276 | json_t * auth_json = json_array(); | ||
277 | json_t * auth_1_json = json_object(); | ||
278 | json_object_set(auth_1_json, "id", did_json); | ||
279 | json_object_set(auth_1_json, "type", auth_type_json); | ||
280 | json_object_set(auth_1_json, "controller", did_json); | ||
281 | json_object_set(auth_1_json, "publicKeyMultiBase", pkey_multibase_json); | ||
282 | json_array_append(auth_json, auth_1_json); | ||
283 | |||
284 | json_t * didd = json_object(); | ||
285 | json_object_set(didd, "@context", context_json); | ||
286 | json_object_set(didd, "id", did_json); | ||
287 | json_object_set(didd, "authentication", auth_json); | ||
288 | |||
289 | // Encode DID Document as JSON string | ||
290 | const size_t didd_str_size = json_dumpb(didd, NULL, 0, JSON_INDENT(2)); | ||
291 | if(didd_str_size == 0) | ||
217 | { | 292 | { |
218 | printf("An ego should only have one DID Document"); | 293 | printf("DID Document could not be encoded"); |
294 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | ||
219 | ret = 1; | 295 | ret = 1; |
220 | return; | 296 | return; |
221 | } | 297 | } |
222 | 298 | ||
223 | printf("%s\n", rd[0].data); | 299 | char * didd_str = malloc(didd_str_size); |
300 | json_dumpb(didd, didd_str, didd_str_size, JSON_INDENT(2)); | ||
224 | 301 | ||
225 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | 302 | // Print DID Docuement to stdout |
226 | ret = 0; | 303 | printf("%s\n", didd_str); |
227 | return; | 304 | |
305 | // Save DID Document to GNS | ||
306 | const struct GNUNET_IDENTITY_PrivateKey * skey = GNUNET_IDENTITY_ego_get_private_key(ego); | ||
307 | const struct GNUNET_GNSRECORD_Data * record_data = { | ||
308 | didd_str, | ||
309 | 86400000000, // =1d TODO: Set to user preference | ||
310 | didd_str_size, | ||
311 | GNUNET_GNSRECORD_typename_to_number("TXT"), | ||
312 | 0 | ||
313 | }; | ||
314 | const unsigned int didd_str_count; | ||
315 | GNUNET_NAMESTORE_records_store( namestore_handle, | ||
316 | skey, | ||
317 | "didd", | ||
318 | 1, | ||
319 | record_data, | ||
320 | &create_did_store_cb, | ||
321 | didd_str); | ||
228 | } | 322 | } |
229 | 323 | ||
324 | /** | ||
325 | * @brief Create a did document object | ||
326 | */ | ||
230 | static void | 327 | static void |
231 | remove_did_document() | 328 | create_did_document() |
232 | { | 329 | { |
233 | if(attr_did == NULL && attr_ego == NULL){ | 330 | if(attr_ego != NULL){ |
234 | printf("Remove requieres an ego or did option\n"); | 331 | GNUNET_IDENTITY_ego_lookup(my_cfg, |
235 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | 332 | attr_ego, |
236 | ret = 1; | 333 | &create_did_ego_lockup_cb, |
237 | return; | 334 | NULL); |
238 | } else if(attr_did != NULL && attr_ego != NULL){ | 335 | } else { |
239 | printf("Only set one of the EGO or DID options\n"); | 336 | printf("Set the EGO argument to create a new DID Document\n"); |
240 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | 337 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); |
241 | ret = 1; | ||
242 | return; | ||
243 | } else if (attr_ego != NULL){ | ||
244 | GNUNET_IDENTITY_ego_lookup(my_cfg, | ||
245 | attr_ego, | ||
246 | &remove_did_ego_lookup_cb, | ||
247 | NULL); | ||
248 | } else if (attr_did != NULL){ | ||
249 | // TODO: Use did->pkey->ego->skey to remove did document | ||
250 | // struct GNUNET_IDENTITY_PublicKey pkey; | ||
251 | // get_pkey_from_attr_did(&pkey); | ||
252 | printf("Remove by DID not supported\n"); | ||
253 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | ||
254 | ret = 1; | 338 | ret = 1; |
255 | return; | 339 | return; |
256 | } else { | ||
257 | printf("Something during the remove went wrong. Make sure you set the options correct\n"); | ||
258 | } | 340 | } |
259 | } | 341 | } |
260 | 342 | ||
261 | static void | ||
262 | remove_did_ego_lookup_cb(void *cls, struct GNUNET_IDENTITY_Ego * ego){ | ||
263 | const struct GNUNET_IDENTITY_PrivateKey * skey = GNUNET_IDENTITY_ego_get_private_key(ego); | ||
264 | const int emp[0]; | ||
265 | struct GNUNET_GNSRECORD_Data rd = { | ||
266 | .data = &emp, | ||
267 | .expiration_time = 0, | ||
268 | .data_size = 0, | ||
269 | .record_type = 0, | ||
270 | .flags = GNUNET_GNSRECORD_RF_NONE | ||
271 | }; | ||
272 | 343 | ||
273 | GNUNET_NAMESTORE_records_store (namestore_handle, | 344 | static void |
274 | skey, | 345 | add_did_document() |
275 | "didd", | 346 | { |
276 | 0, | 347 | printf("Do nothing\n"); |
277 | &rd, | ||
278 | &remove_did_callback, | ||
279 | NULL); | ||
280 | } | 348 | } |
281 | 349 | ||
350 | |||
282 | static void | 351 | static void |
283 | remove_did_callback(){ | 352 | run (void *cls, |
284 | // Test if record was removed from Namestore | 353 | char *const *args, |
285 | printf("DID Document has been removed\n"); | 354 | const char *cfgfile, |
286 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | 355 | const struct GNUNET_CONFIGURATION_Handle *c) |
287 | ret = 0; | 356 | { |
288 | return; | 357 | gns_handle = GNUNET_GNS_connect(c); |
358 | namestore_handle = GNUNET_NAMESTORE_connect(c); | ||
359 | my_cfg = c; | ||
360 | |||
361 | // check if GNS_handle could connect | ||
362 | if(gns_handle == NULL) { | ||
363 | ret = 1; | ||
364 | return; | ||
365 | } | ||
366 | |||
367 | // check if NAMESTORE_handle could connect | ||
368 | if(namestore_handle == NULL) { | ||
369 | ret = 1; | ||
370 | return; | ||
371 | } | ||
372 | |||
373 | // check for more than one argument given | ||
374 | //if (NULL != attr_did && NULL != attr_delete || | ||
375 | // NULL != attr_did && NULL != attr_add || | ||
376 | // NULL != attr_delete && NULL != attr_add) | ||
377 | if(false) | ||
378 | { | ||
379 | ret = 1; | ||
380 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | ||
381 | return; | ||
382 | } | ||
383 | |||
384 | if (NULL != attr_add) { | ||
385 | add_did_document(); | ||
386 | } else if (1 == attr_get) { | ||
387 | resolve_did_document(); | ||
388 | } else if (1 == attr_remove) { | ||
389 | remove_did_document(); | ||
390 | } else if (1 == attr_create) { | ||
391 | create_did_document(); | ||
392 | } else { | ||
393 | // No Argument found | ||
394 | printf("No correct argument combination found. Use gnunet-did -h for help"); | ||
395 | ret = 1; | ||
396 | GNUNET_SCHEDULER_add_now(cleanup, NULL); | ||
397 | return; | ||
398 | } | ||
289 | } | 399 | } |
290 | 400 | ||
291 | static void | 401 | int |
292 | cleanup(void * cls){ | 402 | main (int argc, char *const argv[]) |
293 | GNUNET_GNS_disconnect(gns_handle); | 403 | { |
294 | GNUNET_NAMESTORE_disconnect(namestore_handle); | 404 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
295 | GNUNET_SCHEDULER_shutdown(); | 405 | GNUNET_GETOPT_option_flag ('C', |
406 | "create", | ||
407 | gettext_noop ("Create a DID Document and display its DID"), | ||
408 | &attr_create), | ||
409 | GNUNET_GETOPT_option_flag ('g', | ||
410 | "get", | ||
411 | gettext_noop ("Get the DID Document associated with the given DID"), | ||
412 | &attr_get), | ||
413 | GNUNET_GETOPT_option_flag ('r', | ||
414 | "remove", | ||
415 | gettext_noop ("Remove the DID Document with DID from GNUNET"), | ||
416 | &attr_remove), | ||
417 | GNUNET_GETOPT_option_string ('d', | ||
418 | "did", | ||
419 | "DID", | ||
420 | gettext_noop ("The DID to work with"), | ||
421 | &attr_did), | ||
422 | GNUNET_GETOPT_option_string ('e', | ||
423 | "ego", | ||
424 | "EGO", | ||
425 | gettext_noop ("The EGO to work with"), | ||
426 | &attr_ego), | ||
427 | GNUNET_GETOPT_OPTION_END | ||
428 | }; | ||
429 | |||
430 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, | ||
431 | argv, | ||
432 | "gnunet-did", | ||
433 | ("did command line tool"), | ||
434 | options, | ||
435 | &run, | ||
436 | NULL)) | ||
437 | return 1; | ||
438 | else | ||
439 | return ret; | ||
296 | } | 440 | } |