Skip to content

Commit 2ffb81f

Browse files
committed
Merge branch '2.2.x' into 2.3.x
Closes gh-24052
2 parents e447be6 + 2425dcd commit 2ffb81f

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/SslConnectorCustomizer.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,8 +69,12 @@ protected void configureSsl(AbstractHttp11JsseProtocol<?> protocol, Ssl ssl, Ssl
6969
protocol.setSSLEnabled(true);
7070
protocol.setSslProtocol(ssl.getProtocol());
7171
configureSslClientAuth(protocol, ssl);
72-
protocol.setKeystorePass(ssl.getKeyStorePassword());
73-
protocol.setKeyPass(ssl.getKeyPassword());
72+
if (ssl.getKeyStorePassword() != null) {
73+
protocol.setKeystorePass(ssl.getKeyStorePassword());
74+
}
75+
if (ssl.getKeyPassword() != null) {
76+
protocol.setKeyPass(ssl.getKeyPassword());
77+
}
7478
protocol.setKeyAlias(ssl.getKeyAlias());
7579
String ciphers = StringUtils.arrayToCommaDelimitedString(ssl.getCiphers());
7680
if (StringUtils.hasText(ciphers)) {

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/SslConnectorCustomizerTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.catalina.connector.Connector;
2929
import org.apache.catalina.startup.Tomcat;
3030
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
31+
import org.apache.coyote.http11.Http11NioProtocol;
3132
import org.apache.tomcat.util.net.SSLHostConfig;
3233
import org.junit.jupiter.api.AfterEach;
3334
import org.junit.jupiter.api.BeforeEach;
@@ -185,6 +186,26 @@ void customizeWhenSslIsEnabledWithNoKeyStoreThrowsWebServerException() {
185186
.withMessageContaining("Could not load key store 'null'");
186187
}
187188

189+
@Test
190+
void keyStorePasswordIsNotSetWhenNull() {
191+
Http11NioProtocol protocol = (Http11NioProtocol) this.tomcat.getConnector().getProtocolHandler();
192+
protocol.setKeystorePass("password");
193+
Ssl ssl = new Ssl();
194+
ssl.setKeyStore("src/test/resources/test.jks");
195+
new SslConnectorCustomizer(ssl, null).customize(this.tomcat.getConnector());
196+
assertThat(protocol.getKeystorePass()).isEqualTo("password");
197+
}
198+
199+
@Test
200+
void keyPasswordIsNotSetWhenNull() {
201+
Http11NioProtocol protocol = (Http11NioProtocol) this.tomcat.getConnector().getProtocolHandler();
202+
protocol.setKeyPass("password");
203+
Ssl ssl = new Ssl();
204+
ssl.setKeyStore("src/test/resources/test.jks");
205+
new SslConnectorCustomizer(ssl, null).customize(this.tomcat.getConnector());
206+
assertThat(protocol.getKeyPass()).isEqualTo("password");
207+
}
208+
188209
private KeyStore loadStore() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
189210
KeyStore keyStore = KeyStore.getInstance("JKS");
190211
Resource resource = new ClassPathResource("test.jks");

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ protected final void testBasicSslWithKeyStore(String keyStore, String keyPasswor
131131
Ssl ssl = new Ssl();
132132
ssl.setKeyStore(keyStore);
133133
ssl.setKeyPassword(keyPassword);
134+
ssl.setKeyStorePassword("secret");
134135
factory.setSsl(ssl);
135136
this.webServer = factory.getWebServer(new EchoHandler());
136137
this.webServer.start();
@@ -150,6 +151,7 @@ void sslWithValidAlias() {
150151
AbstractReactiveWebServerFactory factory = getFactory();
151152
Ssl ssl = new Ssl();
152153
ssl.setKeyStore(keyStore);
154+
ssl.setKeyStorePassword("secret");
153155
ssl.setKeyPassword(keyPassword);
154156
ssl.setKeyAlias("test-alias");
155157
factory.setSsl(ssl);
@@ -198,6 +200,7 @@ void sslWantsClientAuthenticationSucceedsWithClientCertificate() throws Exceptio
198200
ssl.setClientAuth(Ssl.ClientAuth.WANT);
199201
ssl.setKeyStore("classpath:test.jks");
200202
ssl.setKeyPassword("password");
203+
ssl.setKeyStorePassword("secret");
201204
ssl.setTrustStore("classpath:test.jks");
202205
testClientAuthSuccess(ssl, buildTrustAllSslWithClientKeyConnector());
203206
}
@@ -209,6 +212,7 @@ void sslWantsClientAuthenticationSucceedsWithoutClientCertificate() {
209212
ssl.setKeyStore("classpath:test.jks");
210213
ssl.setKeyPassword("password");
211214
ssl.setTrustStore("classpath:test.jks");
215+
ssl.setKeyStorePassword("secret");
212216
testClientAuthSuccess(ssl, buildTrustAllSslConnector());
213217
}
214218

@@ -243,6 +247,7 @@ void sslNeedsClientAuthenticationSucceedsWithClientCertificate() throws Exceptio
243247
Ssl ssl = new Ssl();
244248
ssl.setClientAuth(Ssl.ClientAuth.NEED);
245249
ssl.setKeyStore("classpath:test.jks");
250+
ssl.setKeyStorePassword("secret");
246251
ssl.setKeyPassword("password");
247252
ssl.setTrustStore("classpath:test.jks");
248253
testClientAuthSuccess(ssl, buildTrustAllSslWithClientKeyConnector());
@@ -253,6 +258,7 @@ void sslNeedsClientAuthenticationFailsWithoutClientCertificate() {
253258
Ssl ssl = new Ssl();
254259
ssl.setClientAuth(Ssl.ClientAuth.NEED);
255260
ssl.setKeyStore("classpath:test.jks");
261+
ssl.setKeyStorePassword("secret");
256262
ssl.setKeyPassword("password");
257263
ssl.setTrustStore("classpath:test.jks");
258264
testClientAuthFailure(ssl, buildTrustAllSslConnector());

0 commit comments

Comments
 (0)