org.idoox.security.pstore
Interface KeyStore

All Known Subinterfaces:
PStoreService

public interface KeyStore

Class representing the protected key store used for storage of key material for asymetric cryptography and trusted certificates. KeyStore is organized into key entries that are are indexed by aliases. Key entry represents trusted certificate chain or private key with associated certificates.

Since:
3.0
Component:
Security-Core

Method Summary
 boolean containsAlias(java.lang.String alias)
          Determines whether the store contains given alias.
 void deleteEntry(java.lang.String alias)
          Deletes entry identified by an alias.
 java.lang.String getAlias(java.security.cert.Certificate cert)
          Returns alias the certificate is associated with.
 AliasEntry[] getAliasEntries()
          Returns all aliases in the key store with the description of their type (i.e.
 java.lang.String[] getAliases()
          Returns all aliases in the key store.
 java.security.cert.Certificate[] getCertificateChain(java.lang.String alias)
          Returns certificate chain associated with an alias.
 java.security.Key getKey(java.lang.String alias, java.lang.String password)
          Returns the key associated with given alias and protected by given password.
 KeyEntry getKeyEntry(java.lang.String alias)
          Returns encrypted key material in the KeyStoreEntry instance.
 boolean isKeyEntry(java.lang.String alias)
          Determines whether the entry identified by an alias is a key entry.
 void setCertificateEntry(java.lang.String alias, java.security.cert.Certificate[] chain)
          Creates or overwrites trusted certificate entry.
 void setKeyEntry(java.lang.String alias, byte[] encKey, byte[] keyAlg, byte[] keyFormat, byte[] salt, java.security.cert.Certificate[] chain)
          Creates or overwrites key entry using the data of the encoded key.
 void setKeyEntry(java.lang.String alias, java.lang.String password, java.security.Key key, java.security.cert.Certificate[] chain)
          Creates or overwrites key entry.
 void setKeyStoreSoure(KeyStoreSource source)
          Sets KeyStoreSource associated with this KeyStore to the given object.
 

Method Detail

containsAlias

public boolean containsAlias(java.lang.String alias)
Determines whether the store contains given alias.

Parameters:
alias - alias name to look for
Returns:
true if the alias exists

deleteEntry

public void deleteEntry(java.lang.String alias)
                 throws KeyStoreException
Deletes entry identified by an alias.

Parameters:
alias - key entry alias
Throws:
KeyStoreException - error during processing

getCertificateChain

public java.security.cert.Certificate[] getCertificateChain(java.lang.String alias)
                                                     throws KeyStoreException
Returns certificate chain associated with an alias.

Parameters:
alias - alias name to return certificate chain for
Returns:
certificate chain associated to the alias
Throws:
KeyStoreException

getAlias

public java.lang.String getAlias(java.security.cert.Certificate cert)
Returns alias the certificate is associated with.

Parameters:
cert - certificate that has to be associated with the returned alias
Returns:
alias or null, if there is no such certificate

getAliases

public java.lang.String[] getAliases()
Returns all aliases in the key store.

Returns:
all unique aliases

getAliasEntries

public AliasEntry[] getAliasEntries()
Returns all aliases in the key store with the description of their type (i.e. KeyEntry or CertificateEntry).

Returns:
aliases with content descriptions
Since:
4.0

getKey

public java.security.Key getKey(java.lang.String alias,
                                java.lang.String password)
                         throws BadPasswordException,
                                KeyStoreException
Returns the key associated with given alias and protected by given password.

Parameters:
alias - alias name to return the key for
password - password to use for key unprotection
Returns:
the key or null if the key doesn't exist
Throws:
BadPasswordException - if bad password was used
KeyStoreException

isKeyEntry

public boolean isKeyEntry(java.lang.String alias)
Determines whether the entry identified by an alias is a key entry.

Parameters:
alias - entry's alias name
Returns:
true if the entry is a key entry

setCertificateEntry

public void setCertificateEntry(java.lang.String alias,
                                java.security.cert.Certificate[] chain)
                         throws BadPasswordException,
                                KeyStoreException
Creates or overwrites trusted certificate entry.

Parameters:
alias - entry's alias name
chain - certificates chain to be associated with given alias
Throws:
BadPasswordException
KeyStoreException

getKeyEntry

public KeyEntry getKeyEntry(java.lang.String alias)
                     throws KeyStoreException
Returns encrypted key material in the KeyStoreEntry instance.

Parameters:
alias - alias of the key entry to be returned
Returns:
instance of the KeyStoreEntry interface containing encrypted key info
Throws:
KeyStoreException

setKeyEntry

public void setKeyEntry(java.lang.String alias,
                        java.lang.String password,
                        java.security.Key key,
                        java.security.cert.Certificate[] chain)
                 throws BadPasswordException,
                        KeyStoreException
Creates or overwrites key entry.

Parameters:
alias - entry's alias name
password - password for protecting the associated key
key - cryptographic key to be associated with the entry
chain - certificate chain to associate with the entry (usually contains public key corresponding to the private key specified in key parameter
Throws:
BadPasswordException
KeyStoreException

setKeyEntry

public void setKeyEntry(java.lang.String alias,
                        byte[] encKey,
                        byte[] keyAlg,
                        byte[] keyFormat,
                        byte[] salt,
                        java.security.cert.Certificate[] chain)
                 throws BadPasswordException,
                        KeyStoreException
Creates or overwrites key entry using the data of the encoded key. The key material should be encrypted.

Parameters:
alias - entry's alias name
encKey - encypted key material
keyAlg - encrypted key algorithm
keyFormat - encrypted format of the encoded key (after decryption of the encKey byte array)
salt - salt value used for the encryption of the key info
chain - certificate chain to associate with the entry
Throws:
BadPasswordException
KeyStoreException

setKeyStoreSoure

public void setKeyStoreSoure(KeyStoreSource source)
Sets KeyStoreSource associated with this KeyStore to the given object. KeyStoreSource object saves the every change of this KeyStore to the database. This method is optional to implement.

Parameters:
source - the given KeyStoreSource to set to.