summaryrefslogtreecommitdiff
path: root/src/identity/gnunet-identity.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/identity/gnunet-identity.c')
-rw-r--r--src/identity/gnunet-identity.c360
1 files changed, 180 insertions, 180 deletions
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c
index 41878fc1e..d86fd2166 100644
--- a/src/identity/gnunet-identity.c
+++ b/src/identity/gnunet-identity.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file identity/gnunet-identity.c 21 * @file identity/gnunet-identity.c
22 * @brief IDENTITY management command line tool 22 * @brief IDENTITY management command line tool
@@ -112,29 +112,29 @@ static int global_ret;
112 * @param cls NULL 112 * @param cls NULL
113 */ 113 */
114static void 114static void
115shutdown_task (void *cls) 115shutdown_task(void *cls)
116{ 116{
117 if (NULL != set_op) 117 if (NULL != set_op)
118 { 118 {
119 GNUNET_IDENTITY_cancel (set_op); 119 GNUNET_IDENTITY_cancel(set_op);
120 set_op = NULL; 120 set_op = NULL;
121 } 121 }
122 if (NULL != create_op) 122 if (NULL != create_op)
123 { 123 {
124 GNUNET_IDENTITY_cancel (create_op); 124 GNUNET_IDENTITY_cancel(create_op);
125 create_op = NULL; 125 create_op = NULL;
126 } 126 }
127 if (NULL != delete_op) 127 if (NULL != delete_op)
128 { 128 {
129 GNUNET_IDENTITY_cancel (delete_op); 129 GNUNET_IDENTITY_cancel(delete_op);
130 delete_op = NULL; 130 delete_op = NULL;
131 } 131 }
132 if (NULL != set_ego) 132 if (NULL != set_ego)
133 { 133 {
134 GNUNET_free (set_ego); 134 GNUNET_free(set_ego);
135 set_ego = NULL; 135 set_ego = NULL;
136 } 136 }
137 GNUNET_IDENTITY_disconnect (sh); 137 GNUNET_IDENTITY_disconnect(sh);
138 sh = NULL; 138 sh = NULL;
139} 139}
140 140
@@ -143,15 +143,15 @@ shutdown_task (void *cls)
143 * Test if we are finished yet. 143 * Test if we are finished yet.
144 */ 144 */
145static void 145static void
146test_finished () 146test_finished()
147{ 147{
148 if ((NULL == create_op) && (NULL == delete_op) && (NULL == set_op) && 148 if ((NULL == create_op) && (NULL == delete_op) && (NULL == set_op) &&
149 (NULL == set_subsystem) && (! list) && (! monitor)) 149 (NULL == set_subsystem) && (!list) && (!monitor))
150 { 150 {
151 if (TIMEOUT_STATUS_CODE == global_ret) 151 if (TIMEOUT_STATUS_CODE == global_ret)
152 global_ret = 0; 152 global_ret = 0;
153 GNUNET_SCHEDULER_shutdown (); 153 GNUNET_SCHEDULER_shutdown();
154 } 154 }
155} 155}
156 156
157 157
@@ -162,14 +162,14 @@ test_finished ()
162 * @param emsg NULL on success, otherwise an error message 162 * @param emsg NULL on success, otherwise an error message
163 */ 163 */
164static void 164static void
165delete_finished (void *cls, const char *emsg) 165delete_finished(void *cls, const char *emsg)
166{ 166{
167 struct GNUNET_IDENTITY_Operation **op = cls; 167 struct GNUNET_IDENTITY_Operation **op = cls;
168 168
169 *op = NULL; 169 *op = NULL;
170 if (NULL != emsg) 170 if (NULL != emsg)
171 fprintf (stderr, "%s\n", gettext (emsg)); 171 fprintf(stderr, "%s\n", gettext(emsg));
172 test_finished (); 172 test_finished();
173} 173}
174 174
175 175
@@ -181,40 +181,40 @@ delete_finished (void *cls, const char *emsg)
181 * @param emsg error message, NULL on success 181 * @param emsg error message, NULL on success
182 */ 182 */
183static void 183static void
184create_finished (void *cls, 184create_finished(void *cls,
185 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, 185 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
186 const char *emsg) 186 const char *emsg)
187{ 187{
188 struct GNUNET_IDENTITY_Operation **op = cls; 188 struct GNUNET_IDENTITY_Operation **op = cls;
189 189
190 *op = NULL; 190 *op = NULL;
191 if (NULL == pk) 191 if (NULL == pk)
192 {
193 fprintf (stderr, _ ("Failed to create ego: %s\n"), emsg);
194 global_ret = 1;
195 }
196 else if (verbose)
197 {
198 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
199 char *pubs;
200
201 GNUNET_CRYPTO_ecdsa_key_get_public (pk, &pub);
202 pubs = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pub);
203 if (private_keys)
204 { 192 {
205 char *privs; 193 fprintf(stderr, _("Failed to create ego: %s\n"), emsg);
206 194 global_ret = 1;
207 privs = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk);
208 fprintf (stdout, "%s - %s\n", pubs, privs);
209 GNUNET_free (privs);
210 } 195 }
211 else 196 else if (verbose)
212 { 197 {
213 fprintf (stdout, "%s\n", pubs); 198 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
199 char *pubs;
200
201 GNUNET_CRYPTO_ecdsa_key_get_public(pk, &pub);
202 pubs = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pub);
203 if (private_keys)
204 {
205 char *privs;
206
207 privs = GNUNET_CRYPTO_ecdsa_private_key_to_string(pk);
208 fprintf(stdout, "%s - %s\n", pubs, privs);
209 GNUNET_free(privs);
210 }
211 else
212 {
213 fprintf(stdout, "%s\n", pubs);
214 }
215 GNUNET_free(pubs);
214 } 216 }
215 GNUNET_free (pubs); 217 test_finished();
216 }
217 test_finished ();
218} 218}
219 219
220 220
@@ -225,15 +225,15 @@ create_finished (void *cls,
225 * @param emsg error message (NULL on success) 225 * @param emsg error message (NULL on success)
226 */ 226 */
227static void 227static void
228set_done (void *cls, const char *emsg) 228set_done(void *cls, const char *emsg)
229{ 229{
230 set_op = NULL; 230 set_op = NULL;
231 if (NULL != emsg) 231 if (NULL != emsg)
232 { 232 {
233 fprintf (stderr, _ ("Failed to set default ego: %s\n"), emsg); 233 fprintf(stderr, _("Failed to set default ego: %s\n"), emsg);
234 global_ret = 1; 234 global_ret = 1;
235 } 235 }
236 test_finished (); 236 test_finished();
237} 237}
238 238
239 239
@@ -269,72 +269,72 @@ set_done (void *cls, const char *emsg)
269 * @param identifier identifier assigned by the user for this ego, 269 * @param identifier identifier assigned by the user for this ego,
270 * NULL if the user just deleted the ego and it 270 * NULL if the user just deleted the ego and it
271 * must thus no longer be used 271 * must thus no longer be used
272*/ 272 */
273static void 273static void
274print_ego (void *cls, 274print_ego(void *cls,
275 struct GNUNET_IDENTITY_Ego *ego, 275 struct GNUNET_IDENTITY_Ego *ego,
276 void **ctx, 276 void **ctx,
277 const char *identifier) 277 const char *identifier)
278{ 278{
279 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 279 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
280 char *s; 280 char *s;
281 char *privs; 281 char *privs;
282 282
283 if ((NULL != set_ego) && (NULL != set_subsystem) && (NULL != ego) && 283 if ((NULL != set_ego) && (NULL != set_subsystem) && (NULL != ego) &&
284 (NULL != identifier) && (0 == strcmp (identifier, set_ego))) 284 (NULL != identifier) && (0 == strcmp(identifier, set_ego)))
285 { 285 {
286 set_op = GNUNET_IDENTITY_set (sh, set_subsystem, ego, &set_done, NULL); 286 set_op = GNUNET_IDENTITY_set(sh, set_subsystem, ego, &set_done, NULL);
287 GNUNET_free (set_subsystem); 287 GNUNET_free(set_subsystem);
288 set_subsystem = NULL; 288 set_subsystem = NULL;
289 GNUNET_free (set_ego); 289 GNUNET_free(set_ego);
290 set_ego = NULL; 290 set_ego = NULL;
291 } 291 }
292 if ((NULL == ego) && (NULL != set_ego) && (NULL != set_subsystem)) 292 if ((NULL == ego) && (NULL != set_ego) && (NULL != set_subsystem))
293 { 293 {
294 fprintf (stderr, 294 fprintf(stderr,
295 "Could not set ego to `%s' for subsystem `%s', ego not known\n", 295 "Could not set ego to `%s' for subsystem `%s', ego not known\n",
296 set_ego, 296 set_ego,
297 set_subsystem); 297 set_subsystem);
298 GNUNET_free (set_subsystem); 298 GNUNET_free(set_subsystem);
299 set_subsystem = NULL; 299 set_subsystem = NULL;
300 GNUNET_free (set_ego); 300 GNUNET_free(set_ego);
301 set_ego = NULL; 301 set_ego = NULL;
302 } 302 }
303 if ((NULL == ego) && (! monitor)) 303 if ((NULL == ego) && (!monitor))
304 { 304 {
305 list = 0; 305 list = 0;
306 test_finished (); 306 test_finished();
307 return; 307 return;
308 } 308 }
309 if (! (list | monitor)) 309 if (!(list | monitor))
310 return; 310 return;
311 if ((NULL == ego) || (NULL == identifier)) 311 if ((NULL == ego) || (NULL == identifier))
312 return; 312 return;
313 if ((NULL != set_ego) && (0 != strcmp (identifier, set_ego))) 313 if ((NULL != set_ego) && (0 != strcmp(identifier, set_ego)))
314 return; 314 return;
315 GNUNET_IDENTITY_ego_get_public_key (ego, &pk); 315 GNUNET_IDENTITY_ego_get_public_key(ego, &pk);
316 s = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); 316 s = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk);
317 privs = GNUNET_CRYPTO_ecdsa_private_key_to_string ( 317 privs = GNUNET_CRYPTO_ecdsa_private_key_to_string(
318 GNUNET_IDENTITY_ego_get_private_key (ego)); 318 GNUNET_IDENTITY_ego_get_private_key(ego));
319 if ((monitor) || (NULL != identifier)) 319 if ((monitor) || (NULL != identifier))
320 {
321 if (quiet)
322 { 320 {
323 if (private_keys) 321 if (quiet)
324 fprintf (stdout, "%s - %s\n", s, privs); 322 {
323 if (private_keys)
324 fprintf(stdout, "%s - %s\n", s, privs);
325 else
326 fprintf(stdout, "%s\n", s);
327 }
325 else 328 else
326 fprintf (stdout, "%s\n", s); 329 {
330 if (private_keys)
331 fprintf(stdout, "%s - %s - %s\n", identifier, s, privs);
332 else
333 fprintf(stdout, "%s - %s\n", identifier, s);
334 }
327 } 335 }
328 else 336 GNUNET_free(privs);
329 { 337 GNUNET_free(s);
330 if (private_keys)
331 fprintf (stdout, "%s - %s - %s\n", identifier, s, privs);
332 else
333 fprintf (stdout, "%s - %s\n", identifier, s);
334 }
335 }
336 GNUNET_free (privs);
337 GNUNET_free (s);
338} 338}
339 339
340 340
@@ -347,30 +347,30 @@ print_ego (void *cls,
347 * @param cfg configuration 347 * @param cfg configuration
348 */ 348 */
349static void 349static void
350run (void *cls, 350run(void *cls,
351 char *const *args, 351 char *const *args,
352 const char *cfgfile, 352 const char *cfgfile,
353 const struct GNUNET_CONFIGURATION_Handle *cfg) 353 const struct GNUNET_CONFIGURATION_Handle *cfg)
354{ 354{
355 if ((NULL != set_subsystem) && (NULL == set_ego)) 355 if ((NULL != set_subsystem) && (NULL == set_ego))
356 { 356 {
357 fprintf (stderr, "Option -s requires option -e to be specified as well.\n"); 357 fprintf(stderr, "Option -s requires option -e to be specified as well.\n");
358 return; 358 return;
359 } 359 }
360 sh = GNUNET_IDENTITY_connect (cfg, 360 sh = GNUNET_IDENTITY_connect(cfg,
361 (monitor | list) || (NULL != set_ego) || 361 (monitor | list) || (NULL != set_ego) ||
362 (NULL != set_subsystem) 362 (NULL != set_subsystem)
363 ? &print_ego 363 ? &print_ego
364 : NULL, 364 : NULL,
365 NULL); 365 NULL);
366 if (NULL != delete_ego) 366 if (NULL != delete_ego)
367 delete_op = 367 delete_op =
368 GNUNET_IDENTITY_delete (sh, delete_ego, &delete_finished, &delete_op); 368 GNUNET_IDENTITY_delete(sh, delete_ego, &delete_finished, &delete_op);
369 if (NULL != create_ego) 369 if (NULL != create_ego)
370 create_op = 370 create_op =
371 GNUNET_IDENTITY_create (sh, create_ego, &create_finished, &create_op); 371 GNUNET_IDENTITY_create(sh, create_ego, &create_finished, &create_op);
372 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 372 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
373 test_finished (); 373 test_finished();
374} 374}
375 375
376 376
@@ -382,64 +382,64 @@ run (void *cls,
382 * @return 0 ok, 1 on error 382 * @return 0 ok, 1 on error
383 */ 383 */
384int 384int
385main (int argc, char *const *argv) 385main(int argc, char *const *argv)
386{ 386{
387 struct GNUNET_GETOPT_CommandLineOption options[] = 387 struct GNUNET_GETOPT_CommandLineOption options[] =
388 {GNUNET_GETOPT_option_string ('C', 388 { GNUNET_GETOPT_option_string('C',
389 "create", 389 "create",
390 "NAME", 390 "NAME",
391 gettext_noop ("create ego NAME"), 391 gettext_noop("create ego NAME"),
392 &create_ego), 392 &create_ego),
393 GNUNET_GETOPT_option_string ('D', 393 GNUNET_GETOPT_option_string('D',
394 "delete", 394 "delete",
395 "NAME", 395 "NAME",
396 gettext_noop ("delete ego NAME "), 396 gettext_noop("delete ego NAME "),
397 &delete_ego), 397 &delete_ego),
398 GNUNET_GETOPT_option_flag ('d', 398 GNUNET_GETOPT_option_flag('d',
399 "display", 399 "display",
400 gettext_noop ("display all egos"), 400 gettext_noop("display all egos"),
401 &list), 401 &list),
402 GNUNET_GETOPT_option_flag ('q', 402 GNUNET_GETOPT_option_flag('q',
403 "quiet", 403 "quiet",
404 gettext_noop ("reduce output"), 404 gettext_noop("reduce output"),
405 &quiet), 405 &quiet),
406 GNUNET_GETOPT_option_string ( 406 GNUNET_GETOPT_option_string(
407 'e', 407 'e',
408 "ego", 408 "ego",
409 "NAME", 409 "NAME",
410 gettext_noop ( 410 gettext_noop(
411 "set default identity to NAME for a subsystem SUBSYSTEM (use together with -s) or restrict results to NAME (use together with -d)"), 411 "set default identity to NAME for a subsystem SUBSYSTEM (use together with -s) or restrict results to NAME (use together with -d)"),
412 &set_ego), 412 &set_ego),
413 GNUNET_GETOPT_option_flag ('m', 413 GNUNET_GETOPT_option_flag('m',
414 "monitor", 414 "monitor",
415 gettext_noop ("run in monitor mode egos"), 415 gettext_noop("run in monitor mode egos"),
416 &monitor), 416 &monitor),
417 GNUNET_GETOPT_option_flag ('p', 417 GNUNET_GETOPT_option_flag('p',
418 "private-keys", 418 "private-keys",
419 gettext_noop ("display private keys as well"), 419 gettext_noop("display private keys as well"),
420 &private_keys), 420 &private_keys),
421 GNUNET_GETOPT_option_string ( 421 GNUNET_GETOPT_option_string(
422 's', 422 's',
423 "set", 423 "set",
424 "SUBSYSTEM", 424 "SUBSYSTEM",
425 gettext_noop ( 425 gettext_noop(
426 "set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"), 426 "set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"),
427 &set_subsystem), 427 &set_subsystem),
428 GNUNET_GETOPT_option_verbose (&verbose), 428 GNUNET_GETOPT_option_verbose(&verbose),
429 GNUNET_GETOPT_OPTION_END}; 429 GNUNET_GETOPT_OPTION_END };
430 int res; 430 int res;
431 431
432 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 432 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
433 return 4; 433 return 4;
434 global_ret = TIMEOUT_STATUS_CODE; /* timeout */ 434 global_ret = TIMEOUT_STATUS_CODE; /* timeout */
435 res = GNUNET_PROGRAM_run (argc, 435 res = GNUNET_PROGRAM_run(argc,
436 argv, 436 argv,
437 "gnunet-identity", 437 "gnunet-identity",
438 gettext_noop ("Maintain egos"), 438 gettext_noop("Maintain egos"),
439 options, 439 options,
440 &run, 440 &run,
441 NULL); 441 NULL);
442 GNUNET_free ((void *) argv); 442 GNUNET_free((void *)argv);
443 443
444 if (GNUNET_OK != res) 444 if (GNUNET_OK != res)
445 return 3; 445 return 3;