diff options
Diffstat (limited to 'src/core/gnunet-service-core_kx.c')
-rw-r--r-- | src/core/gnunet-service-core_kx.c | 378 |
1 files changed, 179 insertions, 199 deletions
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c index 7d27378ac..d49e06e2a 100644 --- a/src/core/gnunet-service-core_kx.c +++ b/src/core/gnunet-service-core_kx.c | |||
@@ -112,7 +112,7 @@ struct PongMessage | |||
112 | * first field after header (this is where we start to encrypt!). | 112 | * first field after header (this is where we start to encrypt!). |
113 | */ | 113 | */ |
114 | uint32_t challenge GNUNET_PACKED; | 114 | uint32_t challenge GNUNET_PACKED; |
115 | 115 | ||
116 | /** | 116 | /** |
117 | * Reserved, always 'GNUNET_BANDWIDTH_VALUE_MAX'. | 117 | * Reserved, always 'GNUNET_BANDWIDTH_VALUE_MAX'. |
118 | */ | 118 | */ |
@@ -495,8 +495,8 @@ do_encrypt (struct GSC_KeyExchangeInfo *kx, | |||
495 | "Encrypted %u bytes for `%4s' using key %u, IV %u\n", | 495 | "Encrypted %u bytes for `%4s' using key %u, IV %u\n", |
496 | (unsigned int) size, GNUNET_i2s (&kx->peer), | 496 | (unsigned int) size, GNUNET_i2s (&kx->peer), |
497 | (unsigned int) kx->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv, | 497 | (unsigned int) kx->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv, |
498 | sizeof | 498 | sizeof |
499 | (iv))); | 499 | (iv))); |
500 | #endif | 500 | #endif |
501 | return GNUNET_OK; | 501 | return GNUNET_OK; |
502 | } | 502 | } |
@@ -526,14 +526,14 @@ do_decrypt (struct GSC_KeyExchangeInfo *kx, | |||
526 | GNUNET_break (0); | 526 | GNUNET_break (0); |
527 | return GNUNET_NO; | 527 | return GNUNET_NO; |
528 | } | 528 | } |
529 | if ((kx->status != KX_STATE_KEY_RECEIVED) && | 529 | if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP)) |
530 | (kx->status != KX_STATE_UP)) | ||
531 | { | 530 | { |
532 | GNUNET_break_op (0); | 531 | GNUNET_break_op (0); |
533 | return GNUNET_SYSERR; | 532 | return GNUNET_SYSERR; |
534 | } | 533 | } |
535 | if (size != | 534 | if (size != |
536 | GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &kx->decrypt_key, iv, out)) | 535 | GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &kx->decrypt_key, iv, |
536 | out)) | ||
537 | { | 537 | { |
538 | GNUNET_break (0); | 538 | GNUNET_break (0); |
539 | return GNUNET_SYSERR; | 539 | return GNUNET_SYSERR; |
@@ -545,8 +545,8 @@ do_decrypt (struct GSC_KeyExchangeInfo *kx, | |||
545 | "Decrypted %u bytes from `%4s' using key %u, IV %u\n", | 545 | "Decrypted %u bytes from `%4s' using key %u, IV %u\n", |
546 | (unsigned int) size, GNUNET_i2s (&kx->peer), | 546 | (unsigned int) size, GNUNET_i2s (&kx->peer), |
547 | (unsigned int) kx->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv, | 547 | (unsigned int) kx->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv, |
548 | sizeof | 548 | sizeof |
549 | (*iv))); | 549 | (*iv))); |
550 | #endif | 550 | #endif |
551 | return GNUNET_OK; | 551 | return GNUNET_OK; |
552 | } | 552 | } |
@@ -573,7 +573,8 @@ set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
573 | struct GSC_KeyExchangeInfo *kx = cls; | 573 | struct GSC_KeyExchangeInfo *kx = cls; |
574 | 574 | ||
575 | kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; | 575 | kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; |
576 | kx->set_key_retry_frequency = GNUNET_TIME_relative_multiply (kx->set_key_retry_frequency, 2); | 576 | kx->set_key_retry_frequency = |
577 | GNUNET_TIME_relative_multiply (kx->set_key_retry_frequency, 2); | ||
577 | send_key (kx); | 578 | send_key (kx); |
578 | } | 579 | } |
579 | 580 | ||
@@ -590,8 +591,7 @@ set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
590 | */ | 591 | */ |
591 | static void | 592 | static void |
592 | process_hello (void *cls, const struct GNUNET_PeerIdentity *peer, | 593 | process_hello (void *cls, const struct GNUNET_PeerIdentity *peer, |
593 | const struct GNUNET_HELLO_Message *hello, | 594 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
594 | const char *err_msg) | ||
595 | { | 595 | { |
596 | struct GSC_KeyExchangeInfo *kx = cls; | 596 | struct GSC_KeyExchangeInfo *kx = cls; |
597 | struct SetKeyMessage *skm; | 597 | struct SetKeyMessage *skm; |
@@ -607,19 +607,19 @@ process_hello (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
607 | { | 607 | { |
608 | kx->pitr = NULL; | 608 | kx->pitr = NULL; |
609 | if (kx->public_key != NULL) | 609 | if (kx->public_key != NULL) |
610 | return; /* done here */ | 610 | return; /* done here */ |
611 | #if DEBUG_CORE | 611 | #if DEBUG_CORE |
612 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 612 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
613 | "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n", | 613 | "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n", |
614 | GNUNET_i2s (&kx->peer)); | 614 | GNUNET_i2s (&kx->peer)); |
615 | #endif | 615 | #endif |
616 | GNUNET_STATISTICS_update (GSC_stats, | 616 | GNUNET_STATISTICS_update (GSC_stats, |
617 | gettext_noop | 617 | gettext_noop |
618 | ("# Delayed connecting due to lack of public key"), | 618 | ("# Delayed connecting due to lack of public key"), |
619 | 1, GNUNET_NO); | 619 | 1, GNUNET_NO); |
620 | kx->retry_set_key_task = | 620 | kx->retry_set_key_task = |
621 | GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, | 621 | GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, |
622 | &set_key_retry_task, kx); | 622 | &set_key_retry_task, kx); |
623 | return; | 623 | return; |
624 | } | 624 | } |
625 | if (kx->public_key != NULL) | 625 | if (kx->public_key != NULL) |
@@ -661,22 +661,19 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid) | |||
661 | struct GSC_KeyExchangeInfo *kx; | 661 | struct GSC_KeyExchangeInfo *kx; |
662 | 662 | ||
663 | #if DEBUG_CORE | 663 | #if DEBUG_CORE |
664 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 664 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initiating key exchange with `%s'\n", |
665 | "Initiating key exchange with `%s'\n", | 665 | GNUNET_i2s (pid)); |
666 | GNUNET_i2s (pid)); | ||
667 | #endif | 666 | #endif |
668 | GNUNET_STATISTICS_update (GSC_stats, | 667 | GNUNET_STATISTICS_update (GSC_stats, |
669 | gettext_noop ("# key exchanges initiated"), | 668 | gettext_noop ("# key exchanges initiated"), 1, |
670 | 1, | 669 | GNUNET_NO); |
671 | GNUNET_NO); | ||
672 | kx = GNUNET_malloc (sizeof (struct GSC_KeyExchangeInfo)); | 670 | kx = GNUNET_malloc (sizeof (struct GSC_KeyExchangeInfo)); |
673 | kx->peer = *pid; | 671 | kx->peer = *pid; |
674 | kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY; | 672 | kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY; |
675 | kx->pitr = GNUNET_PEERINFO_iterate (peerinfo, | 673 | kx->pitr = |
676 | pid, | 674 | GNUNET_PEERINFO_iterate (peerinfo, pid, |
677 | GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */, | 675 | GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ , |
678 | &process_hello, | 676 | &process_hello, kx); |
679 | kx); | ||
680 | return kx; | 677 | return kx; |
681 | } | 678 | } |
682 | 679 | ||
@@ -689,10 +686,8 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid) | |||
689 | void | 686 | void |
690 | GSC_KX_stop (struct GSC_KeyExchangeInfo *kx) | 687 | GSC_KX_stop (struct GSC_KeyExchangeInfo *kx) |
691 | { | 688 | { |
692 | GNUNET_STATISTICS_update (GSC_stats, | 689 | GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# key exchanges stopped"), |
693 | gettext_noop ("# key exchanges stopped"), | 690 | 1, GNUNET_NO); |
694 | 1, | ||
695 | GNUNET_NO); | ||
696 | if (kx->pitr != NULL) | 691 | if (kx->pitr != NULL) |
697 | { | 692 | { |
698 | GNUNET_PEERINFO_iterate_cancel (kx->pitr); | 693 | GNUNET_PEERINFO_iterate_cancel (kx->pitr); |
@@ -726,7 +721,7 @@ GSC_KX_stop (struct GSC_KeyExchangeInfo *kx) | |||
726 | */ | 721 | */ |
727 | void | 722 | void |
728 | GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, | 723 | GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, |
729 | const struct GNUNET_MessageHeader *msg) | 724 | const struct GNUNET_MessageHeader *msg) |
730 | { | 725 | { |
731 | const struct SetKeyMessage *m; | 726 | const struct SetKeyMessage *m; |
732 | struct GNUNET_TIME_Absolute t; | 727 | struct GNUNET_TIME_Absolute t; |
@@ -735,16 +730,16 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, | |||
735 | struct PongMessage *pong; | 730 | struct PongMessage *pong; |
736 | enum KxStateMachine sender_status; | 731 | enum KxStateMachine sender_status; |
737 | uint16_t size; | 732 | uint16_t size; |
738 | 733 | ||
739 | size = ntohs (msg->size); | 734 | size = ntohs (msg->size); |
740 | if (size != sizeof (struct SetKeyMessage)) | 735 | if (size != sizeof (struct SetKeyMessage)) |
741 | { | 736 | { |
742 | GNUNET_break_op (0); | 737 | GNUNET_break_op (0); |
743 | return; | 738 | return; |
744 | } | 739 | } |
745 | m = (const struct SetKeyMessage*) msg; | 740 | m = (const struct SetKeyMessage *) msg; |
746 | GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# session keys received"), | 741 | GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# session keys received"), |
747 | 1, GNUNET_NO); | 742 | 1, GNUNET_NO); |
748 | 743 | ||
749 | #if DEBUG_CORE | 744 | #if DEBUG_CORE |
750 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 745 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -754,15 +749,16 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, | |||
754 | if (kx->public_key == NULL) | 749 | if (kx->public_key == NULL) |
755 | { | 750 | { |
756 | GNUNET_free_non_null (kx->skm_received); | 751 | GNUNET_free_non_null (kx->skm_received); |
757 | kx->skm_received = (struct SetKeyMessage*) GNUNET_copy_message (msg); | 752 | kx->skm_received = (struct SetKeyMessage *) GNUNET_copy_message (msg); |
758 | return; | 753 | return; |
759 | } | 754 | } |
760 | if (0 != | 755 | if (0 != |
761 | memcmp (&m->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) | 756 | memcmp (&m->target, &GSC_my_identity, |
757 | sizeof (struct GNUNET_PeerIdentity))) | ||
762 | { | 758 | { |
763 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 759 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
764 | _("`%s' is for `%s', not for me. Ignoring.\n"), | 760 | _("`%s' is for `%s', not for me. Ignoring.\n"), "SET_KEY", |
765 | "SET_KEY", GNUNET_i2s (&m->target)); | 761 | GNUNET_i2s (&m->target)); |
766 | return; | 762 | return; |
767 | } | 763 | } |
768 | if ((ntohl (m->purpose.size) != | 764 | if ((ntohl (m->purpose.size) != |
@@ -779,8 +775,7 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, | |||
779 | return; | 775 | return; |
780 | } | 776 | } |
781 | t = GNUNET_TIME_absolute_ntoh (m->creation_time); | 777 | t = GNUNET_TIME_absolute_ntoh (m->creation_time); |
782 | if (((kx->status == KX_STATE_KEY_RECEIVED) || | 778 | if (((kx->status == KX_STATE_KEY_RECEIVED) || (kx->status == KX_STATE_UP)) && |
783 | (kx->status == KX_STATE_UP)) && | ||
784 | (t.abs_value < kx->decrypt_key_created.abs_value)) | 779 | (t.abs_value < kx->decrypt_key_created.abs_value)) |
785 | { | 780 | { |
786 | /* this could rarely happen due to massive re-ordering of | 781 | /* this could rarely happen due to massive re-ordering of |
@@ -803,9 +798,8 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, | |||
803 | gettext_noop ("# SET_KEY messages decrypted"), 1, | 798 | gettext_noop ("# SET_KEY messages decrypted"), 1, |
804 | GNUNET_NO); | 799 | GNUNET_NO); |
805 | #if DEBUG_CORE | 800 | #if DEBUG_CORE |
806 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 801 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received SET_KEY from `%s'\n", |
807 | "Received SET_KEY from `%s'\n", | 802 | GNUNET_i2s (&kx->peer)); |
808 | GNUNET_i2s (&kx->peer)); | ||
809 | #endif | 803 | #endif |
810 | kx->decrypt_key = k; | 804 | kx->decrypt_key = k; |
811 | if (kx->decrypt_key_created.abs_value != t.abs_value) | 805 | if (kx->decrypt_key_created.abs_value != t.abs_value) |
@@ -831,9 +825,9 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, | |||
831 | /* we're not up, so we are already doing 'send_key' */ | 825 | /* we're not up, so we are already doing 'send_key' */ |
832 | break; | 826 | break; |
833 | case KX_STATE_UP: | 827 | case KX_STATE_UP: |
834 | if ( (sender_status == KX_STATE_DOWN) || | 828 | if ((sender_status == KX_STATE_DOWN) || |
835 | (sender_status == KX_STATE_KEY_SENT) ) | 829 | (sender_status == KX_STATE_KEY_SENT)) |
836 | send_key (kx); /* we are up, but other peer is not! */ | 830 | send_key (kx); /* we are up, but other peer is not! */ |
837 | break; | 831 | break; |
838 | default: | 832 | default: |
839 | GNUNET_break (0); | 833 | GNUNET_break (0); |
@@ -865,7 +859,7 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, | |||
865 | */ | 859 | */ |
866 | void | 860 | void |
867 | GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, | 861 | GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, |
868 | const struct GNUNET_MessageHeader *msg) | 862 | const struct GNUNET_MessageHeader *msg) |
869 | { | 863 | { |
870 | const struct PingMessage *m; | 864 | const struct PingMessage *m; |
871 | struct PingMessage t; | 865 | struct PingMessage t; |
@@ -876,22 +870,21 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, | |||
876 | 870 | ||
877 | msize = ntohs (msg->size); | 871 | msize = ntohs (msg->size); |
878 | if (msize != sizeof (struct PingMessage)) | 872 | if (msize != sizeof (struct PingMessage)) |
879 | { | 873 | { |
880 | GNUNET_break_op (0); | 874 | GNUNET_break_op (0); |
881 | return; | 875 | return; |
882 | } | 876 | } |
883 | GNUNET_STATISTICS_update (GSC_stats, | 877 | GNUNET_STATISTICS_update (GSC_stats, |
884 | gettext_noop ("# PING messages received"), | 878 | gettext_noop ("# PING messages received"), 1, |
885 | 1, GNUNET_NO); | 879 | GNUNET_NO); |
886 | if ( (kx->status != KX_STATE_KEY_RECEIVED) && | 880 | if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP)) |
887 | (kx->status != KX_STATE_UP) ) | 881 | { |
888 | { | 882 | /* defer */ |
889 | /* defer */ | 883 | GNUNET_free_non_null (kx->ping_received); |
890 | GNUNET_free_non_null (kx->ping_received); | 884 | kx->ping_received = (struct PingMessage *) GNUNET_copy_message (msg); |
891 | kx->ping_received = (struct PingMessage*) GNUNET_copy_message (msg); | 885 | return; |
892 | return; | 886 | } |
893 | } | 887 | m = (const struct PingMessage *) msg; |
894 | m = (const struct PingMessage*) msg; | ||
895 | #if DEBUG_CORE | 888 | #if DEBUG_CORE |
896 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 889 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
897 | "Core service receives `%s' request from `%4s'.\n", "PING", | 890 | "Core service receives `%s' request from `%4s'.\n", "PING", |
@@ -915,15 +908,15 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, | |||
915 | GNUNET_snprintf (sender, sizeof (sender), "%8s", GNUNET_i2s (&kx->peer)); | 908 | GNUNET_snprintf (sender, sizeof (sender), "%8s", GNUNET_i2s (&kx->peer)); |
916 | GNUNET_snprintf (peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target)); | 909 | GNUNET_snprintf (peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target)); |
917 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 910 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
918 | _("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"), | 911 | _ |
912 | ("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"), | ||
919 | sender, GNUNET_i2s (&GSC_my_identity), peer); | 913 | sender, GNUNET_i2s (&GSC_my_identity), peer); |
920 | GNUNET_break_op (0); | 914 | GNUNET_break_op (0); |
921 | return; | 915 | return; |
922 | } | 916 | } |
923 | #if DEBUG_CORE | 917 | #if DEBUG_CORE |
924 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 918 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PING from `%s'\n", |
925 | "Received PING from `%s'\n", | 919 | GNUNET_i2s (&kx->peer)); |
926 | GNUNET_i2s (&kx->peer)); | ||
927 | #endif | 920 | #endif |
928 | /* construct PONG */ | 921 | /* construct PONG */ |
929 | tx.reserved = GNUNET_BANDWIDTH_VALUE_MAX; | 922 | tx.reserved = GNUNET_BANDWIDTH_VALUE_MAX; |
@@ -937,12 +930,10 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, | |||
937 | do_encrypt (kx, &iv, &tx.challenge, &tp.challenge, | 930 | do_encrypt (kx, &iv, &tx.challenge, &tp.challenge, |
938 | sizeof (struct PongMessage) - ((void *) &tp.challenge - | 931 | sizeof (struct PongMessage) - ((void *) &tp.challenge - |
939 | (void *) &tp)); | 932 | (void *) &tp)); |
940 | GNUNET_STATISTICS_update (GSC_stats, | 933 | GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages created"), |
941 | gettext_noop ("# PONG messages created"), 1, | 934 | 1, GNUNET_NO); |
942 | GNUNET_NO); | 935 | GSC_NEIGHBOURS_transmit (&kx->peer, &tp.header, |
943 | GSC_NEIGHBOURS_transmit (&kx->peer, | 936 | GNUNET_TIME_UNIT_FOREVER_REL /* FIXME: timeout */ ); |
944 | &tp.header, | ||
945 | GNUNET_TIME_UNIT_FOREVER_REL /* FIXME: timeout */); | ||
946 | } | 937 | } |
947 | 938 | ||
948 | 939 | ||
@@ -963,21 +954,22 @@ setup_fresh_setkey (struct GSC_KeyExchangeInfo *kx) | |||
963 | skm->header.size = htons (sizeof (struct SetKeyMessage)); | 954 | skm->header.size = htons (sizeof (struct SetKeyMessage)); |
964 | skm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY); | 955 | skm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY); |
965 | skm->purpose.size = | 956 | skm->purpose.size = |
966 | htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + | 957 | htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + |
967 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + | 958 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + |
968 | sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) + | 959 | sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) + |
969 | sizeof (struct GNUNET_PeerIdentity)); | 960 | sizeof (struct GNUNET_PeerIdentity)); |
970 | skm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY); | 961 | skm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY); |
971 | skm->creation_time = GNUNET_TIME_absolute_hton (kx->encrypt_key_created); | 962 | skm->creation_time = GNUNET_TIME_absolute_hton (kx->encrypt_key_created); |
972 | skm->target = kx->peer; | 963 | skm->target = kx->peer; |
973 | GNUNET_assert (GNUNET_OK == | 964 | GNUNET_assert (GNUNET_OK == |
974 | GNUNET_CRYPTO_rsa_encrypt (&kx->encrypt_key, | 965 | GNUNET_CRYPTO_rsa_encrypt (&kx->encrypt_key, |
975 | sizeof (struct | 966 | sizeof (struct |
976 | GNUNET_CRYPTO_AesSessionKey), | 967 | GNUNET_CRYPTO_AesSessionKey), |
977 | kx->public_key, &skm->encrypted_key)); | 968 | kx->public_key, |
969 | &skm->encrypted_key)); | ||
978 | GNUNET_assert (GNUNET_OK == | 970 | GNUNET_assert (GNUNET_OK == |
979 | GNUNET_CRYPTO_rsa_sign (my_private_key, &skm->purpose, | 971 | GNUNET_CRYPTO_rsa_sign (my_private_key, &skm->purpose, |
980 | &skm->signature)); | 972 | &skm->signature)); |
981 | } | 973 | } |
982 | 974 | ||
983 | 975 | ||
@@ -997,13 +989,13 @@ setup_fresh_ping (struct GSC_KeyExchangeInfo *kx) | |||
997 | pm->header.size = htons (sizeof (struct PingMessage)); | 989 | pm->header.size = htons (sizeof (struct PingMessage)); |
998 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); | 990 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); |
999 | pm->iv_seed = | 991 | pm->iv_seed = |
1000 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | 992 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); |
1001 | derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, &kx->peer); | 993 | derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, &kx->peer); |
1002 | pp.challenge = kx->ping_challenge; | 994 | pp.challenge = kx->ping_challenge; |
1003 | pp.target = kx->peer; | 995 | pp.target = kx->peer; |
1004 | do_encrypt (kx, &iv, &pp.target, &pm->target, | 996 | do_encrypt (kx, &iv, &pp.target, &pm->target, |
1005 | sizeof (struct PingMessage) - ((void *) &pm->target - | 997 | sizeof (struct PingMessage) - ((void *) &pm->target - |
1006 | (void *) pm)); | 998 | (void *) pm)); |
1007 | } | 999 | } |
1008 | 1000 | ||
1009 | 1001 | ||
@@ -1024,33 +1016,29 @@ send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1024 | kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; | 1016 | kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; |
1025 | left = GNUNET_TIME_absolute_get_remaining (kx->timeout); | 1017 | left = GNUNET_TIME_absolute_get_remaining (kx->timeout); |
1026 | if (left.rel_value == 0) | 1018 | if (left.rel_value == 0) |
1027 | { | 1019 | { |
1028 | GNUNET_STATISTICS_update (GSC_stats, | 1020 | GNUNET_STATISTICS_update (GSC_stats, |
1029 | gettext_noop ("# sessions terminated by timeout"), | 1021 | gettext_noop ("# sessions terminated by timeout"), |
1030 | 1, | 1022 | 1, GNUNET_NO); |
1031 | GNUNET_NO); | ||
1032 | GSC_SESSIONS_end (&kx->peer); | 1023 | GSC_SESSIONS_end (&kx->peer); |
1033 | kx->status = KX_STATE_DOWN; | 1024 | kx->status = KX_STATE_DOWN; |
1034 | return; | 1025 | return; |
1035 | } | 1026 | } |
1036 | #if DEBUG_CORE | 1027 | #if DEBUG_CORE |
1037 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1028 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending KEEPALIVE to `%s'\n", |
1038 | "Sending KEEPALIVE to `%s'\n", | 1029 | GNUNET_i2s (&kx->peer)); |
1039 | GNUNET_i2s (&kx->peer)); | ||
1040 | #endif | 1030 | #endif |
1041 | GNUNET_STATISTICS_update (GSC_stats, | 1031 | GNUNET_STATISTICS_update (GSC_stats, |
1042 | gettext_noop ("# keepalive messages sent"), | 1032 | gettext_noop ("# keepalive messages sent"), 1, |
1043 | 1, | 1033 | GNUNET_NO); |
1044 | GNUNET_NO); | ||
1045 | setup_fresh_ping (kx); | 1034 | setup_fresh_ping (kx); |
1046 | GSC_NEIGHBOURS_transmit (&kx->peer, | 1035 | GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header, |
1047 | &kx->ping.header, | 1036 | kx->set_key_retry_frequency); |
1048 | kx->set_key_retry_frequency); | ||
1049 | retry = | 1037 | retry = |
1050 | GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), | 1038 | GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), |
1051 | MIN_PING_FREQUENCY); | 1039 | MIN_PING_FREQUENCY); |
1052 | kx->keep_alive_task = | 1040 | kx->keep_alive_task = |
1053 | GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx); | 1041 | GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx); |
1054 | } | 1042 | } |
1055 | 1043 | ||
1056 | 1044 | ||
@@ -1064,13 +1052,15 @@ send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1064 | static void | 1052 | static void |
1065 | update_timeout (struct GSC_KeyExchangeInfo *kx) | 1053 | update_timeout (struct GSC_KeyExchangeInfo *kx) |
1066 | { | 1054 | { |
1067 | kx->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1055 | kx->timeout = |
1056 | GNUNET_TIME_relative_to_absolute | ||
1057 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
1068 | if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) | 1058 | if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) |
1069 | GNUNET_SCHEDULER_cancel (kx->keep_alive_task); | 1059 | GNUNET_SCHEDULER_cancel (kx->keep_alive_task); |
1070 | kx->keep_alive_task = | 1060 | kx->keep_alive_task = |
1071 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide | 1061 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide |
1072 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1062 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
1073 | 2), &send_keep_alive, kx); | 1063 | 2), &send_keep_alive, kx); |
1074 | } | 1064 | } |
1075 | 1065 | ||
1076 | 1066 | ||
@@ -1081,7 +1071,8 @@ update_timeout (struct GSC_KeyExchangeInfo *kx) | |||
1081 | * @param m the encrypted PONG message itself | 1071 | * @param m the encrypted PONG message itself |
1082 | */ | 1072 | */ |
1083 | void | 1073 | void |
1084 | GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageHeader *msg) | 1074 | GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, |
1075 | const struct GNUNET_MessageHeader *msg) | ||
1085 | { | 1076 | { |
1086 | const struct PongMessage *m; | 1077 | const struct PongMessage *m; |
1087 | struct PongMessage t; | 1078 | struct PongMessage t; |
@@ -1095,19 +1086,19 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH | |||
1095 | GNUNET_break_op (0); | 1086 | GNUNET_break_op (0); |
1096 | return; | 1087 | return; |
1097 | } | 1088 | } |
1098 | GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages received"), | 1089 | GNUNET_STATISTICS_update (GSC_stats, |
1099 | 1, GNUNET_NO); | 1090 | gettext_noop ("# PONG messages received"), 1, |
1100 | if ( (kx->status != KX_STATE_KEY_RECEIVED) && | 1091 | GNUNET_NO); |
1101 | (kx->status != KX_STATE_UP) ) | 1092 | if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP)) |
1102 | { | 1093 | { |
1103 | if (kx->status == KX_STATE_KEY_SENT) | 1094 | if (kx->status == KX_STATE_KEY_SENT) |
1104 | { | 1095 | { |
1105 | GNUNET_free_non_null (kx->pong_received); | 1096 | GNUNET_free_non_null (kx->pong_received); |
1106 | kx->pong_received = (struct PongMessage*) GNUNET_copy_message (msg); | 1097 | kx->pong_received = (struct PongMessage *) GNUNET_copy_message (msg); |
1107 | } | 1098 | } |
1108 | return; | 1099 | return; |
1109 | } | 1100 | } |
1110 | m = (const struct PongMessage*) msg; | 1101 | m = (const struct PongMessage *) msg; |
1111 | #if DEBUG_HANDSHAKE | 1102 | #if DEBUG_HANDSHAKE |
1112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1113 | "Core service receives `%s' response from `%4s'.\n", "PONG", | 1104 | "Core service receives `%s' response from `%4s'.\n", "PONG", |
@@ -1125,8 +1116,9 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH | |||
1125 | GNUNET_break_op (0); | 1116 | GNUNET_break_op (0); |
1126 | return; | 1117 | return; |
1127 | } | 1118 | } |
1128 | GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages decrypted"), | 1119 | GNUNET_STATISTICS_update (GSC_stats, |
1129 | 1, GNUNET_NO); | 1120 | gettext_noop ("# PONG messages decrypted"), 1, |
1121 | GNUNET_NO); | ||
1130 | if ((0 != memcmp (&t.target, &kx->peer, sizeof (struct GNUNET_PeerIdentity))) | 1122 | if ((0 != memcmp (&t.target, &kx->peer, sizeof (struct GNUNET_PeerIdentity))) |
1131 | || (kx->ping_challenge != t.challenge)) | 1123 | || (kx->ping_challenge != t.challenge)) |
1132 | { | 1124 | { |
@@ -1143,9 +1135,8 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH | |||
1143 | return; | 1135 | return; |
1144 | } | 1136 | } |
1145 | #if DEBUG_CORE | 1137 | #if DEBUG_CORE |
1146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PONG from `%s'\n", |
1147 | "Received PONG from `%s'\n", | 1139 | GNUNET_i2s (&kx->peer)); |
1148 | GNUNET_i2s (&kx->peer)); | ||
1149 | #endif | 1140 | #endif |
1150 | switch (kx->status) | 1141 | switch (kx->status) |
1151 | { | 1142 | { |
@@ -1170,7 +1161,8 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH | |||
1170 | { | 1161 | { |
1171 | emsg = kx->emsg_received; | 1162 | emsg = kx->emsg_received; |
1172 | kx->emsg_received = NULL; | 1163 | kx->emsg_received = NULL; |
1173 | GSC_KX_handle_encrypted_message (kx, &emsg->header, NULL, 0 /* FIXME: ATSI */); | 1164 | GSC_KX_handle_encrypted_message (kx, &emsg->header, NULL, |
1165 | 0 /* FIXME: ATSI */ ); | ||
1174 | GNUNET_free (emsg); | 1166 | GNUNET_free (emsg); |
1175 | } | 1167 | } |
1176 | update_timeout (kx); | 1168 | update_timeout (kx); |
@@ -1194,20 +1186,20 @@ static void | |||
1194 | send_key (struct GSC_KeyExchangeInfo *kx) | 1186 | send_key (struct GSC_KeyExchangeInfo *kx) |
1195 | { | 1187 | { |
1196 | GNUNET_assert (kx->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK); | 1188 | GNUNET_assert (kx->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK); |
1197 | if (KX_STATE_UP == kx->status) | 1189 | if (KX_STATE_UP == kx->status) |
1198 | return; /* nothing to do */ | 1190 | return; /* nothing to do */ |
1199 | if (kx->public_key == NULL) | 1191 | if (kx->public_key == NULL) |
1200 | { | 1192 | { |
1201 | /* lookup public key, then try again */ | 1193 | /* lookup public key, then try again */ |
1202 | #if DEBUG_CORE | 1194 | #if DEBUG_CORE |
1203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1204 | "Trying to obtain public key for `%s'\n", | 1196 | "Trying to obtain public key for `%s'\n", |
1205 | GNUNET_i2s (&kx->peer)); | 1197 | GNUNET_i2s (&kx->peer)); |
1206 | #endif | 1198 | #endif |
1207 | kx->pitr = | 1199 | kx->pitr = |
1208 | GNUNET_PEERINFO_iterate (peerinfo, &kx->peer, | 1200 | GNUNET_PEERINFO_iterate (peerinfo, &kx->peer, |
1209 | GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */, | 1201 | GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ , |
1210 | &process_hello, kx); | 1202 | &process_hello, kx); |
1211 | return; | 1203 | return; |
1212 | } | 1204 | } |
1213 | 1205 | ||
@@ -1215,14 +1207,14 @@ send_key (struct GSC_KeyExchangeInfo *kx) | |||
1215 | switch (kx->status) | 1207 | switch (kx->status) |
1216 | { | 1208 | { |
1217 | case KX_STATE_DOWN: | 1209 | case KX_STATE_DOWN: |
1218 | kx->status = KX_STATE_KEY_SENT; | 1210 | kx->status = KX_STATE_KEY_SENT; |
1219 | /* setup SET KEY message */ | 1211 | /* setup SET KEY message */ |
1220 | setup_fresh_setkey (kx); | 1212 | setup_fresh_setkey (kx); |
1221 | setup_fresh_ping (kx); | 1213 | setup_fresh_ping (kx); |
1222 | GNUNET_STATISTICS_update (GSC_stats, | 1214 | GNUNET_STATISTICS_update (GSC_stats, |
1223 | gettext_noop | 1215 | gettext_noop |
1224 | ("# SET_KEY and PING messages created"), 1, | 1216 | ("# SET_KEY and PING messages created"), 1, |
1225 | GNUNET_NO); | 1217 | GNUNET_NO); |
1226 | break; | 1218 | break; |
1227 | case KX_STATE_KEY_SENT: | 1219 | case KX_STATE_KEY_SENT: |
1228 | break; | 1220 | break; |
@@ -1239,19 +1231,16 @@ send_key (struct GSC_KeyExchangeInfo *kx) | |||
1239 | /* always update sender status in SET KEY message */ | 1231 | /* always update sender status in SET KEY message */ |
1240 | kx->skm.sender_status = htonl ((int32_t) kx->status); | 1232 | kx->skm.sender_status = htonl ((int32_t) kx->status); |
1241 | #if DEBUG_CORE | 1233 | #if DEBUG_CORE |
1242 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1234 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SET_KEY and PING to `%s'\n", |
1243 | "Sending SET_KEY and PING to `%s'\n", | 1235 | GNUNET_i2s (&kx->peer)); |
1244 | GNUNET_i2s (&kx->peer)); | ||
1245 | #endif | 1236 | #endif |
1246 | GSC_NEIGHBOURS_transmit (&kx->peer, | 1237 | GSC_NEIGHBOURS_transmit (&kx->peer, &kx->skm.header, |
1247 | &kx->skm.header, | 1238 | kx->set_key_retry_frequency); |
1248 | kx->set_key_retry_frequency); | 1239 | GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header, |
1249 | GSC_NEIGHBOURS_transmit (&kx->peer, | 1240 | kx->set_key_retry_frequency); |
1250 | &kx->ping.header, | ||
1251 | kx->set_key_retry_frequency); | ||
1252 | kx->retry_set_key_task = | 1241 | kx->retry_set_key_task = |
1253 | GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, | 1242 | GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, |
1254 | &set_key_retry_task, kx); | 1243 | &set_key_retry_task, kx); |
1255 | } | 1244 | } |
1256 | 1245 | ||
1257 | 1246 | ||
@@ -1264,18 +1253,17 @@ send_key (struct GSC_KeyExchangeInfo *kx) | |||
1264 | */ | 1253 | */ |
1265 | void | 1254 | void |
1266 | GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, | 1255 | GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, |
1267 | const void *payload, | 1256 | const void *payload, size_t payload_size) |
1268 | size_t payload_size) | ||
1269 | { | 1257 | { |
1270 | size_t used = payload_size + sizeof (struct EncryptedMessage); | 1258 | size_t used = payload_size + sizeof (struct EncryptedMessage); |
1271 | char pbuf[used]; /* plaintext */ | 1259 | char pbuf[used]; /* plaintext */ |
1272 | char cbuf[used]; /* ciphertext */ | 1260 | char cbuf[used]; /* ciphertext */ |
1273 | struct EncryptedMessage *em; /* encrypted message */ | 1261 | struct EncryptedMessage *em; /* encrypted message */ |
1274 | struct EncryptedMessage *ph; /* plaintext header */ | 1262 | struct EncryptedMessage *ph; /* plaintext header */ |
1275 | struct GNUNET_CRYPTO_AesInitializationVector iv; | 1263 | struct GNUNET_CRYPTO_AesInitializationVector iv; |
1276 | struct GNUNET_CRYPTO_AuthKey auth_key; | 1264 | struct GNUNET_CRYPTO_AuthKey auth_key; |
1277 | 1265 | ||
1278 | ph = (struct EncryptedMessage*) pbuf; | 1266 | ph = (struct EncryptedMessage *) pbuf; |
1279 | ph->iv_seed = | 1267 | ph->iv_seed = |
1280 | htonl (GNUNET_CRYPTO_random_u32 | 1268 | htonl (GNUNET_CRYPTO_random_u32 |
1281 | (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); | 1269 | (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); |
@@ -1290,22 +1278,20 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, | |||
1290 | em->iv_seed = ph->iv_seed; | 1278 | em->iv_seed = ph->iv_seed; |
1291 | derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, &kx->peer); | 1279 | derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, &kx->peer); |
1292 | GNUNET_assert (GNUNET_OK == | 1280 | GNUNET_assert (GNUNET_OK == |
1293 | do_encrypt (kx, &iv, &ph->sequence_number, &em->sequence_number, | 1281 | do_encrypt (kx, &iv, &ph->sequence_number, |
1282 | &em->sequence_number, | ||
1294 | used - ENCRYPTED_HEADER_SIZE)); | 1283 | used - ENCRYPTED_HEADER_SIZE)); |
1295 | #if DEBUG_CORE | 1284 | #if DEBUG_CORE |
1296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted %u bytes for %s\n", |
1297 | "Encrypted %u bytes for %s\n", | 1286 | used - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer)); |
1298 | used - ENCRYPTED_HEADER_SIZE, | ||
1299 | GNUNET_i2s (&kx->peer)); | ||
1300 | #endif | 1287 | #endif |
1301 | derive_auth_key (&auth_key, &kx->encrypt_key, ph->iv_seed, | 1288 | derive_auth_key (&auth_key, &kx->encrypt_key, ph->iv_seed, |
1302 | kx->encrypt_key_created); | 1289 | kx->encrypt_key_created); |
1303 | GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number, | 1290 | GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number, |
1304 | used - ENCRYPTED_HEADER_SIZE, &em->hmac); | 1291 | used - ENCRYPTED_HEADER_SIZE, &em->hmac); |
1305 | GSC_NEIGHBOURS_transmit (&kx->peer, | 1292 | GSC_NEIGHBOURS_transmit (&kx->peer, &em->header, |
1306 | &em->header, | 1293 | GNUNET_TIME_UNIT_FOREVER_REL); |
1307 | GNUNET_TIME_UNIT_FOREVER_REL); | 1294 | } |
1308 | } | ||
1309 | 1295 | ||
1310 | 1296 | ||
1311 | /** | 1297 | /** |
@@ -1313,7 +1299,7 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, | |||
1313 | */ | 1299 | */ |
1314 | struct DeliverMessageContext | 1300 | struct DeliverMessageContext |
1315 | { | 1301 | { |
1316 | 1302 | ||
1317 | /** | 1303 | /** |
1318 | * Performance information for the connection. | 1304 | * Performance information for the connection. |
1319 | */ | 1305 | */ |
@@ -1330,7 +1316,7 @@ struct DeliverMessageContext | |||
1330 | uint32_t atsi_count; | 1316 | uint32_t atsi_count; |
1331 | }; | 1317 | }; |
1332 | 1318 | ||
1333 | 1319 | ||
1334 | /** | 1320 | /** |
1335 | * We received an encrypted message. Decrypt, validate and | 1321 | * We received an encrypted message. Decrypt, validate and |
1336 | * pass on to the appropriate clients. | 1322 | * pass on to the appropriate clients. |
@@ -1341,10 +1327,10 @@ struct DeliverMessageContext | |||
1341 | * @param atsi_count number of entries in ats (excluding 0-termination) | 1327 | * @param atsi_count number of entries in ats (excluding 0-termination) |
1342 | */ | 1328 | */ |
1343 | void | 1329 | void |
1344 | GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, | 1330 | GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, |
1345 | const struct GNUNET_MessageHeader *msg, | 1331 | const struct GNUNET_MessageHeader *msg, |
1346 | const struct GNUNET_ATS_Information *atsi, | 1332 | const struct GNUNET_ATS_Information *atsi, |
1347 | uint32_t atsi_count) | 1333 | uint32_t atsi_count) |
1348 | { | 1334 | { |
1349 | const struct EncryptedMessage *m; | 1335 | const struct EncryptedMessage *m; |
1350 | struct EncryptedMessage *pt; /* plaintext */ | 1336 | struct EncryptedMessage *pt; /* plaintext */ |
@@ -1363,21 +1349,20 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, | |||
1363 | GNUNET_break_op (0); | 1349 | GNUNET_break_op (0); |
1364 | return; | 1350 | return; |
1365 | } | 1351 | } |
1366 | m = (const struct EncryptedMessage*) msg; | 1352 | m = (const struct EncryptedMessage *) msg; |
1367 | if ( (kx->status != KX_STATE_KEY_RECEIVED) && | 1353 | if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP)) |
1368 | (kx->status != KX_STATE_UP) ) | ||
1369 | { | 1354 | { |
1370 | GNUNET_STATISTICS_update (GSC_stats, | 1355 | GNUNET_STATISTICS_update (GSC_stats, |
1371 | gettext_noop | 1356 | gettext_noop |
1372 | ("# failed to decrypt message (no session key)"), | 1357 | ("# failed to decrypt message (no session key)"), |
1373 | 1, GNUNET_NO); | 1358 | 1, GNUNET_NO); |
1374 | return; | 1359 | return; |
1375 | } | 1360 | } |
1376 | if (kx->status == KX_STATE_KEY_RECEIVED) | 1361 | if (kx->status == KX_STATE_KEY_RECEIVED) |
1377 | { | 1362 | { |
1378 | /* defer */ | 1363 | /* defer */ |
1379 | GNUNET_free_non_null (kx->ping_received); | 1364 | GNUNET_free_non_null (kx->ping_received); |
1380 | kx->emsg_received = (struct EncryptedMessage*) GNUNET_copy_message (msg); | 1365 | kx->emsg_received = (struct EncryptedMessage *) GNUNET_copy_message (msg); |
1381 | return; | 1366 | return; |
1382 | } | 1367 | } |
1383 | /* validate hash */ | 1368 | /* validate hash */ |
@@ -1398,10 +1383,8 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, | |||
1398 | size - ENCRYPTED_HEADER_SIZE)) | 1383 | size - ENCRYPTED_HEADER_SIZE)) |
1399 | return; | 1384 | return; |
1400 | #if DEBUG_CORE | 1385 | #if DEBUG_CORE |
1401 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypted %u bytes from %s\n", |
1402 | "Decrypted %u bytes from %s\n", | 1387 | size - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer)); |
1403 | size - ENCRYPTED_HEADER_SIZE, | ||
1404 | GNUNET_i2s (&kx->peer)); | ||
1405 | #endif | 1388 | #endif |
1406 | pt = (struct EncryptedMessage *) buf; | 1389 | pt = (struct EncryptedMessage *) buf; |
1407 | 1390 | ||
@@ -1480,7 +1463,8 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, | |||
1480 | dmc.atsi_count = atsi_count; | 1463 | dmc.atsi_count = atsi_count; |
1481 | dmc.peer = &kx->peer; | 1464 | dmc.peer = &kx->peer; |
1482 | if (GNUNET_OK != | 1465 | if (GNUNET_OK != |
1483 | GNUNET_SERVER_mst_receive (mst, &dmc, &buf[sizeof (struct EncryptedMessage)], | 1466 | GNUNET_SERVER_mst_receive (mst, &dmc, |
1467 | &buf[sizeof (struct EncryptedMessage)], | ||
1484 | size - sizeof (struct EncryptedMessage), | 1468 | size - sizeof (struct EncryptedMessage), |
1485 | GNUNET_YES, GNUNET_NO)) | 1469 | GNUNET_YES, GNUNET_NO)) |
1486 | GNUNET_break_op (0); | 1470 | GNUNET_break_op (0); |
@@ -1490,7 +1474,7 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, | |||
1490 | /** | 1474 | /** |
1491 | * Deliver P2P message to interested clients. | 1475 | * Deliver P2P message to interested clients. |
1492 | * Invokes send twice, once for clients that want the full message, and once | 1476 | * Invokes send twice, once for clients that want the full message, and once |
1493 | * for clients that only want the header | 1477 | * for clients that only want the header |
1494 | * | 1478 | * |
1495 | * @param cls always NULL | 1479 | * @param cls always NULL |
1496 | * @param client who sent us the message (struct GSC_KeyExchangeInfo) | 1480 | * @param client who sent us the message (struct GSC_KeyExchangeInfo) |
@@ -1505,20 +1489,15 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m) | |||
1505 | { | 1489 | { |
1506 | case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: | 1490 | case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: |
1507 | case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: | 1491 | case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: |
1508 | GSC_SESSIONS_set_typemap (dmc->peer, | 1492 | GSC_SESSIONS_set_typemap (dmc->peer, m); |
1509 | m); | ||
1510 | return; | 1493 | return; |
1511 | default: | 1494 | default: |
1512 | GSC_CLIENTS_deliver_message (dmc->peer, | 1495 | GSC_CLIENTS_deliver_message (dmc->peer, dmc->atsi, dmc->atsi_count, m, |
1513 | dmc->atsi, dmc->atsi_count, | 1496 | ntohs (m->size), |
1514 | m, | 1497 | GNUNET_CORE_OPTION_SEND_FULL_INBOUND); |
1515 | ntohs (m->size), | 1498 | GSC_CLIENTS_deliver_message (dmc->peer, dmc->atsi, dmc->atsi_count, m, |
1516 | GNUNET_CORE_OPTION_SEND_FULL_INBOUND); | 1499 | sizeof (struct GNUNET_MessageHeader), |
1517 | GSC_CLIENTS_deliver_message (dmc->peer, | 1500 | GNUNET_CORE_OPTION_SEND_HDR_INBOUND); |
1518 | dmc->atsi, dmc->atsi_count, | ||
1519 | m, | ||
1520 | sizeof (struct GNUNET_MessageHeader), | ||
1521 | GNUNET_CORE_OPTION_SEND_HDR_INBOUND); | ||
1522 | } | 1501 | } |
1523 | } | 1502 | } |
1524 | 1503 | ||
@@ -1528,17 +1507,18 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m) | |||
1528 | * | 1507 | * |
1529 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | 1508 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure |
1530 | */ | 1509 | */ |
1531 | int | 1510 | int |
1532 | GSC_KX_init () | 1511 | GSC_KX_init () |
1533 | { | 1512 | { |
1534 | char *keyfile; | 1513 | char *keyfile; |
1535 | 1514 | ||
1536 | if (GNUNET_OK != | 1515 | if (GNUNET_OK != |
1537 | GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, "GNUNETD", "HOSTKEY", | 1516 | GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, "GNUNETD", "HOSTKEY", |
1538 | &keyfile)) | 1517 | &keyfile)) |
1539 | { | 1518 | { |
1540 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1519 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1541 | _("Core service is lacking HOSTKEY configuration setting. Exiting.\n")); | 1520 | _ |
1521 | ("Core service is lacking HOSTKEY configuration setting. Exiting.\n")); | ||
1542 | return GNUNET_SYSERR; | 1522 | return GNUNET_SYSERR; |
1543 | } | 1523 | } |
1544 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | 1524 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); |
@@ -1569,7 +1549,7 @@ GSC_KX_init () | |||
1569 | /** | 1549 | /** |
1570 | * Shutdown KX subsystem. | 1550 | * Shutdown KX subsystem. |
1571 | */ | 1551 | */ |
1572 | void | 1552 | void |
1573 | GSC_KX_done () | 1553 | GSC_KX_done () |
1574 | { | 1554 | { |
1575 | if (my_private_key != NULL) | 1555 | if (my_private_key != NULL) |