#ifndef SERVICES_NETWORK_TLS_SOCKET_FACTORY_H_
#define SERVICES_NETWORK_TLS_SOCKET_FACTORY_H_
#include <memory>
#include <vector>
#include "base/component_export.h"
#include "base/memory/raw_ptr.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/unique_receiver_set.h"
#include "net/socket/ssl_client_socket.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/mojom/tcp_socket.mojom.h"
#include "services/network/public/mojom/tls_socket.mojom-forward.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace net {
class ClientSocketFactory;
class SSLConfigService;
class StreamSocket;
class URLRequestContext;
}
namespace network {
class COMPONENT_EXPORT(NETWORK_SERVICE) TLSSocketFactory {
public:
class Delegate {
public:
virtual const net::StreamSocket* BorrowSocket() = 0;
virtual std::unique_ptr<net::StreamSocket> TakeSocket() = 0;
};
using UpgradeToTLSCallback =
base::OnceCallback<void(int32_t net_error,
mojo::ScopedDataPipeConsumerHandle receive_stream,
mojo::ScopedDataPipeProducerHandle send_stream,
const absl::optional<net::SSLInfo>& ssl_info)>;
explicit TLSSocketFactory(net::URLRequestContext* url_request_context);
TLSSocketFactory(const TLSSocketFactory&) = delete;
TLSSocketFactory& operator=(const TLSSocketFactory&) = delete;
virtual ~TLSSocketFactory();
void UpgradeToTLS(
Delegate* socket_delegate,
const net::HostPortPair& host_port_pair,
mojom::TLSClientSocketOptionsPtr socket_options,
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
mojo::PendingReceiver<mojom::TLSClientSocket> receiver,
mojo::PendingRemote<mojom::SocketObserver> observer,
UpgradeToTLSCallback callback);
private:
void CreateTLSClientSocket(
const net::HostPortPair& host_port_pair,
mojom::TLSClientSocketOptionsPtr socket_options,
mojo::PendingReceiver<mojom::TLSClientSocket> receiver,
std::unique_ptr<net::StreamSocket> underlying_socket,
mojo::PendingRemote<mojom::SocketObserver> observer,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
mojom::TCPConnectedSocket::UpgradeToTLSCallback callback);
std::unique_ptr<net::CertVerifier> no_verification_cert_verifier_;
std::unique_ptr<net::TransportSecurityState>
no_verification_transport_security_state_;
std::unique_ptr<net::CTPolicyEnforcer> no_verification_ct_policy_enforcer_;
std::unique_ptr<net::SSLClientContext> no_verification_ssl_client_context_;
net::SSLClientContext ssl_client_context_;
raw_ptr<net::ClientSocketFactory> client_socket_factory_;
const raw_ptr<net::SSLConfigService> ssl_config_service_;
mojo::UniqueReceiverSet<mojom::TLSClientSocket> tls_socket_receivers_;
};
}
#endif