Browse Source

Protect against NPE when keystore is missing

Update `SslInfo` to protect against a potential `NullPointerException`.

Fixes gh-43078
pull/43085/head
Phillip Webb 1 year ago
parent
commit
77817ae314
  1. 3
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/SslInfo.java
  2. 10
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/info/SslInfoTests.java

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

@ -76,6 +76,9 @@ public class SslInfo { @@ -76,6 +76,9 @@ public class SslInfo {
}
private List<CertificateChainInfo> extractCertificateChains(KeyStore keyStore) {
if (keyStore == null) {
return Collections.emptyList();
}
try {
return Collections.list(keyStore.aliases())
.stream()

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

@ -34,6 +34,7 @@ import org.springframework.boot.info.SslInfo.CertificateInfo; @@ -34,6 +34,7 @@ import org.springframework.boot.info.SslInfo.CertificateInfo;
import org.springframework.boot.info.SslInfo.CertificateValidityInfo.Status;
import org.springframework.boot.ssl.DefaultSslBundleRegistry;
import org.springframework.boot.ssl.SslBundle;
import org.springframework.boot.ssl.SslBundleKey;
import org.springframework.boot.ssl.SslStoreBundle;
import org.springframework.boot.ssl.jks.JksSslStoreBundle;
import org.springframework.boot.ssl.jks.JksSslStoreDetails;
@ -211,6 +212,15 @@ class SslInfoTests { @@ -211,6 +212,15 @@ class SslInfoTests {
});
}
@Test
void nullKeyStore() {
DefaultSslBundleRegistry sslBundleRegistry = new DefaultSslBundleRegistry();
sslBundleRegistry.registerBundle("test", SslBundle.of(SslStoreBundle.NONE, SslBundleKey.NONE));
SslInfo sslInfo = new SslInfo(sslBundleRegistry, Duration.ofDays(7));
assertThat(sslInfo.getBundles()).hasSize(1);
assertThat(sslInfo.getBundles().get(0).getCertificateChains()).isEmpty();
}
private SslInfo createSslInfo(String... locations) {
DefaultSslBundleRegistry sslBundleRegistry = new DefaultSslBundleRegistry();
for (int i = 0; i < locations.length; i++) {

Loading…
Cancel
Save