Search in sources :

Example 1 with IMetaAlgorithm

use of org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm in project core by jcryptool.

the class FlexiProviderRootElement method initSecretKeyAlgorithms.

@SuppressWarnings("unchecked")
private static void initSecretKeyAlgorithms(RegistryType type, Element secretKeyAlgorithmParent) {
    List<Element> cipherChildren = new ArrayList<Element>(secretKeyAlgorithmParent.getChildren());
    Iterator<Element> it = cipherChildren.iterator();
    while (it.hasNext()) {
        Element current = it.next();
        // replace element with blockCipherElement
        String className = current.getAttributeValue(AlgorithmsXMLConstants._class);
        IMetaOID oid = null;
        if (current.getAttributeValue(AlgorithmsXMLConstants._oid) != null) {
            oid = new MetaOID(current.getAttributeValue(AlgorithmsXMLConstants._oid));
        }
        List<String> names = new ArrayList<String>();
        if (current.getChild(AlgorithmsXMLConstants._Names) != null) {
            if (current.getChild(AlgorithmsXMLConstants._Names).getText().contains(",")) {
                // $NON-NLS-1$
                StringTokenizer tokenizer = // $NON-NLS-1$
                new StringTokenizer(current.getChild(AlgorithmsXMLConstants._Names).getText(), ",");
                while (tokenizer.hasMoreTokens()) {
                    names.add(tokenizer.nextToken());
                }
            } else {
                names.add(current.getChild(AlgorithmsXMLConstants._Names).getText());
            }
        }
        IMetaAlgorithm meta = new MetaAlgorithm(type, oid, names, className);
        // parameter specs
        if (current.getChild(AlgorithmsXMLConstants._ParameterSpec) != null) {
            meta.setParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
            if (current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttribute(AlgorithmsXMLConstants._disabled) == null) {
                meta.setParameterSpecDisabled(true);
            }
        }
        // parameter generators
        if (current.getChild(AlgorithmsXMLConstants._ParameterGenerator) != null) {
            meta.setParameterGeneratorClassName(current.getChild(AlgorithmsXMLConstants._ParameterGenerator).getAttributeValue(AlgorithmsXMLConstants._class));
            meta.setParamGenParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterGenerator).getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
        }
        if (current.getChild(AlgorithmsXMLConstants._BlockLengths) != null) {
            meta.setDefaultBlockLength(Integer.valueOf(current.getChild(AlgorithmsXMLConstants._BlockLengths).getAttributeValue(AlgorithmsXMLConstants._default)));
            if (current.getChild(AlgorithmsXMLConstants._BlockLengths).getText() != null) {
                List<Integer> blockLengths = new ArrayList<Integer>(0);
                StringTokenizer tokenizer = // $NON-NLS-1$
                new StringTokenizer(current.getChild(AlgorithmsXMLConstants._BlockLengths).getText(), ",");
                while (tokenizer.hasMoreTokens()) {
                    blockLengths.add(Integer.valueOf(tokenizer.nextToken()));
                }
                meta.setBlockLengths(blockLengths);
            }
        }
        if (current.getChild(AlgorithmsXMLConstants._StandardParameters) != null) {
            StringTokenizer standardParams = // $NON-NLS-1$
            new StringTokenizer(current.getChildText(AlgorithmsXMLConstants._StandardParameters), ",");
            while (standardParams.hasMoreTokens()) {
                meta.addStandardParams(standardParams.nextToken());
            }
        }
        if (type.equals(RegistryType.MAC)) {
            if (current.getChild(AlgorithmsXMLConstants._BlockCipherReference) != null) {
                meta.setBlockCipherName(current.getChild(AlgorithmsXMLConstants._BlockCipherReference).getAttributeValue(AlgorithmsXMLConstants._name));
                if (current.getChild(AlgorithmsXMLConstants._BlockCipherReference).getAttributeValue(AlgorithmsXMLConstants._oid) != null) {
                    meta.setBlockCipherOID(new MetaOID(current.getChild(AlgorithmsXMLConstants._BlockCipherReference).getAttributeValue(AlgorithmsXMLConstants._oid)));
                }
                meta.setBlockCipherMode(current.getChild(AlgorithmsXMLConstants._BlockCipherReference).getAttributeValue(AlgorithmsXMLConstants._mode));
            }
        }
        if (current.getAttribute(AlgorithmsXMLConstants._disabled) == null) {
            add(type, meta);
        }
    }
}
Also used : IMetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID) Element(org.jdom.Element) ArrayList(java.util.ArrayList) MetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaOID) IMetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID) StringTokenizer(java.util.StringTokenizer) IMetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm) IMetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm) MetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaAlgorithm)

