diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-07-19 12:22:55 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-07-19 12:22:55 +0000 |
commit | 7917851e22a2e09ad5e32138d67fc68f10ef68ca (patch) | |
tree | e6b0cd74bb1a5f9615c4693715855c66fb24d556 /src/transport/gnunet-service-transport.c | |
parent | 2d980e4c1be3e4f5e0d8d116b34b2a4cb0819e00 (diff) | |
download | gnunet-7917851e22a2e09ad5e32138d67fc68f10ef68ca.tar.gz gnunet-7917851e22a2e09ad5e32138d67fc68f10ef68ca.zip |
- issues with multiple services accessing one hostkey
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 125 |
1 files changed, 30 insertions, 95 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index c0c721fbf..9b9b0fdb3 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -61,19 +61,6 @@ struct GNUNET_PeerIdentity GST_my_identity; | |||
61 | */ | 61 | */ |
62 | struct GNUNET_PEERINFO_Handle *GST_peerinfo; | 62 | struct GNUNET_PEERINFO_Handle *GST_peerinfo; |
63 | 63 | ||
64 | |||
65 | /** | ||
66 | * Hostkey generation context | ||
67 | */ | ||
68 | struct GNUNET_CRYPTO_RsaKeyGenerationContext *GST_keygen; | ||
69 | |||
70 | /** | ||
71 | * Closure for hostkey generation | ||
72 | */ | ||
73 | |||
74 | struct KeyGenerationContext *GST_keygen_cls; | ||
75 | |||
76 | |||
77 | /** | 64 | /** |
78 | * Our public key. | 65 | * Our public key. |
79 | */ | 66 | */ |
@@ -95,13 +82,6 @@ struct GNUNET_ATS_SchedulingHandle *GST_ats; | |||
95 | static int connections; | 82 | static int connections; |
96 | 83 | ||
97 | 84 | ||
98 | struct KeyGenerationContext | ||
99 | { | ||
100 | struct GNUNET_SERVER_Handle *server; | ||
101 | const struct GNUNET_CONFIGURATION_Handle *c; | ||
102 | }; | ||
103 | |||
104 | |||
105 | /** | 85 | /** |
106 | * Transmit our HELLO message to the given (connected) neighbour. | 86 | * Transmit our HELLO message to the given (connected) neighbour. |
107 | * | 87 | * |
@@ -291,7 +271,7 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
291 | break; | 271 | break; |
292 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: | 272 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: |
293 | GST_neighbours_handle_session_ack (message, peer, &address, session, ats, | 273 | GST_neighbours_handle_session_ack (message, peer, &address, session, ats, |
294 | ats_count); | 274 | ats_count); |
295 | break; | 275 | break; |
296 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: | 276 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: |
297 | GST_neighbours_handle_disconnect_message (peer, message); | 277 | GST_neighbours_handle_disconnect_message (peer, message); |
@@ -558,18 +538,6 @@ neighbours_address_notification (void *cls, | |||
558 | static void | 538 | static void |
559 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 539 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
560 | { | 540 | { |
561 | if (NULL != GST_keygen) | ||
562 | { | ||
563 | GNUNET_CRYPTO_rsa_key_create_stop (GST_keygen); | ||
564 | GST_keygen = NULL; | ||
565 | } | ||
566 | |||
567 | if (NULL != GST_keygen_cls) | ||
568 | { | ||
569 | GNUNET_free (GST_keygen_cls); | ||
570 | GST_keygen_cls = NULL; | ||
571 | } | ||
572 | |||
573 | GST_neighbours_stop (); | 541 | GST_neighbours_stop (); |
574 | GST_validation_stop (); | 542 | GST_validation_stop (); |
575 | GST_plugins_unload (); | 543 | GST_plugins_unload (); |
@@ -597,34 +565,43 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
597 | } | 565 | } |
598 | } | 566 | } |
599 | 567 | ||
568 | |||
600 | /** | 569 | /** |
601 | * Callback for hostkey read/generation | 570 | * Initiate transport service. |
602 | * @param cls NULL | 571 | * |
603 | * @param pk the privatekey | 572 | * @param cls closure |
604 | * @param emsg error message | 573 | * @param server the initialized server |
574 | * @param c configuration to use | ||
605 | */ | 575 | */ |
606 | static void | 576 | static void |
607 | key_generation_cb (void *cls, | 577 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
608 | struct GNUNET_CRYPTO_RsaPrivateKey *pk, | 578 | const struct GNUNET_CONFIGURATION_Handle *c) |
609 | const char *emsg) | ||
610 | { | 579 | { |
580 | char *keyfile; | ||
611 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded tmp; | 581 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded tmp; |
612 | GNUNET_assert (NULL != GST_keygen_cls); | 582 | /* setup globals */ |
613 | GST_keygen = NULL; | 583 | GST_cfg = c; |
614 | if (NULL == pk) | 584 | if (GNUNET_OK != |
585 | GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY", | ||
586 | &keyfile)) | ||
615 | { | 587 | { |
616 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 588 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
617 | _("Transport service could not access hostkey: %s. Exiting.\n"), | 589 | _ |
618 | emsg); | 590 | ("Transport service is lacking key configuration settings. Exiting.\n")); |
619 | GNUNET_free (GST_keygen_cls); | ||
620 | GST_keygen_cls = NULL; | ||
621 | GNUNET_SCHEDULER_shutdown (); | 591 | GNUNET_SCHEDULER_shutdown (); |
622 | return; | 592 | return; |
623 | } | 593 | } |
624 | GST_my_private_key = pk; | 594 | GST_my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); |
625 | 595 | GNUNET_free (keyfile); | |
626 | GST_stats = GNUNET_STATISTICS_create ("transport", GST_keygen_cls->c); | 596 | if (GST_my_private_key == NULL) |
627 | GST_peerinfo = GNUNET_PEERINFO_connect (GST_keygen_cls->c); | 597 | { |
598 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
599 | _("Transport service could not access hostkey. Exiting.\n")); | ||
600 | GNUNET_SCHEDULER_shutdown (); | ||
601 | return; | ||
602 | } | ||
603 | GST_stats = GNUNET_STATISTICS_create ("transport", c); | ||
604 | GST_peerinfo = GNUNET_PEERINFO_connect (c); | ||
628 | memset (&GST_my_public_key, '\0', sizeof (GST_my_public_key)); | 605 | memset (&GST_my_public_key, '\0', sizeof (GST_my_public_key)); |
629 | memset (&tmp, '\0', sizeof (tmp)); | 606 | memset (&tmp, '\0', sizeof (tmp)); |
630 | GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key); | 607 | GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key); |
@@ -647,7 +624,7 @@ key_generation_cb (void *cls, | |||
647 | /* start subsystems */ | 624 | /* start subsystems */ |
648 | GST_hello_start (&process_hello_update, NULL); | 625 | GST_hello_start (&process_hello_update, NULL); |
649 | GNUNET_assert (NULL != GST_hello_get()); | 626 | GNUNET_assert (NULL != GST_hello_get()); |
650 | GST_blacklist_start (GST_keygen_cls->server); | 627 | GST_blacklist_start (server); |
651 | GST_ats = | 628 | GST_ats = |
652 | GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); | 629 | GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); |
653 | GST_plugins_load (&plugin_env_receive_callback, | 630 | GST_plugins_load (&plugin_env_receive_callback, |
@@ -658,50 +635,8 @@ key_generation_cb (void *cls, | |||
658 | &neighbours_connect_notification, | 635 | &neighbours_connect_notification, |
659 | &neighbours_disconnect_notification, | 636 | &neighbours_disconnect_notification, |
660 | &neighbours_address_notification); | 637 | &neighbours_address_notification); |
661 | GST_clients_start (GST_keygen_cls->server); | 638 | GST_clients_start (server); |
662 | GST_validation_start (); | 639 | GST_validation_start (); |
663 | GNUNET_free (GST_keygen_cls); | ||
664 | GST_keygen_cls = NULL; | ||
665 | } | ||
666 | |||
667 | |||
668 | /** | ||
669 | * Initiate transport service. | ||
670 | * | ||
671 | * @param cls closure | ||
672 | * @param server the initialized server | ||
673 | * @param c configuration to use | ||
674 | */ | ||
675 | static void | ||
676 | run (void *cls, struct GNUNET_SERVER_Handle *server, | ||
677 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
678 | { | ||
679 | char *keyfile; | ||
680 | |||
681 | /* setup globals */ | ||
682 | GST_cfg = c; | ||
683 | if (GNUNET_OK != | ||
684 | GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY", | ||
685 | &keyfile)) | ||
686 | { | ||
687 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
688 | _ | ||
689 | ("Transport service is lacking key configuration settings. Exiting.\n")); | ||
690 | GNUNET_SCHEDULER_shutdown (); | ||
691 | return; | ||
692 | } | ||
693 | GST_keygen_cls = GNUNET_malloc (sizeof (struct KeyGenerationContext)); | ||
694 | GST_keygen_cls->c = c; | ||
695 | GST_keygen_cls->server = server; | ||
696 | |||
697 | GST_keygen = GNUNET_CRYPTO_rsa_key_create_start (keyfile, key_generation_cb, GST_keygen_cls); | ||
698 | GNUNET_free (keyfile); | ||
699 | if (NULL == GST_keygen) | ||
700 | { | ||
701 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
702 | _("Transport service is unable to access hostkey. Exiting.\n")); | ||
703 | GNUNET_SCHEDULER_shutdown (); | ||
704 | } | ||
705 | } | 640 | } |
706 | 641 | ||
707 | 642 | ||