Skip to content

Revert https proxy support. #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: m125_release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions p2p/base/basic_packet_socket_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ AsyncPacketSocket* BasicPacketSocketFactory::CreateClientTcpSocket(
<< socket->GetError();
}

if (proxy_info.type == PROXY_HTTPS) {
socket =
new AsyncHttpsProxySocket(socket, user_agent, proxy_info.address,
proxy_info.username, proxy_info.password);
}

// Assert that at most one TLS option is used.
int tlsOpts = tcp_options.opts & (PacketSocketFactory::OPT_TLS |
PacketSocketFactory::OPT_TLS_FAKE |
Expand Down
49 changes: 38 additions & 11 deletions p2p/base/p2p_transport_channel_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ static const SocketAddress kAlternateAddrs[2] = {
static const SocketAddress kIPv6AlternateAddrs[2] = {
SocketAddress("2401:4030:1:2c00:be30:abcd:efab:cdef", 0),
SocketAddress("2601:0:1000:1b03:2e41:38ff:fea6:f2a4", 0)};
// Addresses for HTTP proxy servers.
static const SocketAddress kHttpsProxyAddrs[2] = {
SocketAddress("11.11.11.1", 443), SocketAddress("22.22.22.1", 443)};
// Addresses for SOCKS proxy servers.
static const SocketAddress kSocksProxyAddrs[2] = {
SocketAddress("11.11.11.1", 1080), SocketAddress("22.22.22.1", 1080)};
// Internal addresses for NAT boxes.
static const SocketAddress kNatAddrs[2] = {SocketAddress("192.168.1.1", 0),
SocketAddress("192.168.2.1", 0)};
Expand Down Expand Up @@ -311,6 +317,7 @@ class P2PTransportChannelTestBase : public ::testing::Test,
BLOCK_UDP, // Firewall, UDP in/out blocked
BLOCK_UDP_AND_INCOMING_TCP, // Firewall, UDP in/out and TCP in blocked
BLOCK_ALL_BUT_OUTGOING_HTTP, // Firewall, only TCP out on 80/443
PROXY_HTTPS, // All traffic through HTTPS proxy
NUM_CONFIGS
};

Expand Down Expand Up @@ -556,6 +563,13 @@ class P2PTransportChannelTestBase : public ::testing::Test,
GetEndpoint(endpoint)->network_manager_.RemoveInterface(addr);
fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, addr);
}
void SetProxy(int endpoint, rtc::ProxyType type) {
rtc::ProxyInfo info;
info.type = type;
info.address = (type == rtc::PROXY_HTTPS) ? kHttpsProxyAddrs[endpoint]
: kSocksProxyAddrs[endpoint];
GetAllocator(endpoint)->set_proxy("unittest/1.0", info);
}
void SetAllocatorFlags(int endpoint, int flags) {
GetAllocator(endpoint)->set_flags(flags);
}
Expand Down Expand Up @@ -1151,6 +1165,7 @@ class P2PTransportChannelTest : public P2PTransportChannelTestBase {
case BLOCK_UDP:
case BLOCK_UDP_AND_INCOMING_TCP:
case BLOCK_ALL_BUT_OUTGOING_HTTP:
case PROXY_HTTPS:
AddAddress(endpoint, kPublicAddrs[endpoint]);
// Block all UDP
fw()->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kPublicAddrs[endpoint]);
Expand All @@ -1166,6 +1181,13 @@ class P2PTransportChannelTest : public P2PTransportChannelTestBase {
SocketAddress(rtc::IPAddress(INADDR_ANY), 443));
fw()->AddRule(false, rtc::FP_TCP, rtc::FD_ANY,
kPublicAddrs[endpoint]);
} else if (config == PROXY_HTTPS) {
// Block all TCP to/from the endpoint except to the proxy server
fw()->AddRule(true, rtc::FP_TCP, kPublicAddrs[endpoint],
kHttpsProxyAddrs[endpoint]);
fw()->AddRule(false, rtc::FP_TCP, rtc::FD_ANY,
kPublicAddrs[endpoint]);
SetProxy(endpoint, rtc::PROXY_HTTPS);
}
break;
default:
Expand Down Expand Up @@ -1205,30 +1227,33 @@ class P2PTransportChannelMatrixTest : public P2PTransportChannelTest,
// Test matrix. Originator behavior defined by rows, receiever by columns.

