From 33954ae13d4d26cefa45ac86f5e2184b6abd724f Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Thu, 6 Aug 2020 16:20:48 +0200 Subject: - fixed tcp communicator rekey --- src/include/gnunet_crypto_lib.h | 2 +- src/transport/gnunet-communicator-tcp.c | 237 +++++++++++++++++---- .../test_communicator_tcp_rekey_peer2.conf | 4 +- src/transport/transport-testing2.c | 14 +- 4 files changed, 207 insertions(+), 50 deletions(-) diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index c1b0b3b1b..f8eef5406 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -1790,7 +1790,7 @@ GNUNET_CRYPTO_eddsa_verify_ ( */ #define GNUNET_CRYPTO_eddsa_verify(purp,ps,sig,pub) ({ \ /* check size is set correctly */ \ - GNUNET_assert (htonl ((ps)->purpose.size) == sizeof (*(ps))); \ + GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ /* check 'ps' begins with the purpose */ \ GNUNET_static_assert (((void*) (ps)) == \ ((void*) &(ps)->purpose)); \ diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index 880145424..df1bdc410 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c @@ -308,6 +308,38 @@ struct TCPRekey struct GNUNET_TIME_AbsoluteNBO monotonic_time; }; +/** + * Signature we use to verify that the ephemeral key was really chosen by + * the specified sender. + */ +struct TcpRekeySignature +{ + /** + * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY + */ + struct GNUNET_CRYPTO_EccSignaturePurpose purpose; + + /** + * Identity of the inititor of the TCP connection (TCP client). + */ + struct GNUNET_PeerIdentity sender; + + /** + * Presumed identity of the target of the TCP connection (TCP server) + */ + struct GNUNET_PeerIdentity receiver; + + /** + * Ephemeral key used by the @e sender. + */ + struct GNUNET_CRYPTO_EcdhePublicKey ephemeral; + + /** + * Monotonic time of @e sender, to possibly help detect replay attacks + * (if receiver persists times by sender). + */ + struct GNUNET_TIME_AbsoluteNBO monotonic_time; +}; /** * TCP finish. Sender asks for the connection to be closed. @@ -798,6 +830,11 @@ size_t unverified_size; */ static struct GNUNET_PEERSTORE_Handle *peerstore; +/** + * A flag indicating we are already doing a shutdown. + */ +int shutdown_running = GNUNET_NO; + /** * We have been notified that our listen socket has something to * read. Do the read and reschedule this function to be called again @@ -858,11 +895,6 @@ queue_destroy (struct Queue *queue) GNUNET_PEERSTORE_iterate_cancel (queue->handshake_ack_monotime_get); queue->handshake_ack_monotime_get = NULL; } - if (NULL != (mq = queue->mq)) - { - queue->mq = NULL; - GNUNET_MQ_destroy (mq); - } if (NULL != queue->qh) { GNUNET_TRANSPORT_communicator_mq_del (queue->qh); @@ -885,7 +917,11 @@ queue_destroy (struct Queue *queue) GNUNET_SCHEDULER_cancel (queue->write_task); queue->write_task = NULL; } - GNUNET_NETWORK_socket_close (queue->sock); + if (GNUNET_SYSERR == GNUNET_NETWORK_socket_close (queue->sock)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "closing socket failed\n"); + } gcry_cipher_close (queue->in_cipher); gcry_cipher_close (queue->out_cipher); GNUNET_free (queue->address); @@ -894,12 +930,18 @@ queue_destroy (struct Queue *queue) else GNUNET_free (queue); - if (NULL == lt->listen_task) + if ((NULL != lt->listen_sock) && (NULL == lt->listen_task)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "add read net listen\n"); lt->listen_task = GNUNET_SCHEDULER_add_read_net ( GNUNET_TIME_UNIT_FOREVER_REL, lt->listen_sock, &listen_cb, lt); + } + else + GNUNET_free (lt); } @@ -1001,6 +1043,13 @@ core_read_finished_cb (void *cls, int success) "# messages lost in communicator API towards CORE", 1, GNUNET_NO); + if (NULL == queue) + return; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "backpressure %u\n", + queue->backpressure); + queue->backpressure--; /* handle deferred queue destruction */ if ((queue->destroyed) && (0 == queue->backpressure)) @@ -1008,15 +1057,18 @@ core_read_finished_cb (void *cls, int success) GNUNET_free (queue); return; } - reschedule_queue_timeout (queue); - /* possibly unchoke reading, now that CORE made progress */ - if (NULL == queue->read_task) - queue->read_task = - GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining ( - queue->timeout), - queue->sock, - &queue_read, - queue); + else if (GNUNET_YES != queue->destroyed) + { + reschedule_queue_timeout (queue); + /* possibly unchoke reading, now that CORE made progress */ + if (NULL == queue->read_task) + queue->read_task = + GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining ( + queue->timeout), + queue->sock, + &queue_read, + queue); + } } @@ -1219,13 +1271,34 @@ rekey_monotime_cb (void *cls, static void do_rekey (struct Queue *queue, const struct TCPRekey *rekey) { - struct TcpHandshakeSignature thp; + struct TcpRekeySignature thp; + thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); thp.purpose.size = htonl (sizeof(thp)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "do_rekey size %u\n", + thp.purpose.size); thp.sender = queue->target; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "sender %s\n", + GNUNET_p2s (&thp.sender.public_key)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "sender %s\n", + GNUNET_p2s (&queue->target.public_key)); thp.receiver = my_identity; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "receiver %s\n", + GNUNET_p2s (&thp.receiver.public_key)); thp.ephemeral = rekey->ephemeral; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "ephemeral %s\n", + GNUNET_e2s (&thp.ephemeral)); thp.monotonic_time = rekey->monotonic_time; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "time %s\n", + GNUNET_STRINGS_absolute_time_to_string ( + GNUNET_TIME_absolute_ntoh (thp.monotonic_time))); + GNUNET_assert (ntohl ((&thp)->purpose.size) == sizeof (*(&thp))); if (GNUNET_OK != GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY, &thp, @@ -1739,11 +1812,19 @@ extract_address (const char *bindto) char *cp; char *rest = NULL; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "extract address with bindto %s\n", + bindto); + if (NULL == bindto) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bindto is NULL\n"); cp = GNUNET_strdup (bindto); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "extract address 2\n"); + start = cp; if (('[' == *cp) && (']' == cp[strlen (cp) - 1])) { @@ -1763,7 +1844,11 @@ extract_address (const char *bindto) } } - GNUNET_free (cp); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "extract address 3\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "extract address with start %s\n", + start); return start; } @@ -1865,10 +1950,25 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) // cp = GNUNET_strdup (bindto); start = extract_address (bindto); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "start %s\n", + start); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "!bindto %s\n", + bindto); + + + if (1 == inet_pton (AF_INET, start, &v4.sin_addr)) { // colon = strrchr (cp, ':'); port = extract_port (bindto); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "port %u\n", + port); + in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port); } else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr)) @@ -1878,6 +1978,8 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port); } + // GNUNET_free (start); + return in; } @@ -1913,7 +2015,7 @@ static void inject_rekey (struct Queue *queue) { struct TCPRekey rekey; - struct TcpHandshakeSignature thp; + struct TcpRekeySignature thp; GNUNET_assert (0 == queue->pwrite_off); memset (&rekey, 0, sizeof(rekey)); @@ -1925,10 +2027,26 @@ inject_rekey (struct Queue *queue) GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); thp.purpose.size = htonl (sizeof(thp)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "inject_rekey size %u\n", + thp.purpose.size); thp.sender = my_identity; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "sender %s\n", + GNUNET_p2s (&thp.sender.public_key)); thp.receiver = queue->target; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "receiver %s\n", + GNUNET_p2s (&thp.receiver.public_key)); thp.ephemeral = rekey.ephemeral; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "ephemeral %s\n", + GNUNET_e2s (&thp.ephemeral)); thp.monotonic_time = rekey.monotonic_time; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "time %s\n", + GNUNET_STRINGS_absolute_time_to_string ( + GNUNET_TIME_absolute_ntoh (thp.monotonic_time))); GNUNET_CRYPTO_eddsa_sign (my_private_key, &thp, &rekey.sender_sig); @@ -2004,10 +2122,11 @@ queue_write (void *cls) queue->cwrite_off += queue->pwrite_off; queue->pwrite_off = 0; } - if ((0 == queue->pwrite_off) && - ((0 == queue->rekey_left_bytes) || - (0 == - GNUNET_TIME_absolute_get_remaining (queue->rekey_time).rel_value_us))) + if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) && + ((0 == queue->rekey_left_bytes) || + (0 == + GNUNET_TIME_absolute_get_remaining ( + queue->rekey_time).rel_value_us)))) { inject_rekey (queue); } @@ -2729,6 +2848,10 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) return GNUNET_SYSERR; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "in %s\n", + GNUNET_a2s (in, in_len)); + sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP); if (NULL == sock) { @@ -2794,6 +2917,11 @@ get_queue_delete_it (void *cls, (void) cls; (void) target; + if (NULL != queue->listen_task) + { + GNUNET_SCHEDULER_cancel (queue->listen_task); + queue->listen_task = NULL; + } queue_destroy (queue); return GNUNET_OK; } @@ -2807,6 +2935,12 @@ get_queue_delete_it (void *cls, static void do_shutdown (void *cls) { + + if (GNUNET_YES == shutdown_running) + return; + else + shutdown_running = GNUNET_YES; + while (NULL != proto_head) free_proto_queue (proto_head); if (NULL != nat) @@ -2836,6 +2970,16 @@ do_shutdown (void *cls) GNUNET_NT_scanner_done (is); is = NULL; } + if (NULL != peerstore) + { + GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_NO); + peerstore = NULL; + } + if (NULL != resolve_request_handle) + { + GNUNET_RESOLVER_request_cancel (resolve_request_handle); + resolve_request_handle = NULL; + } } @@ -3059,8 +3203,7 @@ nat_register () { saddr_lens[i] = addrs_head->addr_len; - saddrs[i] = GNUNET_malloc (saddr_lens[i]); - saddrs[i] = addrs_head->addr; + saddrs[i] = GNUNET_memdup (addrs_head->addr, saddr_lens[i]); i++; @@ -3078,8 +3221,8 @@ nat_register () i = 0; - /*for (i = addrs_lens - 1; i >= 0; i--) - GNUNET_free (saddrs[i]);*/ + for (i = addrs_lens - 1; i >= 0; i--) + GNUNET_free (saddrs[i]); GNUNET_free (saddrs); GNUNET_free (saddr_lens); @@ -3221,9 +3364,6 @@ run (void *cls, return; } - // cp = GNUNET_strdup (bindto); - start = extract_address (bindto); - if (1 == sscanf (bindto, "%u%1s", &port, dummy)) { po = tcp_address_to_sockaddr_port_only (bindto, &port); @@ -3248,9 +3388,16 @@ run (void *cls, add_addr (po->addr_ipv6, addr_len_ipv6); } + GNUNET_free (po); nat_register (); + GNUNET_free (bindto); + + return; } - else if (1 == inet_pton (AF_INET, start, &v4.sin_addr)) + + start = extract_address (bindto); + + if (1 == inet_pton (AF_INET, start, &v4.sin_addr)) { port = extract_port (bindto); @@ -3258,26 +3405,30 @@ run (void *cls, init_socket (in, in_len); add_addr (in, in_len); nat_register (); + GNUNET_free (bindto); + return; } - else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr)) + + if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr)) { port = extract_port (bindto); in = tcp_address_to_sockaddr_numeric_v6 (&in_len, v6, port); init_socket (in, in_len); add_addr (in, in_len); nat_register (); + GNUNET_free (bindto); + return; } - else - { - port = extract_port (bindto); - resolve_request_handle = GNUNET_RESOLVER_ip_get (strtok_r (bindto, ":", - &rest), - AF_UNSPEC, - GNUNET_TIME_UNIT_MINUTES, - &init_socket_resolv, - &port); - } + + port = extract_port (bindto); + + resolve_request_handle = GNUNET_RESOLVER_ip_get (strtok_r (bindto, ":", + &rest), + AF_UNSPEC, + GNUNET_TIME_UNIT_MINUTES, + &init_socket_resolv, + &port); GNUNET_free (bindto); } diff --git a/src/transport/test_communicator_tcp_rekey_peer2.conf b/src/transport/test_communicator_tcp_rekey_peer2.conf index 138650a3b..643b037b2 100644 --- a/src/transport/test_communicator_tcp_rekey_peer2.conf +++ b/src/transport/test_communicator_tcp_rekey_peer2.conf @@ -31,10 +31,10 @@ UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_2.sock UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_2.sock [communicator-tcp] -#PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args +#PREFIX = xterm -geometry 100x85 -T peer2 -e gdb --args #PREFIX = valgrind --leak-check=full --track-origins=yes BINDTO = 60003 -DISABLE_V6 = YES +DISABLE_V6 = NO REKEY_INTERVAL = 100ms [communicator-udp] diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c index 10b064241..0c85660dd 100644 --- a/src/transport/transport-testing2.c +++ b/src/transport/transport-testing2.c @@ -939,8 +939,7 @@ communicator_start ( binary = GNUNET_OS_get_libexec_binary_path (binary_name); - tc_h->c_proc = GNUNET_OS_start_process_s (GNUNET_YES, - GNUNET_OS_INHERIT_STD_OUT_AND_ERR, + tc_h->c_proc = GNUNET_OS_start_process_s (GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, loprefix, binary, @@ -1026,8 +1025,10 @@ peerstore_start ( LOG (GNUNET_ERROR_TYPE_DEBUG, "peerstore_start\n"); binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-peerstore"); - tc_h->ps_proc = GNUNET_OS_start_process (GNUNET_YES, - GNUNET_OS_INHERIT_STD_OUT_AND_ERR, + LOG (GNUNET_ERROR_TYPE_DEBUG, "peerstore_start binary %s\n", + binary); + LOG (GNUNET_ERROR_TYPE_DEBUG, "peerstore_start 2\n"); + tc_h->ps_proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, NULL, @@ -1036,6 +1037,7 @@ peerstore_start ( "-c", tc_h->cfg_filename, NULL); + LOG (GNUNET_ERROR_TYPE_DEBUG, "peerstore_start 3\n"); if (NULL == tc_h->ps_proc) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start Peerstore!"); @@ -1057,6 +1059,8 @@ nat_start ( LOG (GNUNET_ERROR_TYPE_DEBUG, "nat_start\n"); binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-nat"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "nat_start binary %s\n", + binary); tc_h->nat_proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_OUT_AND_ERR | GNUNET_OS_USE_PIPE_CONTROL, NULL, @@ -1154,6 +1158,8 @@ void GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop ( struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "transport communicator service stop\n"); shutdown_communicator (tc_h->c_proc); shutdown_service (tc_h->sh); shutdown_nat (tc_h->nat_proc); -- cgit v1.2.3 From 03f6a0233f72c2c4c3925f0d6f6f7a81987c6530 Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Fri, 28 Aug 2020 08:20:57 +0200 Subject: - fixed some bugs --- src/transport/gnunet-communicator-tcp.c | 109 ++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 39 deletions(-) diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index df1bdc410..1783edb91 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c @@ -835,6 +835,11 @@ static struct GNUNET_PEERSTORE_Handle *peerstore; */ int shutdown_running = GNUNET_NO; +/** + * The port the communicator should be assigned to. + */ +unsigned int bind_port; + /** * We have been notified that our listen socket has something to * read. Do the read and reschedule this function to be called again @@ -856,7 +861,6 @@ listen_cb (void *cls); static void queue_destroy (struct Queue *queue) { - struct GNUNET_MQ_Handle *mq; struct ListenTask *lt; lt = GNUNET_new (struct ListenTask); lt->listen_sock = queue->listen_sock; @@ -1432,7 +1436,7 @@ try_handle_plaintext (struct Queue *queue) if ((-1 != unverified_size) && (unverified_size > INITIAL_CORE_KX_SIZE)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Already received data of size %u bigger than KX size %u!\n", + "Already received data of size %lu bigger than KX size %lu!\n", unverified_size, INITIAL_CORE_KX_SIZE); GNUNET_break_op (0); @@ -1709,6 +1713,8 @@ tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len, struct sockaddr_in6 v6, #if HAVE_SOCKADDR_IN_SIN_LEN v6.sin6_len = sizeof(sizeof(struct sockaddr_in6)); #endif + v6.sin6_flowinfo = 0; + v6.sin6_scope_id = 0; in = GNUNET_memdup (&v6, sizeof(v6)); *sock_len = sizeof(struct sockaddr_in6); @@ -1976,6 +1982,8 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) // colon = strrchr (cp, ':'); port = extract_port (bindto); in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port); + }else{ + GNUNET_assert (0); } // GNUNET_free (start); @@ -2826,7 +2834,7 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) struct Queue *queue; const char *path; struct sockaddr *in; - socklen_t in_len; + socklen_t in_len = 0; struct GNUNET_NETWORK_Handle *sock; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -3030,6 +3038,10 @@ nat_address_cb (void *cls, char *my_addr; struct GNUNET_TRANSPORT_AddressIdentifier *ai; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "nat address cb %s\n", + GNUNET_a2s (addr, addrlen)); + if (GNUNET_YES == add_remove) { enum GNUNET_NetworkType nt; @@ -3055,6 +3067,35 @@ nat_address_cb (void *cls, } } +/** + * This method adds addresses to the DLL, that are later register at the NAT service. + */ +static void +add_addr (struct sockaddr *in, socklen_t in_len) +{ + + struct Addresses *saddrs; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "add address %s\n", + GNUNET_a2s (in, in_len)); + + saddrs = GNUNET_new (struct Addresses); + saddrs->addr = in; + saddrs->addr_len = in_len; + GNUNET_CONTAINER_DLL_insert (addrs_head, addrs_tail, saddrs); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "after add address %s\n", + GNUNET_a2s (in, in_len)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "add address %s\n", + GNUNET_a2s (saddrs->addr, saddrs->addr_len)); + + addrs_lens++; +} + /** * This method launch network interactions for each address we like to bind to. * @@ -3063,7 +3104,7 @@ nat_address_cb (void *cls, * @return GNUNET_SYSERR in case of error. GNUNET_OK in case we are successfully listen to the address. */ static int -init_socket (const struct sockaddr *addr, +init_socket (struct sockaddr *addr, socklen_t in_len) { struct sockaddr_storage in_sto; @@ -3178,6 +3219,7 @@ init_socket (const struct sockaddr *addr, return GNUNET_SYSERR; } + add_addr (addr, in_len); return GNUNET_OK; } @@ -3194,6 +3236,10 @@ nat_register () int i; struct Addresses *pos; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "starting nat register!\n"); + i = 0; saddrs = GNUNET_malloc ((addrs_lens + 1) * sizeof(struct sockaddr *)); @@ -3202,6 +3248,10 @@ nat_register () for (pos = addrs_head; NULL != pos; pos = pos->next) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "registering address %s\n", + GNUNET_a2s (addrs_head->addr, addrs_head->addr_len)); + saddr_lens[i] = addrs_head->addr_len; saddrs[i] = GNUNET_memdup (addrs_head->addr, saddr_lens[i]); @@ -3235,22 +3285,6 @@ nat_register () } } -/** - * This method adds addresses to the DLL, that are later register at the NAT service. - */ -static void -add_addr (struct sockaddr *in, socklen_t in_len) -{ - - struct Addresses *saddrs; - - saddrs = GNUNET_new (struct Addresses); - saddrs->addr = in; - saddrs->addr_len = in_len; - GNUNET_CONTAINER_DLL_insert (addrs_head, addrs_tail, saddrs); - addrs_lens++; -} - /** * This method is the callback called by the resolver API, and wraps method init_socket. * @@ -3266,22 +3300,19 @@ init_socket_resolv (void *cls, struct sockaddr_in *v4; struct sockaddr_in6 *v6; struct sockaddr *in; - unsigned int *port; - port = cls; + (void) cls; if (NULL != addr) { if (AF_INET == addr->sa_family) { v4 = (struct sockaddr_in *) addr; - in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, *port);// _global); - add_addr (in, in_len); + in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, bind_port);// _global); } else if (AF_INET6 == addr->sa_family) { v6 = (struct sockaddr_in6 *) addr; - in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, *port);// _global); - add_addr (in, in_len); + in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, bind_port);// _global); } else { @@ -3292,13 +3323,17 @@ init_socket_resolv (void *cls, AF_INET6); return; } - init_socket (in, - in_len); + init_socket (in, in_len); } else { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Address is NULL. This might be an error or the resolver finished resolving.\n"); + if (NULL == addrs_head){ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Resolver finished resolving, but we do not listen to an address!.\n"); + return; + } nat_register (); } } @@ -3364,9 +3399,9 @@ run (void *cls, return; } - if (1 == sscanf (bindto, "%u%1s", &port, dummy)) + if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy)) { - po = tcp_address_to_sockaddr_port_only (bindto, &port); + po = tcp_address_to_sockaddr_port_only (bindto, &bind_port); addr_len_ipv4 = po->addr_len_ipv4; @@ -3378,14 +3413,12 @@ run (void *cls, if (NULL != po->addr_ipv4) { init_socket (po->addr_ipv4, addr_len_ipv4); - add_addr (po->addr_ipv4, addr_len_ipv4); } if (NULL != po->addr_ipv6) { addr_len_ipv6 = po->addr_len_ipv6; init_socket (po->addr_ipv6, addr_len_ipv6); - add_addr (po->addr_ipv6, addr_len_ipv6); } GNUNET_free (po); @@ -3399,11 +3432,10 @@ run (void *cls, if (1 == inet_pton (AF_INET, start, &v4.sin_addr)) { - port = extract_port (bindto); + bind_port = extract_port (bindto); - in = tcp_address_to_sockaddr_numeric_v4 (&in_len, v4, port); + in = tcp_address_to_sockaddr_numeric_v4 (&in_len, v4, bind_port); init_socket (in, in_len); - add_addr (in, in_len); nat_register (); GNUNET_free (bindto); return; @@ -3411,17 +3443,16 @@ run (void *cls, if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr)) { - port = extract_port (bindto); - in = tcp_address_to_sockaddr_numeric_v6 (&in_len, v6, port); + bind_port = extract_port (bindto); + in = tcp_address_to_sockaddr_numeric_v6 (&in_len, v6, bind_port); init_socket (in, in_len); - add_addr (in, in_len); nat_register (); GNUNET_free (bindto); return; } - port = extract_port (bindto); + bind_port = extract_port (bindto); resolve_request_handle = GNUNET_RESOLVER_ip_get (strtok_r (bindto, ":", &rest), -- cgit v1.2.3 From 72cb328c689aacf5a20a0107e5762c1749ea2886 Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Fri, 28 Aug 2020 18:01:10 +0200 Subject: - fixed some bugs --- src/include/gnunet_transport_communication_service.h | 8 ++++++++ src/transport/gnunet-communicator-tcp.c | 12 +++++++++--- src/transport/transport_api2_communication.c | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/include/gnunet_transport_communication_service.h b/src/include/gnunet_transport_communication_service.h index ea6b95e2d..431b9a671 100644 --- a/src/include/gnunet_transport_communication_service.h +++ b/src/include/gnunet_transport_communication_service.h @@ -336,6 +336,14 @@ void GNUNET_TRANSPORT_communicator_address_remove ( struct GNUNET_TRANSPORT_AddressIdentifier *ai); +/** + * Notify transport service that this communicator no longer provides all its addresses for this peer. + * + * @param ch The communicator handle. + */ +void +GNUNET_TRANSPORT_communicator_address_remove_all ( + struct GNUNET_TRANSPORT_CommunicatorHandle *ch); /** * The communicator asks the transport service to route a message via diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index 1783edb91..4caef909c 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c @@ -2944,6 +2944,10 @@ static void do_shutdown (void *cls) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Shutdown %s!\n", + shutdown_running ? "running" : "not running"); + if (GNUNET_YES == shutdown_running) return; else @@ -2958,6 +2962,7 @@ do_shutdown (void *cls) } GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL); GNUNET_CONTAINER_multipeermap_destroy (queue_map); + GNUNET_TRANSPORT_communicator_address_remove_all (ch); if (NULL != ch) { GNUNET_TRANSPORT_communicator_disconnect (ch); @@ -3038,8 +3043,9 @@ nat_address_cb (void *cls, char *my_addr; struct GNUNET_TRANSPORT_AddressIdentifier *ai; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "nat address cb %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "nat address cb %s %s\n", + add_remove ? "add" : "remove", GNUNET_a2s (addr, addrlen)); if (GNUNET_YES == add_remove) @@ -3162,7 +3168,7 @@ init_socket (struct sockaddr *addr, sto_len = in_len; } - addr = (struct sockaddr *) &in_sto; + //addr = (struct sockaddr *) &in_sto; in_len = sto_len; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c index d1e28cc36..b048ad851 100644 --- a/src/transport/transport_api2_communication.c +++ b/src/transport/transport_api2_communication.c @@ -1081,7 +1081,6 @@ GNUNET_TRANSPORT_communicator_address_add ( return ai; } - /** * Notify transport service about an address that this communicator no * longer provides for this peer. @@ -1100,6 +1099,20 @@ GNUNET_TRANSPORT_communicator_address_remove ( GNUNET_free (ai); } +/** + * Notify transport service that this communicator no longer provides all its addresses for this peer. + * + * @param ch The communicator handle. + */ +void +GNUNET_TRANSPORT_communicator_address_remove_all ( + struct GNUNET_TRANSPORT_CommunicatorHandle *ch) +{ + for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai; + ai = ai->next) + GNUNET_TRANSPORT_communicator_address_remove (ai); +} + /* ************************* Backchannel *************************** */ -- cgit v1.2.3 From f7fc952898b73753dd5d0d0657db85f5290486cc Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Wed, 2 Sep 2020 13:26:48 +0200 Subject: - run the tng test test_communicator_basic-tcp in buildbot CI --- .buildbot/firefly-x86_64-amdepyc_test.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.buildbot/firefly-x86_64-amdepyc_test.sh b/.buildbot/firefly-x86_64-amdepyc_test.sh index db202a112..8949ddc0c 100755 --- a/.buildbot/firefly-x86_64-amdepyc_test.sh +++ b/.buildbot/firefly-x86_64-amdepyc_test.sh @@ -1,3 +1,7 @@ #!/bin/bash -echo "Skipped" +# echo "Skipped" + +pushd src/transport +make check TESTS='test_communicator_basic-tcp' +popd -- cgit v1.2.3 From 78ae71345ff48b10c264fd100b9d2b1003c442d8 Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Wed, 2 Sep 2020 14:23:14 +0200 Subject: - add content of test-suite.log to buildbot output after running test --- .buildbot/firefly-x86_64-amdepyc_test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.buildbot/firefly-x86_64-amdepyc_test.sh b/.buildbot/firefly-x86_64-amdepyc_test.sh index 8949ddc0c..ef1401734 100755 --- a/.buildbot/firefly-x86_64-amdepyc_test.sh +++ b/.buildbot/firefly-x86_64-amdepyc_test.sh @@ -4,4 +4,5 @@ pushd src/transport make check TESTS='test_communicator_basic-tcp' +cat src/transport/test-suite.log popd -- cgit v1.2.3 From 03c26ccd4c23a7854e4e6290aa4c34e487471771 Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Wed, 2 Sep 2020 15:07:33 +0200 Subject: - killing all gnunet processes still running after running the test --- .buildbot/firefly-x86_64-amdepyc_test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.buildbot/firefly-x86_64-amdepyc_test.sh b/.buildbot/firefly-x86_64-amdepyc_test.sh index ef1401734..626bf91f4 100755 --- a/.buildbot/firefly-x86_64-amdepyc_test.sh +++ b/.buildbot/firefly-x86_64-amdepyc_test.sh @@ -5,4 +5,5 @@ pushd src/transport make check TESTS='test_communicator_basic-tcp' cat src/transport/test-suite.log +pkill --signal 9 -U buildbot gnunet popd -- cgit v1.2.3 From 95f0adbc3c9f56ee94852da8e2a7ab276db79474 Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Wed, 2 Sep 2020 15:26:19 +0200 Subject: - wrong path --- .buildbot/firefly-x86_64-amdepyc_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildbot/firefly-x86_64-amdepyc_test.sh b/.buildbot/firefly-x86_64-amdepyc_test.sh index 626bf91f4..cef0c0cdb 100755 --- a/.buildbot/firefly-x86_64-amdepyc_test.sh +++ b/.buildbot/firefly-x86_64-amdepyc_test.sh @@ -4,6 +4,6 @@ pushd src/transport make check TESTS='test_communicator_basic-tcp' -cat src/transport/test-suite.log +cat test-suite.log pkill --signal 9 -U buildbot gnunet popd -- cgit v1.2.3 From 2c797708b38729effe82328484d67a2be02412ed Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Wed, 2 Sep 2020 16:22:21 +0200 Subject: - added second make check, because there is still an issue with second communnicator process not finishing correctly. --- .buildbot/firefly-x86_64-amdepyc_test.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.buildbot/firefly-x86_64-amdepyc_test.sh b/.buildbot/firefly-x86_64-amdepyc_test.sh index cef0c0cdb..d665d3a7c 100755 --- a/.buildbot/firefly-x86_64-amdepyc_test.sh +++ b/.buildbot/firefly-x86_64-amdepyc_test.sh @@ -5,5 +5,7 @@ pushd src/transport make check TESTS='test_communicator_basic-tcp' cat test-suite.log -pkill --signal 9 -U buildbot gnunet +pkill --signal 9 -U buildbot gnunet +make check TESTS='test_communicator_rekey-tcp' +pkill --signal 9 -U buildbot gnunet popd -- cgit v1.2.3 From 3ec73fc6825c6a0bd2a51364f8f8849245c89e25 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Wed, 2 Sep 2020 19:26:37 +0200 Subject: gnunet-qr/uri: Fix exit code handling; fix memory corruption --- src/util/gnunet-qr.c | 7 +++++-- src/util/gnunet-uri.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/util/gnunet-qr.c b/src/util/gnunet-qr.c index 83b2af2fc..451d61d40 100644 --- a/src/util/gnunet-qr.c +++ b/src/util/gnunet-qr.c @@ -36,7 +36,7 @@ /** * Video device to capture from. Sane default for GNU/Linux systems. */ -static char *device = "/dev/video0"; +static char *device; /** * --verbose option @@ -51,7 +51,7 @@ static int silent = false; /** * Handler exit code */ -static long unsigned int exit_code = 1; +static long unsigned int exit_code = 0; /** * Helper process we started. @@ -228,6 +228,8 @@ get_symbol (zbar_processor_t *proc) } /* initialize the Processor */ + if (NULL == device) + device = GNUNET_strdup ("/dev/video0"); if (0 != (rc = zbar_processor_init (proc, device, 1))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -306,6 +308,7 @@ run_zbar () ret = GNUNET_strdup (data); /* clean up */ zbar_processor_destroy (proc); + GNUNET_free (device); return ret; } diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c index 9443c9120..de0ff1f92 100644 --- a/src/util/gnunet-uri.c +++ b/src/util/gnunet-uri.c @@ -29,7 +29,7 @@ /** * Handler exit code */ -static long unsigned int exit_code = 1; +static long unsigned int exit_code = 0; /** * Helper process we started. -- cgit v1.2.3 From 538277ed86693dcd8b7edc7f53d197709b65390a Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Fri, 4 Sep 2020 04:07:46 +0200 Subject: reclaim: fix cli parameter name for credential ID --- src/reclaim/gnunet-reclaim.c | 2 +- src/reclaim/plugin_reclaim_credential_jwt.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c index ab281a645..b9306b802 100644 --- a/src/reclaim/gnunet-reclaim.c +++ b/src/reclaim/gnunet-reclaim.c @@ -862,7 +862,7 @@ main (int argc, char *const argv[]) gettext_noop ("List credentials for EGO"), &list_credentials), GNUNET_GETOPT_option_string ('I', - "Credential ID", + "credential-id", "CREDENTIAL_ID", gettext_noop ( "Credential to use for attribute"), diff --git a/src/reclaim/plugin_reclaim_credential_jwt.c b/src/reclaim/plugin_reclaim_credential_jwt.c index 148865223..6f52f3a4e 100644 --- a/src/reclaim/plugin_reclaim_credential_jwt.c +++ b/src/reclaim/plugin_reclaim_credential_jwt.c @@ -177,6 +177,8 @@ jwt_parse_attributes (void *cls, json_object_foreach (json_val, key, value) { if (0 == strcmp ("iss", key)) continue; + if (0 == strcmp ("jti", key)) + continue; if (0 == strcmp ("exp", key)) continue; if (0 == strcmp ("iat", key)) -- cgit v1.2.3 From 35d7c1f88785f12547ca6081780b8780f29602ba Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Fri, 4 Sep 2020 20:12:00 +0200 Subject: fix: depend on libsodium >=1.0.17. Fixes #6506 --- configure.ac | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index bd92bd0e9..75e11bd4f 100644 --- a/configure.ac +++ b/configure.ac @@ -1036,9 +1036,10 @@ AC_CHECK_LIB([kvm],[kvm_open]) AC_CHECK_LIB([kstat],[kstat_open]) libsodium=0 -# test for libsodium +# test for libsodium >=1.017 (introduction of +# crypto_scalarmult_ed25519_base_noclamp API) AC_CHECK_HEADER([sodium.h], - [AC_CHECK_LIB([sodium], [crypto_pwhash_argon2id], + [AC_CHECK_LIB([sodium], [crypto_scalarmult_ed25519_base_noclamp], [libsodium=1])]) AS_IF([test x$libsodium = x0], -- cgit v1.2.3 From 6a451abb42176d85e53f37522584f6c4dcdaeaad Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Fri, 4 Sep 2020 20:12:27 +0200 Subject: - update readme for dependency change --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index d95022de2..e6ba9c07e 100644 --- a/README +++ b/README @@ -96,7 +96,7 @@ These are the direct dependencies for running GNUnet: - which (contrib/apparmor(?), gnunet-bugreport, and possibly more) - zlib -- libsodium >= 1.0.11 (for elliptic curve cryptography) +- libsodium >= 1.0.17 (for elliptic curve cryptography) These are the dependencies for GNUnet's testsuite: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.2.3 From b87f7ec22fdf8a0e88d8ec31d009d11701599872 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Sat, 5 Sep 2020 19:18:52 +0200 Subject: - fix gns proxy test API changes --- src/gns/test_gns_proxy.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/gns/test_gns_proxy.c b/src/gns/test_gns_proxy.c index 13764d520..579de774f 100644 --- a/src/gns/test_gns_proxy.c +++ b/src/gns/test_gns_proxy.c @@ -189,7 +189,7 @@ copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx) } -static int +static enum MHD_Result mhd_ahc (void *cls, struct MHD_Connection *connection, const char *url, @@ -528,8 +528,6 @@ run (void *cls, int main (int argc, char *const *argv) { - char *tmp_argv; - struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_option_uint16 ('p', "port", @@ -559,7 +557,7 @@ main (int argc, char *const *argv) } if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, - &argc, &tmp_argv)) + &argc, &argv)) return 2; GNUNET_log_setup ("gnunet-gns-proxy-test", "WARNING", @@ -570,7 +568,7 @@ main (int argc, char *const *argv) options, &run, NULL)) return 1; - GNUNET_free (tmp_argv); + GNUNET_free_nz ((void*) argv); return global_ret; } -- cgit v1.2.3 From ac165b5babe8a0fb77177aafc9990abefb053c0f Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Sat, 5 Sep 2020 19:49:14 +0200 Subject: - add some dummy test_setu.conf --- src/setu/test_setu.conf | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/setu/test_setu.conf diff --git a/src/setu/test_setu.conf b/src/setu/test_setu.conf new file mode 100644 index 000000000..4eaf3f0c0 --- /dev/null +++ b/src/setu/test_setu.conf @@ -0,0 +1,32 @@ +@INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf + +[PATHS] +GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-set/ + +[setu] +START_ON_DEMAND = YES +#PREFIX = valgrind --leak-check=full +#PREFIX = gdbserver :1234 +OPTIONS = -L INFO + +[transport] +PLUGINS = unix +OPTIONS = -LERROR + +[nat] +RETURN_LOCAL_ADDRESSES = YES +DISABLEV6 = YES +USE_LOCALADDR = YES + +[peerinfo] +NO_IO = YES + +[nat] +# Use addresses from the local network interfaces (inluding loopback, but also others) +USE_LOCALADDR = YES + +# Disable IPv6 support +DISABLEV6 = NO + +# Do we use addresses from localhost address ranges? (::1, 127.0.0.0/8) +RETURN_LOCAL_ADDRESSES = YES -- cgit v1.2.3