diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundle.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundle.java index 184c31b1719..39512f2b3e8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundle.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundle.java @@ -112,14 +112,18 @@ public final class PropertiesSslBundle implements SslBundle { } private static SslStoreBundle asSslStoreBundle(PemSslBundleProperties properties) { - PemSslStore keyStore = asPemSslStore(properties.getKeystore(), properties.getKey().getAlias()); - PemSslStore trustStore = asPemSslStore(properties.getTruststore(), properties.getKey().getAlias()); + PemSslStore keyStore = asPemSslStore(properties.getKeystore()); + if (keyStore != null) { + keyStore = keyStore.withAlias(properties.getKey().getAlias()) + .withPassword(properties.getKey().getPassword()); + } + PemSslStore trustStore = asPemSslStore(properties.getTruststore()); return new PemSslStoreBundle(keyStore, trustStore); } - private static PemSslStore asPemSslStore(PemSslBundleProperties.Store properties, String alias) { + private static PemSslStore asPemSslStore(PemSslBundleProperties.Store properties) { try { - PemSslStoreDetails details = asStoreDetails(properties, alias); + PemSslStoreDetails details = asStoreDetails(properties); PemSslStore pemSslStore = PemSslStore.load(details); if (properties.isVerifyKeys()) { CertificateMatcher certificateMatcher = new CertificateMatcher(pemSslStore.privateKey()); @@ -133,9 +137,9 @@ public final class PropertiesSslBundle implements SslBundle { } } - private static PemSslStoreDetails asStoreDetails(PemSslBundleProperties.Store properties, String alias) { - return new PemSslStoreDetails(properties.getType(), alias, null, properties.getCertificate(), - properties.getPrivateKey(), properties.getPrivateKeyPassword()); + private static PemSslStoreDetails asStoreDetails(PemSslBundleProperties.Store properties) { + return new PemSslStoreDetails(properties.getType(), properties.getCertificate(), properties.getPrivateKey(), + properties.getPrivateKeyPassword()); } private static SslStoreBundle asSslStoreBundle(JksSslBundleProperties properties) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundleTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundleTests.java index 6143a7919d3..52447f47b62 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundleTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundleTests.java @@ -66,10 +66,10 @@ class PropertiesSslBundleTests { Certificate certificate = sslBundle.getStores().getKeyStore().getCertificate("alias"); assertThat(certificate).isNotNull(); assertThat(certificate.getType()).isEqualTo("X.509"); - Key key = sslBundle.getStores().getKeyStore().getKey("alias", null); + Key key = sslBundle.getStores().getKeyStore().getKey("alias", "secret".toCharArray()); assertThat(key).isNotNull(); assertThat(key.getAlgorithm()).isEqualTo("RSA"); - certificate = sslBundle.getStores().getTrustStore().getCertificate("alias"); + certificate = sslBundle.getStores().getTrustStore().getCertificate("ssl"); assertThat(certificate).isNotNull(); assertThat(certificate.getType()).isEqualTo("X.509"); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/WebServerSslBundle.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/WebServerSslBundle.java index c9f989bfae0..adcff6722b0 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/WebServerSslBundle.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/WebServerSslBundle.java @@ -65,8 +65,7 @@ public final class WebServerSslBundle implements SslBundle { ssl.getCertificatePrivateKey()) .withAlias(ssl.getKeyAlias()); PemSslStoreDetails trustStoreDetails = new PemSslStoreDetails(ssl.getTrustStoreType(), - ssl.getTrustCertificate(), ssl.getTrustCertificatePrivateKey()) - .withAlias(ssl.getKeyAlias()); + ssl.getTrustCertificate(), ssl.getTrustCertificatePrivateKey()); return new PemSslStoreBundle(keyStoreDetails, trustStoreDetails); }