Class KeystoreCredential

  • All Implemented Interfaces:
    X509Credential

    public class KeystoreCredential
    extends AbstractX509Credential
    Wraps a Java KeyStore in form suitable for use in JSSE.
    Author:
    K. Benedyczak
    • 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 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:
        java.io.IOException - if the keystore can not be read
        java.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 path
        ksPassword - key store password
        Returns:
        Detected type
        Throws:
        java.io.IOException - if error occurred when reading the file
        java.security.KeyStoreException - if autodetection failed