Example 2 with IMetaAlgorithm

use of org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm in project core by jcryptool.

the class FlexiProviderAlgorithmsViewContentProvider method init.

private static CategoryNode init(String label, List<IMetaAlgorithm> algorithms) {
    CategoryNode category = new CategoryNode(label);
    // should be sorted already. just to be on the save side.
    Collections.sort(algorithms);
    // top level entries
    for (IMetaAlgorithm meta : algorithms) {
        if (!meta.getClassName().contains("$")) {
            // $NON-NLS-1$
            category.addChild(new AlgorithmNode(meta));
        }
    }
    // sub level entries
    for (IMetaAlgorithm meta : algorithms) {
        if (meta.getClassName().contains("$")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String primaryPrefix = meta.getClassName().substring(0, meta.getClassName().indexOf("$"));
            if (containsClassName(primaryPrefix, algorithms)) {
                // recursive entries
                buildAlgorithmHierarchy(category, meta);
            } else {
                // folder entries
                // $NON-NLS-1$ //$NON-NLS-2$
                String prefix = meta.getClassName().substring(meta.getClassName().lastIndexOf(".") + 1, meta.getClassName().indexOf("$"));
                ITreeNode folder = new FolderNode(prefix);
                for (IMetaAlgorithm meta2 : algorithms) {
                    if (meta2.getClassName().contains("$")) {
                        // $NON-NLS-1$
                        if (meta2.getClassName().contains("." + prefix)) {
                            // $NON-NLS-1$
                            folder.addChild(new AlgorithmNode(meta2));
                        }
                    }
                }
                category.addChild(folder);
            }
        }
    }
    return category;
}
Also used : CategoryNode(org.jcryptool.crypto.flexiprovider.algorithms.ui.views.nodes.CategoryNode) ITreeNode(org.jcryptool.crypto.flexiprovider.ui.nodes.ITreeNode) IMetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm) FolderNode(org.jcryptool.crypto.flexiprovider.algorithms.ui.views.nodes.FolderNode) AlgorithmNode(org.jcryptool.crypto.flexiprovider.algorithms.ui.views.nodes.AlgorithmNode)

Example 3 with IMetaAlgorithm

use of org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm in project core by jcryptool.

the class AlgorithmsManager method performMacCalled.

private static void performMacCalled(IMetaAlgorithm algorithm) {
    if (algorithm.getBlockCipherName() != null) {
        IMetaAlgorithm bc = null;
        // $NON-NLS-1$
        LogUtil.logInfo("BC name: " + algorithm.getBlockCipherName());
        if (algorithm.getBlockCipherOID() != null) {
            // $NON-NLS-1$
            LogUtil.logInfo("BC oid: " + algorithm.getBlockCipherOID());
            bc = AlgorithmsXMLManager.getInstance().getBlockCipher(algorithm.getBlockCipherOID());
        } else {
            bc = AlgorithmsXMLManager.getInstance().getBlockCipher(algorithm.getBlockCipherName());
        }
        // $NON-NLS-1$
        LogUtil.logInfo("BC mode: " + algorithm.getBlockCipherMode());
        if (bc != null) {
            blockCipherWizard = new BlockCipherWizard(bc, algorithm.getBlockCipherMode());
            dialog = new BlockCipherWizardDialog(shell, blockCipherWizard);
            dialog.setMinimumPageSize(300, 175);
            int result = dialog.open();
            if (result == Window.OK) {
                AlgorithmDescriptor blockCipherDescriptor = blockCipherWizard.getDescriptor();
                AlgorithmDescriptor macDescriptor = new AlgorithmDescriptor(algorithm.getName(), RegistryType.MAC, blockCipherDescriptor.getAlgorithmParameterSpec());
                NewOperationManager.getInstance().fireNewOperation(macDescriptor);
                return;
            }
        }
    }
    if (algorithm.getParameterSpecClassName() != null && !algorithm.isParameterSpecDisabled()) {
        algorithmWizard = new AlgorithmWizard(algorithm);
        dialog = new WizardDialog(shell, algorithmWizard);
        dialog.setMinimumPageSize(300, 100);
        int result = dialog.open();
        if (result == Window.OK) {
            // $NON-NLS-1$
            LogUtil.logInfo("adding mac");
            NewOperationManager.getInstance().fireNewOperation(algorithmWizard.getDescriptor());
        } else {
            // $NON-NLS-1$
            LogUtil.logInfo("adding mac w/o parameter spec");
            // $NON-NLS-1$
            LogUtil.logInfo("has param generator: " + (algorithm.getParameterGeneratorClassName() != null));
            if (algorithm.getParameterGeneratorClassName() != null) {
                AlgorithmParameterSpec generatedSpec = Reflector.getInstance().generateDefaultParameterSpec(algorithm);
                NewOperationManager.getInstance().fireNewOperation(new AlgorithmDescriptor(algorithm.getName(), RegistryType.MAC, generatedSpec));
            } else {
                NewOperationManager.getInstance().fireNewOperation(new AlgorithmDescriptor(algorithm.getName(), RegistryType.MAC, null));
            }
        }
    }
}
Also used : BlockCipherWizardDialog(org.jcryptool.crypto.flexiprovider.algorithms.ui.wizards.blockcipher.BlockCipherWizardDialog) IMetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm) AlgorithmWizard(org.jcryptool.crypto.flexiprovider.algorithms.ui.wizards.AlgorithmWizard) BlockCipherWizard(org.jcryptool.crypto.flexiprovider.algorithms.ui.wizards.blockcipher.BlockCipherWizard) AlgorithmDescriptor(org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor) WizardDialog(org.eclipse.jface.wizard.WizardDialog) BlockCipherWizardDialog(org.jcryptool.crypto.flexiprovider.algorithms.ui.wizards.blockcipher.BlockCipherWizardDialog) AlgorithmParameterSpec(de.flexiprovider.api.parameters.AlgorithmParameterSpec)

