Skip to content

Be able to configure SSL client protocols and ciphers #2905

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;

import org.springframework.util.CollectionUtils;

/**
* @author Alberto C. Ríos
*/
Expand Down Expand Up @@ -53,6 +55,14 @@ private SslContext getSslContext() throws SSLException {
sslContextBuilder.trustManager(getTrustedX509CertificatesForTrustManager());
}

if (!CollectionUtils.isEmpty(ssl.getProtocols())) {
sslContextBuilder.protocols(ssl.getProtocols());
}

if (!CollectionUtils.isEmpty(ssl.getCiphers())) {
sslContextBuilder.ciphers(ssl.getCiphers());
}

return sslContextBuilder.keyManager(getKeyManagerFactory()).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ public static class Ssl {
/** Key password, default is same as keyStorePassword. */
private String keyPassword;

/** The protocols to enable, or empty to enable the default protocols. */
private List<String> protocols = new ArrayList<>();

/** The cipher suites to enable, in the order of preference. empty to use default cipher suites. */
private List<String> ciphers = new ArrayList<>();

public String getKeyStorePassword() {
return keyStorePassword;
}
Expand Down Expand Up @@ -456,6 +462,22 @@ public void setKeyPassword(String keyPassword) {
this.keyPassword = keyPassword;
}

public List<String> getProtocols() {
return protocols;
}

public void setProtocols(List<String> protocols) {
this.protocols = protocols;
}

public List<String> getCiphers() {
return ciphers;
}

public void setCiphers(List<String> ciphers) {
this.ciphers = ciphers;
}

public List<String> getTrustedX509Certificates() {
return trustedX509Certificates;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import reactor.netty.tcp.SslProvider;

import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.util.CollectionUtils;

public class HttpClientSslConfigurer extends AbstractSslConfigurer<HttpClient, HttpClient> {

Expand Down Expand Up @@ -60,6 +61,13 @@ else if (ssl.isUseInsecureTrustManager()) {
setTrustManager(sslContextBuilder, InsecureTrustManagerFactory.INSTANCE);
}

if (!CollectionUtils.isEmpty(ssl.getProtocols())) {
sslContextBuilder.protocols(ssl.getProtocols());
}
if (!CollectionUtils.isEmpty(ssl.getCiphers())) {
sslContextBuilder.ciphers(ssl.getCiphers());
}

try {
sslContextBuilder.keyManager(getKeyManagerFactory());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2013-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.cloud.gateway.test.ssl;

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;

import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

@SpringBootTest(webEnvironment = RANDOM_PORT)
@DirtiesContext
@ActiveProfiles("forced-client-protocols-ssl")
public class ForcedClientProtocolsSSLTests extends SingleCertSSLTests {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
spring:
cloud:
gateway:
httpclient:
ssl:
protocols:
- TLSv1.3
- TLSv1.2
- TLSv1.1
- TLSv1
ciphers:
- TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
- TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256