You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ra...@apache.org on 2026/10/20 23:52:36 UTC
(logging-log4j2) branch 2.x updated: fix: handle SSL stores without an explicit type (#4359)
This is an automated email from the ASF dual-hosted git repository.
ramanathan1504 pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/2.x by this push:
new a8ba265d9d fix: handle SSL stores without an explicit type (#4359)
a8ba265d9d is described below
commit a8ba265d9df2ade5389a8e550153e55e17934ec1
Author: Efe <ef...@rexcode.co.uk>
AuthorDate: Wed Oct 21 02:52:30 2026 +0300
fix: handle SSL stores without an explicit type (#4359)
* fix: handle SSL stores without an explicit type
Signed-off-by: Efe Gökdemir <ef...@rexcode.co.uk>
* fix: handle default SSL store types consistently
Assisted-by: Codex (GPT-5)
Signed-off-by: Efe Gökdemir <ef...@rexcode.co.uk>
* style: apply Spotless formatting
* Test empty-password PKCS12 keystore loading
* Update src/changelog/.2.x.x/4346_default_keystore_type.xml
---------
Signed-off-by: Efe Gökdemir <ef...@rexcode.co.uk>
Co-authored-by: Ramanathan Muthu <ra...@apache.org>
---
.../core/net/ssl/SslConfigurationFactoryTest.java | 47 ++++++++++++++++++++++
.../core/net/ssl/SslConfigurationFactory.java | 5 ++-
.../.2.x.x/4346_default_keystore_type.xml | 11 +++++
3 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationFactoryTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationFactoryTest.java
index 308f7546ef..f554f6556b 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationFactoryTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationFactoryTest.java
@@ -16,9 +16,11 @@
*/
package org.apache.logging.log4j.core.net.ssl;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import java.security.KeyStore;
import java.util.Properties;
import java.util.stream.Stream;
import org.apache.logging.log4j.test.junit.UsingStatusListener;
@@ -91,6 +93,51 @@ class SslConfigurationFactoryTest {
assertNotNull(sslConfiguration.getTrustStoreConfig());
}
+ @Test
+ void testStoreLocationWithoutTypeUsesDefaultType() {
+ final Properties props = new Properties();
+ props.setProperty(KEYSTORE_LOCATION_PROP_NAME, SslKeyStoreConstants.KEYSTORE_LOCATION);
+
+ final SslConfiguration configuration =
+ SslConfigurationFactory.createSslConfiguration(new PropertiesUtil(props));
+
+ assertNotNull(configuration);
+ assertNotNull(configuration.getKeyStoreConfig());
+ assertEquals(
+ SslConfigurationDefaults.KEYSTORE_TYPE,
+ configuration.getKeyStoreConfig().getKeyStoreType());
+ }
+
+ @Test
+ void testTrustStoreLocationWithoutTypeUsesDefaultType() {
+ final Properties props = new Properties();
+ props.setProperty(TRUSTSTORE_LOCATION_PROP_NAME, SslKeyStoreConstants.TRUSTSTORE_LOCATION);
+
+ final SslConfiguration configuration =
+ SslConfigurationFactory.createSslConfiguration(new PropertiesUtil(props));
+
+ assertNotNull(configuration);
+ assertNotNull(configuration.getTrustStoreConfig());
+ assertEquals(
+ SslConfigurationDefaults.KEYSTORE_TYPE,
+ configuration.getTrustStoreConfig().getKeyStoreType());
+ }
+
+ @Test
+ void testEmptyPasswordLoadsCertificateWithoutExplicitStoreType() throws Exception {
+ final Properties props = new Properties();
+ props.setProperty(KEYSTORE_LOCATION_PROP_NAME, SslKeyStoreConstants.KEYSTORE_P12_NOPASS_LOCATION);
+ props.setProperty(KEYSTORE_PASSWORD_PROP_NAME, "");
+
+ final SslConfiguration configuration =
+ SslConfigurationFactory.createSslConfiguration(new PropertiesUtil(props));
+
+ assertNotNull(configuration);
+ assertNotNull(configuration.getKeyStoreConfig());
+ final KeyStore loadedKeyStore = configuration.getKeyStoreConfig().getKeyStore();
+ assertNotNull(loadedKeyStore.getCertificate("1"));
+ }
+
static Stream<Arguments> windowsKeystoreConfigs() {
final String[] emptyOrNull = {"", null};
final Stream.Builder<Arguments> builder = Stream.builder();
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationFactory.java
index 2da16b886d..a604b2bf4c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationFactory.java
@@ -94,6 +94,8 @@ public class SslConfigurationFactory {
}
private static char[] getPassword(final String password, final String keyStoreType) {
+ final String effectiveKeyStoreType =
+ keyStoreType == null ? SslConfigurationDefaults.KEYSTORE_TYPE : keyStoreType;
// Note from Tomcat's SSLUtiBase#getStore:
//
// JKS key stores treat null and "" interchangeably.
@@ -103,7 +105,8 @@ public class SslConfigurationFactory {
// - generally use null if pass is null or ""
// - for JKS or PKCS12 only use null if pass is null
// (because JKS will auto-switch to PKCS12)
- if (keyStoreType.equals(StoreConfiguration.JKS) || keyStoreType.equals(StoreConfiguration.PKCS12)) {
+ if (StoreConfiguration.JKS.equalsIgnoreCase(effectiveKeyStoreType)
+ || StoreConfiguration.PKCS12.equalsIgnoreCase(effectiveKeyStoreType)) {
return password != null ? password.toCharArray() : null;
}
return Strings.isEmpty(password) ? null : password.toCharArray();
diff --git a/src/changelog/.2.x.x/4346_default_keystore_type.xml b/src/changelog/.2.x.x/4346_default_keystore_type.xml
new file mode 100644
index 0000000000..2684d4d907
--- /dev/null
+++ b/src/changelog/.2.x.x/4346_default_keystore_type.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns="https://logging.apache.org/xml/ns"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="fixed">
+ <issue id="4346" link="https://github.com/apache/logging-log4j2/issues/4346"/>
+ <issue id="4359" link="https://github.com/apache/logging-log4j2/pull/4359"/>
+ <description format="asciidoc">
+ Fix `NullPointerException` when an SSL store location is set without a store type.
+ </description>
+</entry>