Search in sources :

Example 1 with ActionCascade

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

the class NewCascadeHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    ActionCascadeService service = ActionCascadeService.getInstance();
    if (service.getCurrentActionCascade() != null && service.getCurrentActionCascade().getSize() > 0) {
        boolean confirmNew = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), Messages.NewCascadeHandler_0, Messages.NewCascadeHandler_1);
        if (confirmNew) {
            // $NON-NLS-1$
            ActionCascade ac = new ActionCascade("actionCascade");
            ActionsUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_STORE_PASSWORDS);
            service.setCurrentActionCascade(ac);
        }
    }
    ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    // $NON-NLS-1$
    Command command = commandService.getCommand("org.jcryptool.actions.recordCommand");
    // $NON-NLS-1$
    State state = command.getState("org.jcryptool.actions.recordCommand.toggleState");
    boolean doRecord = (Boolean) state.getValue();
    if (doRecord) {
        state.setValue(!doRecord);
        // $NON-NLS-1$
        commandService.refreshElements("org.jcryptool.actions.recordCommand", null);
    }
    return null;
}
Also used : Command(org.eclipse.core.commands.Command) State(org.eclipse.core.commands.State) ActionCascadeService(org.jcryptool.actions.core.registry.ActionCascadeService) ActionCascade(org.jcryptool.actions.core.types.ActionCascade) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 2 with ActionCascade

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

the class RecordHandler method startRecording.

private boolean startRecording(IEditorPart editor, ActionView view) {
    String activeEditorFile = editor.getTitle();
    if (activeEditorFile.contains(".")) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        activeEditorFile = activeEditorFile.substring(0, activeEditorFile.indexOf("."));
    }
    ActionCascade cascade = null;
    if (view.hasContent()) {
        return true;
    } else {
        // $NON-NLS-1$
        cascade = new ActionCascade(activeEditorFile + "Cascade");
        ActionsUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_STORE_PASSWORDS);
        ActionCascadeService.getInstance().setCurrentActionCascade(cascade);
        return true;
    }
}
Also used : ActionCascade(org.jcryptool.actions.core.types.ActionCascade)

Example 3 with ActionCascade

use of org.jcryptool.actions.core.types.ActionCascade 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 4 with ActionCascade

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

Aggregations

ActionCascade (org.jcryptool.actions.core.types.ActionCascade)4 ActionItem (org.jcryptool.actions.core.types.ActionItem)2 File (java.io.File)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 Command (org.eclipse.core.commands.Command)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 State (org.eclipse.core.commands.State)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 ICommandService (org.eclipse.ui.commands.ICommandService)1 ActionCascadeService (org.jcryptool.actions.core.registry.ActionCascadeService)1 CommandInfo (org.jcryptool.core.operations.CommandInfo)1 OperationsPlugin (org.jcryptool.core.operations.OperationsPlugin)1 ShadowAlgorithmHandler (org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler)1 IFlexiProviderOperation (org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation)1 AlgorithmDescriptor (org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor)1 BlockCipherDescriptor (org.jcryptool.crypto.flexiprovider.descriptors.algorithms.BlockCipherDescriptor)1 SecureRandomDescriptor (org.jcryptool.crypto.flexiprovider.descriptors.algorithms.SecureRandomDescriptor)1 IntegratorOperation (org.jcryptool.crypto.flexiprovider.integrator.IntegratorOperation)1