Skip to content
Merged
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
4 changes: 4 additions & 0 deletions include/envoy/ssl/context_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class ClientContextConfig : public virtual ContextConfig {
virtual bool allowRenegotiation() const PURE;
};

typedef std::unique_ptr<ClientContextConfig> ClientContextConfigPtr;

class ServerContextConfig : public virtual ContextConfig {
public:
struct SessionTicketKey {
Expand All @@ -148,5 +150,7 @@ class ServerContextConfig : public virtual ContextConfig {
virtual const std::vector<SessionTicketKey>& sessionTicketKeys() const PURE;
};

typedef std::unique_ptr<ServerContextConfig> ServerContextConfigPtr;

} // namespace Ssl
} // namespace Envoy
11 changes: 7 additions & 4 deletions source/common/ssl/ssl_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,22 +382,25 @@ std::string SslSocket::subjectLocalCertificate() const {
return getSubjectFromCertificate(cert);
}

ClientSslSocketFactory::ClientSslSocketFactory(const ClientContextConfig& config,
ClientSslSocketFactory::ClientSslSocketFactory(ClientContextConfigPtr config,
Ssl::ContextManager& manager,
Stats::Scope& stats_scope)
: ssl_ctx_(manager.createSslClientContext(stats_scope, config)) {}
: manager_(manager), stats_scope_(stats_scope), config_(std::move(config)),
ssl_ctx_(manager_.createSslClientContext(stats_scope_, *config_)) {}

Network::TransportSocketPtr ClientSslSocketFactory::createTransportSocket() const {
return std::make_unique<Ssl::SslSocket>(ssl_ctx_, Ssl::InitialState::Client);
}

bool ClientSslSocketFactory::implementsSecureTransport() const { return true; }

ServerSslSocketFactory::ServerSslSocketFactory(const ServerContextConfig& config,
ServerSslSocketFactory::ServerSslSocketFactory(ServerContextConfigPtr config,
Ssl::ContextManager& manager,
Stats::Scope& stats_scope,
const std::vector<std::string>& server_names)
: ssl_ctx_(manager.createSslServerContext(stats_scope, config, server_names)) {}
: manager_(manager), stats_scope_(stats_scope), config_(std::move(config)),
server_names_(server_names),
ssl_ctx_(manager_.createSslServerContext(stats_scope_, *config_, server_names_)) {}

Network::TransportSocketPtr ServerSslSocketFactory::createTransportSocket() const {
return std::make_unique<Ssl::SslSocket>(ssl_ctx_, Ssl::InitialState::Server);
Expand Down
11 changes: 9 additions & 2 deletions source/common/ssl/ssl_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,32 @@ class SslSocket : public Network::TransportSocket,

class ClientSslSocketFactory : public Network::TransportSocketFactory {
public:
ClientSslSocketFactory(const ClientContextConfig& config, Ssl::ContextManager& manager,
ClientSslSocketFactory(ClientContextConfigPtr config, Ssl::ContextManager& manager,
Stats::Scope& stats_scope);

Network::TransportSocketPtr createTransportSocket() const override;
bool implementsSecureTransport() const override;

private:
Ssl::ContextManager& manager_;
Stats::Scope& stats_scope_;
ClientContextConfigPtr config_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to retain those? IT doesn't seem that those are used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be used in a later PR to create a new context when context_config is updated with new secret.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the code to use it

void ServerSslSocketFactory::onConfigUpdate() {
  ssl_ctx_ = manager_.createSslServerContext(stats_scope_, *config_, server_names_);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks!

ClientContextSharedPtr ssl_ctx_;
};

class ServerSslSocketFactory : public Network::TransportSocketFactory {
public:
ServerSslSocketFactory(const ServerContextConfig& config, Ssl::ContextManager& manager,
ServerSslSocketFactory(ServerContextConfigPtr config, Ssl::ContextManager& manager,
Stats::Scope& stats_scope, const std::vector<std::string>& server_names);

Network::TransportSocketPtr createTransportSocket() const override;
bool implementsSecureTransport() const override;

private:
Ssl::ContextManager& manager_;
Stats::Scope& stats_scope_;
ServerContextConfigPtr config_;
const std::vector<std::string> server_names_;
ServerContextSharedPtr ssl_ctx_;
};

Expand Down
18 changes: 8 additions & 10 deletions source/extensions/transport_sockets/ssl/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ namespace SslTransport {
Network::TransportSocketFactoryPtr UpstreamSslSocketFactory::createTransportSocketFactory(
const Protobuf::Message& message,
Server::Configuration::TransportSocketFactoryContext& context) {
auto client_config = std::make_unique<Ssl::ClientContextConfigImpl>(
MessageUtil::downcastAndValidate<const envoy::api::v2::auth::UpstreamTlsContext&>(message),
context.secretManager());
return std::make_unique<Ssl::ClientSslSocketFactory>(
Ssl::ClientContextConfigImpl(
MessageUtil::downcastAndValidate<const envoy::api::v2::auth::UpstreamTlsContext&>(
message),
context.secretManager()),
context.sslContextManager(), context.statsScope());
std::move(client_config), context.sslContextManager(), context.statsScope());
}

ProtobufTypes::MessagePtr UpstreamSslSocketFactory::createEmptyConfigProto() {
Expand All @@ -35,12 +34,11 @@ static Registry::RegisterFactory<UpstreamSslSocketFactory,
Network::TransportSocketFactoryPtr DownstreamSslSocketFactory::createTransportSocketFactory(
const Protobuf::Message& message, Server::Configuration::TransportSocketFactoryContext& context,
const std::vector<std::string>& server_names) {
auto server_config = std::make_unique<Ssl::ServerContextConfigImpl>(
MessageUtil::downcastAndValidate<const envoy::api::v2::auth::DownstreamTlsContext&>(message),
context.secretManager());
return std::make_unique<Ssl::ServerSslSocketFactory>(
Ssl::ServerContextConfigImpl(
MessageUtil::downcastAndValidate<const envoy::api::v2::auth::DownstreamTlsContext&>(
message),
context.secretManager()),
context.sslContextManager(), context.statsScope(), server_names);
std::move(server_config), context.sslContextManager(), context.statsScope(), server_names);
}

ProtobufTypes::MessagePtr DownstreamSslSocketFactory::createEmptyConfigProto() {
Expand Down
10 changes: 5 additions & 5 deletions test/common/grpc/grpc_client_integration_test_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,10 @@ class GrpcSslClientIntegrationTest : public GrpcClientIntegrationTest {
tls_cert->mutable_private_key()->set_filename(
TestEnvironment::runfilesPath("test/config/integration/certs/clientkey.pem"));
}
Ssl::ClientContextConfigImpl cfg(tls_context, secret_manager_);
auto cfg = std::make_unique<Ssl::ClientContextConfigImpl>(tls_context, secret_manager_);

mock_cluster_info_->transport_socket_factory_ =
std::make_unique<Ssl::ClientSslSocketFactory>(cfg, context_manager_, *stats_store_);
mock_cluster_info_->transport_socket_factory_ = std::make_unique<Ssl::ClientSslSocketFactory>(
std::move(cfg), context_manager_, *stats_store_);
ON_CALL(*mock_cluster_info_, transportSocketFactory())
.WillByDefault(ReturnRef(*mock_cluster_info_->transport_socket_factory_));
async_client_transport_socket_ =
Expand All @@ -489,11 +489,11 @@ class GrpcSslClientIntegrationTest : public GrpcClientIntegrationTest {
TestEnvironment::runfilesPath("test/config/integration/certs/cacert.pem"));
}

Ssl::ServerContextConfigImpl cfg(tls_context, secret_manager_);
auto cfg = std::make_unique<Ssl::ServerContextConfigImpl>(tls_context, secret_manager_);

static Stats::Scope* upstream_stats_store = new Stats::IsolatedStoreImpl();
return std::make_unique<Ssl::ServerSslSocketFactory>(
cfg, context_manager_, *upstream_stats_store, std::vector<std::string>{});
std::move(cfg), context_manager_, *upstream_stats_store, std::vector<std::string>{});
}

bool use_client_cert_{};
Expand Down
Loading