|
|
@ -460,8 +460,8 @@ TorController::TorController(struct event_base* _base, const std::string& _targe |
|
|
|
if (!reconnect_ev) |
|
|
|
if (!reconnect_ev) |
|
|
|
LogPrintf("tor: Failed to create event for reconnection: out of memory?\n"); |
|
|
|
LogPrintf("tor: Failed to create event for reconnection: out of memory?\n"); |
|
|
|
// Start connection attempts immediately
|
|
|
|
// Start connection attempts immediately
|
|
|
|
if (!conn.Connect(_target, boost::bind(&TorController::connected_cb, this, _1), |
|
|
|
if (!conn.Connect(_target, boost::bind(&TorController::connected_cb, this, boost::placeholders::_1), |
|
|
|
boost::bind(&TorController::disconnected_cb, this, _1) )) { |
|
|
|
boost::bind(&TorController::disconnected_cb, this, boost::placeholders::_1) )) { |
|
|
|
LogPrintf("tor: Initiating connection to Tor control port %s failed\n", _target); |
|
|
|
LogPrintf("tor: Initiating connection to Tor control port %s failed\n", _target); |
|
|
|
} |
|
|
|
} |
|
|
|
// Read service private key if cached
|
|
|
|
// Read service private key if cached
|
|
|
@ -539,7 +539,7 @@ void TorController::auth_cb(TorControlConnection& _conn, const TorControlReply& |
|
|
|
// Note that the 'virtual' port doesn't have to be the same as our internal port, but this is just a convenient
|
|
|
|
// Note that the 'virtual' port doesn't have to be the same as our internal port, but this is just a convenient
|
|
|
|
// choice. TODO; refactor the shutdown sequence some day.
|
|
|
|
// choice. TODO; refactor the shutdown sequence some day.
|
|
|
|
_conn.Command(strprintf("ADD_ONION %s Port=%i,127.0.0.1:%i", private_key, GetListenPort(), GetListenPort()), |
|
|
|
_conn.Command(strprintf("ADD_ONION %s Port=%i,127.0.0.1:%i", private_key, GetListenPort(), GetListenPort()), |
|
|
|
boost::bind(&TorController::add_onion_cb, this, _1, _2)); |
|
|
|
boost::bind(&TorController::add_onion_cb, this, boost::placeholders::_1, boost::placeholders::_2)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
LogPrintf("tor: Authentication failed\n"); |
|
|
|
LogPrintf("tor: Authentication failed\n"); |
|
|
|
} |
|
|
|
} |
|
|
@ -598,7 +598,7 @@ void TorController::authchallenge_cb(TorControlConnection& _conn, const TorContr |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::vector<uint8_t> computedClientHash = ComputeResponse(TOR_SAFE_CLIENTKEY, cookie, clientNonce, serverNonce); |
|
|
|
std::vector<uint8_t> computedClientHash = ComputeResponse(TOR_SAFE_CLIENTKEY, cookie, clientNonce, serverNonce); |
|
|
|
_conn.Command("AUTHENTICATE " + HexStr(computedClientHash), boost::bind(&TorController::auth_cb, this, _1, _2)); |
|
|
|
_conn.Command("AUTHENTICATE " + HexStr(computedClientHash), boost::bind(&TorController::auth_cb, this, boost::placeholders::_1, boost::placeholders::_2)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
LogPrintf("tor: Invalid reply to AUTHCHALLENGE\n"); |
|
|
|
LogPrintf("tor: Invalid reply to AUTHCHALLENGE\n"); |
|
|
|
} |
|
|
|
} |
|
|
@ -647,23 +647,23 @@ void TorController::protocolinfo_cb(TorControlConnection& _conn, const TorContro |
|
|
|
if (methods.count("HASHEDPASSWORD")) { |
|
|
|
if (methods.count("HASHEDPASSWORD")) { |
|
|
|
LogPrint(BCLog::TOR, "tor: Using HASHEDPASSWORD authentication\n"); |
|
|
|
LogPrint(BCLog::TOR, "tor: Using HASHEDPASSWORD authentication\n"); |
|
|
|
boost::replace_all(torpassword, "\"", "\\\""); |
|
|
|
boost::replace_all(torpassword, "\"", "\\\""); |
|
|
|
_conn.Command("AUTHENTICATE \"" + torpassword + "\"", boost::bind(&TorController::auth_cb, this, _1, _2)); |
|
|
|
_conn.Command("AUTHENTICATE \"" + torpassword + "\"", boost::bind(&TorController::auth_cb, this, boost::placeholders::_1, boost::placeholders::_2)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
LogPrintf("tor: Password provided with -torpassword, but HASHEDPASSWORD authentication is not available\n"); |
|
|
|
LogPrintf("tor: Password provided with -torpassword, but HASHEDPASSWORD authentication is not available\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (methods.count("NULL")) { |
|
|
|
} else if (methods.count("NULL")) { |
|
|
|
LogPrint(BCLog::TOR, "tor: Using NULL authentication\n"); |
|
|
|
LogPrint(BCLog::TOR, "tor: Using NULL authentication\n"); |
|
|
|
_conn.Command("AUTHENTICATE", boost::bind(&TorController::auth_cb, this, _1, _2)); |
|
|
|
_conn.Command("AUTHENTICATE", boost::bind(&TorController::auth_cb, this, boost::placeholders::_1, boost::placeholders::_2)); |
|
|
|
} else if (methods.count("SAFECOOKIE")) { |
|
|
|
} else if (methods.count("SAFECOOKIE")) { |
|
|
|
// Cookie: hexdump -e '32/1 "%02x""\n"' ~/.tor/control_auth_cookie
|
|
|
|
// Cookie: hexdump -e '32/1 "%02x""\n"' ~/.tor/control_auth_cookie
|
|
|
|
LogPrint(BCLog::TOR, "tor: Using SAFECOOKIE authentication, reading cookie authentication from %s\n", cookiefile); |
|
|
|
LogPrint(BCLog::TOR, "tor: Using SAFECOOKIE authentication, reading cookie authentication from %s\n", cookiefile); |
|
|
|
std::pair<bool,std::string> status_cookie = ReadBinaryFile(cookiefile, TOR_COOKIE_SIZE); |
|
|
|
std::pair<bool,std::string> status_cookie = ReadBinaryFile(cookiefile, TOR_COOKIE_SIZE); |
|
|
|
if (status_cookie.first && status_cookie.second.size() == TOR_COOKIE_SIZE) { |
|
|
|
if (status_cookie.first && status_cookie.second.size() == TOR_COOKIE_SIZE) { |
|
|
|
// _conn.Command("AUTHENTICATE " + HexStr(status_cookie.second), boost::bind(&TorController::auth_cb, this, _1, _2));
|
|
|
|
// _conn.Command("AUTHENTICATE " + HexStr(status_cookie.second), boost::bind(&TorController::auth_cb, this, boost::placeholders::_1, boost::placeholders::_2));
|
|
|
|
cookie = std::vector<uint8_t>(status_cookie.second.begin(), status_cookie.second.end()); |
|
|
|
cookie = std::vector<uint8_t>(status_cookie.second.begin(), status_cookie.second.end()); |
|
|
|
clientNonce = std::vector<uint8_t>(TOR_NONCE_SIZE, 0); |
|
|
|
clientNonce = std::vector<uint8_t>(TOR_NONCE_SIZE, 0); |
|
|
|
GetRandBytes(clientNonce.data(), TOR_NONCE_SIZE); |
|
|
|
GetRandBytes(clientNonce.data(), TOR_NONCE_SIZE); |
|
|
|
_conn.Command("AUTHCHALLENGE SAFECOOKIE " + HexStr(clientNonce), boost::bind(&TorController::authchallenge_cb, this, _1, _2)); |
|
|
|
_conn.Command("AUTHCHALLENGE SAFECOOKIE " + HexStr(clientNonce), boost::bind(&TorController::authchallenge_cb, this, boost::placeholders::_1, boost::placeholders::_2)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (status_cookie.first) { |
|
|
|
if (status_cookie.first) { |
|
|
|
LogPrintf("tor: Authentication cookie %s is not exactly %i bytes, as is required by the spec\n", cookiefile, TOR_COOKIE_SIZE); |
|
|
|
LogPrintf("tor: Authentication cookie %s is not exactly %i bytes, as is required by the spec\n", cookiefile, TOR_COOKIE_SIZE); |
|
|
@ -685,7 +685,7 @@ void TorController::connected_cb(TorControlConnection& _conn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
reconnect_timeout = RECONNECT_TIMEOUT_START; |
|
|
|
reconnect_timeout = RECONNECT_TIMEOUT_START; |
|
|
|
// First send a PROTOCOLINFO command to figure out what authentication is expected
|
|
|
|
// First send a PROTOCOLINFO command to figure out what authentication is expected
|
|
|
|
if (!_conn.Command("PROTOCOLINFO 1", boost::bind(&TorController::protocolinfo_cb, this, _1, _2))) |
|
|
|
if (!_conn.Command("PROTOCOLINFO 1", boost::bind(&TorController::protocolinfo_cb, this, boost::placeholders::_1, boost::placeholders::_2))) |
|
|
|
LogPrintf("tor: Error sending initial protocolinfo command\n"); |
|
|
|
LogPrintf("tor: Error sending initial protocolinfo command\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -712,8 +712,8 @@ void TorController::Reconnect() |
|
|
|
/* Try to reconnect and reestablish if we get booted - for example, Tor
|
|
|
|
/* Try to reconnect and reestablish if we get booted - for example, Tor
|
|
|
|
* may be restarting. |
|
|
|
* may be restarting. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (!conn.Connect(target, boost::bind(&TorController::connected_cb, this, _1), |
|
|
|
if (!conn.Connect(target, boost::bind(&TorController::connected_cb, this, boost::placeholders::_1), |
|
|
|
boost::bind(&TorController::disconnected_cb, this, _1) )) { |
|
|
|
boost::bind(&TorController::disconnected_cb, this, boost::placeholders::_1) )) { |
|
|
|
LogPrintf("tor: Re-initiating connection to Tor control port %s failed\n", target); |
|
|
|
LogPrintf("tor: Re-initiating connection to Tor control port %s failed\n", target); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -773,4 +773,3 @@ void StopTorControl() |
|
|
|
gBase = nullptr; |
|
|
|
gBase = nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|