new Listener()
{
public void
handleEvent(Event event)
{
MessageBoxShell mb = new MessageBoxShell(
SWT.ICON_WARNING | SWT.OK | SWT.CANCEL,
MessageText.getString("ConfigView.section.security.resetkey.warning.title"),
MessageText.getString("ConfigView.section.security.resetkey.warning"));
mb.setDefaultButtonUsingStyle(SWT.CANCEL);
mb.setParent(parent.getShell());
mb.open(new UserPrompterResultListener() {
public void prompterClosed(int returnVal) {
if (returnVal != SWT.OK) {
return;
}
try{
crypt_man.getECCHandler().resetKeys( "Manual key reset" );
}catch( Throwable e ){
MessageBoxShell mb = new MessageBoxShell(
SWT.ICON_ERROR | SWT.OK,
MessageText.getString( "ConfigView.section.security.resetkey.error.title"),
getError( e ));
mb.setParent(parent.getShell());
mb.open(null);
}
}
});
}
});
new Label(crypto_group, SWT.NULL );
// unlock
Label priv_key_label = new Label(crypto_group, SWT.NULL );
Messages.setLanguageText(priv_key_label, "ConfigView.section.security.unlockkey");
Button priv_key_button = new Button(crypto_group, SWT.PUSH);
Messages.setLanguageText(priv_key_button, "ConfigView.section.security.unlockkey.button");
priv_key_button.addListener(SWT.Selection,
new Listener()
{
public void
handleEvent(Event event)
{
try{
crypt_man.getECCHandler().getEncryptedPrivateKey( "Manual unlock" );
}catch( Throwable e ){
MessageBoxShell mb = new MessageBoxShell(
SWT.ICON_ERROR | SWT.OK,
MessageText.getString( "ConfigView.section.security.resetkey.error.title" ),
getError( e ));
mb.setParent(parent.getShell());
mb.open(null);
};
}
});
new Label(crypto_group, SWT.NULL );
// backup
Label backup_keys_label = new Label(crypto_group, SWT.NULL );
Messages.setLanguageText(backup_keys_label, "ConfigView.section.security.backupkeys");
final Button backup_keys_button = new Button(crypto_group, SWT.PUSH);
Messages.setLanguageText(backup_keys_button, "ConfigView.section.security.backupkeys.button");
backup_keys_button.addListener(SWT.Selection,
new Listener()
{
public void
handleEvent(Event event)
{
FileDialog dialog = new FileDialog( backup_keys_button.getShell(), SWT.APPLICATION_MODAL );
String target = dialog.open();
if ( target != null ){
try{
String keys = crypt_man.getECCHandler().exportKeys();
PrintWriter pw = new PrintWriter(new FileWriter( target ));
pw.println( keys );
pw.close();
}catch( Throwable e ){
MessageBoxShell mb = new MessageBoxShell(
SWT.ICON_ERROR | SWT.OK,
MessageText.getString( "ConfigView.section.security.op.error.title" ),
MessageText.getString( "ConfigView.section.security.op.error",
new String[]{ getError(e) }));
mb.setParent(parent.getShell());
mb.open(null);
}
}
}
});
new Label(crypto_group, SWT.NULL );
// restore
Label restore_keys_label = new Label(crypto_group, SWT.NULL );
Messages.setLanguageText(restore_keys_label, "ConfigView.section.security.restorekeys");
final Button restore_keys_button = new Button(crypto_group, SWT.PUSH);
Messages.setLanguageText(restore_keys_button, "ConfigView.section.security.restorekeys.button");
restore_keys_button.addListener(SWT.Selection,
new Listener()
{
public void
handleEvent(Event event)
{
FileDialog dialog = new FileDialog( backup_keys_button.getShell(), SWT.APPLICATION_MODAL );
String target = dialog.open();
if ( target != null ){
try{
LineNumberReader reader = new LineNumberReader( new FileReader( target ));
String str = "";
while( true ){
String line = reader.readLine();
if ( line == null ){
break;
}
str += line + "\r\n";
}
boolean restart = crypt_man.getECCHandler().importKeys(str);
if ( restart ){
MessageBoxShell mb = new MessageBoxShell(
SWT.ICON_INFORMATION | SWT.OK,
MessageText.getString( "ConfigView.section.security.restart.title" ),
MessageText.getString( "ConfigView.section.security.restart.msg" ));
mb.setParent(parent.getShell());
mb.open(null);
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if ( uiFunctions != null ){
uiFunctions.dispose(true, false);
}
}
}catch( Throwable e ){
MessageBoxShell mb = new MessageBoxShell(
SWT.ICON_ERROR | SWT.OK,
MessageText.getString( "ConfigView.section.security.op.error.title" ),
MessageText.getString( "ConfigView.section.security.op.error",
new String[]{ getError( e )}));
mb.setParent(parent.getShell());
mb.open(null);
}
}
}
});