Skip to content

Commit 77817ae

Browse files
committed
Protect against NPE when keystore is missing
Update `SslInfo` to protect against a potential `NullPointerException`. Fixes gh-43078
1 parent 151d408 commit 77817ae

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/SslInfo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ private BundleInfo(String name, SslBundle sslBundle) {
7676
}
7777

7878
private List<CertificateChainInfo> extractCertificateChains(KeyStore keyStore) {
79+
if (keyStore == null) {
80+
return Collections.emptyList();
81+
}
7982
try {
8083
return Collections.list(keyStore.aliases())
8184
.stream()

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/info/SslInfoTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.springframework.boot.info.SslInfo.CertificateValidityInfo.Status;
3535
import org.springframework.boot.ssl.DefaultSslBundleRegistry;
3636
import org.springframework.boot.ssl.SslBundle;
37+
import org.springframework.boot.ssl.SslBundleKey;
3738
import org.springframework.boot.ssl.SslStoreBundle;
3839
import org.springframework.boot.ssl.jks.JksSslStoreBundle;
3940
import org.springframework.boot.ssl.jks.JksSslStoreDetails;
@@ -211,6 +212,15 @@ void multipleBundlesShouldProvideSslInfo(@TempDir Path tempDir) throws IOExcepti
211212
});
212213
}
213214

215+
@Test
216+
void nullKeyStore() {
217+
DefaultSslBundleRegistry sslBundleRegistry = new DefaultSslBundleRegistry();
218+
sslBundleRegistry.registerBundle("test", SslBundle.of(SslStoreBundle.NONE, SslBundleKey.NONE));
219+
SslInfo sslInfo = new SslInfo(sslBundleRegistry, Duration.ofDays(7));
220+
assertThat(sslInfo.getBundles()).hasSize(1);
221+
assertThat(sslInfo.getBundles().get(0).getCertificateChains()).isEmpty();
222+
}
223+
214224
private SslInfo createSslInfo(String... locations) {
215225
DefaultSslBundleRegistry sslBundleRegistry = new DefaultSslBundleRegistry();
216226
for (int i = 0; i < locations.length; i++) {

0 commit comments

Comments
 (0)