From 9737aa1ddc49a8b08b4f1046b7ff2751b70041d7 Mon Sep 17 00:00:00 2001 From: Aurora Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Tue, 16 Aug 2022 22:20:43 +0300 Subject: [PATCH] Fix NPE on null Keystore when using old .jks cert --- .../plan/delivery/webserver/http/JettyWebserver.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/http/JettyWebserver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/http/JettyWebserver.java index c84ba8b56..150333aa3 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/http/JettyWebserver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/http/JettyWebserver.java @@ -33,6 +33,7 @@ import org.eclipse.jetty.util.ssl.SslContextFactory; import javax.inject.Inject; import javax.inject.Singleton; import java.io.File; +import java.security.KeyStore; import java.security.KeyStoreException; import java.security.cert.Certificate; import java.security.cert.X509Certificate; @@ -130,14 +131,14 @@ public class JettyWebserver implements WebServer { } webserverLogMessages.infoWebserverEnabled(getPort()); - sslContext.ifPresent(this::logCertificateExpiryInformation); + sslContext.map(SslContextFactory::getKeyStore).ifPresent(this::logCertificateExpiryInformation); responseResolver.registerPages(); } - private void logCertificateExpiryInformation(SslContextFactory.Server sslContext) { + private void logCertificateExpiryInformation(KeyStore keyStore) { try { - Certificate certificate = sslContext.getKeyStore().getCertificate(webserverConfiguration.getAlias()); + Certificate certificate = keyStore.getCertificate(webserverConfiguration.getAlias()); if (certificate instanceof X509Certificate) { long expires = ((X509Certificate) certificate).getNotAfter().getTime(); long timeLeft = expires - System.currentTimeMillis();