Search in sources :

Example 6 with ActionItem

use of org.jcryptool.actions.core.types.ActionItem 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)

Example 7 with ActionItem

use of org.jcryptool.actions.core.types.ActionItem in project core by jcryptool.

the class StartHandler method execute.

public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ActionView view = (ActionView) HandlerUtil.getActivePart(event);
    if (!view.hasContent()) {
        MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.StartHandler_0, Messages.StartHandler_1);
    } else {
        final ActionItem a = (ActionItem) ((IStructuredSelection) (view.getViewer().getSelection())).getFirstElement();
        Job job = new Job(Messages.StartHandler_5) {

            public IStatus run(final IProgressMonitor monitor) {
                return execute(view, a, HandlerUtil.getActiveShell(event), monitor);
            }
        };
        job.setUser(true);
        job.schedule();
    }
    return null;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ActionItem(org.jcryptool.actions.core.types.ActionItem) ActionView(org.jcryptool.actions.ui.views.ActionView) Job(org.eclipse.core.runtime.jobs.Job)

Example 8 with ActionItem

use of org.jcryptool.actions.core.types.ActionItem in project core by jcryptool.

the class ImportUtils method createActionCascade.

public ActionCascade createActionCascade() {
    Document doc;
    try {
        DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        doc = dBuilder.parse(new File(filename));
        doc.getDocumentElement().normalize();
    } catch (Exception ex) {
        // $NON-NLS-1$ //$NON-NLS-2$
        LogUtil.logError("XML-Parsing of " + filename + " failed.", ex);
        return null;
    }
    ActionCascade ac = // $NON-NLS-1$
    new ActionCascade(doc.getDocumentElement().getAttributes().getNamedItem("name").getTextContent());
    // $NON-NLS-1$
    ac.setSavePasswords(Boolean.parseBoolean(doc.getDocumentElement().getAttributes().getNamedItem("passwords").getTextContent()));
    // $NON-NLS-1$
    NodeList nList = doc.getElementsByTagName("ActionItem");
    for (int i = 0; i < nList.getLength(); i++) {
        // $NON-NLS-1$
        String actionname = "";
        // $NON-NLS-1$
        String filename = "";
        // $NON-NLS-1$
        String pluginId = "";
        // $NON-NLS-1$
        String actionType = "";
        // $NON-NLS-1$
        String alphabet = "";
        // $NON-NLS-1$
        String dataObjectType = "";
        NodeList values = nList.item(i).getChildNodes();
        for (int j = 0; j < values.getLength(); j++) {
            String nodeName = values.item(j).getNodeName();
            if (nodeName.equals("FileName")) {
                // $NON-NLS-1$
                filename = values.item(j).getTextContent();
            } else if (nodeName.equals("ActionName")) {
                // $NON-NLS-1$
                actionname = values.item(j).getTextContent();
                // $NON-NLS-1$
                pluginId = values.item(j).getAttributes().getNamedItem("plugin").getTextContent();
            } else if (nodeName.equals("ActionType")) {
                // $NON-NLS-1$
                actionType = values.item(j).getTextContent();
            } else if (nodeName.equals("Alphabet")) {
                // $NON-NLS-1$
                alphabet = values.item(j).getTextContent();
            }
        }
        ActionItem ai = new ActionItem(filename, actionname);
        ai.setActionType(actionType);
        ai.setPluginId(pluginId);
        ai.setAlphabet(alphabet);
        for (int j = 0; j < values.getLength(); j++) {
            String nodeName = values.item(j).getNodeName();
            if (nodeName.equals("Parameters")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                dataObjectType = values.item(j).getAttributes().getNamedItem("dataobjecttype").getTextContent();
                ai.setDataObjectType(dataObjectType);
                NodeList params = values.item(j).getChildNodes();
                for (int m = 0; m < params.getLength(); m++) {
                    NodeList paramAtts = params.item(m).getChildNodes();
                    String key = null;
                    String value = null;
                    for (int n = 0; n < paramAtts.getLength(); n++) {
                        String paramNodeName = paramAtts.item(n).getNodeName();
                        if (paramNodeName.equals("Key")) {
                            // $NON-NLS-1$
                            key = paramAtts.item(n).getTextContent();
                        } else if (paramNodeName.equals("Value")) {
                            // $NON-NLS-1$
                            value = paramAtts.item(n).getTextContent();
                        }
                        ai.addParam(key, value);
                    }
                }
            }
        }
        ac.addItem(ai);
    }
    return ac;
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) ActionItem(org.jcryptool.actions.core.types.ActionItem) Document(org.w3c.dom.Document) File(java.io.File) ActionCascade(org.jcryptool.actions.core.types.ActionCascade)

