BIP155 (addrv2)
Tor v3 + i2p
This commit is contained in:
@@ -5,9 +5,12 @@
|
||||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
|
||||
#include "torcontrol.h"
|
||||
#include "utilstrencodings.h"
|
||||
#include "chainparams.h"
|
||||
#include "util/strencodings.h"
|
||||
#include "net.h"
|
||||
#include "util.h"
|
||||
#include "util/readwritefile.h"
|
||||
#include "utiltime.h"
|
||||
#include "crypto/hmac_sha256.h"
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
@@ -133,7 +136,7 @@ TorControlConnection::~TorControlConnection()
|
||||
|
||||
void TorControlConnection::readcb(struct bufferevent *bev, void *ctx)
|
||||
{
|
||||
TorControlConnection *self = (TorControlConnection*)ctx;
|
||||
TorControlConnection *self = static_cast<TorControlConnection*>(ctx);
|
||||
struct evbuffer *input = bufferevent_get_input(bev);
|
||||
size_t n_read_out = 0;
|
||||
char *line;
|
||||
@@ -178,7 +181,7 @@ void TorControlConnection::readcb(struct bufferevent *bev, void *ctx)
|
||||
|
||||
void TorControlConnection::eventcb(struct bufferevent *bev, short what, void *ctx)
|
||||
{
|
||||
TorControlConnection *self = (TorControlConnection*)ctx;
|
||||
TorControlConnection *self = static_cast<TorControlConnection*>(ctx);
|
||||
if (what & BEV_EVENT_CONNECTED) {
|
||||
LogPrint("tor", "tor: Successfully connected!\n");
|
||||
self->connected(*self);
|
||||
@@ -356,52 +359,6 @@ static std::map<std::string,std::string> ParseTorReplyMapping(const std::string
|
||||
return mapping;
|
||||
}
|
||||
|
||||
/** Read full contents of a file and return them in a std::string.
|
||||
* Returns a pair <status, string>.
|
||||
* If an error occured, status will be false, otherwise status will be true and the data will be returned in string.
|
||||
*
|
||||
* @param maxsize Puts a maximum size limit on the file that is read. If the file is larger than this, truncated data
|
||||
* (with len > maxsize) will be returned.
|
||||
*/
|
||||
static std::pair<bool,std::string> ReadBinaryFile(const std::string &filename, size_t maxsize=std::numeric_limits<size_t>::max())
|
||||
{
|
||||
FILE *f = fopen(filename.c_str(), "rb");
|
||||
if (f == NULL)
|
||||
return std::make_pair(false,"");
|
||||
std::string retval;
|
||||
char buffer[128];
|
||||
size_t n;
|
||||
while ((n=fread(buffer, 1, sizeof(buffer), f)) > 0) {
|
||||
// Check for reading errors so we don't return any data if we couldn't
|
||||
// read the entire file (or up to maxsize)
|
||||
if (ferror(f)) {
|
||||
fclose(f);
|
||||
return std::make_pair(false,"");
|
||||
}
|
||||
retval.append(buffer, buffer+n);
|
||||
if (retval.size() > maxsize)
|
||||
break;
|
||||
}
|
||||
fclose(f);
|
||||
return std::make_pair(true,retval);
|
||||
}
|
||||
|
||||
/** Write contents of std::string to a file.
|
||||
* @return true on success.
|
||||
*/
|
||||
static bool WriteBinaryFile(const std::string &filename, const std::string &data)
|
||||
{
|
||||
FILE *f = fopen(filename.c_str(), "wb");
|
||||
if (f == NULL)
|
||||
return false;
|
||||
if (fwrite(data.data(), 1, data.size(), f) != data.size()) {
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
/****** Bitcoin specific TorController implementation ********/
|
||||
|
||||
/** Controller that connects to Tor control socket, authenticate, then create
|
||||
@@ -502,8 +459,8 @@ void TorController::add_onion_cb(TorControlConnection& conn, const TorControlRep
|
||||
return;
|
||||
}
|
||||
|
||||
service = CService(service_id+".onion", GetListenPort(), false);
|
||||
LogPrintf("tor: Got service ID %s, advertizing service %s\n", service_id, service.ToString());
|
||||
service = LookupNumeric(std::string(service_id+".onion").c_str(), GetListenPort());
|
||||
LogPrintf("tor: Got service ID %s, advertising service %s\n", service_id, service.ToString());
|
||||
if (WriteBinaryFile(GetPrivateKeyFile(), private_key)) {
|
||||
LogPrint("tor", "tor: Cached service private key to %s\n", GetPrivateKeyFile());
|
||||
} else {
|
||||
@@ -526,14 +483,16 @@ void TorController::auth_cb(TorControlConnection& conn, const TorControlReply& r
|
||||
// Now that we know Tor is running setup the proxy for onion addresses
|
||||
// if -onion isn't set to something else.
|
||||
if (GetArg("-onion", "") == "") {
|
||||
proxyType addrOnion = proxyType(CService("127.0.0.1", 9050), true);
|
||||
CService resolved(LookupNumeric("127.0.0.1", 9050));
|
||||
proxyType addrOnion = proxyType(resolved, true);
|
||||
SetProxy(NET_ONION, addrOnion);
|
||||
SetLimited(NET_ONION, false);
|
||||
SetReachable(NET_ONION, true);
|
||||
}
|
||||
|
||||
// Finally - now create the service
|
||||
if (private_key.empty()) // No private key, generate one
|
||||
private_key = "NEW:RSA1024"; // Explicitly request RSA1024 - see issue #9214
|
||||
if (private_key.empty()) { // No private key, generate one
|
||||
private_key = "NEW:ED25519-V3"; // Explicitly request key type - see issue #9214
|
||||
}
|
||||
// Request hidden service, redirect port.
|
||||
// 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.
|
||||
@@ -564,10 +523,10 @@ static std::vector<uint8_t> ComputeResponse(const std::string &key, const std::v
|
||||
{
|
||||
CHMAC_SHA256 computeHash((const uint8_t*)key.data(), key.size());
|
||||
std::vector<uint8_t> computedHash(CHMAC_SHA256::OUTPUT_SIZE, 0);
|
||||
computeHash.Write(begin_ptr(cookie), cookie.size());
|
||||
computeHash.Write(begin_ptr(clientNonce), clientNonce.size());
|
||||
computeHash.Write(begin_ptr(serverNonce), serverNonce.size());
|
||||
computeHash.Finalize(begin_ptr(computedHash));
|
||||
computeHash.Write(cookie.data(), cookie.size());
|
||||
computeHash.Write(clientNonce.data(), clientNonce.size());
|
||||
computeHash.Write(serverNonce.data(), serverNonce.size());
|
||||
computeHash.Finalize(computedHash.data());
|
||||
return computedHash;
|
||||
}
|
||||
|
||||
@@ -724,7 +683,7 @@ std::string TorController::GetPrivateKeyFile()
|
||||
|
||||
void TorController::reconnect_cb(evutil_socket_t fd, short what, void *arg)
|
||||
{
|
||||
TorController *self = (TorController*)arg;
|
||||
TorController *self = static_cast<TorController*>(arg);
|
||||
self->Reconnect();
|
||||
}
|
||||
|
||||
@@ -772,4 +731,3 @@ void StopTorControl()
|
||||
gBase = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user