// TODO(?): Fix NULLs caused by lack of TCP support in NATSocket.
// TODO(?): Fix NULLs caused by no HTTP proxy support.
// TODO(?): Rearrange rows/columns from best to worst.
const P2PTransportChannelMatrixTest::Result*
P2PTransportChannelMatrixTest::kMatrix[NUM_CONFIGS][NUM_CONFIGS] = {
// OPEN CONE ADDR PORT SYMM 2CON SCON !UDP !TCP HTTP
// OPEN CONE ADDR PORT SYMM 2CON SCON !UDP !TCP HTTP PRXH
/*OP*/
{LULU, LUSU, LUSU, LUSU, LUPU, LUSU, LUPU, LTPT, LTPT, LSRS},
{LULU, LUSU, LUSU, LUSU, LUPU, LUSU, LUPU, LTPT, LTPT, LSRS, NULL},
/*CO*/
{SULU, SUSU, SUSU, SUSU, SUPU, SUSU, SUPU, NULL, NULL, LSRS},
{SULU, SUSU, SUSU, SUSU, SUPU, SUSU, SUPU, NULL, NULL, LSRS, NULL},
/*AD*/
{SULU, SUSU, SUSU, SUSU, SUPU, SUSU, SUPU, NULL, NULL, LSRS},
{SULU, SUSU, SUSU, SUSU, SUPU, SUSU, SUPU, NULL, NULL, LSRS, NULL},
/*PO*/
{SULU, SUSU, SUSU, SUSU, RUPU, SUSU, RUPU, NULL, NULL, LSRS},
{SULU, SUSU, SUSU, SUSU, RUPU, SUSU, RUPU, NULL, NULL, LSRS, NULL},
/*SY*/
{PULU, PUSU, PUSU, PURU, PURU, PUSU, PURU, NULL, NULL, LSRS},
{PULU, PUSU, PUSU, PURU, PURU, PUSU, PURU, NULL, NULL, LSRS, NULL},
/*2C*/
{SULU, SUSU, SUSU, SUSU, SUPU, SUSU, SUPU, NULL, NULL, LSRS},
{SULU, SUSU, SUSU, SUSU, SUPU, SUSU, SUPU, NULL, NULL, LSRS, NULL},
/*SC*/
{PULU, PUSU, PUSU, PURU, PURU, PUSU, PURU, NULL, NULL, LSRS},
{PULU, PUSU, PUSU, PURU, PURU, PUSU, PURU, NULL, NULL, LSRS, NULL},
/*!U*/
{LTPT, NULL, NULL, NULL, NULL, NULL, NULL, LTPT, LTPT, LSRS},
{LTPT, NULL, NULL, NULL, NULL, NULL, NULL, LTPT, LTPT, LSRS, NULL},
/*!T*/
{PTLT, NULL, NULL, NULL, NULL, NULL, NULL, PTLT, LTRT, LSRS},
{PTLT, NULL, NULL, NULL, NULL, NULL, NULL, PTLT, LTRT, LSRS, NULL},
/*HT*/
{LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS},
{LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, NULL},
/*PR*/
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
};

// The actual tests that exercise all the various configurations.
Expand Down Expand Up @@ -1256,6 +1281,7 @@ const P2PTransportChannelMatrixTest::Result*
P2P_TEST(x, BLOCK_UDP) \
P2P_TEST(x, BLOCK_UDP_AND_INCOMING_TCP) \
P2P_TEST(x, BLOCK_ALL_BUT_OUTGOING_HTTP) \
P2P_TEST(x, PROXY_HTTPS)

P2P_TEST_SET(OPEN)
P2P_TEST_SET(NAT_FULL_CONE)
Expand All @@ -1267,6 +1293,7 @@ P2P_TEST_SET(NAT_SYMMETRIC_THEN_CONE)
P2P_TEST_SET(BLOCK_UDP)
P2P_TEST_SET(BLOCK_UDP_AND_INCOMING_TCP)
P2P_TEST_SET(BLOCK_ALL_BUT_OUTGOING_HTTP)
P2P_TEST_SET(PROXY_HTTPS)

