Search in sources :

Example 11 with AlgorithmDescriptor

use of org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor in project core by jcryptool.

the class ExportRootElement method getEntryNode.

public EntryNode getEntryNode() {
    // $NON-NLS-1$
    String name = getAttributeValue("name");
    // $NON-NLS-1$
    long timestamp = Long.valueOf(getAttributeValue("timestamp"));
    // algorithm
    AlgorithmDescriptor descriptor = null;
    if (getChild("AlgorithmDescriptor") != null) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        AlgorithmDescriptorElement descriptorElement = new AlgorithmDescriptorElement(getChild("AlgorithmDescriptor"));
        descriptor = descriptorElement.getDescriptor();
    } else if (getChild("SecureRandomDescriptor") != null) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        SecureRandomDescriptorElement descriptorElement = new SecureRandomDescriptorElement(getChild("SecureRandomDescriptor"));
        descriptor = descriptorElement.getDescriptor();
    } else if (getChild("BlockCipherDescriptor") != null) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        BlockCipherDescriptorElement descriptorElement = new BlockCipherDescriptorElement(getChild("BlockCipherDescriptor"));
        descriptor = descriptorElement.getDescriptor();
    }
    return new EntryNode(name, timestamp, descriptor);
}
Also used : AlgorithmDescriptorElement(org.jcryptool.crypto.flexiprovider.operations.xml.algorithms.AlgorithmDescriptorElement) SecureRandomDescriptorElement(org.jcryptool.crypto.flexiprovider.operations.xml.algorithms.SecureRandomDescriptorElement) EntryNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.EntryNode) BlockCipherDescriptorElement(org.jcryptool.crypto.flexiprovider.operations.xml.algorithms.BlockCipherDescriptorElement) AlgorithmDescriptor(org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor)

Example 12 with AlgorithmDescriptor

use of org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor in project core by jcryptool.

the class StartHandler method execute.

