com.ca.commons.security
Class KeystoreGUI

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Dialog
                          |
                          +--javax.swing.JDialog
                                |
                                +--com.ca.commons.cbutil.CBDialog
                                      |
                                      +--com.ca.commons.security.KeystoreGUI
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.RootPaneContainer, java.io.Serializable, javax.swing.WindowConstants

public class KeystoreGUI
extends CBDialog
implements java.awt.event.ActionListener

See Also:
Serialized Form

Nested Class Summary
static class KeystoreGUI.CertItem
          A representation of a certificate that is displayed in the certificate list.
 class KeystoreGUI.PasswordDialog
          The keystore has a particular password protecting its contents.
 
Nested classes inherited from class javax.swing.JDialog
javax.swing.JDialog.AccessibleJDialog
 
Nested classes inherited from class java.awt.Dialog
java.awt.Dialog.AccessibleAWTDialog
 
Nested classes inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.lang.String DELETEDCERT
           
static java.lang.String ERRORCERT
           
protected  CBHelpSystem helpBroker
           
protected  java.security.KeyStore keystore
           
protected  java.lang.String keystoreFile
           
protected  java.lang.String keystoreType
           
static javax.swing.ImageIcon smallCert
           
static javax.swing.ImageIcon smallKeyCert
           
 
Fields inherited from class com.ca.commons.cbutil.CBDialog
buttonPanel, Cancel, display, Help, OK, owner
 
Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
KeystoreGUI(java.awt.Frame owner, java.util.Properties props, java.lang.String keyStoreLocation, char[] keyStorePassword, java.lang.String keyStoreType, java.lang.String title, boolean handlePrivateKeys, java.lang.String helpTopic)
          This creates the Keystore config window to manage a particular keystore.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          checks actions on the various keystore affecting buttons.
protected  void addNewCert()
          Allows the User to browse to a new Cert (on disk) and import it.
protected  boolean checkPassword()
          checks that the user has entered a valid password.
protected  void clearPassword(char[] c)
           
protected  void deleteCurrentCert(KeystoreGUI.CertItem certItem)
          Checks the list to see which the currently selected certificate is, and then prompts the user to confirm the deletion.
 void doCancel()
          When the user hits 'cancel', the window is shut down.
 void doOK()
          If the user is satisfied with their changes, attempt to write the keystore.
protected  void exportKey(KeystoreGUI.CertItem certItem)
          Allows the user to export a private key with a particular certificate.
 javax.swing.ImageIcon getImageIcon(java.lang.String name)
           
protected  java.io.File getKeyFile(java.lang.String title)
          This prompts the user to select a pkcs8 file to import, and attach to an existing certificate.
static KeystoreGUI.CertItem[] getKeyStoreCerts(java.security.KeyStore keystore)
          This extracts an array of CertItem-s from a keystore, for display in the GUI.
protected  void importKey(KeystoreGUI.CertItem certItem)
          Allows the user to match a private key with a particular certificate.
static void main(java.lang.String[] argsv)
          Main method for stand alone usage and provider testing.
static java.security.KeyStore readKeyStore(char[] pass, java.lang.String storeType, java.lang.String keyFile)
          initialises the keystore by reading the saved keystore file.
protected  void refreshView()
          Reread the key store after an addition or deletion operation, and refresh certListModel.
protected  boolean setPassword()
          This allows the user to enter their password, which remains valid for the life of this component.
protected  void setupCertificateList()
          Initialises a selection list of CertItems from the keystore.
protected  void setupCertificateListGUI()
          Initialise empty list models, and associate the certificate list renderer with the cert list.
protected  boolean setupKeyStore()
          Sets up the keystore variable, using the current password (may be null) and keystore file.
protected  void setupPasswords()
          This allows the user to change the password used to protect the keystore.
protected  void viewCurrentCert(KeystoreGUI.CertItem cert)
          Uses the CertViewer to display the contents of the selected certificate.
static boolean writeKeyStore(char[] password, java.security.KeyStore keystore, java.lang.String keyFile, java.lang.String keystoreType)
          writes the keystore to a password protected file.
 
Methods inherited from class com.ca.commons.cbutil.CBDialog
add, addln, escKeyCheck, getDisplayPanel, makeHeavy, makeLight, makeWide, quit, setHelpLink, wasCancelled
 
Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Dialog
addNotify, dispose, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setResizable, setTitle, setUndecorated, show
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, finalize, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, removeNotify, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ERRORCERT

public static final java.lang.String ERRORCERT
See Also:
Constant Field Values

DELETEDCERT

public static final java.lang.String DELETEDCERT
See Also:
Constant Field Values

keystore

protected java.security.KeyStore keystore

smallCert

public static javax.swing.ImageIcon smallCert

smallKeyCert

public static javax.swing.ImageIcon smallKeyCert

helpBroker

protected CBHelpSystem helpBroker

keystoreFile

protected java.lang.String keystoreFile

keystoreType

protected java.lang.String keystoreType
Constructor Detail