INSTANTIATE_TEST_SUITE_P(
All,
Expand Down
12 changes: 3 additions & 9 deletions p2p/base/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "rtc_base/network.h"
#include "rtc_base/network/received_packet.h"
#include "rtc_base/network/sent_packet.h"
#include "rtc_base/proxy_info.h"
#include "rtc_base/rate_tracker.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/system/rtc_export.h"
Expand Down Expand Up @@ -323,18 +324,11 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> {
const std::vector<uint16_t>& unknown_types);

void set_proxy(absl::string_view user_agent, const rtc::ProxyInfo& proxy) {
RTC_DCHECK_NOTREACHED();
user_agent_ = std::string(user_agent);
proxy_ = proxy;
}
const std::string& user_agent() override {
RTC_DCHECK_NOTREACHED();
return user_agent_;
}
const rtc::ProxyInfo& proxy() override {
RTC_DCHECK_NOTREACHED();
return proxy_;
}
const std::string& user_agent() override { return user_agent_; }
const rtc::ProxyInfo& proxy() override { return proxy_; }

void EnablePortPackets() override;

Expand Down
22 changes: 22 additions & 0 deletions p2p/base/port_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "rtc_base/checks.h"
#include "rtc_base/helpers.h"
#include "rtc_base/network.h"
#include "rtc_base/proxy_info.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/ssl_certificate.h"
#include "rtc_base/system/rtc_export.h"
Expand Down Expand Up @@ -462,6 +463,25 @@ class RTC_EXPORT PortAllocator : public sigslot::has_slots<> {
flags_ = flags;
}

// These three methods are deprecated. If connections need to go through a
// proxy, the application should create a BasicPortAllocator given a custom
// PacketSocketFactory that creates proxy sockets.
const std::string& user_agent() const {
CheckRunOnValidThreadIfInitialized();
return agent_;
}

const rtc::ProxyInfo& proxy() const {
CheckRunOnValidThreadIfInitialized();
return proxy_;
}

void set_proxy(absl::string_view agent, const rtc::ProxyInfo& proxy) {
CheckRunOnValidThreadIfInitialized();
agent_ = std::string(agent);
proxy_ = proxy;
}

// Gets/Sets the port range to use when choosing client ports.
int min_port() const {
CheckRunOnValidThreadIfInitialized();
Expand Down Expand Up @@ -609,6 +629,8 @@ class RTC_EXPORT PortAllocator : public sigslot::has_slots<> {

bool initialized_ = false;
uint32_t flags_;
std::string agent_;
rtc::ProxyInfo proxy_;
int min_port_;
int max_port_;
int max_ipv6_networks_;
Expand Down
6 changes: 2 additions & 4 deletions p2p/base/port_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,8 @@ class PortInterface {

// The factory used to create the sockets of this port.
virtual rtc::PacketSocketFactory* socket_factory() const = 0;
[[deprecated("Unsupported function")]] virtual const std::string&
user_agent() = 0;
[[deprecated("Unsupported function")]] virtual const rtc::ProxyInfo&
proxy() = 0;
virtual const std::string& user_agent() = 0;
virtual const rtc::ProxyInfo& proxy() = 0;

// Identifies the generation that this port was created in.
virtual uint32_t generation() const = 0;
Expand Down
3 changes: 2 additions & 1 deletion p2p/base/tcp_port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,8 @@ void TCPConnection::CreateOutgoingTcpSocket() {
tcp_opts.opts = opts;
socket_.reset(port()->socket_factory()->CreateClientTcpSocket(
rtc::SocketAddress(port()->Network()->GetBestIP(), 0),
remote_candidate().address(), rtc::ProxyInfo(), std::string(), tcp_opts));
remote_candidate().address(), port()->proxy(), port()->user_agent(),
tcp_opts));
if (socket_) {
RTC_LOG(LS_VERBOSE) << ToString() << ": Connecting from "
<< socket_->GetLocalAddress().ToSensitiveString()
Expand Down
2 changes: 1 addition & 1 deletion p2p/base/turn_port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ bool TurnPort::CreateTurnClientSocket() {
tcp_options.tls_cert_verifier = tls_cert_verifier_;
socket_ = socket_factory()->CreateClientTcpSocket(
rtc::SocketAddress(Network()->GetBestIP(), 0), server_address_.address,
rtc::ProxyInfo(), std::string(), tcp_options);
proxy(), user_agent(), tcp_options);
}

if (!socket_) {
Expand Down
2 changes: 2 additions & 0 deletions p2p/client/basic_port_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,8 @@ void BasicPortAllocatorSession::AddAllocatedPort(Port* port,
port->set_content_name(content_name());
port->set_component(component());
port->set_generation(generation());
if (allocator_->proxy().type != rtc::PROXY_NONE)
port->set_proxy(allocator_->user_agent(), allocator_->proxy());
port->set_send_retransmit_count_attribute(
(flags() & PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE) != 0);

Expand Down
29 changes: 27 additions & 2 deletions rtc_base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,7 @@ rtc_library("socket_adapters") {
":byte_buffer",
":checks",
":crypt_string",
":http_common",
":logging",
":stringutils",
":zero_memory",
Expand Down Expand Up @@ -1388,8 +1389,14 @@ rtc_library("dscp") {

rtc_library("proxy_info") {
visibility = [ "*" ]
sources = [ "proxy_info.h" ]
deps = []
sources = [
"proxy_info.cc",
"proxy_info.h",
]
deps = [
":crypt_string",
":socket_address",
]
}

rtc_library("file_rotating_stream") {
Expand Down Expand Up @@ -1587,6 +1594,24 @@ rtc_library("crypt_string") {
]
}

rtc_library("http_common") {
sources = [
"http_common.cc",
"http_common.h",
]
deps = [
":crypt_string",
":logging",
":socket_address",
":ssl",
":stringutils",
":zero_memory",
"third_party/base64",
]

absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
}

rtc_source_set("gtest_prod") {
sources = [ "gtest_prod_util.h" ]
}
Expand Down
Loading