TrueZIP Driver TZP (ZIP.RAES) 7.0-rc1

de.schlichtherle.truezip.crypto.raes.param.swing
Class AesCipherParametersUI

java.lang.Object
  extended by de.schlichtherle.truezip.crypto.raes.param.swing.AesCipherParametersUI
All Implemented Interfaces:
PromptingKeyProvider.UI<AesCipherParameters>

public final class AesCipherParametersUI
extends Object
implements PromptingKeyProvider.UI<AesCipherParameters>

A Swing based user interface to prompt for passwords or key files.

Author:
Christian Schlichtherle

Field Summary
private static String CLASS_NAME
           
(package private) static URI INITIAL_RESOURCE
           
private  InvalidKeyFeedback invalidKeyFeedback
           
static int KEY_FILE_LEN
          This is the number of bytes to load from the beginning of a key file.
(package private) static URI lastResource
          The last resource ID used when prompting.
private static Map<PromptingKeyProvider<?>,OpenKeyPanel> openKeyPanels
           
private static ResourceBundle resources
           
private static ServiceLocator serviceLocator
           
private static long START_PROMPTING_TIMEOUT
          The timeout for the EDT to start prompting for a key in milliseconds.
private  UnknownKeyFeedback unknownKeyFeedback
           
 
Constructor Summary
AesCipherParametersUI()
           
 
Method Summary
private static void eventuallyDispose(Window window)
          The following is a double work around for Sun's J2SE 1.4.2 which has been tested with 1.4.2-b28 and 1.4.2_12-b03 on the Windows platform.
(package private)  InvalidKeyFeedback getInvalidKeyFeedback()
           
(package private)  UnknownKeyFeedback getUnknownKeyFeedback()
           
private static void multiplexOnEDT(Runnable task)
          Invokes the given task on the AWT Event Dispatching Thread (EDT) and waits until it's finished.
 void promptCreateKey(PromptingKeyProvider<? super AesCipherParameters> provider)
          Prompts the user for the key which may be used to create a new protected resource or entirely replace the contents of an already existing protected resource.
private  void promptCreateKeyEDT(PromptingKeyProvider<? super AesCipherParameters> provider)
          This method is only called by the AWT Event Dispatch Thread, so it doesn't need to be thread safe.
 void promptOpenKey(PromptingKeyProvider<? super AesCipherParameters> provider, boolean invalid)
          Prompts the user for the key which may be used to open an existing protected resource in order to access its contents.
private  void promptOpenKeyEDT(PromptingKeyProvider<? super AesCipherParameters> provider, boolean invalid)
          This method is only called by the AWT Event Dispatch Thread, so it doesn't need to be thread safe.
(package private) static byte[] readKeyFile(File file)
          Reads the encryption key as a byte sequence from the given pathname into a buffer of exactly KEY_FILE_LEN bytes and returns it.
(package private)  void setInvalidKeyFeedback(InvalidKeyFeedback ickf)
           
(package private)  void setUnkownKeyFeedback(UnknownKeyFeedback uckf)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_NAME

private static final String CLASS_NAME

resources

private static final ResourceBundle resources

INITIAL_RESOURCE

static final URI INITIAL_RESOURCE

START_PROMPTING_TIMEOUT

private static final long START_PROMPTING_TIMEOUT
The timeout for the EDT to start prompting for a key in milliseconds.

See Also:
Constant Field Values

KEY_FILE_LEN

public static final int KEY_FILE_LEN
This is the number of bytes to load from the beginning of a key file. A valid key file for encryption must contain at least this number of bytes!

See Also:
Constant Field Values

openKeyPanels

private static final Map<PromptingKeyProvider<?>,OpenKeyPanel> openKeyPanels

serviceLocator

private static final ServiceLocator serviceLocator

lastResource

static volatile URI lastResource
The last resource ID used when prompting. Initialized to the empty string.


unknownKeyFeedback

private volatile UnknownKeyFeedback unknownKeyFeedback

invalidKeyFeedback

private volatile InvalidKeyFeedback invalidKeyFeedback
Constructor Detail

AesCipherParametersUI

public AesCipherParametersUI()
Method Detail

readKeyFile

static byte[] readKeyFile(File file)
                   throws IOException
Reads the encryption key as a byte sequence from the given pathname into a buffer of exactly KEY_FILE_LEN bytes and returns it.

Throws:
EOFException - If the file is not at least KEY_FILE_LEN bytes long.
IOException - on any other I/O related issue.

getUnknownKeyFeedback

UnknownKeyFeedback getUnknownKeyFeedback()

setUnkownKeyFeedback

void setUnkownKeyFeedback(UnknownKeyFeedback uckf)

