Skip to content

Commit 873a45f

Browse files
committed
Merge bitcoin/bitcoin#32200: net: Add Tor extended SOCKS5 error codes
b639417 net: Add Tor extended SOCKS5 error codes (laanwj) Pull request description: Add support for reporting Tor extended SOCKS5 error codes as defined here: - https://spec.torproject.org/socks-extensions.html#extended-error-codes - https://gitlab.torproject.org/tpo/core/arti/-/blob/main/crates/tor-socksproto/src/msg.rs?ref_type=heads#L183 These give a more direct indication of the problem in case of errors connecting to hidden services, for example: ``` 2025-04-02T10:34:13Z [net] Socks5() connect to [elided].onion:8333 failed: onion service descriptor can not be found ``` In the C Tor implementation, to get these one should set the "ExtendedErrors" flag on the "SocksPort" definition, introduced in version 0.4.3.1. In Arti, extended error codes are always enabled. Also, report the raw error code in case of unknown reply values. ACKs for top commit: 1440000bytes: utACK bitcoin/bitcoin@b639417 w0xlt: utACK bitcoin/bitcoin@b639417 pablomartin4btc: utACK b639417 Tree-SHA512: b30e65cb0f5c9183701373b0ee64cdec40680a3de1a1a365b006538c4d0b7ca8a047d7c6f81a7f5b8a36bae3a20b47a4c2a9850423c7034866e3837fa8fdbfe2
2 parents 8d2ead2 + b639417 commit 873a45f

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

src/netbase.cpp

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,25 @@ enum SOCKS5Command: uint8_t {
266266
UDP_ASSOCIATE = 0x03
267267
};
268268

269-
/** Values defined for REP in RFC1928 */
269+
/** Values defined for REP in RFC1928 and https://spec.torproject.org/socks-extensions.html */
270270
enum SOCKS5Reply: uint8_t {
271-
SUCCEEDED = 0x00, //!< Succeeded
272-
GENFAILURE = 0x01, //!< General failure
273-
NOTALLOWED = 0x02, //!< Connection not allowed by ruleset
274-
NETUNREACHABLE = 0x03, //!< Network unreachable
275-
HOSTUNREACHABLE = 0x04, //!< Network unreachable
276-
CONNREFUSED = 0x05, //!< Connection refused
277-
TTLEXPIRED = 0x06, //!< TTL expired
278-
CMDUNSUPPORTED = 0x07, //!< Command not supported
279-
ATYPEUNSUPPORTED = 0x08, //!< Address type not supported
271+
SUCCEEDED = 0x00, //!< RFC1928: Succeeded
272+
GENFAILURE = 0x01, //!< RFC1928: General failure
273+
NOTALLOWED = 0x02, //!< RFC1928: Connection not allowed by ruleset
274+
NETUNREACHABLE = 0x03, //!< RFC1928: Network unreachable
275+
HOSTUNREACHABLE = 0x04, //!< RFC1928: Network unreachable
276+
CONNREFUSED = 0x05, //!< RFC1928: Connection refused
277+
TTLEXPIRED = 0x06, //!< RFC1928: TTL expired
278+
CMDUNSUPPORTED = 0x07, //!< RFC1928: Command not supported
279+
ATYPEUNSUPPORTED = 0x08, //!< RFC1928: Address type not supported
280+
TOR_HS_DESC_NOT_FOUND = 0xf0, //!< Tor: Onion service descriptor can not be found
281+
TOR_HS_DESC_INVALID = 0xf1, //!< Tor: Onion service descriptor is invalid
282+
TOR_HS_INTRO_FAILED = 0xf2, //!< Tor: Onion service introduction failed
283+
TOR_HS_REND_FAILED = 0xf3, //!< Tor: Onion service rendezvous failed
284+
TOR_HS_MISSING_CLIENT_AUTH = 0xf4, //!< Tor: Onion service missing client authorization
285+
TOR_HS_WRONG_CLIENT_AUTH = 0xf5, //!< Tor: Onion service wrong client authorization
286+
TOR_HS_BAD_ADDRESS = 0xf6, //!< Tor: Onion service invalid address
287+
TOR_HS_INTRO_TIMEOUT = 0xf7, //!< Tor: Onion service introduction timed out
280288
};
281289

282290
/** Values defined for ATYPE in RFC1928 */
@@ -364,8 +372,24 @@ static std::string Socks5ErrorString(uint8_t err)
364372
return "protocol error";
365373
case SOCKS5Reply::ATYPEUNSUPPORTED:
366374
return "address type not supported";
375+
case SOCKS5Reply::TOR_HS_DESC_NOT_FOUND:
376+
return "onion service descriptor can not be found";
377+
case SOCKS5Reply::TOR_HS_DESC_INVALID:
378+
return "onion service descriptor is invalid";
379+
case SOCKS5Reply::TOR_HS_INTRO_FAILED:
380+
return "onion service introduction failed";
381+
case SOCKS5Reply::TOR_HS_REND_FAILED:
382+
return "onion service rendezvous failed";
383+
case SOCKS5Reply::TOR_HS_MISSING_CLIENT_AUTH:
384+
return "onion service missing client authorization";
385+
case SOCKS5Reply::TOR_HS_WRONG_CLIENT_AUTH:
386+
return "onion service wrong client authorization";
387+
case SOCKS5Reply::TOR_HS_BAD_ADDRESS:
388+
return "onion service invalid address";
389+
case SOCKS5Reply::TOR_HS_INTRO_TIMEOUT:
390+
return "onion service introduction timed out";
367391
default:
368-
return "unknown";
392+
return strprintf("unknown (0x%02x)", err);
369393
}
370394
}
371395

0 commit comments

Comments
 (0)