Search in sources :

Example 6 with IKeyStoreAlias

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;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SelectKeyDialog(org.jcryptool.crypto.keystore.ui.dialogs.SelectKeyDialog) Style(org.jcryptool.crypto.keystore.ui.KeystoreWidget.Style) IKeyStoreAlias(org.jcryptool.crypto.keystore.keys.IKeyStoreAlias)

Example 7 with IKeyStoreAlias

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);
    }
}
Also used : IKeyStoreAlias(org.jcryptool.crypto.keystore.keys.IKeyStoreAlias) KeyStoreException(java.security.KeyStoreException)

Example 8 with IKeyStoreAlias

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;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) FlexiProviderOperationsView(org.jcryptool.crypto.flexiprovider.operations.ui.views.FlexiProviderOperationsView) ISelection(org.eclipse.jface.viewers.ISelection) EntryNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.EntryNode) SecretKeyNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.keys.SecretKeyNode) KeyNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.keys.KeyNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SecretKeyNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.keys.SecretKeyNode) IKeyStoreAlias(org.jcryptool.crypto.keystore.keys.IKeyStoreAlias) KeyPairNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.keys.KeyPairNode)

Example 9 with IKeyStoreAlias

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;
}
Also used : AbstractKeyNode(org.jcryptool.crypto.keystore.ui.views.nodes.keys.AbstractKeyNode) UnrecoverableEntryException(java.security.UnrecoverableEntryException) IKeyStoreAlias(org.jcryptool.crypto.keystore.keys.IKeyStoreAlias)

Example 10 with IKeyStoreAlias

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);
}
Also used : ContactDescriptorNode(org.jcryptool.crypto.keystore.ui.views.nodes.ContactDescriptorNode) CertificateNode(org.jcryptool.crypto.keystore.ui.views.nodes.keys.CertificateNode) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) SecretKeyNode(org.jcryptool.crypto.keystore.ui.views.nodes.keys.SecretKeyNode) Menu(org.eclipse.swt.widgets.Menu) IMenuListener(org.eclipse.jface.action.IMenuListener) KeyPairNode(org.jcryptool.crypto.keystore.ui.views.nodes.keys.KeyPairNode) IKeyStoreAlias(org.jcryptool.crypto.keystore.keys.IKeyStoreAlias)

Aggregations

IKeyStoreAlias (org.jcryptool.crypto.keystore.keys.IKeyStoreAlias)10 UnrecoverableEntryException (java.security.UnrecoverableEntryException)3 AbstractKeyNode (org.jcryptool.crypto.keystore.ui.views.nodes.keys.AbstractKeyNode)3 CertificateNode (org.jcryptool.crypto.keystore.ui.views.nodes.keys.CertificateNode)3 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Certificate (java.security.cert.Certificate)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 TableEntry (org.jcryptool.crypto.keystore.ui.dialogs.TableEntry)2 DSAPrivateKey (de.flexiprovider.core.dsa.DSAPrivateKey)1 DSAPublicKey (de.flexiprovider.core.dsa.DSAPublicKey)1 SSVElGamalPrivateKey (de.flexiprovider.core.elgamal.semanticallysecure.SSVElGamalPrivateKey)1 SSVElGamalPublicKey (de.flexiprovider.core.elgamal.semanticallysecure.SSVElGamalPublicKey)1 MpRSAPrivateKey (de.flexiprovider.core.mprsa.MpRSAPrivateKey)1 ECPrivateKey (de.flexiprovider.ec.keys.ECPrivateKey)1 ECSecretKey (de.flexiprovider.ec.keys.ECSecretKey)1 IQDSAPrivateKey (de.flexiprovider.nf.iq.iqdsa.IQDSAPrivateKey)1 IQDSAPublicKey (de.flexiprovider.nf.iq.iqdsa.IQDSAPublicKey)1 IQGQPublicKey (de.flexiprovider.nf.iq.iqgq.IQGQPublicKey)1