mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
Add a class TorsStreamIsolationCredentialsGenerator that generates unique credentials based on a randomly generated session prefix and an atomic counter. This makes sure that different launches of the application won't share the same credentials, and thus circuits, even in edge cases. Example with `-debug=proxy`: ``` 2025-03-31T16:30:27Z [proxy] SOCKS5 sending proxy authentication 0afb2da441f5c105-0:0afb2da441f5c105-0 2025-03-31T16:30:31Z [proxy] SOCKS5 sending proxy authentication 0afb2da441f5c105-1:0afb2da441f5c105-1 ``` Thanks to hodlinator for the idea.
65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
// Copyright (c) The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <common/args.h>
|
|
#include <i2p.h>
|
|
#include <netaddress.h>
|
|
#include <netbase.h>
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
#include <test/fuzz/fuzz.h>
|
|
#include <test/fuzz/util.h>
|
|
#include <test/fuzz/util/net.h>
|
|
#include <test/util/setup_common.h>
|
|
#include <util/fs_helpers.h>
|
|
#include <util/threadinterrupt.h>
|
|
|
|
void initialize_i2p()
|
|
{
|
|
static const auto testing_setup = MakeNoLogFileContext<>();
|
|
}
|
|
|
|
FUZZ_TARGET(i2p, .init = initialize_i2p)
|
|
{
|
|
SeedRandomStateForTest(SeedRand::ZEROS);
|
|
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
|
|
|
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
|
|
|
// Mock CreateSock() to create FuzzedSock.
|
|
auto CreateSockOrig = CreateSock;
|
|
CreateSock = [&fuzzed_data_provider](int, int, int) {
|
|
return std::make_unique<FuzzedSock>(fuzzed_data_provider);
|
|
};
|
|
|
|
const fs::path private_key_path = gArgs.GetDataDirNet() / "fuzzed_i2p_private_key";
|
|
const CService addr{in6_addr(IN6ADDR_LOOPBACK_INIT), 7656};
|
|
const Proxy sam_proxy{addr, /*tor_stream_isolation=*/false};
|
|
CThreadInterrupt interrupt;
|
|
|
|
i2p::sam::Session session{private_key_path, sam_proxy, &interrupt};
|
|
i2p::Connection conn;
|
|
|
|
if (session.Listen(conn)) {
|
|
if (session.Accept(conn)) {
|
|
try {
|
|
(void)conn.sock->RecvUntilTerminator('\n', 10ms, interrupt, i2p::sam::MAX_MSG_SIZE);
|
|
} catch (const std::runtime_error&) {
|
|
}
|
|
}
|
|
}
|
|
|
|
bool proxy_error;
|
|
|
|
if (session.Connect(CService{}, conn, proxy_error)) {
|
|
try {
|
|
conn.sock->SendComplete("verack\n", 10ms, interrupt);
|
|
} catch (const std::runtime_error&) {
|
|
}
|
|
}
|
|
|
|
fs::remove_all(private_key_path);
|
|
|
|
CreateSock = CreateSockOrig;
|
|
}
|