Example 4 with IMetaAlgorithm

use of org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm in project core by jcryptool.

the class FlexiProviderRootElement method initAlgorithms.

@SuppressWarnings("unchecked")
private static void initAlgorithms(RegistryType type, Element algorithmParent) {
    List<Element> messageDigestChildren = new ArrayList<Element>(algorithmParent.getChildren());
    Iterator<Element> it = messageDigestChildren.iterator();
    while (it.hasNext()) {
        Element current = it.next();
        // replace element with blockCipherElement
        String className = current.getAttributeValue(AlgorithmsXMLConstants._class);
        IMetaOID oid = null;
        if (current.getAttributeValue(AlgorithmsXMLConstants._oid) != null) {
            oid = new MetaOID(current.getAttributeValue(AlgorithmsXMLConstants._oid));
        }
        List<String> names = new ArrayList<String>();
        if (current.getChild(AlgorithmsXMLConstants._Names) != null) {
            if (current.getChild(AlgorithmsXMLConstants._Names).getText().contains(",")) {
                // $NON-NLS-1$
                StringTokenizer tokenizer = // $NON-NLS-1$
                new StringTokenizer(current.getChild(AlgorithmsXMLConstants._Names).getText(), ",");
                while (tokenizer.hasMoreTokens()) {
                    names.add(tokenizer.nextToken());
                }
            } else {
                names.add(current.getChild(AlgorithmsXMLConstants._Names).getText());
            }
        }
        IMetaAlgorithm meta = new MetaAlgorithm(type, oid, names, className);
        // // parameter specs
        if (current.getChild(AlgorithmsXMLConstants._ParameterSpec) != null) {
            meta.setParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
            if (current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttribute(AlgorithmsXMLConstants._disabled) == null) {
                meta.setParameterSpecDisabled(true);
            }
        }
        // parameter generators
        if (current.getChild(AlgorithmsXMLConstants._ParameterGenerator) != null) {
            meta.setParameterGeneratorClassName(current.getChild(AlgorithmsXMLConstants._ParameterGenerator).getAttributeValue(AlgorithmsXMLConstants._class));
            meta.setParamGenParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterGenerator).getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
        }
        if (current.getChild(AlgorithmsXMLConstants._StandardParameters) != null) {
            StringTokenizer standardParams = // $NON-NLS-1$
            new StringTokenizer(current.getChildText(AlgorithmsXMLConstants._StandardParameters), ",");
            while (standardParams.hasMoreTokens()) {
                meta.addStandardParams(standardParams.nextToken());
            }
        }
        if (current.getAttribute(AlgorithmsXMLConstants._disabled) == null) {
            add(type, meta);
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) IMetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID) IMetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm) Element(org.jdom.Element) ArrayList(java.util.ArrayList) MetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaOID) IMetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID) IMetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm) MetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaAlgorithm)

