Package eu.emi.security.authn.x509.impl
Class KeystoreCredential
- java.lang.Object
-
- eu.emi.security.authn.x509.helpers.AbstractX509Credential
-
- eu.emi.security.authn.x509.impl.KeystoreCredential
-
- All Implemented Interfaces:
X509Credential
public class KeystoreCredential extends AbstractX509Credential
Wraps a Java KeyStore in form suitable for use in JSSE.- Author:
- K. Benedyczak
-
-
Field Summary
-
Fields inherited from class eu.emi.security.authn.x509.helpers.AbstractX509Credential
ALIAS, KEY_PASSWD, ks
-
-
Constructor Summary
Constructors Constructor Description KeystoreCredential(java.lang.String keystorePath, char[] storePasswd, char[] keyPasswd, java.lang.String keyAlias, java.lang.String storeType)
Reads a Java KeyStore to provide an interface suitable to use it in JSSE.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
autodetectType(java.lang.String ksPath, char[] ksPassword)
Tries to autodetect keystore type.protected java.lang.String
checkKeystore(java.security.KeyStore ks, char[] keyPasswd, java.lang.String keyAlias)
protected void
createSingleKeyView(java.security.KeyStore original, java.lang.String alias, char[] password)
protected java.lang.String
getDefaultKeyAlias(java.security.KeyStore keystore)
protected java.security.KeyStore
loadKeystore(java.lang.String keystorePath, char[] storePasswd, java.lang.String storeType)
-
Methods inherited from class eu.emi.security.authn.x509.helpers.AbstractX509Credential
getCertificate, getCertificateChain, getKey, getKeyAlias, getKeyManager, getKeyPassword, getKeyStore, getSubjectName
-
-
-
-
Constructor Detail
-
KeystoreCredential
public KeystoreCredential(java.lang.String keystorePath, char[] storePasswd, char[] keyPasswd, java.lang.String keyAlias, java.lang.String storeType) throws java.io.IOException, java.security.KeyStoreException
Reads a Java KeyStore to provide an interface suitable to use it in JSSE.- Parameters:
keystorePath
- keystore pathstorePasswd
- keystore passwordkeyPasswd
- private key passwordkeyAlias
- private key alias or null. In case of null, alias will be autodetected, however this will work only it the keystore contains exactly one key entry.storeType
- type of the keystore, "JKS" or "PKCS12". null value is forbidden, but if autodetection is desired the static autodetectType() method of this can be used.- Throws:
java.io.IOException
- if the keystore can not be readjava.security.KeyStoreException
- if the keystore can not be parsed or if passwords are incorrect
-
-
Method Detail
-
loadKeystore
protected java.security.KeyStore loadKeystore(java.lang.String keystorePath, char[] storePasswd, java.lang.String storeType) throws java.security.KeyStoreException, java.io.IOException
- Throws:
java.security.KeyStoreException
java.io.IOException
-
checkKeystore
protected java.lang.String checkKeystore(java.security.KeyStore ks, char[] keyPasswd, java.lang.String keyAlias) throws java.security.KeyStoreException
- Throws:
java.security.KeyStoreException
-
getDefaultKeyAlias
protected java.lang.String getDefaultKeyAlias(java.security.KeyStore keystore) throws java.security.KeyStoreException
- Throws:
java.security.KeyStoreException
-
createSingleKeyView
protected void createSingleKeyView(java.security.KeyStore original, java.lang.String alias, char[] password)
-
autodetectType
public static java.lang.String autodetectType(java.lang.String ksPath, char[] ksPassword) throws java.io.IOException, java.security.KeyStoreException
Tries to autodetect keystore type.- Parameters:
ksPath
- key store pathksPassword
- key store password- Returns:
- Detected type
- Throws:
java.io.IOException
- if error occurred when reading the filejava.security.KeyStoreException
- if autodetection failed
-
-