Search in sources :

Example 1 with KeyStoreAlias

use of org.jcryptool.crypto.keystore.backend.KeyStoreAlias in project core by jcryptool.

the class AbstractKeyStoreHandler method addSecretKeyStatic.

public static KeyStoreAlias addSecretKeyStatic(INewEntryDescriptor descriptor, SecretKey key) {
    // $NON-NLS-1$
    LogUtil.logInfo("adding SecretKey");
    KeyStoreAlias alias = new KeyStoreAlias(descriptor.getContactName(), KeyType.SECRETKEY, // key.getAlgorithm(),
    descriptor.getDisplayedName(), (key.getEncoded().length * 8), ByteArrayUtils.toHexString(getHashValue(descriptor)), key.getClass().getName());
    KeyStoreManager.getInstance().addSecretKey(key, descriptor.getPassword().toCharArray(), alias);
    return alias;
}
Also used : KeyStoreAlias(org.jcryptool.crypto.keystore.backend.KeyStoreAlias)

Example 2 with KeyStoreAlias

use of org.jcryptool.crypto.keystore.backend.KeyStoreAlias in project core by jcryptool.

the class IntegratorWizardPage method makeNewKey.

protected void makeNewKey() {
    Job[] preJobs = Job.getJobManager().find(KeyStoreHelper.KEYSTOREHELPER_FAMILY);
    int preJobCount = preJobs.length;
    KeyStoreHelper.makeSymmetricKeyByWizard(showKeyGroup).addObserver(new Observer() {

        public void update(Observable o, final Object arg) {
            if (arg != null) {
                keyFromKeystoreGroup.getDisplay().syncExec(new Runnable() {

                    public void run() {
                        KeyStoreAlias ref = (KeyStoreAlias) arg;
                        setKeyForShowcase(ref);
                    }
                });
            }
        }
    });
    Job[] jobs = Job.getJobManager().find(KeyStoreHelper.KEYSTOREHELPER_FAMILY);
    if (jobs.length > preJobCount) {
        createNewKeyButton.getDisplay().syncExec(new Runnable() {

            public void run() {
                buttonTextBeforeJobrunningMsg = createNewKeyButton.getText();
                // $NON-NLS-1$
                createNewKeyButton.setText(Messages.getString("IntegratorWizardPage.generatingButtonHint"));
                disableControls();
            }
        });
        Job job = jobs[jobs.length - 1];
        IJobChangeListener listener = new IJobChangeListener() {

            public void sleeping(IJobChangeEvent event) {
            }

            public void done(IJobChangeEvent event) {
                createNewKeyButton.getDisplay().syncExec(new Runnable() {

                    public void run() {
                        createNewKeyButton.setText(buttonTextBeforeJobrunningMsg);
                        enableControls();
                    }
                });
            }

            public void awake(IJobChangeEvent event) {
            }

            public void aboutToRun(IJobChangeEvent event) {
            }

            public void running(IJobChangeEvent event) {
            }

            public void scheduled(IJobChangeEvent event) {
            }
        };
        if (job.getState() != Job.NONE)
            job.addJobChangeListener(listener);
        else {
            listener.done(null);
        }
    }
}
Also used : KeyStoreAlias(org.jcryptool.crypto.keystore.backend.KeyStoreAlias) Observer(java.util.Observer) IJobChangeListener(org.eclipse.core.runtime.jobs.IJobChangeListener) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) Observable(java.util.Observable)

Example 3 with KeyStoreAlias

use of org.jcryptool.crypto.keystore.backend.KeyStoreAlias in project core by jcryptool.

the class IntegratorWizardPage method refreshKeysFromKeystore.

private void refreshKeysFromKeystore(KeyStoreAlias previousSelection) {
    publicKeyMap.clear();
    privateKeyMap.clear();
    comboKeyMap.clear();
    try {
        Enumeration<String> aliases = KeyStoreManager.getInstance().getAliases();
        KeyStoreAlias localKeyStoreAlias = null;
        while (aliases.hasMoreElements()) {
            localKeyStoreAlias = new KeyStoreAlias(aliases.nextElement());
            // String op = localKeyStoreAlias.getOperation();
            if (localKeyStoreAlias.isOperationMatchingKeyId(showKeyGroup)) {
                // $NON-NLS-1$
                if (localKeyStoreAlias.getKeyStoreEntryType().getType().contains(KeyType.KEYPAIR.getType())) {
                    // asymmetric
                    if (localKeyStoreAlias.getKeyStoreEntryType().equals(KeyType.KEYPAIR_PUBLIC_KEY)) {
                        publicKeyMap.add(localKeyStoreAlias);
                    }
                    if (localKeyStoreAlias.getKeyStoreEntryType().equals(KeyType.KEYPAIR_PRIVATE_KEY)) {
                        privateKeyMap.add(localKeyStoreAlias);
                    }
                } else {
                    // symmetric
                    publicKeyMap.add(localKeyStoreAlias);
                    privateKeyMap.add(localKeyStoreAlias);
                }
            }
        }
    } catch (Exception e) {
        LogUtil.logError(e);
    }
    // if (publicKeyMap.isEmpty() || privateKeyMap.isEmpty()) {
    // if(keyFromKeystoreButton != null) keyFromKeystoreButton.setEnabled(false);
    // this.setErrorMessage(Messages.getString("DummyWizardPage.23") + " " + showKeyGroup + " " + Messages.getString("DummyWizardPage.232")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    // }
    selectCurrentKey(previousSelection);
}
Also used : KeyStoreAlias(org.jcryptool.crypto.keystore.backend.KeyStoreAlias)

