Skip to content

Commit 30a7426

Browse files
committed
Apply key property to the keystore and not to the truststore
Update `PropertiesSslBundle` so that key properties are now only applied to the keystore and not the truststore. Closes gh-38125
1 parent 5dc5c2a commit 30a7426

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundle.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,18 @@ public static SslBundle get(JksSslBundleProperties properties) {
112112
}
113113

114114
private static SslStoreBundle asSslStoreBundle(PemSslBundleProperties properties) {
115-
PemSslStore keyStore = asPemSslStore(properties.getKeystore(), properties.getKey().getAlias());
116-
PemSslStore trustStore = asPemSslStore(properties.getTruststore(), properties.getKey().getAlias());
115+
PemSslStore keyStore = asPemSslStore(properties.getKeystore());
116+
if (keyStore != null) {
117+
keyStore = keyStore.withAlias(properties.getKey().getAlias())
118+
.withPassword(properties.getKey().getPassword());
119+
}
120+
PemSslStore trustStore = asPemSslStore(properties.getTruststore());
117121
return new PemSslStoreBundle(keyStore, trustStore);
118122
}
119123

120-
private static PemSslStore asPemSslStore(PemSslBundleProperties.Store properties, String alias) {
124+
private static PemSslStore asPemSslStore(PemSslBundleProperties.Store properties) {
121125
try {
122-
PemSslStoreDetails details = asStoreDetails(properties, alias);
126+
PemSslStoreDetails details = asStoreDetails(properties);
123127
PemSslStore pemSslStore = PemSslStore.load(details);
124128
if (properties.isVerifyKeys()) {
125129
CertificateMatcher certificateMatcher = new CertificateMatcher(pemSslStore.privateKey());
@@ -133,9 +137,9 @@ private static PemSslStore asPemSslStore(PemSslBundleProperties.Store properties
133137
}
134138
}
135139

136-
private static PemSslStoreDetails asStoreDetails(PemSslBundleProperties.Store properties, String alias) {
137-
return new PemSslStoreDetails(properties.getType(), alias, null, properties.getCertificate(),
138-
properties.getPrivateKey(), properties.getPrivateKeyPassword());
140+
private static PemSslStoreDetails asStoreDetails(PemSslBundleProperties.Store properties) {
141+
return new PemSslStoreDetails(properties.getType(), properties.getCertificate(), properties.getPrivateKey(),
142+
properties.getPrivateKeyPassword());
139143
}
140144

141145
private static SslStoreBundle asSslStoreBundle(JksSslBundleProperties properties) {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundleTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ void pemPropertiesAreMappedToSslBundle() throws Exception {
6666
Certificate certificate = sslBundle.getStores().getKeyStore().getCertificate("alias");
6767
assertThat(certificate).isNotNull();
6868
assertThat(certificate.getType()).isEqualTo("X.509");
69-
Key key = sslBundle.getStores().getKeyStore().getKey("alias", null);
69+
Key key = sslBundle.getStores().getKeyStore().getKey("alias", "secret".toCharArray());
7070
assertThat(key).isNotNull();
7171
assertThat(key.getAlgorithm()).isEqualTo("RSA");
72-
certificate = sslBundle.getStores().getTrustStore().getCertificate("alias");
72+
certificate = sslBundle.getStores().getTrustStore().getCertificate("ssl");
7373
assertThat(certificate).isNotNull();
7474
assertThat(certificate.getType()).isEqualTo("X.509");
7575
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/WebServerSslBundle.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ private static SslStoreBundle createPemStoreBundle(Ssl ssl) {
6565
ssl.getCertificatePrivateKey())
6666
.withAlias(ssl.getKeyAlias());
6767
PemSslStoreDetails trustStoreDetails = new PemSslStoreDetails(ssl.getTrustStoreType(),
68-
ssl.getTrustCertificate(), ssl.getTrustCertificatePrivateKey())
69-
.withAlias(ssl.getKeyAlias());
68+
ssl.getTrustCertificate(), ssl.getTrustCertificatePrivateKey());
7069
return new PemSslStoreBundle(keyStoreDetails, trustStoreDetails);
7170
}
7271

0 commit comments

Comments
 (0)