Package io.cui.tools.net.ssl
Class KeyStoreProvider
- java.lang.Object
-
- io.cui.tools.net.ssl.KeyStoreProvider
-
- All Implemented Interfaces:
Serializable
public class KeyStoreProvider extends Object implements Serializable
Provides instances ofKeyStoredefined by either given file / storePassword combination or one or moreKeyMaterialHoldercontaining key-material as a byte-array.Some words on the String-representation of passwords
No it is not (much) more secure to store them in a char[] because of not being part of the string-pool:- If an attacker is on your machine debugging the string-pool you are doomed anyway.
- In most frameworks / user-land code there are some places where input / configuration data is represented as String on the way to the more secure "give me a char[]" parts. So it is usually in the String pool anyway.
So: In theory the statements made by the Java Cryptography Architecture guide ("...") are correct but in our scenarios they will increase security only a small amount and introduce potential bugs and will therefore be ignored for this keyStoreType.
It is more important to avoid accidental printing on logs and such, what is handled by this keyStoreType.
Therefore, this class uses String-based handling of credentials, for simplification and provide shortcuts for creating char[], seegetStorePasswordAsCharArray()andgetKeyPasswordAsCharArray()- Author:
- Oliver Wolff, Nikola Marijan
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classKeyStoreProvider.KeyStoreProviderBuilder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static KeyStoreProvider.KeyStoreProviderBuilderbuilder()protected booleancanEqual(Object other)booleanequals(Object o)char[]getKeyOrStorePassword()In case of accessing data on theKeyStoresometimes it is needed to access the defined key-password.StringgetKeyPassword()(Optional) password for the keystore-key.char[]getKeyPasswordAsCharArray()Collection<KeyMaterialHolder>getKeys()@NonNull KeyStoreTypegetKeyStoreType()FilegetLocation()StringgetStorePassword()The password for the keystore aka the storage.char[]getStorePasswordAsCharArray()inthashCode()Optional<KeyStore>resolveKeyStore()Instantiates aKeyStoreaccording to the given parameter.StringtoString()
-
-
-
Method Detail
-
resolveKeyStore
public Optional<KeyStore> resolveKeyStore()
Instantiates aKeyStoreaccording to the given parameter. In case ofgetKeys()andgetLocation()being present theKeyStorewill only be created from thegetKeys(). The file will be ignored.- Returns:
- an
Optionalon aKeyStorecreated from the configured parameter. In case ofgetKeys()andgetLocation()beingnull/ empty it will returnOptional.empty() - Throws:
IllegalStateException- in case the location-file is not null but not readable or of the key-store creation did fail.
-
getStorePasswordAsCharArray
public char[] getStorePasswordAsCharArray()
- Returns:
- NPE-safe char-array representation of
getStorePassword(). If storePassword isnullor empty it returns an empty char[], nevernull
-
getKeyPasswordAsCharArray
public char[] getKeyPasswordAsCharArray()
- Returns:
- NPE-safe char-array representation of
getKeyPassword(). If keyPassword isnullor empty it returns an empty char[], nevernull
-
getKeyOrStorePassword
public char[] getKeyOrStorePassword()
In case of accessing data on theKeyStoresometimes it is needed to access the defined key-password. If not present the api needs the store-password instead. This is method is a convenience method for dealing with that case.- Returns:
- the keyPassword, if set or the store-password otherwise
-
builder
public static KeyStoreProvider.KeyStoreProviderBuilder builder()
-
getKeyStoreType
@NonNull public @NonNull KeyStoreType getKeyStoreType()
-
getLocation
public File getLocation()
-
getStorePassword
public String getStorePassword()
The password for the keystore aka the storage.
-
getKeyPassword
public String getKeyPassword()
(Optional) password for the keystore-key. Due to its nature this is usually only necessary forKeyStoreType.KEY_STORE
-
getKeys
public Collection<KeyMaterialHolder> getKeys()
-
-