![]() |
Bitcoin Core 31.99.0
P2P Digital Currency
|
#include <torcontrol.h>#include <chainparams.h>#include <chainparamsbase.h>#include <common/args.h>#include <compat/compat.h>#include <crypto/hmac_sha256.h>#include <logging.h>#include <net.h>#include <netaddress.h>#include <netbase.h>#include <random.h>#include <tinyformat.h>#include <util/check.h>#include <util/fs.h>#include <util/readwritefile.h>#include <util/strencodings.h>#include <util/string.h>#include <util/thread.h>#include <util/time.h>#include <algorithm>#include <cassert>#include <chrono>#include <cstdint>#include <cstdlib>#include <deque>#include <functional>#include <map>#include <optional>#include <set>#include <thread>#include <utility>#include <vector>Go to the source code of this file.
Functions | |
| std::pair< std::string, std::string > | SplitTorReplyLine (const std::string &s) |
| std::map< std::string, std::string > | ParseTorReplyMapping (const std::string &s) |
| Parse reply arguments in the form 'METHODS=COOKIE,SAFECOOKIE COOKIEFILE=".../control_auth_cookie"'. More... | |
| static std::string | MakeAddOnionCmd (const std::string &private_key, const std::string &target, bool enable_pow) |
| static std::vector< uint8_t > | ComputeResponse (std::string_view key, std::span< const uint8_t > cookie, std::span< const uint8_t > client_nonce, std::span< const uint8_t > server_nonce) |
| Compute Tor SAFECOOKIE response. More... | |
| CService | DefaultOnionServiceTarget (uint16_t port) |
Variables | |
| const std::string | DEFAULT_TOR_CONTROL = "127.0.0.1:" + ToString(DEFAULT_TOR_CONTROL_PORT) |
| Default control ip and port. More... | |
| constexpr int | TOR_COOKIE_SIZE = 32 |
| Tor cookie size (from control-spec.txt) More... | |
| constexpr int | TOR_NONCE_SIZE = 32 |
| Size of client/server nonce for SAFECOOKIE. More... | |
| static const std::string | TOR_SAFE_SERVERKEY = "Tor safe cookie authentication server-to-controller hash" |
| For computing server_hash in SAFECOOKIE. More... | |
| static const std::string | TOR_SAFE_CLIENTKEY = "Tor safe cookie authentication controller-to-server hash" |
| For computing clientHash in SAFECOOKIE. More... | |
| constexpr std::chrono::duration< double > | RECONNECT_TIMEOUT_START {1.0} |
| Exponential backoff configuration - initial timeout in seconds. More... | |
| constexpr double | RECONNECT_TIMEOUT_EXP = 1.5 |
| Exponential backoff configuration - growth factor. More... | |
| constexpr std::chrono::duration< double > | RECONNECT_TIMEOUT_MAX {600.0} |
| Maximum reconnect timeout in seconds to prevent excessive delays. More... | |
| constexpr int | MAX_LINE_LENGTH = 100000 |
| Maximum length for lines received on TorControlConnection. More... | |
| constexpr auto | SOCKET_SEND_TIMEOUT = 10s |
| Timeout for socket operations. More... | |
|
static |
Compute Tor SAFECOOKIE response.
ServerHash is computed as: HMAC-SHA256("Tor safe cookie authentication server-to-controller hash", CookieString | ClientNonce | ServerNonce) (with the HMAC key as its first argument)
After a controller sends a successful AUTHCHALLENGE command, the next command sent on the connection must be an AUTHENTICATE command, and the only authentication string which that AUTHENTICATE command will accept is:
HMAC-SHA256("Tor safe cookie authentication controller-to-server hash", CookieString | ClientNonce | ServerNonce)
Definition at line 590 of file torcontrol.cpp.
| CService DefaultOnionServiceTarget | ( | uint16_t | port | ) |
Definition at line 742 of file torcontrol.cpp.
|
static |
Definition at line 498 of file torcontrol.cpp.
| std::map< std::string, std::string > ParseTorReplyMapping | ( | const std::string & | s | ) |
Parse reply arguments in the form 'METHODS=COOKIE,SAFECOOKIE COOKIEFILE=".../control_auth_cookie"'.
Returns a map of keys to values, or an empty map if there was an error. Grammar is implicitly defined in https://spec.torproject.org/control-spec by the server reply formats for PROTOCOLINFO (S3.21), AUTHCHALLENGE (S3.24), and ADD_ONION (S3.27). See also sections 2.1 and 2.3.
Unescape value. Per https://spec.torproject.org/control-spec section 2.1.1:
For future-proofing, controller implementers MAY use the following rules to be compatible with buggy Tor implementations and with future ones that implement the spec as intended:
Read
\t \r and \0 ... \377 as C escapes. Treat a backslash followed by any other character as that character.
Definition at line 251 of file torcontrol.cpp.
| std::pair< std::string, std::string > SplitTorReplyLine | ( | const std::string & | s | ) |
| const std::string DEFAULT_TOR_CONTROL = "127.0.0.1:" + ToString(DEFAULT_TOR_CONTROL_PORT) |
Default control ip and port.
Definition at line 46 of file torcontrol.cpp.
|
constexpr |
Maximum length for lines received on TorControlConnection.
tor-control-spec.txt mentions that there is explicitly no limit defined to line length, this is belt-and-suspenders sanity limit to prevent memory exhaustion.
Definition at line 65 of file torcontrol.cpp.
|
constexpr |
Exponential backoff configuration - growth factor.
Definition at line 58 of file torcontrol.cpp.
|
constexpr |
Maximum reconnect timeout in seconds to prevent excessive delays.
Definition at line 60 of file torcontrol.cpp.
|
constexpr |
Exponential backoff configuration - initial timeout in seconds.
Definition at line 56 of file torcontrol.cpp.
|
constexpr |
Timeout for socket operations.
Definition at line 67 of file torcontrol.cpp.
|
constexpr |
Tor cookie size (from control-spec.txt)
Definition at line 48 of file torcontrol.cpp.
|
constexpr |
Size of client/server nonce for SAFECOOKIE.
Definition at line 50 of file torcontrol.cpp.
|
static |
For computing clientHash in SAFECOOKIE.
Definition at line 54 of file torcontrol.cpp.
|
static |
For computing server_hash in SAFECOOKIE.
Definition at line 52 of file torcontrol.cpp.