#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 <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <map>
#include <optional>
#include <set>
#include <thread>
#include <utility>
#include <vector>
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#include <event2/event.h>
#include <event2/thread.h>
#include <event2/util.h>
Go to the source code of this file.
◆ ComputeResponse()
| std::vector< uint8_t > ComputeResponse |
( |
const std::string & | key, |
|
|
const std::vector< uint8_t > & | cookie, |
|
|
const std::vector< uint8_t > & | clientNonce, |
|
|
const std::vector< uint8_t > & | serverNonce ) |
|
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 504 of file torcontrol.cpp.
◆ DefaultOnionServiceTarget()
| CService DefaultOnionServiceTarget |
( |
uint16_t | port | ) |
|
◆ InterruptTorControl()
| void InterruptTorControl |
( |
| ) |
|
◆ ParseTorReplyMapping()
| 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 233 of file torcontrol.cpp.
◆ ReplaceAll()
| void util::ReplaceAll |
( |
std::string & | in_out, |
|
|
const std::string & | search, |
|
|
const std::string & | substitute ) |
◆ SplitString()
◆ SplitTorReplyLine()
| std::pair< std::string, std::string > SplitTorReplyLine |
( |
const std::string & | s | ) |
|
◆ StartTorControl()
| void StartTorControl |
( |
CService | onion_service_target | ) |
|
◆ StopTorControl()
◆ TorControlThread()
| void TorControlThread |
( |
CService | onion_service_target | ) |
|
|
static |
◆ ToString()
Locale-independent version of std::to_string.
Definition at line 246 of file string.h.
◆ DEFAULT_TOR_CONTROL
◆ gBase
◆ MAX_LINE_LENGTH
| const int MAX_LINE_LENGTH = 100000 |
|
static |
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 73 of file torcontrol.cpp.
◆ RECONNECT_TIMEOUT_EXP
| const float RECONNECT_TIMEOUT_EXP = 1.5 |
|
static |
Exponential backoff configuration - growth factor.
Definition at line 66 of file torcontrol.cpp.
◆ RECONNECT_TIMEOUT_MAX
| const float RECONNECT_TIMEOUT_MAX = 600.0 |
|
static |
Maximum reconnect timeout in seconds to prevent excessive delays.
Definition at line 68 of file torcontrol.cpp.
◆ RECONNECT_TIMEOUT_START
| const float RECONNECT_TIMEOUT_START = 1.0 |
|
static |
Exponential backoff configuration - initial timeout in seconds.
Definition at line 64 of file torcontrol.cpp.
◆ TOR_COOKIE_SIZE
| const int TOR_COOKIE_SIZE = 32 |
|
static |
Tor cookie size (from control-spec.txt).
Definition at line 53 of file torcontrol.cpp.
◆ TOR_NONCE_SIZE
| const int TOR_NONCE_SIZE = 32 |
|
static |
Size of client/server nonce for SAFECOOKIE.
Definition at line 55 of file torcontrol.cpp.
◆ TOR_REPLY_OK
| const int TOR_REPLY_OK = 250 |
|
static |
◆ TOR_REPLY_UNRECOGNIZED
| const int TOR_REPLY_UNRECOGNIZED = 510 |
|
static |
◆ TOR_SAFE_CLIENTKEY
| const std::string TOR_SAFE_CLIENTKEY = "Tor safe cookie authentication controller-to-server hash" |
|
static |
For computing clientHash in SAFECOOKIE.
Definition at line 62 of file torcontrol.cpp.
◆ TOR_SAFE_SERVERKEY
| const std::string TOR_SAFE_SERVERKEY = "Tor safe cookie authentication server-to-controller hash" |
|
static |
For computing serverHash in SAFECOOKIE.
Definition at line 60 of file torcontrol.cpp.
◆ torControlThread
| std::thread torControlThread |
|
static |