KeystoreGUI

public KeystoreGUI(java.awt.Frame owner,
                   java.util.Properties props,
                   java.lang.String keyStoreLocation,
                   char[] keyStorePassword,
                   java.lang.String keyStoreType,
                   java.lang.String title,
                   boolean handlePrivateKeys,
                   java.lang.String helpTopic)
This creates the Keystore config window to manage a particular keystore.

Parameters:
owner - the parent frame (used for internal GUI stuff)
props - the JX property list (used to get and set default keystore directories)
keyStoreLocation - the location of the java keystore to manage.
keyStorePassword - the password of the encrypted keystore - may be null, in which case the user will be prompted.
keyStoreType - the java abreviation of the keystore type (typically 'jks' for 'java keystore' - the default java file based keystore).
title - a meaningfull (to the user) name for the keystore
handlePrivateKeys - whether the keystore manager will allow the user to associate a private key with a particular certificate.
helpTopic - the link into the default java help system (if used). See
See Also:
CBHelpSystem
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
checks actions on the various keystore affecting buttons. Note that the OK and Cancel button are handled by doOK() and doCancel() inherited from the base class.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

doOK

public void doOK()
If the user is satisfied with their changes, attempt to write the keystore. Some checks may be required first, depending on the keystore type.

Overrides:
doOK in class CBDialog

doCancel

public void doCancel()
Description copied from class: CBDialog
When the user hits 'cancel', the window is shut down.

Overrides:
doCancel in class CBDialog

importKey

protected void importKey(KeystoreGUI.CertItem certItem)
Allows the user to match a private key with a particular certificate. (Currently limited to pkcs 8 - other may be possible depending on keystore implementation).


exportKey

protected void exportKey(KeystoreGUI.CertItem certItem)
Allows the user to export a private key with a particular certificate. (Currently limited to pkcs 8 - other may be possible depending on keystore implementation).


getKeyFile

protected java.io.File getKeyFile(java.lang.String title)
This prompts the user to select a pkcs8 file to import, and attach to an existing certificate.

Returns:
the File name of the selected pkcs8 file.

viewCurrentCert

protected void viewCurrentCert(KeystoreGUI.CertItem cert)
Uses the CertViewer to display the contents of the selected certificate.

Parameters:
cert - the certificate to display.

deleteCurrentCert

protected void deleteCurrentCert(KeystoreGUI.CertItem certItem)
Checks the list to see which the currently selected certificate is, and then prompts the user to confirm the deletion.


checkPassword

protected boolean checkPassword()
checks that the user has entered a valid password. If they haven't, it prompts for one.

Returns:
whether a valid password has been entered and checked against the keystore.

setPassword

protected boolean setPassword()

This allows the user to enter their password, which remains valid for the life of this component.

This also sets up the keystore

Returns:
whether the password successfully opened the keystore.

setupKeyStore

protected boolean setupKeyStore()
Sets up the keystore variable, using the current password (may be null) and keystore file.


addNewCert

protected void addNewCert()
Allows the User to browse to a new Cert (on disk) and import it.


refreshView

protected void refreshView()
Reread the key store after an addition or deletion operation, and refresh certListModel.


setupCertificateListGUI

protected void setupCertificateListGUI()
Initialise empty list models, and associate the certificate list renderer with the cert list.


setupCertificateList

protected void setupCertificateList()
Initialises a selection list of CertItems from the keystore.

Returns:
the JList component containing the read CertItems.

setupPasswords

protected void setupPasswords()
This allows the user to change the password used to protect the keystore.


clearPassword

protected void clearPassword(char[] c)

getKeyStoreCerts

public static KeystoreGUI.CertItem[] getKeyStoreCerts(java.security.KeyStore keystore)
This extracts an array of CertItem-s from a keystore, for display in the GUI.

Parameters:
keystore - the keystore to use.
Returns:
an array of CertItem-s representing the certificates and aliases stored in the keystore.

readKeyStore

public static java.security.KeyStore readKeyStore(char[] pass,
                                                  java.lang.String storeType,
                                                  java.lang.String keyFile)
initialises the keystore by reading the saved keystore file.

Parameters:
storeType - - the type of the keystore. Unless a custom security provider is being used, this will almost certainly be 'jks'.
keyFile - the file name of the keystore.
Returns:
the new keystore, or null if an error occurred.

writeKeyStore

public static boolean writeKeyStore(char[] password,
                                    java.security.KeyStore keystore,
                                    java.lang.String keyFile,
                                    java.lang.String keystoreType)
writes the keystore to a password protected file.

Parameters:
password - the password to use while saving it.
keystore - the certificate key store to save.
keyFile - the name of the file to save to.
keystoreType - the type of store - e.g. "JKS" or "KSE" or "PKCS12"
Returns:
the success status of the operation.

getImageIcon

public javax.swing.ImageIcon getImageIcon(java.lang.String name)

main

public static void main(java.lang.String[] argsv)
Main method for stand alone usage and provider testing.