Line data Source code
1 : #pragma once 2 : 3 : #include "source/common/quic/quic_transport_socket_factory.h" 4 : 5 : namespace Envoy { 6 : namespace Quic { 7 : 8 : class QuicClientTransportSocketFactory : public Network::CommonUpstreamTransportSocketFactory, 9 : public QuicTransportSocketFactoryBase { 10 : public: 11 : QuicClientTransportSocketFactory( 12 : Ssl::ClientContextConfigPtr config, 13 : Server::Configuration::TransportSocketFactoryContext& factory_context); 14 : 15 : void initialize() override; 16 0 : bool implementsSecureTransport() const override { return true; } 17 0 : bool supportsAlpn() const override { return true; } 18 0 : absl::string_view defaultServerNameIndication() const override { 19 0 : return clientContextConfig()->serverNameIndication(); 20 0 : } 21 : 22 : // As documented above for QuicTransportSocketFactoryBase, the actual HTTP/3 23 : // code does not create transport sockets. 24 : // QuicClientTransportSocketFactory::createTransportSocket is called by the 25 : // connection grid when upstream HTTP/3 fails over to TCP, and a raw SSL socket 26 : // is needed. In this case the QuicClientTransportSocketFactory falls over to 27 : // using the fallback factory. 28 : Network::TransportSocketPtr 29 : createTransportSocket(Network::TransportSocketOptionsConstSharedPtr options, 30 0 : Upstream::HostDescriptionConstSharedPtr host) const override { 31 0 : return fallback_factory_->createTransportSocket(options, host); 32 0 : } 33 : 34 0 : Envoy::Ssl::ClientContextSharedPtr sslCtx() override { return fallback_factory_->sslCtx(); } 35 : 36 0 : OptRef<const Ssl::ClientContextConfig> clientContextConfig() const override { 37 0 : return fallback_factory_->clientContextConfig(); 38 0 : } 39 : 40 : // Returns a crypto config generated from the up-to-date client context config. Once the passed in 41 : // context config gets updated, a new crypto config object will be returned by this method. 42 : std::shared_ptr<quic::QuicCryptoClientConfig> getCryptoConfig() override; 43 : 44 : protected: 45 : // fallback_factory_ will update the context. 46 0 : void onSecretUpdated() override {} 47 : 48 : private: 49 : // The QUIC client transport socket can create TLS sockets for fallback to TCP. 50 : std::unique_ptr<Extensions::TransportSockets::Tls::ClientSslSocketFactory> fallback_factory_; 51 : // Latch the latest client context, to determine if it has updated since last 52 : // checked. 53 : Envoy::Ssl::ClientContextSharedPtr client_context_; 54 : // If client_context_ changes, client config will be updated as well. 55 : std::shared_ptr<quic::QuicCryptoClientConfig> crypto_config_; 56 : }; 57 : 58 : class QuicClientTransportSocketConfigFactory 59 : : public QuicTransportSocketConfigFactory, 60 : public Server::Configuration::UpstreamTransportSocketConfigFactory { 61 : public: 62 : // Server::Configuration::UpstreamTransportSocketConfigFactory 63 : Network::UpstreamTransportSocketFactoryPtr createTransportSocketFactory( 64 : const Protobuf::Message& config, 65 : Server::Configuration::TransportSocketFactoryContext& context) override; 66 : 67 : // Server::Configuration::TransportSocketConfigFactory 68 : ProtobufTypes::MessagePtr createEmptyConfigProto() override; 69 : }; 70 : 71 : DECLARE_FACTORY(QuicClientTransportSocketConfigFactory); 72 : 73 : } // namespace Quic 74 : } // namespace Envoy