public IStatus execute(final ActionView view, final ActionItem startItem, final Shell shell, IProgressMonitor monitor) {
    ActionCascade ac = view.getActionCascade();
    final TableViewer viewer = view.getViewer();
    // $NON-NLS-1$
    LogUtil.logInfo("Running Action Cascade " + ac.getName());
    boolean start = false;
    for (final ActionItem a : ac.getAllItems()) {
        int steps = ac.getSize();
        // Start the execution at the first selected element
        if (a == startItem) {
            start = true;
            monitor.beginTask(a.getActionName(), steps);
        } else
            steps--;
        if (start) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            try {
                boolean executed = false;
                // Set focus on moved row. Just look and feel ...
                display.asyncExec(new Runnable() {

                    public void run() {
                        viewer.setSelection(new StructuredSelection(a), true);
                    }
                });
                OperationsPlugin op = OperationsPlugin.getDefault();
                CommandInfo[] commands = op.getAlgorithmsManager().getShadowAlgorithmCommands();
                // Try to find an CryptoAlgorithm-Plug-in (Classic or Modern)
                for (int i = 0, length = commands.length; i < length; i++) {
                    if (commands[i].getHandler() != null && a.getPluginId().equals(commands[i].getCommandId())) {
                        ((ShadowAlgorithmHandler) commands[i].getHandler()).run(convert(a));
                        executed = true;
                    }
                }
                // Try to find a FlexiProvider algorithm
                if (!executed) {
                    // $NON-NLS-1$
                    LogUtil.logInfo("Trying to execute FlexiProvider algorithm");
                    for (RegistryType rt : RegistryType.values()) {
                        if (rt.getName().equals(a.getPluginId())) {
                            AlgorithmDescriptor descriptor = new AlgorithmDescriptor(a.getActionName(), rt, null);
                            if (a.getParam("algorithm type").equals(RegistryType.BLOCK_CIPHER.getName())) {
                                // $NON-NLS-1$
                                descriptor = new BlockCipherDescriptor(descriptor.getAlgorithmName(), a.getParam("mode"), a.getParam("padding scheme"), null, // $NON-NLS-1$ //$NON-NLS-2$
                                null);
                            } else if (a.getParam("algorithm type").equals(RegistryType.SECURE_RANDOM.getName())) {
                                // $NON-NLS-1$
                                // TODO Get property "alphabet" from item
                                byte[][] alphabet = null;
                                if (alphabet == null) {
                                    descriptor = new SecureRandomDescriptor(descriptor.getAlgorithmName(), // $NON-NLS-1$
                                    Integer.parseInt(a.getParam("random size")));
                                }
                            }
                            final IFlexiProviderOperation operation = new IntegratorOperation(descriptor);
                            operation.setInput(Messages.InputType);
                            operation.setOutput(Messages.StartHandler_6);
                            // $NON-NLS-1$
                            operation.setSignature(a.getParam("signature"));
                            if ("encrypt".equals(a.getActionType())) {
                                // $NON-NLS-1$
                                operation.setOperation(OperationType.ENCRYPT);
                            } else if ("decrypt".equals(a.getActionType())) {
                                // $NON-NLS-1$
                                operation.setOperation(OperationType.DECRYPT);
                            } else if ("sign".equals(a.getActionType())) {
                                // $NON-NLS-1$
                                operation.setOperation(OperationType.SIGN);
                            } else if ("verify".equals(a.getActionType())) {
                                // $NON-NLS-1$
                                operation.setOperation(OperationType.VERIFY);
                            } else {
                                operation.setOperation(OperationType.UNKNOWN);
                            }
                            // $NON-NLS-1$
                            String alias = a.getParam("key alias");
                            if (alias != null) {
                                operation.setKeyStoreAlias(new KeyStoreAlias(alias));
                            }
                            // $NON-NLS-1$
                            String password = a.getParam("key password");
                            if (password != null) {
                                operation.setPassword(password.toCharArray());
                            }
                            display.asyncExec(new Runnable() {

                                public void run() {
                                    PerformOperationManager.getInstance().firePerformOperation(operation);
                                }
                            });
                            executed = true;
                        }
                    }
                }
                if (!executed) {
                    throw new Exception(Messages.StartHandler_2 + a.getPluginId());
                }
            } catch (final Exception e) {
                if (ActionsUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_IGNORE_ERRORS)) {
                    // $NON-NLS-1$
                    LogUtil.logError(ActionsUIPlugin.PLUGIN_ID, a.getActionName() + ": " + e.getMessage(), e, false);
                    if (!ActionsUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_DONT_SHOW_MESSAGES)) {
                        display.syncExec(new Runnable() {

                            public void run() {
                                MessageDialog.openWarning(shell, Messages.StartHandler_3, e.getMessage());
                            }
                        });
                    }
                } else {
                    display.asyncExec(new Runnable() {

                        public void run() {
                            MessageDialog.openError(shell, Messages.StartHandler_3, e.getMessage() + // $NON-NLS-1$
                            Messages.StartHandler_4);
                        }
                    });
                    return Status.CANCEL_STATUS;
                }
            } finally {
                monitor.worked(ac.getSize() - steps);
            }
        }
    }
    monitor.done();
    return Status.OK_STATUS;
}
Also used : KeyStoreAlias(org.jcryptool.crypto.keystore.backend.KeyStoreAlias) RegistryType(org.jcryptool.crypto.flexiprovider.types.RegistryType) ShadowAlgorithmHandler(org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler) ActionItem(org.jcryptool.actions.core.types.ActionItem) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AlgorithmDescriptor(org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor) ActionCascade(org.jcryptool.actions.core.types.ActionCascade) OperationsPlugin(org.jcryptool.core.operations.OperationsPlugin) ExecutionException(org.eclipse.core.commands.ExecutionException) SecureRandomDescriptor(org.jcryptool.crypto.flexiprovider.descriptors.algorithms.SecureRandomDescriptor) CommandInfo(org.jcryptool.core.operations.CommandInfo) BlockCipherDescriptor(org.jcryptool.crypto.flexiprovider.descriptors.algorithms.BlockCipherDescriptor) IntegratorOperation(org.jcryptool.crypto.flexiprovider.integrator.IntegratorOperation) TableViewer(org.eclipse.jface.viewers.TableViewer) IFlexiProviderOperation(org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation)

Aggregations

AlgorithmDescriptor (org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor)12 WizardDialog (org.eclipse.jface.wizard.WizardDialog)6 BlockCipherWizardDialog (org.jcryptool.crypto.flexiprovider.algorithms.ui.wizards.blockcipher.BlockCipherWizardDialog)5 AlgorithmWizard (org.jcryptool.crypto.flexiprovider.algorithms.ui.wizards.AlgorithmWizard)4 BlockCipherDescriptor (org.jcryptool.crypto.flexiprovider.descriptors.algorithms.BlockCipherDescriptor)3 SecureRandomDescriptor (org.jcryptool.crypto.flexiprovider.descriptors.algorithms.SecureRandomDescriptor)3 AlgorithmParameterSpec (de.flexiprovider.api.parameters.AlgorithmParameterSpec)2 ActionItem (org.jcryptool.actions.core.types.ActionItem)2 EntryNode (org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.EntryNode)2 AlgorithmDescriptorElement (org.jcryptool.crypto.flexiprovider.operations.xml.algorithms.AlgorithmDescriptorElement)2 BlockCipherDescriptorElement (org.jcryptool.crypto.flexiprovider.operations.xml.algorithms.BlockCipherDescriptorElement)2 SecureRandomDescriptorElement (org.jcryptool.crypto.flexiprovider.operations.xml.algorithms.SecureRandomDescriptorElement)2 KeyStoreAlias (org.jcryptool.crypto.keystore.backend.KeyStoreAlias)2 MessageDigest (de.flexiprovider.api.MessageDigest)1 NoSuchAlgorithmException (de.flexiprovider.api.exceptions.NoSuchAlgorithmException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1