From: Matthias Wachs Date: Thu, 19 Jul 2012 12:22:55 +0000 (+0000) Subject: - issues with multiple services accessing one hostkey X-Git-Tag: initial-import-from-subversion-38251~12414 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7917851e22a2e09ad5e32138d67fc68f10ef68ca;p=oweals%2Fgnunet.git - issues with multiple services accessing one hostkey --- 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; */ struct GNUNET_PEERINFO_Handle *GST_peerinfo; - -/** - * Hostkey generation context - */ -struct GNUNET_CRYPTO_RsaKeyGenerationContext *GST_keygen; - -/** - * Closure for hostkey generation - */ - -struct KeyGenerationContext *GST_keygen_cls; - - /** * Our public key. */ @@ -95,13 +82,6 @@ struct GNUNET_ATS_SchedulingHandle *GST_ats; static int connections; -struct KeyGenerationContext -{ - struct GNUNET_SERVER_Handle *server; - const struct GNUNET_CONFIGURATION_Handle *c; -}; - - /** * Transmit our HELLO message to the given (connected) neighbour. * @@ -291,7 +271,7 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: GST_neighbours_handle_session_ack (message, peer, &address, session, ats, - ats_count); + ats_count); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: GST_neighbours_handle_disconnect_message (peer, message); @@ -558,18 +538,6 @@ neighbours_address_notification (void *cls, static void shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - if (NULL != GST_keygen) - { - GNUNET_CRYPTO_rsa_key_create_stop (GST_keygen); - GST_keygen = NULL; - } - - if (NULL != GST_keygen_cls) - { - GNUNET_free (GST_keygen_cls); - GST_keygen_cls = NULL; - } - GST_neighbours_stop (); GST_validation_stop (); GST_plugins_unload (); @@ -597,34 +565,43 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } } + /** - * Callback for hostkey read/generation - * @param cls NULL - * @param pk the privatekey - * @param emsg error message + * Initiate transport service. + * + * @param cls closure + * @param server the initialized server + * @param c configuration to use */ static void -key_generation_cb (void *cls, - struct GNUNET_CRYPTO_RsaPrivateKey *pk, - const char *emsg) +run (void *cls, struct GNUNET_SERVER_Handle *server, + const struct GNUNET_CONFIGURATION_Handle *c) { + char *keyfile; struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded tmp; - GNUNET_assert (NULL != GST_keygen_cls); - GST_keygen = NULL; - if (NULL == pk) + /* setup globals */ + GST_cfg = c; + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY", + &keyfile)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Transport service could not access hostkey: %s. Exiting.\n"), - emsg); - GNUNET_free (GST_keygen_cls); - GST_keygen_cls = NULL; + _ + ("Transport service is lacking key configuration settings. Exiting.\n")); GNUNET_SCHEDULER_shutdown (); return; } - GST_my_private_key = pk; - - GST_stats = GNUNET_STATISTICS_create ("transport", GST_keygen_cls->c); - GST_peerinfo = GNUNET_PEERINFO_connect (GST_keygen_cls->c); + GST_my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); + GNUNET_free (keyfile); + if (GST_my_private_key == NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Transport service could not access hostkey. Exiting.\n")); + GNUNET_SCHEDULER_shutdown (); + return; + } + GST_stats = GNUNET_STATISTICS_create ("transport", c); + GST_peerinfo = GNUNET_PEERINFO_connect (c); memset (&GST_my_public_key, '\0', sizeof (GST_my_public_key)); memset (&tmp, '\0', sizeof (tmp)); GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key); @@ -647,7 +624,7 @@ key_generation_cb (void *cls, /* start subsystems */ GST_hello_start (&process_hello_update, NULL); GNUNET_assert (NULL != GST_hello_get()); - GST_blacklist_start (GST_keygen_cls->server); + GST_blacklist_start (server); GST_ats = GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); GST_plugins_load (&plugin_env_receive_callback, @@ -658,50 +635,8 @@ key_generation_cb (void *cls, &neighbours_connect_notification, &neighbours_disconnect_notification, &neighbours_address_notification); - GST_clients_start (GST_keygen_cls->server); + GST_clients_start (server); GST_validation_start (); - GNUNET_free (GST_keygen_cls); - GST_keygen_cls = NULL; -} - - -/** - * Initiate transport service. - * - * @param cls closure - * @param server the initialized server - * @param c configuration to use - */ -static void -run (void *cls, struct GNUNET_SERVER_Handle *server, - const struct GNUNET_CONFIGURATION_Handle *c) -{ - char *keyfile; - - /* setup globals */ - GST_cfg = c; - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY", - &keyfile)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ - ("Transport service is lacking key configuration settings. Exiting.\n")); - GNUNET_SCHEDULER_shutdown (); - return; - } - GST_keygen_cls = GNUNET_malloc (sizeof (struct KeyGenerationContext)); - GST_keygen_cls->c = c; - GST_keygen_cls->server = server; - - GST_keygen = GNUNET_CRYPTO_rsa_key_create_start (keyfile, key_generation_cb, GST_keygen_cls); - GNUNET_free (keyfile); - if (NULL == GST_keygen) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Transport service is unable to access hostkey. Exiting.\n")); - GNUNET_SCHEDULER_shutdown (); - } }