use of org.jcryptool.crypto.keystore.keys.IKeyStoreAlias in project core by jcryptool.
the class SelectKeyHandler method select.
/**
* @param event
* @param )
* @return
*/
private IKeyStoreAlias select(int options, ExecutionEvent event) {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
String algorithm = null;
SelectKeyDialog dialog = new SelectKeyDialog(window.getShell(), new Style(options), algorithm);
dialog.create();
dialog.open();
IKeyStoreAlias selectionFromDialog = null;
switch(dialog.getReturnCode()) {
case Window.OK:
selectionFromDialog = dialog.getSelectedAlias();
this.cancel = false;
break;
case Window.CANCEL:
this.cancel = true;
break;
}
;
return selectionFromDialog;
}
use of org.jcryptool.crypto.keystore.keys.IKeyStoreAlias in project core by jcryptool.
the class KeyStoreManager method deleteEntry.
/**
* Deletes the selected keystore entry. A selected public key automatically deletes the corresponding private key
* and vice versa.
*
* @param alias The keystore entry to delete
*/
public void deleteEntry(IKeyStoreAlias alias) {
try {
if (alias.getKeyStoreEntryType().equals(KeyType.KEYPAIR_PRIVATE_KEY)) {
KeyStoreAlias pub = getPublicForPrivate(alias);
if (pub != null) {
keyStore.deleteEntry(pub.getAliasString());
}
} else if (alias.getKeyStoreEntryType().equals(KeyType.KEYPAIR_PUBLIC_KEY)) {
KeyStoreAlias priv = getPrivateForPublic(alias);
if (priv != null) {
keyStore.deleteEntry(priv.getAliasString());
}
}
keyStore.deleteEntry(alias.getAliasString());
saveKeystore();
ContactManager.getInstance().removeEntry(alias);
} catch (KeyStoreException e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, NLS.bind(Messages.KeyStoreManager_3, alias.getAliasString()), e, true);
}
}
use of org.jcryptool.crypto.keystore.keys.IKeyStoreAlias in project core by jcryptool.
the class SelectKeyHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
Object selectedNode = ((IStructuredSelection) selection).getFirstElement();
if (selectedNode instanceof KeyNode) {
KeyNode keyNode = (KeyNode) selectedNode;
IKeyStoreAlias selectionFromDialog = null;
if (keyNode instanceof KeyPairNode) {
selectionFromDialog = select(Style.SHOW_PRIVATEKEYNODES | Style.SHOW_PUBLICKEYNODES, event);
if (this.cancel)
return null;
if (selectionFromDialog != null) {
if (!(selectionFromDialog.getKeyStoreEntryType() == KeyType.KEYPAIR_PRIVATE_KEY || selectionFromDialog.getKeyStoreEntryType() == KeyType.KEYPAIR_PUBLIC_KEY)) {
selectionFromDialog = null;
}
}
}
if (keyNode instanceof SecretKeyNode) {
selectionFromDialog = select(Style.SHOW_SECRETKEYNODES, event);
if (this.cancel)
return null;
if (selectionFromDialog != null) {
if (!(selectionFromDialog.getKeyStoreEntryType() == KeyType.SECRETKEY)) {
selectionFromDialog = null;
}
}
}
if (selectionFromDialog == null) {
JCTMessageDialog.showInfoDialog(new Status(IStatus.INFO, FlexiProviderOperationsPlugin.PLUGIN_ID, Messages.SelectKeyHandler_WrongKey));
return null;
}
FlexiProviderOperationsView operationsView = (FlexiProviderOperationsView) HandlerUtil.getActivePart(event);
EntryNode operationNode = operationsView.getFlexiProviderOperation();
operationNode.setKeyStoreAlias(selectionFromDialog);
}
}
return null;
}
use of org.jcryptool.crypto.keystore.keys.IKeyStoreAlias in project core by jcryptool.
the class AbstractKeyNodeContentProvider method getKey.
/**
* Tries to retrieve the key from keystore using the default password. If the operation succeeds, the default
* password will be updated, if it fails, the user have to enter a password into a prompt window.
*/
protected Key getKey(Object inputElement) {
AbstractKeyNode abstractKeyNode = (AbstractKeyNode) inputElement;
IKeyStoreAlias alias = abstractKeyNode.getAlias();
try {
return KeyStoreManager.getInstance().getKey(alias, KeyStoreManager.KEY_PASSWORD);
} catch (UnrecoverableEntryException ex) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, "The entered password was not correct.", ex, true);
} catch (java.security.NoSuchAlgorithmException ex) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, "The requested algorithm is not supported.", ex, true);
}
return null;
}
use of org.jcryptool.crypto.keystore.keys.IKeyStoreAlias in project core by jcryptool.
the class KeystoreView method hookContextMenu.
private void hookContextMenu() {
// $NON-NLS-1$
MenuManager menuMgr = new MenuManager("#PopupMenu");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
if (viewer.getTree().getSelection().length == 0) {
fillAddContactMenu(manager);
return;
}
Object selection = viewer.getTree().getSelection()[0].getData();
if (selection instanceof ContactDescriptorNode) {
selectedNodeType = NodeType.CONTACT_NODE;
selectedNodeInfo = ((ContactDescriptorNode) selection).getName();
fillContactContextMenu(manager);
} else if (selection instanceof SecretKeyNode) {
LogUtil.logInfo(((SecretKeyNode) selection).getAlias().getAliasString());
selectedNodeType = NodeType.SECRETKEY_NODE;
selectedNodeAlias = ((SecretKeyNode) selection).getAlias();
selectedSecretKeyNode = ((SecretKeyNode) selection);
fillSecretKeyContextMenu(manager);
} else if (selection instanceof KeyPairNode) {
if (((KeyPairNode) selection).getPrivateKeyAlias() != null)
LogUtil.logInfo(((KeyPairNode) selection).getPrivateKeyAlias().getAliasString());
selectedNodeType = NodeType.KEYPAIR_NODE;
selectedNodeAlias = ((KeyPairNode) selection).getPrivateKeyAlias();
selectedKeyPairNode = ((KeyPairNode) selection);
fillKeyPairContextMenu(manager);
} else if (selection instanceof CertificateNode) {
IKeyStoreAlias alias = ((CertificateNode) selection).getAlias();
if (alias.getKeyStoreEntryType().equals(KeyType.PUBLICKEY)) {
selectedNodeType = NodeType.PUBLICKEY_NODE;
selectedNodeAlias = ((CertificateNode) selection).getAlias();
selectedPublicKeyNode = ((CertificateNode) selection);
fillCertificateContextMenu(manager);
} else if (alias.getKeyStoreEntryType().equals(KeyType.KEYPAIR_PUBLIC_KEY)) {
selectedNodeType = NodeType.PUBLICKEY_NODE;
selectedNodeAlias = ((CertificateNode) selection).getAlias();
selectedPublicKeyNode = ((CertificateNode) selection);
fillKeyPairPublicContextMenu(manager);
}
}
}
});
Menu menu = menuMgr.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu("org.jcryptool.crypto.keystore.popup", menuMgr, viewer);
}
Aggregations