Skip to content

Commit 8a26567

Browse files
committed
torcontrol: Use the default/standard network port for Tor hidden services, even if the internal port is set differently
Currently, the hidden service is published on the same port as the public listening port. But if a non-standard port is configured, this can be used to guess (pretty reliably) that the public IP and the hidden service are the same node.
1 parent 37f236a commit 8a26567

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/torcontrol.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6+
#include <chainparams.h>
67
#include <torcontrol.h>
78
#include <util/strencodings.h>
89
#include <netbase.h>
@@ -500,7 +501,7 @@ void TorController::add_onion_cb(TorControlConnection& _conn, const TorControlRe
500501
}
501502
return;
502503
}
503-
service = LookupNumeric(std::string(service_id+".onion").c_str(), GetListenPort());
504+
service = LookupNumeric(std::string(service_id+".onion").c_str(), Params().GetDefaultPort());
504505
LogPrintf("tor: Got service ID %s, advertising service %s\n", service_id, service.ToString());
505506
if (WriteBinaryFile(GetPrivateKeyFile(), private_key)) {
506507
LogPrint(BCLog::TOR, "tor: Cached service private key to %s\n", GetPrivateKeyFile().string());
@@ -534,9 +535,8 @@ void TorController::auth_cb(TorControlConnection& _conn, const TorControlReply&
534535
if (private_key.empty()) // No private key, generate one
535536
private_key = "NEW:RSA1024"; // Explicitly request RSA1024 - see issue #9214
536537
// Request hidden service, redirect port.
537-
// Note that the 'virtual' port doesn't have to be the same as our internal port, but this is just a convenient
538-
// choice. TODO; refactor the shutdown sequence some day.
539-
_conn.Command(strprintf("ADD_ONION %s Port=%i,127.0.0.1:%i", private_key, GetListenPort(), GetListenPort()),
538+
// Note that the 'virtual' port is always the default port to avoid decloaking nodes using other ports.
539+
_conn.Command(strprintf("ADD_ONION %s Port=%i,127.0.0.1:%i", private_key, Params().GetDefaultPort(), GetListenPort()),
540540
std::bind(&TorController::add_onion_cb, this, std::placeholders::_1, std::placeholders::_2));
541541
} else {
542542
LogPrintf("tor: Authentication failed\n");

0 commit comments

Comments
 (0)