diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-07-09 07:35:46 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-07-09 07:35:46 +0000 |
commit | 4f95fb582c633d5d1b89bd6982efbfc540524314 (patch) | |
tree | 4e3e3fcd61781b68d8a545dcd141bee6e8ac9f6d /src/nse | |
parent | a83e4dee60810a6e78657a5537a3d4a747dc9445 (diff) | |
download | gnunet-4f95fb582c633d5d1b89bd6982efbfc540524314.tar.gz gnunet-4f95fb582c633d5d1b89bd6982efbfc540524314.zip |
-simplify zone key loading by using synchronous ECC key API
Diffstat (limited to 'src/nse')
-rw-r--r-- | src/nse/gnunet-service-nse.c | 145 |
1 files changed, 57 insertions, 88 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index a693dcf0f..b93f7bb14 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -306,11 +306,6 @@ static uint64_t my_proof; | |||
306 | */ | 306 | */ |
307 | static struct GNUNET_SERVER_Handle *srv; | 307 | static struct GNUNET_SERVER_Handle *srv; |
308 | 308 | ||
309 | /** | ||
310 | * Hostkey generation context | ||
311 | */ | ||
312 | static struct GNUNET_CRYPTO_EccKeyGenerationContext *keygen; | ||
313 | |||
314 | 309 | ||
315 | /** | 310 | /** |
316 | * Initialize a message to clients with the current network | 311 | * Initialize a message to clients with the current network |
@@ -1303,11 +1298,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1303 | proof_task = GNUNET_SCHEDULER_NO_TASK; | 1298 | proof_task = GNUNET_SCHEDULER_NO_TASK; |
1304 | write_proof (); /* remember progress */ | 1299 | write_proof (); /* remember progress */ |
1305 | } | 1300 | } |
1306 | if (NULL != keygen) | ||
1307 | { | ||
1308 | GNUNET_CRYPTO_ecc_key_create_stop (keygen); | ||
1309 | keygen = NULL; | ||
1310 | } | ||
1311 | if (NULL != nc) | 1301 | if (NULL != nc) |
1312 | { | 1302 | { |
1313 | GNUNET_SERVER_notification_context_destroy (nc); | 1303 | GNUNET_SERVER_notification_context_destroy (nc); |
@@ -1389,16 +1379,16 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, | |||
1389 | 1379 | ||
1390 | 1380 | ||
1391 | /** | 1381 | /** |
1392 | * Callback for hostkey read/generation | 1382 | * Handle network size estimate clients. |
1393 | * | 1383 | * |
1394 | * @param cls NULL | 1384 | * @param cls closure |
1395 | * @param pk the private key | 1385 | * @param server the initialized server |
1396 | * @param emsg error message | 1386 | * @param c configuration to use |
1397 | */ | 1387 | */ |
1398 | static void | 1388 | static void |
1399 | key_generation_cb (void *cls, | 1389 | run (void *cls, |
1400 | struct GNUNET_CRYPTO_EccPrivateKey *pk, | 1390 | struct GNUNET_SERVER_Handle *server, |
1401 | const char *emsg) | 1391 | const struct GNUNET_CONFIGURATION_Handle *c) |
1402 | { | 1392 | { |
1403 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 1393 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
1404 | {&handle_start_message, NULL, GNUNET_MESSAGE_TYPE_NSE_START, | 1394 | {&handle_start_message, NULL, GNUNET_MESSAGE_TYPE_NSE_START, |
@@ -1411,77 +1401,8 @@ key_generation_cb (void *cls, | |||
1411 | {NULL, 0, 0} | 1401 | {NULL, 0, 0} |
1412 | }; | 1402 | }; |
1413 | char *proof; | 1403 | char *proof; |
1414 | |||
1415 | keygen = NULL; | ||
1416 | if (NULL == pk) | ||
1417 | { | ||
1418 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1419 | _("Could not access hostkey: %s. Exiting.\n"), | ||
1420 | emsg); | ||
1421 | GNUNET_SCHEDULER_shutdown (); | ||
1422 | return; | ||
1423 | } | ||
1424 | my_private_key = pk; | ||
1425 | GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key); | ||
1426 | GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), | ||
1427 | &my_identity.hashPubKey); | ||
1428 | if (GNUNET_OK != | ||
1429 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) | ||
1430 | { | ||
1431 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1432 | _ | ||
1433 | ("NSE service is lacking key configuration settings. Exiting.\n")); | ||
1434 | GNUNET_CRYPTO_ecc_key_free (my_private_key); | ||
1435 | my_private_key = NULL; | ||
1436 | GNUNET_SCHEDULER_shutdown (); | ||
1437 | return; | ||
1438 | } | ||
1439 | if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) || | ||
1440 | (sizeof (my_proof) != | ||
1441 | GNUNET_DISK_fn_read (proof, &my_proof, sizeof (my_proof)))) | ||
1442 | my_proof = 0; | ||
1443 | GNUNET_free (proof); | ||
1444 | proof_task = | ||
1445 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | ||
1446 | &find_proof, NULL); | ||
1447 | |||
1448 | peers = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); | ||
1449 | GNUNET_SERVER_add_handlers (srv, handlers); | ||
1450 | nc = GNUNET_SERVER_notification_context_create (srv, 1); | ||
1451 | /* Connect to core service and register core handlers */ | ||
1452 | coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */ | ||
1453 | NULL, /* Closure passed to functions */ | ||
1454 | &core_init, /* Call core_init once connected */ | ||
1455 | &handle_core_connect, /* Handle connects */ | ||
1456 | &handle_core_disconnect, /* Handle disconnects */ | ||
1457 | NULL, /* Don't want notified about all incoming messages */ | ||
1458 | GNUNET_NO, /* For header only inbound notification */ | ||
1459 | NULL, /* Don't want notified about all outbound messages */ | ||
1460 | GNUNET_NO, /* For header only outbound notification */ | ||
1461 | core_handlers); /* Register these handlers */ | ||
1462 | if (NULL == coreAPI) | ||
1463 | { | ||
1464 | GNUNET_SCHEDULER_shutdown (); | ||
1465 | return; | ||
1466 | } | ||
1467 | stats = GNUNET_STATISTICS_create ("nse", cfg); | ||
1468 | GNUNET_SERVER_resume (srv); | ||
1469 | } | ||
1470 | |||
1471 | |||
1472 | /** | ||
1473 | * Handle network size estimate clients. | ||
1474 | * | ||
1475 | * @param cls closure | ||
1476 | * @param server the initialized server | ||
1477 | * @param c configuration to use | ||
1478 | */ | ||
1479 | static void | ||
1480 | run (void *cls, | ||
1481 | struct GNUNET_SERVER_Handle *server, | ||
1482 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
1483 | { | ||
1484 | char *keyfile; | 1404 | char *keyfile; |
1405 | struct GNUNET_CRYPTO_EccPrivateKey *pk; | ||
1485 | 1406 | ||
1486 | cfg = c; | 1407 | cfg = c; |
1487 | srv = server; | 1408 | srv = server; |
@@ -1533,8 +1454,56 @@ run (void *cls, | |||
1533 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | 1454 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
1534 | NULL); | 1455 | NULL); |
1535 | GNUNET_SERVER_suspend (srv); | 1456 | GNUNET_SERVER_suspend (srv); |
1536 | keygen = GNUNET_CRYPTO_ecc_key_create_start (keyfile, &key_generation_cb, NULL); | 1457 | |
1458 | |||
1459 | pk = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile); | ||
1537 | GNUNET_free (keyfile); | 1460 | GNUNET_free (keyfile); |
1461 | GNUNET_assert (NULL != pk); | ||
1462 | my_private_key = pk; | ||
1463 | GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key); | ||
1464 | GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), | ||
1465 | &my_identity.hashPubKey); | ||
1466 | if (GNUNET_OK != | ||
1467 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) | ||
1468 | { | ||
1469 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1470 | _ | ||
1471 | ("NSE service is lacking key configuration settings. Exiting.\n")); | ||
1472 | GNUNET_CRYPTO_ecc_key_free (my_private_key); | ||
1473 | my_private_key = NULL; | ||
1474 | GNUNET_SCHEDULER_shutdown (); | ||
1475 | return; | ||
1476 | } | ||
1477 | if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) || | ||
1478 | (sizeof (my_proof) != | ||
1479 | GNUNET_DISK_fn_read (proof, &my_proof, sizeof (my_proof)))) | ||
1480 | my_proof = 0; | ||
1481 | GNUNET_free (proof); | ||
1482 | proof_task = | ||
1483 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | ||
1484 | &find_proof, NULL); | ||
1485 | |||
1486 | peers = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); | ||
1487 | GNUNET_SERVER_add_handlers (srv, handlers); | ||
1488 | nc = GNUNET_SERVER_notification_context_create (srv, 1); | ||
1489 | /* Connect to core service and register core handlers */ | ||
1490 | coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */ | ||
1491 | NULL, /* Closure passed to functions */ | ||
1492 | &core_init, /* Call core_init once connected */ | ||
1493 | &handle_core_connect, /* Handle connects */ | ||
1494 | &handle_core_disconnect, /* Handle disconnects */ | ||
1495 | NULL, /* Don't want notified about all incoming messages */ | ||
1496 | GNUNET_NO, /* For header only inbound notification */ | ||
1497 | NULL, /* Don't want notified about all outbound messages */ | ||
1498 | GNUNET_NO, /* For header only outbound notification */ | ||
1499 | core_handlers); /* Register these handlers */ | ||
1500 | if (NULL == coreAPI) | ||
1501 | { | ||
1502 | GNUNET_SCHEDULER_shutdown (); | ||
1503 | return; | ||
1504 | } | ||
1505 | stats = GNUNET_STATISTICS_create ("nse", cfg); | ||
1506 | GNUNET_SERVER_resume (srv); | ||
1538 | } | 1507 | } |
1539 | 1508 | ||
1540 | 1509 | ||