org.faceless.pdf2.viewer2
Class KeyStoreManager

java.lang.Object
  extended by org.faceless.pdf2.viewer2.KeyStoreManager

public abstract class KeyStoreManager
extends Object

This class deals with managing digital identities in a KeyStore. It's primary focus is to enable the following activities

This class is abstract - subclasses need to implement the loadKeyStore(), saveKeyStore(java.security.KeyStore) and friends methods.

Since:
2.8.3

Field Summary
protected  KeyStore keystore
           
protected  Component parent
           
 
Constructor Summary
protected KeyStoreManager(Component parent)
          Create a new KeyStoreManager
 
Method Summary
static KeyStoreManager createDefaultKeyStoreManager(Component parent)
           
static KeyStoreManager createFixedKeyStoreManager(Component parent, String filename, char[] password, String type, String provider, boolean create)
          Create a new File-based KeyStoreManager.
static KeyStoreManager createPromptKeyStoreManager(Component parent, String filename, char[] password, String type, String provider, boolean create)
          Create a new File-based KeyStoreManager.
protected  char[] getDefaultKeyPassword()
          Return the default password to try when decrypting private keys.
 KeyStore getKeyStore()
          Get the KeyStore.
protected  void initializeKeyStore(KeyStore keystore)
          Initialize the keystore.
protected abstract  boolean isKeyStoreReloadable()
          Return true if the user should have an option to reload the KeyStore
protected abstract  KeyStore loadKeyStore()
          Load or initialise a KeyStore
protected  KeyStore reloadKeyStore()
          Reload the keystore
protected abstract  boolean saveKeyStore(KeyStore keystore)
          Save the KeyStore
 Map showDecryptionKeySelectionDialog(String alias, char[] password, Object extra)
          Select and return a private key for decryption
 void showIdentityManagementDialog()
          Show the "Identity Management" dialog, which allows keys and certificats to be created/imported, viewed, exported or deleted.
 Map showSigningKeySelectionDialog(String alias, char[] password, Object extra)
          Select and return a private key for signing
 void trustCertificate(String alias, X509Certificate cert)
          Add the specified Certificate to the list of trusted root certificates and save the KeyStore.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keystore

protected KeyStore keystore

parent

protected final Component parent
Constructor Detail

KeyStoreManager

protected KeyStoreManager(Component parent)
Create a new KeyStoreManager

Parameters:
parent - the Component to use as a parent for any dialogs - may be null
Method Detail

getKeyStore

public final KeyStore getKeyStore()
Get the KeyStore. May cause the KeyStore to be loaded or initialized


loadKeyStore

protected abstract KeyStore loadKeyStore()
                                  throws GeneralSecurityException,
                                         IOException
Load or initialise a KeyStore

Throws:
GeneralSecurityException
IOException

isKeyStoreReloadable

protected abstract boolean isKeyStoreReloadable()
Return true if the user should have an option to reload the KeyStore


reloadKeyStore

protected KeyStore reloadKeyStore()
                           throws GeneralSecurityException,
                                  IOException
Reload the keystore

Throws:
GeneralSecurityException
IOException

initializeKeyStore

protected void initializeKeyStore(KeyStore keystore)
                           throws GeneralSecurityException
Initialize the keystore. Creates a new keystore and add the root certificates from the default Java keystore

Throws:
GeneralSecurityException

saveKeyStore

protected abstract boolean saveKeyStore(KeyStore keystore)
                                 throws GeneralSecurityException,
                                        IOException
Save the KeyStore

Parameters:
keystore - the KeyStore
Returns:
true if the KeyStore was saved or an unrecoverable error occurred, false otherwise
Throws:
GeneralSecurityException
IOException

getDefaultKeyPassword

protected char[] getDefaultKeyPassword()
Return the default password to try when decrypting private keys. This is typically null, but may be the password set when the KeyStore was loaded.


showIdentityManagementDialog

public void showIdentityManagementDialog()
Show the "Identity Management" dialog, which allows keys and certificats to be created/imported, viewed, exported or deleted.


showDecryptionKeySelectionDialog

public Map showDecryptionKeySelectionDialog(String alias,
                                            char[] password,
                                            Object extra)
Select and return a private key for decryption

Parameters:
alias - the alias to preselect, if appropriate
password - the password to use on the alias
extra - additional information for the dialog
Returns:
a Map containing an "Alias" and "Password" value or null if no matching alias is available or the dialog was cancelled.

showSigningKeySelectionDialog

public Map showSigningKeySelectionDialog(String alias,
                                         char[] password,
                                         Object extra)
Select and return a private key for signing

Parameters:
alias - the alias to preselect, if appropriate
password - the password to use on the alias
extra - Additional information for the dialog. Currently, the only acceptable value is a Map containing "Name", "Reason" and "Location" keys mapping to Strings.
Returns:
a Map containing an "Alias" and "Password" value or null if no matching alias is available or the dialog was cancelled.

trustCertificate

public void trustCertificate(String alias,
                             X509Certificate cert)
Add the specified Certificate to the list of trusted root certificates and save the KeyStore.

Parameters:
alias - the alias to store it under - may be null
cert - the X509 Certificate to store

createFixedKeyStoreManager

public static KeyStoreManager createFixedKeyStoreManager(Component parent,
                                                         String filename,
                                                         char[] password,
                                                         String type,
                                                         String provider,
                                                         boolean create)
Create a new File-based KeyStoreManager. The KeyStore filename is fixed, and if "create" is true the keystore will be created if it doesn't already exist.

Parameters:
parent - the root Component for dialogs
filename - the File
password - the password to verify the KeyStore or null
type - the type of KeyStore, or null to choose an appropriate type
provider - the Provider, or null to use the default provider
create - whether to create the KeyStore if it doesn't exist

createPromptKeyStoreManager

public static KeyStoreManager createPromptKeyStoreManager(Component parent,
                                                          String filename,
                                                          char[] password,
                                                          String type,
                                                          String provider,
                                                          boolean create)
Create a new File-based KeyStoreManager. Although the KeyStore filename is specified, the user may load a new KeyStore at any time. If the KeyStore doesn't exist and the create parameter is true, the user will be prompted to select a KeyStore on load.

Parameters:
parent - the root Component for dialogs
filename - the File
password - the password to verify the KeyStore or null
type - the type of KeyStore, or null to choose an appropriate type
provider - the Provider, or null to use the default provider
create - whether to create the KeyStore if it doesn't exist

createDefaultKeyStoreManager

public static KeyStoreManager createDefaultKeyStoreManager(Component parent)


Copyright © 2001-2008 Big Faceless Organization