Example 9 with ActionItem

use of org.jcryptool.actions.core.types.ActionItem in project core by jcryptool.

the class ActionView method selectFirstActionItem.

private void selectFirstActionItem() {
    List<ActionItem> actionItems = ActionCascadeService.getInstance().getActionItems();
    if (actionItems != null && actionItems.size() > 0) {
        ActionItem firstItem = actionItems.get(0);
        viewer.setSelection(new StructuredSelection(firstItem), true);
    }
}
Also used : ActionItem(org.jcryptool.actions.core.types.ActionItem) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 10 with ActionItem

use of org.jcryptool.actions.core.types.ActionItem in project core by jcryptool.

the class ActionView method createActionTable.

private void createActionTable(Composite parent) {
    // Creating a table viewer
    viewer = new TableViewer(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    TableViewerColumn column = new TableViewerColumn(viewer, SWT.LEFT);
    column.getColumn().setText(Messages.ActionView_5);
    column.getColumn().setToolTipText(Messages.ActionView_6);
    column.getColumn().setWidth(50);
    column.getColumn().setMoveable(true);
    column = new TableViewerColumn(viewer, SWT.LEFT);
    column.getColumn().setText(Messages.ActionView_0);
    column.getColumn().setToolTipText(Messages.ActionView_1);
    column.getColumn().setWidth(80);
    column.getColumn().setMoveable(true);
    filenameColumn = new TableViewerColumn(viewer, SWT.LEFT);
    filenameColumn.getColumn().setText(Messages.ActionView_2);
    filenameColumn.getColumn().setToolTipText(Messages.ActionView_3);
    filenameColumn.getColumn().setMoveable(true);
    setFilenameVisibility();
    viewer.setContentProvider(new ObservableListContentProvider());
    viewer.setLabelProvider(new ActionLabelProvider());
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent e) {
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent e) {
            ActionItem action = (ActionItem) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (action != null) {
                detailTextfield.setText(action.getDetails());
                if (detailTextfield.getLineCount() > 0) {
                    detailTextfield.setLineBackground(0, 1, colorLightShadow);
                    StyleRange styleRange = new StyleRange();
                    styleRange.start = 0;
                    styleRange.length = detailTextfield.getText().indexOf(CRLF);
                    styleRange.fontStyle = SWT.BOLD;
                    detailTextfield.setStyleRange(styleRange);
                    detailTextfield.setTabs(20);
                    int i = 0;
                    int l = 0;
                    while (i >= 0) {
                        i = detailTextfield.getText().indexOf(CRLF, i + 1);
                        // $NON-NLS-1$
                        l = detailTextfield.getText().indexOf(":", i + 1) - i;
                        if (l > 0 && i >= 0) {
                            styleRange.start = i;
                            styleRange.length = l;
                            detailTextfield.setStyleRange(styleRange);
                        }
                    }
                }
            } else {
                // $NON-NLS-1$
                detailTextfield.setText("");
            }
        }
    });
    viewer.setInput(ActionCascadeService.getInstance().observeActionItems());
    ActionCascadeService.getInstance().observeActionItems().addListChangeListener(this);
    getSite().setSelectionProvider(viewer);
}
Also used : ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ActionItem(org.jcryptool.actions.core.types.ActionItem) StyleRange(org.eclipse.swt.custom.StyleRange) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer) ActionLabelProvider(org.jcryptool.actions.ui.views.provider.ActionLabelProvider) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

ActionItem (org.jcryptool.actions.core.types.ActionItem)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 TableViewer (org.eclipse.jface.viewers.TableViewer)4 ISelection (org.eclipse.jface.viewers.ISelection)3 ActionView (org.jcryptool.actions.ui.views.ActionView)3 ICommandService (org.eclipse.ui.commands.ICommandService)2 ActionCascade (org.jcryptool.actions.core.types.ActionCascade)2 AlgorithmDescriptor (org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor)2 BlockCipherDescriptor (org.jcryptool.crypto.flexiprovider.descriptors.algorithms.BlockCipherDescriptor)2 SecureRandomDescriptor (org.jcryptool.crypto.flexiprovider.descriptors.algorithms.SecureRandomDescriptor)2 File (java.io.File)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1