getInvalidKeyFeedback

InvalidKeyFeedback getInvalidKeyFeedback()

setInvalidKeyFeedback

void setInvalidKeyFeedback(InvalidKeyFeedback ickf)

promptCreateKey

public void promptCreateKey(PromptingKeyProvider<? super AesCipherParameters> provider)
                     throws UnknownKeyException
Description copied from interface: PromptingKeyProvider.UI
Prompts the user for the key which may be used to create a new protected resource or entirely replace the contents of an already existing protected resource. Upon return, the implementation should have updated the key property of the given provider.

If the implementation has called PromptingKeyProvider.setKey(K) with a non-null parameter, then a clone of this object will be used as the key of the given provider.

Otherwise, prompting for a key is permanently disabled and each subsequent call to SafeKeyProvider.getCreateKey() or SafeKeyProvider.getOpenKey(boolean) results in a KeyPromptingCancelledException until PromptingKeyProvider.resetCancelledKey() or PromptingKeyProvider.resetUnconditionally() gets called.

Specified by:
promptCreateKey in interface PromptingKeyProvider.UI<AesCipherParameters>
Parameters:
provider - The key provider to store the result in.
Throws:
UnknownKeyException - if key prompting fails for any reason.

promptOpenKey

public void promptOpenKey(PromptingKeyProvider<? super AesCipherParameters> provider,
                          boolean invalid)
                   throws UnknownKeyException
Description copied from interface: PromptingKeyProvider.UI
Prompts the user for the key which may be used to open an existing protected resource in order to access its contents. Upon return, the implementation should have updated the key property of the given provider.

If the implementation has called PromptingKeyProvider.setKey(K) with a non-null parameter, then a clone of this object will be used as the key of the given provider.

Otherwise, if the implementation has called PromptingKeyProvider.setKey(K) with a null parameter or throws a KeyPromptingCancelledException, then prompting for the key is permanently disabled and each subsequent call to SafeKeyProvider.getCreateKey() or SafeKeyProvider.getOpenKey(boolean) results in a KeyPromptingCancelledException until PromptingKeyProvider.resetCancelledKey() or PromptingKeyProvider.resetUnconditionally() gets called.

Otherwise, the state of the key provider is not changed and this method gets called again.

Specified by:
promptOpenKey in interface PromptingKeyProvider.UI<AesCipherParameters>
Parameters:
provider - The key provider to store the result in.
invalid - true iff a previous call to this method resulted in an invalid key.
Throws:
KeyPromptingCancelledException - if key prompting has been cancelled by the user.
UnknownKeyException - if key prompting fails for any other reason.

promptCreateKeyEDT

private void promptCreateKeyEDT(PromptingKeyProvider<? super AesCipherParameters> provider)
This method is only called by the AWT Event Dispatch Thread, so it doesn't need to be thread safe.


promptOpenKeyEDT

private void promptOpenKeyEDT(PromptingKeyProvider<? super AesCipherParameters> provider,
                              boolean invalid)
This method is only called by the AWT Event Dispatch Thread, so it doesn't need to be thread safe.


eventuallyDispose

private static void eventuallyDispose(Window window)
The following is a double work around for Sun's J2SE 1.4.2 which has been tested with 1.4.2-b28 and 1.4.2_12-b03 on the Windows platform. The issue for which this work around is required is known to be present in the Java code of the AWT package, so this should pertain to all platforms. This issue has been fixed with Sun's JSE 1.5.0-b64 or higher.

The issue is that an application will not terminate until all Window's have been dispose()d or System.exit() has been called - it is not sufficient just to hide() all Window's.

The JOptionPane properly dispose()s its Dialog which displays our password panels. However, by default JOptionPane uses an internal Frame as its parent window if the application does not specify a parent window explicitly. JOptionPane never dispose()s the parent window, so the client application may eventually not terminate.

The workaround is to dispose the parent window if it's not showing.


multiplexOnEDT

private static void multiplexOnEDT(Runnable task)
                            throws UnknownKeyException
Invokes the given task on the AWT Event Dispatching Thread (EDT) and waits until it's finished.

In multithreaded environments, although technically possible, do not allow multiple threads to prompt for a key concurrently, because this would only confuse users. By explicitly locking the class object rather than the instance, we enforce this even if multiple implementations and instances are used.

If the current thread is interrupted, an UndeclaredThrowableException is thrown with a KeyPromptingInterruptedException as its cause.

If a Throwable is thrown by the EDT, then it's wrapped in an UndeclaredThrowableException and re-thrown by this thread.

Throws:
UnknownKeyException

TrueZIP Driver TZP (ZIP.RAES) 7.0-rc1

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.