Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

hk.hku.cecid.phoenix.pki
Class CompositeKeyStore  view CompositeKeyStore download CompositeKeyStore.java

java.lang.Object
  extended byhk.hku.cecid.phoenix.pki.CompositeKeyStore

public class CompositeKeyStore
extends java.lang.Object

Composite keystore which manages keystores of different types. A typical Java keystore supports only one keystore type per file. That will be inconvenient for applications to manage several types of keystore. Also, this composite keystore supports managing multiple keystore files. This can be viewed as a keystore registry, that is, this object manages a pool of keystore files.

Version:
$Revision: 1.13 $

Field Summary
protected  java.util.Hashtable cache
          Internal storage of the aliases inside the keystore file
protected  java.util.Vector keystores
          Internal storage of the keystore object
protected static hk.hku.cecid.phoenix.common.util.Logger logger
          Logger
protected  java.util.Hashtable storage
          Internal storage of the keystore file information
 
Constructor Summary
CompositeKeyStore()
          Default constructor.
 
Method Summary
protected  void addKeyStoreFile(java.io.File keyFile, java.lang.String type, char[] password)
          Adds a keystore file to the keystore management pool.
 void addKeyStoreFile(java.lang.String keyFile, java.lang.String type, char[] password)
          Adds a keystore file to the keystore management pool.
 java.util.Enumeration aliases()
          Gets all the aliases of the keystores pointed by this composite keystore.
 boolean containsAlias(java.lang.String alias)
          Determines whether a given alias exists in one of the keystores pointed by this composite keystore or not.
 java.security.cert.Certificate getCertificate(java.lang.String alias)
          Gets the certificate named by the given alias, from the collection of keystores pointed by this composite keystore.
 java.lang.String getCertificateAlias(java.security.cert.Certificate cert)
          Gets the alias of the specified certificate.
 java.security.cert.Certificate[] getCertificateChain(java.lang.String alias)
          Gets the certificate chain by the specified alias.
 java.util.Date getCreationDate(java.lang.String alias)
          Gets the creation date of the key/certificate by the specified alias.
 java.security.Key getKey(java.lang.String alias, char[] password)
          Gets the key by the specified alias.
 java.security.KeyStore getKeyStore()
          Gets the first KeyStore object from the keystore management pool.
 boolean isCertificateEntry(java.lang.String alias)
          Determines whether the specified alias is specifying a certificate or not.
 boolean isKeyEntry(java.lang.String alias)
          Determines whether the specified alias is specifying a key or not.
protected static boolean isUsingJSSE()
          Determines whether JSSE should be used to access PKCS#12 formatted keystore.
 void load(java.io.File storeFile)
          Loads the composite keystore from a persistent file in the file system.
 void load(java.lang.String storeFileName)
          Loads the composite keystore from a persistent file in the file system.
protected  void loadCache()
          Loads the keystores pointed by this composite keystore into memory and create a caching of aliases.
protected  java.security.KeyStore loadKeyStore(java.lang.String fileName, KeyStoreFileProp ksp)
          Gets an instance of the keystore of correct type.
protected  void removeKeyStoreFile(java.io.File keyFile)
          Removes a keystore file from the keystore management pool.
 void removeKeyStoreFile(java.lang.String keyFile)
          Removes a keystore file from the keystore management pool.
 int size()
          Gets the total number of keys/certificates in all the keystores pointed by this composite keystore.
 void store(java.io.File storeFile)
          Stores the composite keystore to a persistent file in the file system.
 void store(java.lang.String storeFileName)
          Stores the composite keystore to a persistent file in the file system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static hk.hku.cecid.phoenix.common.util.Logger logger
Logger


storage

protected java.util.Hashtable storage
Internal storage of the keystore file information


cache

protected java.util.Hashtable cache
Internal storage of the aliases inside the keystore file


keystores

protected java.util.Vector keystores
Internal storage of the keystore object

