Skip to content

signal-cli broken (ipv6 issue?)

$ torsocks -d ./signal-cli link
...
1652748828 DEBUG torsocks[3430431]: [getaddrinfo] Node chat.signal.org resolved to 76.223.92.165 (in tsocks_getaddrinfo() at getaddrinfo.c:107)
...
1652748828 DEBUG torsocks[3430431]: Connect caught on fd 35 (in tsocks_connect() at connect.c:118)
1652748828 DEBUG torsocks[3430431]: [connect] Socket family AF_INET6 and type 1 (in tsocks_validate_socket() at connect.c:76)
1652748828 DEBUG torsocks[3430431]: Connecting to the Tor network on fd 35 (in tsocks_connect_to_tor() at torsocks.c:473)
1652748828 DEBUG torsocks[3430431]: Setting up a connection to the Tor network on fd 35 (in setup_tor_connection() at torsocks.c:368)
1652748828 PERROR torsocks[3430431]: socks5 libc connect: Invalid argument (in socks5_connect() at socks5.c:202)
1652748828 DEBUG torsocks[3430431]: [close] Close caught for fd 35 (in tsocks_close() at close.c:33)
Link request error: Connection closed!
1652748828 DEBUG torsocks[3430431]: [onion] Destroying onion pool containing 0 entry (in onion_pool_destroy() at onion.c:148)

It appears to get a v4 address, and subsequently create a v6 socket.

Inside socks5_connect it chooses the address type based on the single immutable configured address type to the local tor daemon, instead of the address type of the socket/connection, which seems wrong. On my machine it tries to connect to the local v4 address using the v6 socket, which I assume is why it's failing.

I tried hacking it up to choose the protocol family to match the connection instead of the configuration, and hard-coded the ipv6 loopback address to my local tor daemon, but that's not working either.

diff --git a/src/common/socks5.c b/src/common/socks5.c
index 9f7853b..e9676bd 100644
--- a/src/common/socks5.c
+++ b/src/common/socks5.c
@@ -19,6 +19,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <inttypes.h>
+#include <signal.h>
 #include <stdlib.h>
 
 #include <lib/torsocks.h>
@@ -160,23 +161,35 @@ int socks5_connect(struct connection *conn)
        assert(conn);
        assert(conn->fd >= 0);
 
+       struct sockaddr_in6 sin6 = {
+               .sin6_family = AF_INET6,
+               .sin6_port = 9050,
+               .sin6_addr = IN6ADDR_LOOPBACK_INIT,
+       };
+
        /*
         * We use the connection domain here since the connect() call MUST match
         * the right socket family. Thus, trying to establish a connection to a
         * remote IPv6, we have to connect to the Tor daemon in v6.
         */
-       switch (tsocks_config.socks5_addr.domain) {
+       DBG("conn.domain:%d config.domain:%d", conn->dest_addr.domain, tsocks_config.socks5_addr.domain);
+       //switch (tsocks_config.socks5_addr.domain) {
+       switch (conn->dest_addr.domain) {
        case CONNECTION_DOMAIN_NAME:
+               DBG("domainname");
                /*
                 * For a domain name such as an onion address, use the default IPv4 to
                 * connect to the Tor SOCKS port.
                 */
        case CONNECTION_DOMAIN_INET:
+               DBG("ipv4");
                socks5_addr = (struct sockaddr *) &tsocks_config.socks5_addr.u.sin;
                len = sizeof(tsocks_config.socks5_addr.u.sin);
                break;
        case CONNECTION_DOMAIN_INET6:
-               socks5_addr = (struct sockaddr *) &tsocks_config.socks5_addr.u.sin6;
+               DBG("ipv6");
+               //socks5_addr = (struct sockaddr *) &tsocks_config.socks5_addr.u.sin6;
+               socks5_addr = &sin6;
                len = sizeof(tsocks_config.socks5_addr.u.sin6);
                break;
        default:
...
1652749541 DEBUG torsocks[3433257]: conn.domain:2 config.domain:1 (in socks5_connect() at socks5.c:175)
1652749541 DEBUG torsocks[3433257]: ipv6 (in socks5_connect() at socks5.c:190)
1652749541 PERROR torsocks[3433257]: socks5 libc connect: Connection refused (in socks5_connect() at socks5.c:216)
1652749541 DEBUG torsocks[3433257]: [close] Close caught for fd 35 (in tsocks_close() at close.c:33)
Link request error: Connection closed!
1652749541 DEBUG torsocks[3433257]: [fclose] Close caught for fd 35 (in tsocks_fclose() at fclose.c:45)
1652749541 DEBUG torsocks[3433257]: [fclose] Close caught for fd 35 (in tsocks_fclose() at fclose.c:45)
1652749541 DEBUG torsocks[3433257]: [onion] Destroying onion pool containing 0 entry (in onion_pool_destroy() at onion.c:148)
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information