Example 5 with IMetaAlgorithm

use of org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm in project core by jcryptool.

the class FlexiProviderRootElement method initKeyPairAlgorithms.

@SuppressWarnings("unchecked")
private static void initKeyPairAlgorithms(RegistryType type, Element keyPairAlgorithmParent) {
    List<Element> signatureChildren = new ArrayList<Element>(keyPairAlgorithmParent.getChildren());
    Iterator<Element> it = signatureChildren.iterator();
    while (it.hasNext()) {
        Element current = it.next();
        String className = current.getAttributeValue(AlgorithmsXMLConstants._class);
        IMetaOID oid = null;
        if (current.getAttributeValue(AlgorithmsXMLConstants._oid) != null) {
            oid = new MetaOID(current.getAttributeValue(AlgorithmsXMLConstants._oid));
        }
        List<String> names = new ArrayList<String>();
        if (current.getChild(AlgorithmsXMLConstants._Names) != null) {
            if (current.getChild(AlgorithmsXMLConstants._Names).getText().contains(",")) {
                // $NON-NLS-1$
                StringTokenizer tokenizer = // $NON-NLS-1$
                new StringTokenizer(current.getChild(AlgorithmsXMLConstants._Names).getText(), ",");
                while (tokenizer.hasMoreTokens()) {
                    names.add(tokenizer.nextToken());
                }
            } else {
                names.add(current.getChild(AlgorithmsXMLConstants._Names).getText());
            }
        }
        IMetaAlgorithm meta = new MetaAlgorithm(type, oid, names, className);
        // parameter specs
        if (current.getChild(AlgorithmsXMLConstants._ParameterSpec) != null) {
            meta.setParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
            if (current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttribute(AlgorithmsXMLConstants._disabled) == null) {
                meta.setParameterSpecDisabled(true);
            }
        }
        // parameter generators
        if (current.getChild(AlgorithmsXMLConstants._ParameterGenerator) != null) {
            meta.setParameterGeneratorClassName(current.getChild(AlgorithmsXMLConstants._ParameterGenerator).getAttributeValue(AlgorithmsXMLConstants._class));
            meta.setParamGenParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterGenerator).getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
        }
        if (current.getChild(AlgorithmsXMLConstants._StandardParameters) != null) {
            StringTokenizer standardParams = // $NON-NLS-1$
            new StringTokenizer(current.getChildText(AlgorithmsXMLConstants._StandardParameters), ",");
            while (standardParams.hasMoreTokens()) {
                meta.addStandardParams(standardParams.nextToken());
            }
        }
        if (current.getAttribute(AlgorithmsXMLConstants._disabled) == null) {
            add(type, meta);
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) IMetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID) IMetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm) Element(org.jdom.Element) ArrayList(java.util.ArrayList) MetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaOID) IMetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID) IMetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm) MetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaAlgorithm)

Aggregations

IMetaAlgorithm (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm)5 ArrayList (java.util.ArrayList)3 StringTokenizer (java.util.StringTokenizer)3 MetaAlgorithm (org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaAlgorithm)3 MetaOID (org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaOID)3 IMetaOID (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID)3 Element (org.jdom.Element)3 AlgorithmParameterSpec (de.flexiprovider.api.parameters.AlgorithmParameterSpec)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 AlgorithmNode (org.jcryptool.crypto.flexiprovider.algorithms.ui.views.nodes.AlgorithmNode)1 CategoryNode (org.jcryptool.crypto.flexiprovider.algorithms.ui.views.nodes.CategoryNode)1 FolderNode (org.jcryptool.crypto.flexiprovider.algorithms.ui.views.nodes.FolderNode)1 AlgorithmWizard (org.jcryptool.crypto.flexiprovider.algorithms.ui.wizards.AlgorithmWizard)1 BlockCipherWizard (org.jcryptool.crypto.flexiprovider.algorithms.ui.wizards.blockcipher.BlockCipherWizard)1 BlockCipherWizardDialog (org.jcryptool.crypto.flexiprovider.algorithms.ui.wizards.blockcipher.BlockCipherWizardDialog)1 AlgorithmDescriptor (org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor)1 ITreeNode (org.jcryptool.crypto.flexiprovider.ui.nodes.ITreeNode)1