Skip to content

Commit 841e1d2

Browse files
committed
Settings: Reimplement keystore format to use FIPS compliant algorithms (#28255)
This commit switches the internal format of the elasticsearch keystore to no longer use java's KeyStore class, but instead encrypt the binary data of the secrets using AES-GCM. The cipher key is generated using PBKDF2WithHmacSHA512. Tests are also added for backcompat reading the v1 and v2 formats.
1 parent c241252 commit 841e1d2

File tree

13 files changed

+449
-218
lines changed

13 files changed

+449
-218
lines changed

distribution/tools/plugin-cli/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,8 @@ private void createKeystoreIfNeeded(Terminal terminal, Environment env, PluginIn
833833
KeyStoreWrapper keystore = KeyStoreWrapper.load(env.configFile());
834834
if (keystore == null) {
835835
terminal.println("Elasticsearch keystore is required by plugin [" + info.getName() + "], creating...");
836-
keystore = KeyStoreWrapper.create(new char[0]);
837-
keystore.save(env.configFile());
836+
keystore = KeyStoreWrapper.create();
837+
keystore.save(env.configFile(), new char[0]);
838838
}
839839
}
840840

distribution/tools/plugin-cli/src/test/java/org/elasticsearch/plugins/InstallPluginCommandTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1148,8 +1148,8 @@ public void testKeystoreNotRequired() throws Exception {
11481148

11491149
public void testKeystoreRequiredAlreadyExists() throws Exception {
11501150
Tuple<Path, Environment> env = createEnv(fs, temp);
1151-
KeyStoreWrapper keystore = KeyStoreWrapper.create(new char[0]);
1152-
keystore.save(env.v2().configFile());
1151+
KeyStoreWrapper keystore = KeyStoreWrapper.create();
1152+
keystore.save(env.v2().configFile(), new char[0]);
11531153
byte[] expectedBytes = Files.readAllBytes(KeyStoreWrapper.keystorePath(env.v2().configFile()));
11541154
Path pluginDir = createPluginDir(temp);
11551155
String pluginZip = createPluginUrl("fake", pluginDir, "requires.keystore", "true");

server/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static SecureSettings loadSecureSettings(Environment initialEnv) throws Bootstra
233233

234234
try {
235235
keystore.decrypt(new char[0] /* TODO: read password from stdin */);
236-
KeyStoreWrapper.upgrade(keystore, initialEnv.configFile());
236+
KeyStoreWrapper.upgrade(keystore, initialEnv.configFile(), new char[0]);
237237
} catch (Exception e) {
238238
throw new BootstrapException(e);
239239
}

server/src/main/java/org/elasticsearch/common/settings/AddFileKeyStoreCommand.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th
6666
terminal.println("Exiting without creating keystore.");
6767
return;
6868
}
69-
keystore = KeyStoreWrapper.create(new char[0] /* always use empty passphrase for auto created keystore */);
70-
keystore.save(env.configFile());
69+
keystore = KeyStoreWrapper.create();
70+
keystore.save(env.configFile(), new char[0] /* always use empty passphrase for auto created keystore */);
7171
terminal.println("Created elasticsearch keystore in " + env.configFile());
7272
} else {
7373
keystore.decrypt(new char[0] /* TODO: prompt for password when they are supported */);
@@ -97,7 +97,7 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th
9797
String.join(", ", argumentValues.subList(2, argumentValues.size())) + "] after filepath");
9898
}
9999
keystore.setFile(setting, Files.readAllBytes(file));
100-
keystore.save(env.configFile());
100+
keystore.save(env.configFile(), new char[0]);
101101
}
102102

103103
@SuppressForbidden(reason="file arg for cli")

server/src/main/java/org/elasticsearch/common/settings/AddStringKeyStoreCommand.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th
6363
terminal.println("Exiting without creating keystore.");
6464
return;
6565
}
66-
keystore = KeyStoreWrapper.create(new char[0] /* always use empty passphrase for auto created keystore */);
67-
keystore.save(env.configFile());
66+
keystore = KeyStoreWrapper.create();
67+
keystore.save(env.configFile(), new char[0] /* always use empty passphrase for auto created keystore */);
6868
terminal.println("Created elasticsearch keystore in " + env.configFile());
6969
} else {
7070
keystore.decrypt(new char[0] /* TODO: prompt for password when they are supported */);
@@ -94,6 +94,6 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th
9494
} catch (IllegalArgumentException e) {
9595
throw new UserException(ExitCodes.DATA_ERROR, "String value must contain only ASCII");
9696
}
97-
keystore.save(env.configFile());
97+
keystore.save(env.configFile(), new char[0]);
9898
}
9999
}

server/src/main/java/org/elasticsearch/common/settings/CreateKeyStoreCommand.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th
5454
throw new UserException(ExitCodes.DATA_ERROR, "Passphrases are not equal, exiting.");
5555
}*/
5656

57-
KeyStoreWrapper keystore = KeyStoreWrapper.create(password);
58-
keystore.save(env.configFile());
57+
KeyStoreWrapper keystore = KeyStoreWrapper.create();
58+
keystore.save(env.configFile(), password);
5959
terminal.println("Created elasticsearch keystore in " + env.configFile());
6060
}
6161
}

0 commit comments

Comments
 (0)