Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/extensions/transport_sockets/quic/v3/quic_transport.pb.h" 4 : #include "envoy/network/transport_socket.h" 5 : #include "envoy/server/transport_socket_config.h" 6 : #include "envoy/ssl/context_config.h" 7 : 8 : #include "source/common/common/assert.h" 9 : #include "source/common/network/transport_socket_options_impl.h" 10 : #include "source/common/quic/quic_transport_socket_factory.h" 11 : #include "source/extensions/transport_sockets/tls/ssl_socket.h" 12 : 13 : namespace Envoy { 14 : namespace Quic { 15 : 16 : // TODO(danzh): when implement ProofSource, examine of it's necessary to 17 : // differentiate server and client side context config. 18 : class QuicServerTransportSocketFactory : public Network::DownstreamTransportSocketFactory, 19 : public QuicTransportSocketFactoryBase { 20 : public: 21 : QuicServerTransportSocketFactory(bool enable_early_data, Stats::Scope& store, 22 : Ssl::ServerContextConfigPtr config) 23 : : QuicTransportSocketFactoryBase(store, "server"), config_(std::move(config)), 24 0 : enable_early_data_(enable_early_data) {} 25 : 26 : // Network::DownstreamTransportSocketFactory 27 0 : Network::TransportSocketPtr createDownstreamTransportSocket() const override { 28 0 : PANIC("not implemented"); 29 0 : } 30 0 : bool implementsSecureTransport() const override { return true; } 31 : 32 : void initialize() override; 33 : 34 : // Return TLS certificates if the context config is ready. 35 : std::vector<std::reference_wrapper<const Envoy::Ssl::TlsCertificateConfig>> 36 0 : getTlsCertificates() const { 37 0 : if (!config_->isReady()) { 38 0 : ENVOY_LOG(warn, "SDS hasn't finished updating Ssl context config yet."); 39 0 : stats_.downstream_context_secrets_not_ready_.inc(); 40 0 : return {}; 41 0 : } 42 0 : return config_->tlsCertificates(); 43 0 : } 44 : 45 0 : bool earlyDataEnabled() const { return enable_early_data_; } 46 : 47 : protected: 48 0 : void onSecretUpdated() override { stats_.context_config_update_by_sds_.inc(); } 49 : 50 : private: 51 : Ssl::ServerContextConfigPtr config_; 52 : bool enable_early_data_; 53 : }; 54 : 55 : class QuicServerTransportSocketConfigFactory 56 : : public QuicTransportSocketConfigFactory, 57 : public Server::Configuration::DownstreamTransportSocketConfigFactory { 58 : public: 59 : // Server::Configuration::DownstreamTransportSocketConfigFactory 60 : Network::DownstreamTransportSocketFactoryPtr 61 : createTransportSocketFactory(const Protobuf::Message& config, 62 : Server::Configuration::TransportSocketFactoryContext& context, 63 : const std::vector<std::string>& server_names) override; 64 : 65 : // Server::Configuration::TransportSocketConfigFactory 66 : ProtobufTypes::MessagePtr createEmptyConfigProto() override; 67 : }; 68 : 69 : DECLARE_FACTORY(QuicServerTransportSocketConfigFactory); 70 : 71 : } // namespace Quic 72 : } // namespace Envoy