diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2024-03-11 15:06:55 +0100 |
---|---|---|
committer | t3serakt <t3ss@posteo.de> | 2024-04-10 20:14:53 +0200 |
commit | c810e726b3d67a9bd09b714ed32acf92883fdf67 (patch) | |
tree | f12689ae0c6149843e0eda218016d6c0ac9c3335 | |
parent | 1176c2c6037af56948fdc0e8d5b92729c5fca87c (diff) | |
download | gnunet-c810e726b3d67a9bd09b714ed32acf92883fdf67.tar.gz gnunet-c810e726b3d67a9bd09b714ed32acf92883fdf67.zip |
transport: Reviewed communicator rekey test. Fixes #6828
The TCP communicator already expires keys according to config, but it
was not possible to configure the maximum rekey bytes.
Note that we also still do not have test that tests this specifically.
Conversely, the UDP communicator test tests the expiration after the
number of bytes, but the option for the expiration is not used still.
-rw-r--r-- | src/service/transport/gnunet-communicator-tcp.c | 36 | ||||
-rw-r--r-- | src/service/transport/gnunet-communicator-udp.c | 2 | ||||
-rw-r--r-- | src/service/transport/test_communicator_basic.c | 35 |
3 files changed, 64 insertions, 9 deletions
diff --git a/src/service/transport/gnunet-communicator-tcp.c b/src/service/transport/gnunet-communicator-tcp.c index ccc32d65c..0ab8c0c82 100644 --- a/src/service/transport/gnunet-communicator-tcp.c +++ b/src/service/transport/gnunet-communicator-tcp.c | |||
@@ -833,6 +833,11 @@ static struct GNUNET_CONTAINER_MultiHashMap *lt_map; | |||
833 | static struct GNUNET_PeerIdentity my_identity; | 833 | static struct GNUNET_PeerIdentity my_identity; |
834 | 834 | ||
835 | /** | 835 | /** |
836 | * The rekey byte maximum | ||
837 | */ | ||
838 | static unsigned long long rekey_max_bytes; | ||
839 | |||
840 | /** | ||
836 | * The rekey interval | 841 | * The rekey interval |
837 | */ | 842 | */ |
838 | static struct GNUNET_TIME_Relative rekey_interval; | 843 | static struct GNUNET_TIME_Relative rekey_interval; |
@@ -1560,7 +1565,7 @@ setup_out_cipher (struct Queue *queue, struct GNUNET_HashCode *dh) | |||
1560 | setup_cipher (dh, &queue->target, &queue->out_cipher, &queue->out_hmac); | 1565 | setup_cipher (dh, &queue->target, &queue->out_cipher, &queue->out_hmac); |
1561 | queue->rekey_time = GNUNET_TIME_relative_to_absolute (rekey_interval); | 1566 | queue->rekey_time = GNUNET_TIME_relative_to_absolute (rekey_interval); |
1562 | queue->rekey_left_bytes = | 1567 | queue->rekey_left_bytes = |
1563 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, REKEY_MAX_BYTES); | 1568 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, rekey_max_bytes); |
1564 | } | 1569 | } |
1565 | 1570 | ||
1566 | 1571 | ||
@@ -2036,6 +2041,14 @@ try_handle_plaintext (struct Queue *queue) | |||
2036 | size = ntohs (hdr->size) + sizeof(*box); | 2041 | size = ntohs (hdr->size) + sizeof(*box); |
2037 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2042 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2038 | "Handling plaintext, box processed!\n"); | 2043 | "Handling plaintext, box processed!\n"); |
2044 | GNUNET_STATISTICS_update (stats, | ||
2045 | "# bytes decrypted with BOX", | ||
2046 | size, | ||
2047 | GNUNET_NO); | ||
2048 | GNUNET_STATISTICS_update (stats, | ||
2049 | "# messages decrypted with BOX", | ||
2050 | 1, | ||
2051 | GNUNET_NO); | ||
2039 | break; | 2052 | break; |
2040 | 2053 | ||
2041 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY: | 2054 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY: |
@@ -2061,6 +2074,10 @@ try_handle_plaintext (struct Queue *queue) | |||
2061 | size = ntohs (hdr->size); | 2074 | size = ntohs (hdr->size); |
2062 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2075 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2063 | "Handling plaintext, rekey processed!\n"); | 2076 | "Handling plaintext, rekey processed!\n"); |
2077 | GNUNET_STATISTICS_update (stats, | ||
2078 | "# rekeying successful", | ||
2079 | 1, | ||
2080 | GNUNET_NO); | ||
2064 | break; | 2081 | break; |
2065 | 2082 | ||
2066 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH: | 2083 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH: |
@@ -3556,7 +3573,7 @@ do_shutdown (void *cls) | |||
3556 | } | 3573 | } |
3557 | if (NULL != stats) | 3574 | if (NULL != stats) |
3558 | { | 3575 | { |
3559 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 3576 | GNUNET_STATISTICS_destroy (stats, GNUNET_YES); |
3560 | stats = NULL; | 3577 | stats = NULL; |
3561 | } | 3578 | } |
3562 | if (NULL != my_private_key) | 3579 | if (NULL != my_private_key) |
@@ -3765,7 +3782,7 @@ init_socket (struct sockaddr *addr, | |||
3765 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3782 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3766 | "Bound to `%s'\n", | 3783 | "Bound to `%s'\n", |
3767 | GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len)); | 3784 | GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len)); |
3768 | stats = GNUNET_STATISTICS_create ("C-TCP", cfg); | 3785 | stats = GNUNET_STATISTICS_create ("communicator-tcp", cfg); |
3769 | 3786 | ||
3770 | if (NULL == is) | 3787 | if (NULL == is) |
3771 | is = GNUNET_NT_scanner_init (); | 3788 | is = GNUNET_NT_scanner_init (); |
@@ -4008,14 +4025,25 @@ run (void *cls, | |||
4008 | COMMUNICATOR_CONFIG_SECTION, | 4025 | COMMUNICATOR_CONFIG_SECTION, |
4009 | "MAX_QUEUE_LENGTH", | 4026 | "MAX_QUEUE_LENGTH", |
4010 | &max_queue_length)) | 4027 | &max_queue_length)) |
4028 | { | ||
4011 | max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; | 4029 | max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; |
4030 | } | ||
4012 | if (GNUNET_OK != | 4031 | if (GNUNET_OK != |
4013 | GNUNET_CONFIGURATION_get_value_time (cfg, | 4032 | GNUNET_CONFIGURATION_get_value_time (cfg, |
4014 | COMMUNICATOR_CONFIG_SECTION, | 4033 | COMMUNICATOR_CONFIG_SECTION, |
4015 | "REKEY_INTERVAL", | 4034 | "REKEY_INTERVAL", |
4016 | &rekey_interval)) | 4035 | &rekey_interval)) |
4036 | { | ||
4017 | rekey_interval = DEFAULT_REKEY_INTERVAL; | 4037 | rekey_interval = DEFAULT_REKEY_INTERVAL; |
4018 | 4038 | } | |
4039 | if (GNUNET_OK != | ||
4040 | GNUNET_CONFIGURATION_get_value_number (cfg, | ||
4041 | COMMUNICATOR_CONFIG_SECTION, | ||
4042 | "REKEY_MAX_BYTES", | ||
4043 | &rekey_max_bytes)) | ||
4044 | { | ||
4045 | rekey_max_bytes = REKEY_MAX_BYTES; | ||
4046 | } | ||
4019 | peerstore = GNUNET_PEERSTORE_connect (cfg); | 4047 | peerstore = GNUNET_PEERSTORE_connect (cfg); |
4020 | if (NULL == peerstore) | 4048 | if (NULL == peerstore) |
4021 | { | 4049 | { |
diff --git a/src/service/transport/gnunet-communicator-udp.c b/src/service/transport/gnunet-communicator-udp.c index 406c52bff..76e5d7906 100644 --- a/src/service/transport/gnunet-communicator-udp.c +++ b/src/service/transport/gnunet-communicator-udp.c | |||
@@ -3491,7 +3491,7 @@ run (void *cls, | |||
3491 | GNUNET_break (0); | 3491 | GNUNET_break (0); |
3492 | my_port = 0; | 3492 | my_port = 0; |
3493 | } | 3493 | } |
3494 | stats = GNUNET_STATISTICS_create ("C-UDP", cfg); | 3494 | stats = GNUNET_STATISTICS_create ("communicator-udp", cfg); |
3495 | senders = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); | 3495 | senders = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); |
3496 | receivers = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); | 3496 | receivers = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); |
3497 | senders_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 3497 | senders_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
diff --git a/src/service/transport/test_communicator_basic.c b/src/service/transport/test_communicator_basic.c index 510791a47..78ac26b25 100644 --- a/src/service/transport/test_communicator_basic.c +++ b/src/service/transport/test_communicator_basic.c | |||
@@ -597,11 +597,32 @@ choose_phase (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) | |||
597 | "backchannel", | 597 | "backchannel", |
598 | test_name))) ) | 598 | test_name))) ) |
599 | { | 599 | { |
600 | LOG (GNUNET_ERROR_TYPE_ERROR, "Getting statistics...\n"); | 600 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Getting statistics UDP...\n"); |
601 | if (NULL != box_stats[peer_nr]) | 601 | if (NULL != box_stats[peer_nr]) |
602 | GNUNET_STATISTICS_get_cancel (box_stats[peer_nr]); | 602 | GNUNET_STATISTICS_get_cancel (box_stats[peer_nr]); |
603 | box_stats[peer_nr] = GNUNET_STATISTICS_get (stats[1], | 603 | box_stats[peer_nr] = GNUNET_STATISTICS_get (stats[1], |
604 | "C-UDP", | 604 | "communicator-udp", |
605 | "# messages decrypted with BOX", | ||
606 | process_statistics_box_done, | ||
607 | &process_statistics, | ||
608 | tc_h); | ||
609 | if (NULL != rekey_stats[peer_nr]) | ||
610 | GNUNET_STATISTICS_get_cancel (rekey_stats[peer_nr]); | ||
611 | rekey_stats[peer_nr] = GNUNET_STATISTICS_get (stats[1], | ||
612 | "communicator-udp", | ||
613 | "# rekeying successful", | ||
614 | process_statistics_rekey_done, | ||
615 | &process_statistics, | ||
616 | tc_h); | ||
617 | } | ||
618 | else if ((0 == strcmp ("tcp", communicator_name)) && (0 == strcmp ("rekey", | ||
619 | test_name))) | ||
620 | { | ||
621 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Getting statistics... TCP\n"); | ||
622 | if (NULL != box_stats[peer_nr]) | ||
623 | GNUNET_STATISTICS_get_cancel (box_stats[peer_nr]); | ||
624 | box_stats[peer_nr] = GNUNET_STATISTICS_get (stats[1], | ||
625 | "communicator-tcp", | ||
605 | //"# messages decrypted with BOX", | 626 | //"# messages decrypted with BOX", |
606 | NULL, | 627 | NULL, |
607 | process_statistics_box_done, | 628 | process_statistics_box_done, |
@@ -610,7 +631,7 @@ choose_phase (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) | |||
610 | if (NULL != rekey_stats[peer_nr]) | 631 | if (NULL != rekey_stats[peer_nr]) |
611 | GNUNET_STATISTICS_get_cancel (rekey_stats[peer_nr]); | 632 | GNUNET_STATISTICS_get_cancel (rekey_stats[peer_nr]); |
612 | rekey_stats[peer_nr] = GNUNET_STATISTICS_get (stats[1], | 633 | rekey_stats[peer_nr] = GNUNET_STATISTICS_get (stats[1], |
613 | "C-UDP", | 634 | "communicator-tcp", |
614 | "# rekeying successful", | 635 | "# rekeying successful", |
615 | process_statistics_rekey_done, | 636 | process_statistics_rekey_done, |
616 | &process_statistics, | 637 | &process_statistics, |
@@ -1084,7 +1105,13 @@ run (void *cls) | |||
1084 | "backchannel", | 1105 | "backchannel", |
1085 | test_name))) ) | 1106 | test_name))) ) |
1086 | { | 1107 | { |
1087 | stats[i] = GNUNET_STATISTICS_create ("C-UDP", | 1108 | stats[i] = GNUNET_STATISTICS_create ("communicator-udp", |
1109 | cfg_peers[i]); | ||
1110 | } | ||
1111 | else if ((0 == strcmp ("tcp", communicator_name)) && (0 == strcmp ("rekey", | ||
1112 | test_name))) | ||
1113 | { | ||
1114 | stats[i] = GNUNET_STATISTICS_create ("communicator-tcp", | ||
1088 | cfg_peers[i]); | 1115 | cfg_peers[i]); |
1089 | } | 1116 | } |
1090 | else if ((0 == strcmp ("bidirect", test_name))) | 1117 | else if ((0 == strcmp ("bidirect", test_name))) |