Class KeyStoreWrapper
java.lang.Object
org.elasticsearch.common.settings.KeyStoreWrapper
- All Implemented Interfaces:
Closeable
,AutoCloseable
,SecureSettings
A disk based container for sensitive settings in Elasticsearch.
Loading a keystore has 2 phases. First, call
load(Path)
. Then call
decrypt(char[])
with the keystore password, or an empty char array if
hasPassword()
is false
. Loading and decrypting should happen
in a single thread. Once decrypted, settings may be read in multiple threads.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final String
The name of the keystore file to read and write.static final int
The version where lucene directory API changed from BE to LE.static final int
Arbitrarily chosen maximum passphrase lengthstatic final Setting<SecureString>
static final int
Legacy versions of the metadata written before the keystore data.static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addBootstrapSeed
(KeyStoreWrapper wrapper) Add the bootstrap seed setting, which may be used as a unique, secure, random value by the nodestatic KeyStoreWrapper
bootstrap
(Path configDir, CheckedSupplier<SecureString, Exception> passwordSupplier) void
close()
static KeyStoreWrapper
create()
Constructs a new keystore with the given password.void
decrypt
(char[] password) Decrypts the underlying keystore data.Return a file setting.int
Get the metadata format version for the keystoreIt is possible to retrieve the setting names even if the keystore is closed.byte[]
getSHA256Digest
(String setting) Returns the SHA256 digest for the setting's value, even after#close()
has been called.Return a string setting.boolean
Return true iff callingdecrypt(char[])
requires a non-empty password.boolean
isLoaded()
Returns true iff the settings are loaded and retrievable.static Path
keystorePath
(Path configDir) Returns a path representing the ES keystore in the given config dir.static KeyStoreWrapper
Loads information about the Elasticsearch keystore from the provided config directory.void
Remove the given setting from the keystore.void
Write the keystore to the given config directory.void
void
Set a file setting.void
Set a string setting.static void
upgrade
(KeyStoreWrapper wrapper, Path configDir, char[] password) Upgrades the format of the keystore, if necessary.static void
validateSettingName
(String setting) Ensure the given setting name is allowed.
-
Field Details
-
MAX_PASSPHRASE_LENGTH
public static final int MAX_PASSPHRASE_LENGTHArbitrarily chosen maximum passphrase length- See Also:
-
SEED_SETTING
-
KEYSTORE_FILENAME
The name of the keystore file to read and write.- See Also:
-
V2_VERSION
public static final int V2_VERSIONLegacy versions of the metadata written before the keystore data.- See Also:
-
V3_VERSION
public static final int V3_VERSION- See Also:
-
V4_VERSION
public static final int V4_VERSION- See Also:
-
LE_VERSION
public static final int LE_VERSIONThe version where lucene directory API changed from BE to LE.- See Also:
-
CURRENT_VERSION
public static final int CURRENT_VERSION- See Also:
-
-
Method Details
-
getFormatVersion
public int getFormatVersion()Get the metadata format version for the keystore -
keystorePath
Returns a path representing the ES keystore in the given config dir. -
create
Constructs a new keystore with the given password. -
addBootstrapSeed
Add the bootstrap seed setting, which may be used as a unique, secure, random value by the node -
bootstrap
public static KeyStoreWrapper bootstrap(Path configDir, CheckedSupplier<SecureString, Exception> passwordSupplier) throws Exception- Throws:
Exception
-
load
Loads information about the Elasticsearch keystore from the provided config directory.decrypt(char[])
must be called before reading or writing any entries. Returnsnull
if no keystore exists.- Throws:
IOException
-
upgrade
public static void upgrade(KeyStoreWrapper wrapper, Path configDir, char[] password) throws Exception Upgrades the format of the keystore, if necessary.- Throws:
Exception
-
isLoaded
public boolean isLoaded()Description copied from interface:SecureSettings
Returns true iff the settings are loaded and retrievable.- Specified by:
isLoaded
in interfaceSecureSettings
-
hasPassword
public boolean hasPassword()Return true iff callingdecrypt(char[])
requires a non-empty password. -
decrypt
Decrypts the underlying keystore data. This may only be called once.- Throws:
GeneralSecurityException
IOException
-
save
Write the keystore to the given config directory.- Throws:
Exception
-
save
- Throws:
Exception
-
getSettingNames
It is possible to retrieve the setting names even if the keystore is closed. This allowsSecureSetting
to correctly determine that a entry exists even though it cannot be read. Thus attempting to read a secure setting after the keystore is closed will generate a "keystore is closed" exception rather than using the fallback setting.- Specified by:
getSettingNames
in interfaceSecureSettings
-
getString
Description copied from interface:SecureSettings
Return a string setting. TheSecureString
should be closed once it is used.- Specified by:
getString
in interfaceSecureSettings
-
getFile
Description copied from interface:SecureSettings
Return a file setting. TheInputStream
should be closed once it is used.- Specified by:
getFile
in interfaceSecureSettings
-
getSHA256Digest
Returns the SHA256 digest for the setting's value, even after#close()
has been called. The setting must exist. The digest is used to check for value changes without actually storing the value.- Specified by:
getSHA256Digest
in interfaceSecureSettings
-
validateSettingName
Ensure the given setting name is allowed.- Throws:
IllegalArgumentException
- if the setting name is not valid
-
setString
Set a string setting. -
setFile
Set a file setting. -
remove
Remove the given setting from the keystore. -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceSecureSettings
-