Skip to content

Commit

Permalink
Protect against NPE when keystore is missing
Browse files Browse the repository at this point in the history
Update `SslInfo` to protect against a potential `NullPointerException`.

Fixes gh-43078
  • Loading branch information
philwebb committed Nov 9, 2024
1 parent 151d408 commit 77817ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ private BundleInfo(String name, SslBundle sslBundle) {
}

private List<CertificateChainInfo> extractCertificateChains(KeyStore keyStore) {
if (keyStore == null) {
return Collections.emptyList();
}
try {
return Collections.list(keyStore.aliases())
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand Down Expand Up @@ -211,6 +212,15 @@ void multipleBundlesShouldProvideSslInfo(@TempDir Path tempDir) throws IOExcepti
});
}

@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++) {
Expand Down

0 comments on commit 77817ae

Please sign in to comment.