Protect against NPE when keystore is missing
Update `SslInfo` to protect against a potential `NullPointerException`. Fixes gh-43078
This commit is contained in:
parent
151d4085af
commit
77817ae314
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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 {
|
|||
});
|
||||
}
|
||||
|
||||
@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…
Reference in New Issue