Skip to content

Commit 117e906

Browse files
authored
Support multiple system store types (#31650)
Support multiple system store types When falling back to using the system keystore and - most usually - truststore, do not assume that it will be a JKS store, but deduct its type from {@code KeyStore#getDefaultKeyStoreType}. This allows the use of any store type the Security Provider supports by setting the keystore.type java security property.
1 parent 0ef22db commit 117e906

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLConfiguration.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.nio.file.Path;
2121
import java.security.GeneralSecurityException;
22+
import java.security.KeyStore;
2223
import java.util.ArrayList;
2324
import java.util.List;
2425
import java.util.Objects;
@@ -194,9 +195,9 @@ private static KeyConfig createKeyConfig(Settings settings, SSLConfiguration glo
194195
if (System.getProperty("javax.net.ssl.keyStore") != null) {
195196
// TODO: we should not support loading a keystore from sysprops...
196197
try (SecureString keystorePassword = new SecureString(System.getProperty("javax.net.ssl.keyStorePassword", ""))) {
197-
return new StoreKeyConfig(System.getProperty("javax.net.ssl.keyStore"), "jks", keystorePassword, keystorePassword,
198-
System.getProperty("ssl.KeyManagerFactory.algorithm", KeyManagerFactory.getDefaultAlgorithm()),
199-
System.getProperty("ssl.TrustManagerFactory.algorithm", TrustManagerFactory.getDefaultAlgorithm()));
198+
return new StoreKeyConfig(System.getProperty("javax.net.ssl.keyStore"), KeyStore.getDefaultType(), keystorePassword,
199+
keystorePassword, System.getProperty("ssl.KeyManagerFactory.algorithm", KeyManagerFactory.getDefaultAlgorithm()),
200+
System.getProperty("ssl.TrustManagerFactory.algorithm", TrustManagerFactory.getDefaultAlgorithm()));
200201
}
201202
}
202203
return KeyConfig.NONE;
@@ -234,7 +235,7 @@ private static TrustConfig createCertChainTrustConfig(Settings settings, KeyConf
234235
return new StoreTrustConfig(trustStorePath, trustStoreType, trustStorePassword, trustStoreAlgorithm);
235236
} else if (global == null && System.getProperty("javax.net.ssl.trustStore") != null) {
236237
try (SecureString truststorePassword = new SecureString(System.getProperty("javax.net.ssl.trustStorePassword", ""))) {
237-
return new StoreTrustConfig(System.getProperty("javax.net.ssl.trustStore"), "jks", truststorePassword,
238+
return new StoreTrustConfig(System.getProperty("javax.net.ssl.trustStore"), KeyStore.getDefaultType(), truststorePassword,
238239
System.getProperty("ssl.TrustManagerFactory.algorithm", TrustManagerFactory.getDefaultAlgorithm()));
239240
}
240241
} else if (global != null && keyConfig == global.keyConfig()) {

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ssl/SSLConfigurationReloaderTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ public void testReloadingTrustStore() throws Exception {
194194
Path trustStorePath = tempDir.resolve("testnode.jks");
195195
Path updatedTruststorePath = tempDir.resolve("testnode_updated.jks");
196196
Files.copy(getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks"), trustStorePath);
197-
Files.copy(getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode_updated.jks"), updatedTruststorePath);
197+
Files.copy(getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode_updated.jks"),
198+
updatedTruststorePath);
198199
MockSecureSettings secureSettings = new MockSecureSettings();
199200
secureSettings.setString("xpack.ssl.truststore.secure_password", "testnode");
200201
Settings settings = Settings.builder()

0 commit comments

Comments
 (0)