Constructor Detail

CompositeKeyStore

public CompositeKeyStore()
Default constructor. The internal variables are being initialized.

Method Detail

addKeyStoreFile

public void addKeyStoreFile(java.lang.String keyFile,
                            java.lang.String type,
                            char[] password)
Adds a keystore file to the keystore management pool.


addKeyStoreFile

protected void addKeyStoreFile(java.io.File keyFile,
                               java.lang.String type,
                               char[] password)
Adds a keystore file to the keystore management pool.


getKeyStore

public java.security.KeyStore getKeyStore()
Gets the first KeyStore object from the keystore management pool.


removeKeyStoreFile

public void removeKeyStoreFile(java.lang.String keyFile)
Removes a keystore file from the keystore management pool.


removeKeyStoreFile

protected void removeKeyStoreFile(java.io.File keyFile)
Removes a keystore file from the keystore management pool.


loadKeyStore

protected java.security.KeyStore loadKeyStore(java.lang.String fileName,
                                              KeyStoreFileProp ksp)
Gets an instance of the keystore of correct type. This function will consider the Java version and determine whether to use JSSE or not. For Java version 1.4 or above, JSSE is built in. So, no need to call an external provider to create an instance of PKCS#12 formatted keystore. Otherwise, JSSE should be used, and we make use of dynamic binding to load the JSSE library.


loadCache

protected void loadCache()
Loads the keystores pointed by this composite keystore into memory and create a caching of aliases.


aliases

public java.util.Enumeration aliases()
Gets all the aliases of the keystores pointed by this composite keystore.


containsAlias

public boolean containsAlias(java.lang.String alias)
Determines whether a given alias exists in one of the keystores pointed by this composite keystore or not.


getCertificate

public java.security.cert.Certificate getCertificate(java.lang.String alias)
                                              throws java.security.KeyStoreException
Gets the certificate named by the given alias, from the collection of keystores pointed by this composite keystore.


getCertificateAlias

public java.lang.String getCertificateAlias(java.security.cert.Certificate cert)
Gets the alias of the specified certificate.


getCertificateChain

public java.security.cert.Certificate[] getCertificateChain(java.lang.String alias)
                                                     throws java.security.KeyStoreException
Gets the certificate chain by the specified alias.


getCreationDate

public java.util.Date getCreationDate(java.lang.String alias)
                               throws java.security.KeyStoreException
Gets the creation date of the key/certificate by the specified alias.


getKey

public java.security.Key getKey(java.lang.String alias,
                                char[] password)
                         throws java.security.KeyStoreException,
                                java.security.NoSuchAlgorithmException,
                                java.security.UnrecoverableKeyException
Gets the key by the specified alias. A password should be given also to retrieve the key.


isCertificateEntry

public boolean isCertificateEntry(java.lang.String alias)
                           throws java.security.KeyStoreException
Determines whether the specified alias is specifying a certificate or not.


isKeyEntry

public boolean isKeyEntry(java.lang.String alias)
                   throws java.security.KeyStoreException
Determines whether the specified alias is specifying a key or not.


size

public int size()
Gets the total number of keys/certificates in all the keystores pointed by this composite keystore.


load

public void load(java.lang.String storeFileName)
          throws InitializationException
Loads the composite keystore from a persistent file in the file system.


load

public void load(java.io.File storeFile)
          throws InitializationException
Loads the composite keystore from a persistent file in the file system.


store

public void store(java.lang.String storeFileName)
           throws StoreException
Stores the composite keystore to a persistent file in the file system.


store

public void store(java.io.File storeFile)
           throws StoreException
Stores the composite keystore to a persistent file in the file system.


isUsingJSSE

protected static boolean isUsingJSSE()
Determines whether JSSE should be used to access PKCS#12 formatted keystore. For JDK1.4 or above, JSSE is built into the JDK. Therefore, no additional provider have to be added.