diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-07-16 12:36:52 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-07-16 12:36:52 +0000 |
commit | ca2e9417277e02ea70628a0f85ab71ae19ee82d8 (patch) | |
tree | cbcf02971b1c2b45848302d808cb557dc5adfc28 /src/transport/gnunet-service-transport.c | |
parent | 05236b7db170d3f10bb513f1535df0d1ff22e2b3 (diff) | |
download | gnunet-ca2e9417277e02ea70628a0f85ab71ae19ee82d8.tar.gz gnunet-ca2e9417277e02ea70628a0f85ab71ae19ee82d8.zip |
- new rsa api
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 106 |
1 files changed, 75 insertions, 31 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index ee08a7a1d..bb6a54b31 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -61,6 +61,12 @@ 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 | |||
64 | /** | 70 | /** |
65 | * Our public key. | 71 | * Our public key. |
66 | */ | 72 | */ |
@@ -538,6 +544,12 @@ neighbours_address_notification (void *cls, | |||
538 | static void | 544 | static void |
539 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 545 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
540 | { | 546 | { |
547 | if (NULL != GST_keygen) | ||
548 | { | ||
549 | GNUNET_CRYPTO_rsa_key_create_stop (GST_keygen); | ||
550 | GST_keygen = NULL; | ||
551 | } | ||
552 | |||
541 | GST_neighbours_stop (); | 553 | GST_neighbours_stop (); |
542 | GST_validation_stop (); | 554 | GST_validation_stop (); |
543 | GST_plugins_unload (); | 555 | GST_plugins_unload (); |
@@ -565,43 +577,34 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
565 | } | 577 | } |
566 | } | 578 | } |
567 | 579 | ||
580 | struct KeyGenerationContext | ||
581 | { | ||
582 | struct GNUNET_SERVER_Handle *server; | ||
583 | const struct GNUNET_CONFIGURATION_Handle *c; | ||
568 | 584 | ||
569 | /** | 585 | }; |
570 | * Initiate transport service. | 586 | |
571 | * | 587 | static void key_generation_cb (void *cls, |
572 | * @param cls closure | 588 | struct GNUNET_CRYPTO_RsaPrivateKey *pk, |
573 | * @param server the initialized server | 589 | const char *emsg) |
574 | * @param c configuration to use | ||
575 | */ | ||
576 | static void | ||
577 | run (void *cls, struct GNUNET_SERVER_Handle *server, | ||
578 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
579 | { | 590 | { |
580 | char *keyfile; | 591 | struct KeyGenerationContext *scx = cls; |
581 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded tmp; | 592 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded tmp; |
582 | /* setup globals */ | 593 | |
583 | GST_cfg = c; | 594 | GST_keygen = NULL; |
584 | if (GNUNET_OK != | 595 | if (NULL == pk) |
585 | GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY", | ||
586 | &keyfile)) | ||
587 | { | ||
588 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
589 | _ | ||
590 | ("Transport service is lacking key configuration settings. Exiting.\n")); | ||
591 | GNUNET_SCHEDULER_shutdown (); | ||
592 | return; | ||
593 | } | ||
594 | GST_my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | ||
595 | GNUNET_free (keyfile); | ||
596 | if (GST_my_private_key == NULL) | ||
597 | { | 596 | { |
598 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 597 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
599 | _("Transport service could not access hostkey. Exiting.\n")); | 598 | _("Transport service could not access hostkey: %s. Exiting.\n"), |
599 | emsg); | ||
600 | GNUNET_free (scx); | ||
600 | GNUNET_SCHEDULER_shutdown (); | 601 | GNUNET_SCHEDULER_shutdown (); |
601 | return; | 602 | return; |
602 | } | 603 | } |
603 | GST_stats = GNUNET_STATISTICS_create ("transport", c); | 604 | GST_my_private_key = pk; |
604 | GST_peerinfo = GNUNET_PEERINFO_connect (c); | 605 | |
606 | GST_stats = GNUNET_STATISTICS_create ("transport", scx->c); | ||
607 | GST_peerinfo = GNUNET_PEERINFO_connect (scx->c); | ||
605 | memset (&GST_my_public_key, '\0', sizeof (GST_my_public_key)); | 608 | memset (&GST_my_public_key, '\0', sizeof (GST_my_public_key)); |
606 | memset (&tmp, '\0', sizeof (tmp)); | 609 | memset (&tmp, '\0', sizeof (tmp)); |
607 | GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key); | 610 | GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key); |
@@ -624,7 +627,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
624 | /* start subsystems */ | 627 | /* start subsystems */ |
625 | GST_hello_start (&process_hello_update, NULL); | 628 | GST_hello_start (&process_hello_update, NULL); |
626 | GNUNET_assert (NULL != GST_hello_get()); | 629 | GNUNET_assert (NULL != GST_hello_get()); |
627 | GST_blacklist_start (server); | 630 | GST_blacklist_start (scx->server); |
628 | GST_ats = | 631 | GST_ats = |
629 | GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); | 632 | GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); |
630 | GST_plugins_load (&plugin_env_receive_callback, | 633 | GST_plugins_load (&plugin_env_receive_callback, |
@@ -635,8 +638,49 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
635 | &neighbours_connect_notification, | 638 | &neighbours_connect_notification, |
636 | &neighbours_disconnect_notification, | 639 | &neighbours_disconnect_notification, |
637 | &neighbours_address_notification); | 640 | &neighbours_address_notification); |
638 | GST_clients_start (server); | 641 | GST_clients_start (scx->server); |
639 | GST_validation_start (); | 642 | GST_validation_start (); |
643 | GNUNET_free (scx); | ||
644 | } | ||
645 | |||
646 | |||
647 | /** | ||
648 | * Initiate transport service. | ||
649 | * | ||
650 | * @param cls closure | ||
651 | * @param server the initialized server | ||
652 | * @param c configuration to use | ||
653 | */ | ||
654 | static void | ||
655 | run (void *cls, struct GNUNET_SERVER_Handle *server, | ||
656 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
657 | { | ||
658 | struct KeyGenerationContext *scx; | ||
659 | char *keyfile; | ||
660 | |||
661 | /* setup globals */ | ||
662 | GST_cfg = c; | ||
663 | if (GNUNET_OK != | ||
664 | GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY", | ||
665 | &keyfile)) | ||
666 | { | ||
667 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
668 | _ | ||
669 | ("Transport service is lacking key configuration settings. Exiting.\n")); | ||
670 | GNUNET_SCHEDULER_shutdown (); | ||
671 | return; | ||
672 | } | ||
673 | scx = GNUNET_malloc (sizeof (struct KeyGenerationContext)); | ||
674 | scx->c = c; | ||
675 | scx->server = server; | ||
676 | GST_keygen = GNUNET_CRYPTO_rsa_key_create_start (keyfile, key_generation_cb, scx); | ||
677 | GNUNET_free (keyfile); | ||
678 | if (NULL == GST_keygen) | ||
679 | { | ||
680 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
681 | _("Transport service is unable to access hostkey. Exiting.\n")); | ||
682 | GNUNET_SCHEDULER_shutdown (); | ||
683 | } | ||
640 | } | 684 | } |
641 | 685 | ||
642 | 686 | ||