Example 4 with KeyStoreAlias

use of org.jcryptool.crypto.keystore.backend.KeyStoreAlias in project core by jcryptool.

the class IntegratorWizardPage method makeNewKeypair.

protected void makeNewKeypair() {
    Job[] preJobs = Job.getJobManager().find(KeyStoreHelper.KEYSTOREHELPER_FAMILY);
    int preJobCount = preJobs.length;
    KeyStoreHelper.makeKeyPairByWizard(showKeyGroup).addObserver(new Observer() {

        public void update(Observable o, final Object arg) {
            if (arg != null) {
                keyFromKeystoreGroup.getDisplay().syncExec(new Runnable() {

                    public void run() {
                        KeyStoreAlias ref = (KeyStoreAlias) arg;
                        setKeyForShowcase(ref);
                    }
                });
            }
        }
    });
    Job[] jobs = Job.getJobManager().find(KeyStoreHelper.KEYSTOREHELPER_FAMILY);
    if (jobs.length > preJobCount) {
        createNewKeyButton.getDisplay().syncExec(new Runnable() {

            public void run() {
                buttonTextBeforeJobrunningMsg = createNewKeyButton.getText();
                // $NON-NLS-1$
                createNewKeyButton.setText(Messages.getString("IntegratorWizardPage.generatingButtonHint"));
                disableControls();
            }
        });
        Job job = jobs[jobs.length - 1];
        IJobChangeListener listener = new IJobChangeListener() {

            public void sleeping(IJobChangeEvent event) {
            }

            public void done(IJobChangeEvent event) {
                createNewKeyButton.getDisplay().syncExec(new Runnable() {

                    public void run() {
                        createNewKeyButton.setText(buttonTextBeforeJobrunningMsg);
                        enableControls();
                    }
                });
            }

            public void awake(IJobChangeEvent event) {
            }

            public void aboutToRun(IJobChangeEvent event) {
            }

            public void running(IJobChangeEvent event) {
            }

            public void scheduled(IJobChangeEvent event) {
            }
        };
        if (job.getState() != Job.NONE)
            job.addJobChangeListener(listener);
        else {
            listener.done(null);
        }
    }
}
Also used : KeyStoreAlias(org.jcryptool.crypto.keystore.backend.KeyStoreAlias) Observer(java.util.Observer) IJobChangeListener(org.eclipse.core.runtime.jobs.IJobChangeListener) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) Observable(java.util.Observable)

Example 5 with KeyStoreAlias

use of org.jcryptool.crypto.keystore.backend.KeyStoreAlias in project core by jcryptool.

the class IntegratorWizardPage method selectCurrentKey.

/**
 * selects current key in the key combo according to previousSelection
 *
 * @param previousSelection
 */
private void selectCurrentKey(KeyStoreAlias previousSelection) {
    comboKeyMap.addAll(encrypt ? publicKeyMap : privateKeyMap);
    keyCombo.setItems(getKeyItems());
    if (keyCombo.getItemCount() == 0) {
        // $NON-NLS-1$
        keyCombo.add(Messages.getString("IntegratorWizardPage.noKeyFound"));
        keyCombo.select(0);
        keyCombo.setEnabled(false);
        keyStoreAlias = null;
    } else {
        keyCombo.setEnabled(true);
        if (previousSelection == null) {
            keyCombo.select(0);
        } else {
            if (comboKeyMap.contains(previousSelection)) {
                keyCombo.select(comboKeyMap.indexOf(previousSelection));
            } else {
                keyCombo.select(0);
                String prevHash = previousSelection.getHashValue();
                for (KeyStoreAlias alias : comboKeyMap) {
                    if (alias.getHashValue().equals(prevHash)) {
                        keyCombo.select(comboKeyMap.indexOf(alias));
                        break;
                    }
                }
            }
        }
        keyStoreAlias = comboKeyMap.get(keyCombo.getSelectionIndex());
    }
}
Also used : KeyStoreAlias(org.jcryptool.crypto.keystore.backend.KeyStoreAlias)

Aggregations

KeyStoreAlias (org.jcryptool.crypto.keystore.backend.KeyStoreAlias)11 ArrayList (java.util.ArrayList)2 Observable (java.util.Observable)2 Observer (java.util.Observer)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 IJobChangeListener (org.eclipse.core.runtime.jobs.IJobChangeListener)2 Job (org.eclipse.core.runtime.jobs.Job)2 AlgorithmDescriptor (org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 X509Certificate (java.security.cert.X509Certificate)1 HashMap (java.util.HashMap)1 List (java.util.List)1 JAXBException (javax.xml.bind.JAXBException)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 Widget (org.eclipse.swt.widgets.Widget)1