eu.emi.security.authn.x509.impl
Class KeystoreCredential

java.lang.Object
  extended by eu.emi.security.authn.x509.helpers.AbstractX509Credential
      extended by 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
KeystoreCredential(String keystorePath, char[] storePasswd, char[] keyPasswd, String keyAlias, String storeType)
          Reads a Java KeyStore to provide an interface suitable to use it in JSSE.
 
Method Summary
static String autodetectType(String ksPath, char[] ksPassword)
          Tries to autodetect keystore type.
protected  String checkKeystore(KeyStore ks, char[] keyPasswd, String keyAlias)
           
protected  void createSingleKeyView(KeyStore original, String alias, char[] password)
           
protected  String getDefaultKeyAlias(KeyStore keystore)
           
protected  KeyStore loadKeystore(String keystorePath, char[] storePasswd, String storeType)
           
 
Methods inherited from class eu.emi.security.authn.x509.helpers.AbstractX509Credential
getCertificate, getCertificateChain, getKey, getKeyAlias, getKeyManager, getKeyPassword, getKeyStore, getSubjectName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeystoreCredential

public KeystoreCredential(String keystorePath,
                          char[] storePasswd,
                          char[] keyPasswd,
                          String keyAlias,
                          String storeType)
                   throws IOException,
                          KeyStoreException
Reads a Java KeyStore to provide an interface suitable to use it in JSSE.

Parameters:
keystorePath - keystore path
storePasswd - keystore password
keyPasswd - private key password
keyAlias - 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:
IOException - if the keystore can not be read
KeyStoreException - if the keystore can not be parsed or if passwords are incorrect
Method Detail

loadKeystore

protected KeyStore loadKeystore(String keystorePath,
                                char[] storePasswd,
                                String storeType)
                         throws KeyStoreException,
                                IOException
Throws:
KeyStoreException
IOException

checkKeystore

protected String checkKeystore(KeyStore ks,
                               char[] keyPasswd,
                               String keyAlias)
                        throws KeyStoreException
Throws:
KeyStoreException

getDefaultKeyAlias

protected String getDefaultKeyAlias(KeyStore keystore)
                             throws KeyStoreException
Throws:
KeyStoreException

createSingleKeyView

protected void createSingleKeyView(KeyStore original,
                                   String alias,
                                   char[] password)

autodetectType

public static String autodetectType(String ksPath,
                                    char[] ksPassword)
                             throws IOException,
                                    KeyStoreException
Tries to autodetect keystore type.

Parameters:
ksPath -
ksPassword -
Returns:
Detected type
Throws:
IOException - if error occurred when reading the file
KeyStoreException - if autodetection failed


Copyright © 2012-2013 European Middleware Initiative. All Rights Reserved.