Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: allow renegotiation when acting as a client. #3551

Merged
merged 4 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions api/envoy/api/v2/auth/cert.proto
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ message UpstreamTlsContext {

// SNI string to use when creating TLS backend connections.
string sni = 2 [(validate.rules).string.max_bytes = 255];

// If true, server-initiated TLS renegotiation will be allowed.
//
// .. attention::
//
// TLS renegotiation is considered insecure and shouldn't be used unless absolutely necessary.
bool allow_renegotiation = 3;
}

message DownstreamTlsContext {
Expand Down
2 changes: 2 additions & 0 deletions docs/root/intro/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ Version history
* tls: added support for multiple
:ref:`verify_certificate_hash <envoy_api_field_auth.CertificateValidationContext.verify_certificate_hash>`
values.
* tls: added support for :ref:`renegotiation <envoy_api_field_auth.UpstreamTlsContext.allow_renegotiation>`
when acting as a client.
* tls: removed support for legacy SHA-2 CBC cipher suites.
* tracing: the sampling decision is now delegated to the tracers, allowing the tracer to decide when and if
to use it. For example, if the :ref:`x-b3-sampled <config_http_conn_man_headers_x-b3-sampled>` header
Expand Down
5 changes: 5 additions & 0 deletions include/envoy/ssl/context_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ class ClientContextConfig : public virtual ContextConfig {
* Otherwise, ""
*/
virtual const std::string& serverNameIndication() const PURE;

/**
* @return true if server-initiated TLS renegotiation will be allowed.
*/
virtual bool allowRenegotiation() const PURE;
};

class ServerContextConfig : public virtual ContextConfig {
Expand Down
3 changes: 2 additions & 1 deletion source/common/ssl/context_config_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ unsigned ContextConfigImpl::tlsVersionFromProto(

ClientContextConfigImpl::ClientContextConfigImpl(
const envoy::api::v2::auth::UpstreamTlsContext& config)
: ContextConfigImpl(config.common_tls_context()), server_name_indication_(config.sni()) {
: ContextConfigImpl(config.common_tls_context()), server_name_indication_(config.sni()),
allow_renegotiation_(config.allow_renegotiation()) {
// BoringSSL treats this as a C string, so embedded NULL characters will not
// be handled correctly.
if (server_name_indication_.find('\0') != std::string::npos) {
Expand Down
2 changes: 2 additions & 0 deletions source/common/ssl/context_config_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ class ClientContextConfigImpl : public ContextConfigImpl, public ClientContextCo

// Ssl::ClientContextConfig
const std::string& serverNameIndication() const override { return server_name_indication_; }
bool allowRenegotiation() const override { return allow_renegotiation_; }

private:
const std::string server_name_indication_;
const bool allow_renegotiation_;
};

class ServerContextConfigImpl : public ContextConfigImpl, public ServerContextConfig {
Expand Down
9 changes: 6 additions & 3 deletions source/common/ssl/context_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,13 @@ std::string ContextImpl::getSerialNumber(const X509* cert) {

ClientContextImpl::ClientContextImpl(ContextManagerImpl& parent, Stats::Scope& scope,
const ClientContextConfig& config)
: ContextImpl(parent, scope, config) {
: ContextImpl(parent, scope, config), server_name_indication_(config.serverNameIndication()),
allow_renegotiation_(config.allowRenegotiation()) {
if (!parsed_alpn_protocols_.empty()) {
int rc = SSL_CTX_set_alpn_protos(ctx_.get(), &parsed_alpn_protocols_[0],
parsed_alpn_protocols_.size());
RELEASE_ASSERT(rc == 0);
}

server_name_indication_ = config.serverNameIndication();
}

bssl::UniquePtr<SSL> ClientContextImpl::newSsl() const {
Expand All @@ -473,6 +472,10 @@ bssl::UniquePtr<SSL> ClientContextImpl::newSsl() const {
RELEASE_ASSERT(rc);
}

if (allow_renegotiation_) {
SSL_set_renegotiate_mode(ssl_con.get(), ssl_renegotiate_freely);
}

return ssl_con;
}

Expand Down
3 changes: 2 additions & 1 deletion source/common/ssl/context_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ class ClientContextImpl : public ContextImpl, public ClientContext {
bssl::UniquePtr<SSL> newSsl() const override;

private:
std::string server_name_indication_;
const std::string server_name_indication_;
const bool allow_renegotiation_;
};

class ServerContextImpl : public ContextImpl, public ServerContext {
Expand Down