Reason for revert:
This CL broke all Chromium WebRTC FYI bots. A roll+fix was attempted here: https://codereview.chromium.org/2590783003/, but failed to land. I'm reverting this CL now to make the tree green again. Make the API change gradual when you reland so that we can update Chromium between.
Original issue's description:
> Add disabled certificate check support to IceServer PeerConnection API.
>
> Refactor "OPT_SSLTCP" renaming it to "OPT_TLS_FAKE", making it clear
> that it's not actually some kind of SSL over TCP. Also making it clear
> that it's mutually exclusive with OPT_TLS.
>
> Add "OPT_TLS_INSECURE" that implements the new certificate-check
> disabled TLS mode, which is also mutually exclusive with the other
> TLS options.
>
> PortAllocator: Add a new TLS policy enum TlsCertPolicy which defines
> the new insecure mode and added it as a RelayCredentials member.
>
> TurnPort: Add new TLS policy member with appropriate getter and setter
> to avoid constructor bloat. Initialize it from the RelayCredentials
> after the TurnPort is created.
>
> Expose the new feature in the PeerConnection API via
> IceServer.tls_certificate_policy as well as via the Android JNI
> PeerConnection API.
>
> For security reasons we ensure that:
>
> 1) The policy is always explicitly initialized to secure.
> 2) API users have to explicitly integrate with the feature to
> use it, and will otherwise get no change in behavior.
> 3) The feature is not immediately exposed in non-native
> contexts. For example, disabling of certificate validation
> is not implemented via URI parsing since this would
> immediately allow it to be used from a web page.
>
> BUG=webrtc:6840
>
> Review-Url: https://codereview.webrtc.org/2557803002
> Cr-Commit-Position: refs/heads/master@{#15670}
> Committed: b0f04fdb9e
TBR=pthatcher@webrtc.org,deadbeef@webrtc.org,hnsl@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:6840
Review-Url: https://codereview.webrtc.org/2590153002
Cr-Commit-Position: refs/heads/master@{#15703}
207 lines
6.2 KiB
C++
207 lines
6.2 KiB
C++
/*
|
|
* Copyright 2011 The WebRTC Project Authors. All rights reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "webrtc/p2p/base/basicpacketsocketfactory.h"
|
|
|
|
#include <string>
|
|
|
|
#include "webrtc/p2p/base/asyncstuntcpsocket.h"
|
|
#include "webrtc/p2p/base/stun.h"
|
|
#include "webrtc/base/asynctcpsocket.h"
|
|
#include "webrtc/base/asyncudpsocket.h"
|
|
#include "webrtc/base/logging.h"
|
|
#include "webrtc/base/nethelpers.h"
|
|
#include "webrtc/base/physicalsocketserver.h"
|
|
#include "webrtc/base/socketadapters.h"
|
|
#include "webrtc/base/ssladapter.h"
|
|
#include "webrtc/base/thread.h"
|
|
|
|
namespace rtc {
|
|
|
|
BasicPacketSocketFactory::BasicPacketSocketFactory()
|
|
: thread_(Thread::Current()),
|
|
socket_factory_(NULL) {
|
|
}
|
|
|
|
BasicPacketSocketFactory::BasicPacketSocketFactory(Thread* thread)
|
|
: thread_(thread),
|
|
socket_factory_(NULL) {
|
|
}
|
|
|
|
BasicPacketSocketFactory::BasicPacketSocketFactory(
|
|
SocketFactory* socket_factory)
|
|
: thread_(NULL),
|
|
socket_factory_(socket_factory) {
|
|
}
|
|
|
|
BasicPacketSocketFactory::~BasicPacketSocketFactory() {
|
|
}
|
|
|
|
AsyncPacketSocket* BasicPacketSocketFactory::CreateUdpSocket(
|
|
const SocketAddress& address,
|
|
uint16_t min_port,
|
|
uint16_t max_port) {
|
|
// UDP sockets are simple.
|
|
AsyncSocket* socket =
|
|
socket_factory()->CreateAsyncSocket(address.family(), SOCK_DGRAM);
|
|
if (!socket) {
|
|
return NULL;
|
|
}
|
|
if (BindSocket(socket, address, min_port, max_port) < 0) {
|
|
LOG(LS_ERROR) << "UDP bind failed with error "
|
|
<< socket->GetError();
|
|
delete socket;
|
|
return NULL;
|
|
}
|
|
return new AsyncUDPSocket(socket);
|
|
}
|
|
|
|
AsyncPacketSocket* BasicPacketSocketFactory::CreateServerTcpSocket(
|
|
const SocketAddress& local_address,
|
|
uint16_t min_port,
|
|
uint16_t max_port,
|
|
int opts) {
|
|
// Fail if TLS is required.
|
|
if (opts & PacketSocketFactory::OPT_TLS) {
|
|
LOG(LS_ERROR) << "TLS support currently is not available.";
|
|
return NULL;
|
|
}
|
|
|
|
AsyncSocket* socket =
|
|
socket_factory()->CreateAsyncSocket(local_address.family(), SOCK_STREAM);
|
|
if (!socket) {
|
|
return NULL;
|
|
}
|
|
|
|
if (BindSocket(socket, local_address, min_port, max_port) < 0) {
|
|
LOG(LS_ERROR) << "TCP bind failed with error "
|
|
<< socket->GetError();
|
|
delete socket;
|
|
return NULL;
|
|
}
|
|
|
|
// If using SSLTCP, wrap the TCP socket in a pseudo-SSL socket.
|
|
if (opts & PacketSocketFactory::OPT_SSLTCP) {
|
|
ASSERT(!(opts & PacketSocketFactory::OPT_TLS));
|
|
socket = new AsyncSSLSocket(socket);
|
|
}
|
|
|
|
// Set TCP_NODELAY (via OPT_NODELAY) for improved performance.
|
|
// See http://go/gtalktcpnodelayexperiment
|
|
socket->SetOption(Socket::OPT_NODELAY, 1);
|
|
|
|
if (opts & PacketSocketFactory::OPT_STUN)
|
|
return new cricket::AsyncStunTCPSocket(socket, true);
|
|
|
|
return new AsyncTCPSocket(socket, true);
|
|
}
|
|
|
|
AsyncPacketSocket* BasicPacketSocketFactory::CreateClientTcpSocket(
|
|
const SocketAddress& local_address, const SocketAddress& remote_address,
|
|
const ProxyInfo& proxy_info, const std::string& user_agent, int opts) {
|
|
AsyncSocket* socket =
|
|
socket_factory()->CreateAsyncSocket(local_address.family(), SOCK_STREAM);
|
|
if (!socket) {
|
|
return NULL;
|
|
}
|
|
|
|
if (BindSocket(socket, local_address, 0, 0) < 0) {
|
|
LOG(LS_ERROR) << "TCP bind failed with error "
|
|
<< socket->GetError();
|
|
delete socket;
|
|
return NULL;
|
|
}
|
|
|
|
// If using a proxy, wrap the socket in a proxy socket.
|
|
if (proxy_info.type == PROXY_SOCKS5) {
|
|
socket = new AsyncSocksProxySocket(
|
|
socket, proxy_info.address, proxy_info.username, proxy_info.password);
|
|
} else if (proxy_info.type == PROXY_HTTPS) {
|
|
socket =
|
|
new AsyncHttpsProxySocket(socket, user_agent, proxy_info.address,
|
|
proxy_info.username, proxy_info.password);
|
|
}
|
|
|
|
// If using TLS, wrap the socket in an SSL adapter.
|
|
if (opts & PacketSocketFactory::OPT_TLS) {
|
|
ASSERT(!(opts & PacketSocketFactory::OPT_SSLTCP));
|
|
|
|
SSLAdapter* ssl_adapter = SSLAdapter::Create(socket);
|
|
if (!ssl_adapter) {
|
|
return NULL;
|
|
}
|
|
|
|
socket = ssl_adapter;
|
|
|
|
if (ssl_adapter->StartSSL(remote_address.hostname().c_str(), false) != 0) {
|
|
delete ssl_adapter;
|
|
return NULL;
|
|
}
|
|
|
|
// If using SSLTCP, wrap the TCP socket in a pseudo-SSL socket.
|
|
} else if (opts & PacketSocketFactory::OPT_SSLTCP) {
|
|
ASSERT(!(opts & PacketSocketFactory::OPT_TLS));
|
|
socket = new AsyncSSLSocket(socket);
|
|
}
|
|
|
|
if (socket->Connect(remote_address) < 0) {
|
|
LOG(LS_ERROR) << "TCP connect failed with error "
|
|
<< socket->GetError();
|
|
delete socket;
|
|
return NULL;
|
|
}
|
|
|
|
// Finally, wrap that socket in a TCP or STUN TCP packet socket.
|
|
AsyncPacketSocket* tcp_socket;
|
|
if (opts & PacketSocketFactory::OPT_STUN) {
|
|
tcp_socket = new cricket::AsyncStunTCPSocket(socket, false);
|
|
} else {
|
|
tcp_socket = new AsyncTCPSocket(socket, false);
|
|
}
|
|
|
|
// Set TCP_NODELAY (via OPT_NODELAY) for improved performance.
|
|
// See http://go/gtalktcpnodelayexperiment
|
|
tcp_socket->SetOption(Socket::OPT_NODELAY, 1);
|
|
|
|
return tcp_socket;
|
|
}
|
|
|
|
AsyncResolverInterface* BasicPacketSocketFactory::CreateAsyncResolver() {
|
|
return new AsyncResolver();
|
|
}
|
|
|
|
int BasicPacketSocketFactory::BindSocket(AsyncSocket* socket,
|
|
const SocketAddress& local_address,
|
|
uint16_t min_port,
|
|
uint16_t max_port) {
|
|
int ret = -1;
|
|
if (min_port == 0 && max_port == 0) {
|
|
// If there's no port range, let the OS pick a port for us.
|
|
ret = socket->Bind(local_address);
|
|
} else {
|
|
// Otherwise, try to find a port in the provided range.
|
|
for (int port = min_port; ret < 0 && port <= max_port; ++port) {
|
|
ret = socket->Bind(SocketAddress(local_address.ipaddr(), port));
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
SocketFactory* BasicPacketSocketFactory::socket_factory() {
|
|
if (thread_) {
|
|
ASSERT(thread_ == Thread::Current());
|
|
return thread_->socketserver();
|
|
} else {
|
|
return socket_factory_;
|
|
}
|
|
}
|
|
|
|
} // namespace rtc
|