Package org.wildfly.security.keystore
Class KeyStoreUtil
- java.lang.Object
-
- org.wildfly.security.keystore.KeyStoreUtil
-
public class KeyStoreUtil extends Object
Utility functions for manipulating KeyStores.- Author:
- Martin Mazanek
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
KeyStoreUtil.ResettableDataFileInputStream
-
Field Summary
Fields Modifier and Type Field Description private static String
BCFKS
private static String
BKS
private static String
JCEKS
private static int
JCEKS_MAGIC
private static String
JKS
private static int
JKS_MAGIC
private static int
PEM_MAGIC
private static String
PKCS12
private static int
SEQUENCE
private static String
UBER
private static int
VERSION_0
private static int
VERSION_1
private static int
VERSION_2
-
Constructor Summary
Constructors Constructor Description KeyStoreUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static KeyStore
loadKeyStore(Supplier<Provider[]> providers, String providerName, FileInputStream is, String filename, char[] password)
Tries to parse a keystore based on known recognizable patterns.private static KeyStore
loadPemAsKeyStore(FileInputStream is, char[] password)
private static KeyStore
tryLoadKeystore(Supplier<Provider[]> providers, String providerName, InputStream is, char[] password, String... types)
-
-
-
Field Detail
-
BCFKS
private static final String BCFKS
- See Also:
- Constant Field Values
-
BKS
private static final String BKS
- See Also:
- Constant Field Values
-
JCEKS
private static final String JCEKS
- See Also:
- Constant Field Values
-
JKS
private static final String JKS
- See Also:
- Constant Field Values
-
PKCS12
private static final String PKCS12
- See Also:
- Constant Field Values
-
UBER
private static final String UBER
- See Also:
- Constant Field Values
-
VERSION_0
private static final int VERSION_0
- See Also:
- Constant Field Values
-
VERSION_1
private static final int VERSION_1
- See Also:
- Constant Field Values
-
VERSION_2
private static final int VERSION_2
- See Also:
- Constant Field Values
-
JCEKS_MAGIC
private static final int JCEKS_MAGIC
- See Also:
- Constant Field Values
-
JKS_MAGIC
private static final int JKS_MAGIC
- See Also:
- Constant Field Values
-
SEQUENCE
private static final int SEQUENCE
- See Also:
- Constant Field Values
-
PEM_MAGIC
private static final int PEM_MAGIC
- See Also:
- Constant Field Values
-
-
Method Detail
-
loadKeyStore
public static KeyStore loadKeyStore(Supplier<Provider[]> providers, String providerName, FileInputStream is, String filename, char[] password) throws IOException, KeyStoreException
Tries to parse a keystore based on known recognizable patterns.This method can parse JKS, JCEKS, PKCS12, BKS, BCFKS and UBER key stores as well as PEM files. At first the method looks for recognizable patterns of JKS, JCEKS, PKCS12 and BKS key store types and tries to parse them if found. If the pattern recognition fails, brute force is used to load the key store.
The provider supplier is used for loading the key stores.
- Parameters:
providers
- provider supplier for loading the keystore (must not benull
)providerName
- if specified only providers with this name will be usedis
- the key store file input stream (must not benull
)filename
- the filename for prioritizing brute force checks using the file extensionpassword
- password of the key store. Should be the empty string for PEM files.- Returns:
- loaded key store if recognized
- Throws:
IOException
KeyStoreException
-
tryLoadKeystore
private static KeyStore tryLoadKeystore(Supplier<Provider[]> providers, String providerName, InputStream is, char[] password, String... types)
-
loadPemAsKeyStore
private static KeyStore loadPemAsKeyStore(FileInputStream is, char[] password) throws KeyStoreException, IOException
- Throws:
KeyStoreException
IOException
-
-