Search in sources :

Example 6 with AlgorithmParameterSpec

use of de.flexiprovider.api.parameters.AlgorithmParameterSpec in project core by jcryptool.

the class NewSymmetricKeyHandler method execute.

/**
 * @see org.eclipse.jface.action.Action#run()
 */
public Object execute(ExecutionEvent event) {
    // $NON-NLS-1$
    LogUtil.logInfo("NewSymmetricKeyAction");
    shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    Wizard wizard = new NewSymmetricKeyWizard();
    dialog = new WizardDialog(shell, wizard);
    dialog.setMinimumPageSize(300, 350);
    int result = dialog.open();
    if (result == Window.OK) {
        if (wizard instanceof INewKeyWizard) {
            INewEntryDescriptor nkd = ((INewKeyWizard) wizard).getNewEntryDescriptor();
            Integer[] argument = new Integer[1];
            argument[0] = nkd.getKeyLength();
            Integer keyLen = argument[0];
            // $NON-NLS-1$
            LogUtil.logInfo("key strength: " + argument[0]);
            try {
                IMetaKeyGenerator gen = AlgorithmsXMLManager.getInstance().getSecretKeyGenerator(nkd.getAlgorithmName());
                IMetaLength validKeyLengths = gen.getLengths();
                // Check if entered key length is valid
                boolean isValidKeyLength = true;
                if (validKeyLengths != null) {
                    isValidKeyLength = (validKeyLengths.getDefaultLength() == keyLen) || (keyLen >= validKeyLengths.getLowerBound() && keyLen <= validKeyLengths.getUpperBound()) || (validKeyLengths.getLengths() != null && validKeyLengths.getLengths().contains(keyLen));
                }
                if (!isValidKeyLength) {
                    throw new InvalidAlgorithmParameterException("illegal key length");
                }
                AlgorithmParameterSpec spec = null;
                if (gen.getParameterSpecClassName() != null) {
                    spec = Reflector.getInstance().instantiateParameterSpec(gen.getParameterSpecClassName(), argument);
                }
                SecretKeyGenerator generator = Registry.getSecretKeyGenerator(nkd.getAlgorithmName());
                if (spec != null) {
                    // $NON-NLS-1$
                    LogUtil.logInfo("initializing generator with spec");
                    generator.init(spec, FlexiProviderKeystorePlugin.getSecureRandom());
                } else {
                    generator.init(FlexiProviderKeystorePlugin.getSecureRandom());
                }
                SecretKey key = generator.generateKey();
                performNewKeyAction(new NewSecretKeyDescriptor(nkd, key));
            } catch (SecurityException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "SecurityException while generating a secret key", e, true);
            } catch (IllegalArgumentException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "IllegalArgumentException while generating a secret key", e, true);
            } catch (ClassNotFoundException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "ClassNotFoundException while generating a secret key", e, true);
            } catch (NoSuchMethodException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "NoSuchMethodException while generating a secret key", e, true);
            } catch (InstantiationException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "InstantiationException while generating a secret key", e, true);
            } catch (IllegalAccessException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "IllegalAccessException while generating a secret key", e, true);
            } catch (InvocationTargetException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "InvocationTargetException while generating a secret key", e, true);
            } catch (NoSuchAlgorithmException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "NoSuchAlgorithmException while generating a secret key", e, true);
            } catch (InvalidAlgorithmParameterException e) {
                LogUtil.logError(FlexiProviderKeystorePlugin.PLUGIN_ID, "InvalidAlgorithmParameterException while generating a secret key", e, true);
            }
        }
    }
    return (null);
}
Also used : NewSecretKeyDescriptor(org.jcryptool.crypto.keystore.descriptors.NewSecretKeyDescriptor) InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) IMetaKeyGenerator(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaKeyGenerator) InvocationTargetException(java.lang.reflect.InvocationTargetException) IMetaLength(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaLength) SecretKey(de.flexiprovider.api.keys.SecretKey) NewSymmetricKeyWizard(org.jcryptool.crypto.flexiprovider.keystore.wizards.NewSymmetricKeyWizard) SecretKeyGenerator(de.flexiprovider.api.keys.SecretKeyGenerator) INewKeyWizard(org.jcryptool.crypto.keystore.descriptors.interfaces.INewKeyWizard) NewSymmetricKeyWizard(org.jcryptool.crypto.flexiprovider.keystore.wizards.NewSymmetricKeyWizard) Wizard(org.eclipse.jface.wizard.Wizard) INewKeyWizard(org.jcryptool.crypto.keystore.descriptors.interfaces.INewKeyWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) AlgorithmParameterSpec(de.flexiprovider.api.parameters.AlgorithmParameterSpec) INewEntryDescriptor(org.jcryptool.crypto.keystore.descriptors.interfaces.INewEntryDescriptor)

Example 7 with AlgorithmParameterSpec

use of de.flexiprovider.api.parameters.AlgorithmParameterSpec in project core by jcryptool.

the class BlockCipherWizardDialog method nextPressed.

public void nextPressed() {
    // $NON-NLS-1$
    LogUtil.logInfo("next pressed");
    if (wizard.hasAlgorithmParameterSpecPage() && getCurrentPage().getName().equals("AlgorithmParameterWizardPage")) {
        // $NON-NLS-1$
        Object[] values = wizard.getAlgorithmParameterValues();
        for (Object value : values) {
            // $NON-NLS-1$ //$NON-NLS-2$
            LogUtil.logInfo("Value: " + value + " of type: " + value.getClass().getName());
        }
        try {
            dummyKey = wizard.getDummyKey();
            BlockCipher cipher = Registry.getBlockCipher(algorithm.getName());
            AlgorithmParameterSpec spec = Reflector.getInstance().instantiateParameterSpec(algorithm.getParameterSpecClassName(), values);
            cipher.initEncrypt(dummyKey, null, spec, FlexiProviderAlgorithmsPlugin.getSecureRandom());
            modeBlockSize = cipher.getBlockSize();
            wizard.setModeBlockSize(modeBlockSize);
        } catch (NoSuchAlgorithmException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "NoSuchAlgorithmException while initializing a block cipher", e, true);
        } catch (NoSuchPaddingException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "NoSuchPaddingException while initializing a block cipher", e, true);
        } catch (InvalidKeyException e) {
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, Messages.BlockCipherWizardDialog_2, e, true);
        } catch (InvalidAlgorithmParameterException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "InvalidAlgorithmParameterException while initializing a block cipher", e, true);
        } catch (SecurityException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "SecurityException while initializing a block cipher", e, true);
        } catch (IllegalArgumentException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "IllegalArgumentException while initializing a block cipher", e, true);
        } catch (ClassNotFoundException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "ClassNotFoundException while initializing a block cipher", e, true);
        } catch (NoSuchMethodException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "NoSuchMethodException while initializing a block cipher", e, true);
        } catch (InstantiationException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "InstantiationException while initializing a block cipher", e, true);
        } catch (IllegalAccessException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "IllegalAccessException while initializing a block cipher", e, true);
        } catch (InvocationTargetException e) {
            // $NON-NLS-1$
            LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, "InvocationTargetException while initializing a block cipher", e, true);
        }
    }
    super.nextPressed();
}
Also used : InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException) BlockCipher(de.flexiprovider.api.BlockCipher) NoSuchPaddingException(de.flexiprovider.api.exceptions.NoSuchPaddingException) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) InvalidKeyException(de.flexiprovider.api.exceptions.InvalidKeyException) InvocationTargetException(java.lang.reflect.InvocationTargetException) AlgorithmParameterSpec(de.flexiprovider.api.parameters.AlgorithmParameterSpec)

Example 8 with AlgorithmParameterSpec

use of de.flexiprovider.api.parameters.AlgorithmParameterSpec in project core by jcryptool.

the class AlgorithmsManager method performMessageDigestCalled.

private static void performMessageDigestCalled(IMetaAlgorithm algorithm) {
    // $NON-NLS-1$
    LogUtil.logInfo("has param generator: " + (algorithm.getParameterGeneratorClassName() != null));
    if (algorithm.getParameterGeneratorClassName() != null && !algorithm.isParameterSpecDisabled()) {
        AlgorithmParameterSpec generatedSpec = Reflector.getInstance().generateDefaultParameterSpec(algorithm);
        NewOperationManager.getInstance().fireNewOperation(new AlgorithmDescriptor(algorithm.getName(), RegistryType.MESSAGE_DIGEST, generatedSpec));
    } else {
        NewOperationManager.getInstance().fireNewOperation(new AlgorithmDescriptor(algorithm.getName(), RegistryType.MESSAGE_DIGEST, null));
    }
}
Also used : AlgorithmParameterSpec(de.flexiprovider.api.parameters.AlgorithmParameterSpec) AlgorithmDescriptor(org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor)

Example 9 with AlgorithmParameterSpec

use of de.flexiprovider.api.parameters.AlgorithmParameterSpec 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 10 with AlgorithmParameterSpec

use of de.flexiprovider.api.parameters.AlgorithmParameterSpec in project core by jcryptool.

the class Reflector method generateDefaultParameterSpec.

public AlgorithmParameterSpec generateDefaultParameterSpec(final IMetaAlgorithm algorithm) {
    final List<String> names = algorithm.getNames();
    // $NON-NLS-1$
    String useName = "-1";
    for (final String name : names) {
        try {
            Registry.getAlgParamGenerator(name);
            useName = name;
            break;
        } catch (final NoSuchAlgorithmException e) {
        }
    }
    try {
        final AlgorithmParameterGenerator generator = Registry.getAlgParamGenerator(useName);
        // $NON-NLS-1$
        final AlgorithmParameterSpec spec = Registry.getAlgParamSpec(useName + "ParamGen");
        generator.init(spec, FlexiProviderPlugin.getSecureRandom());
        return generator.generateParameters();
    } catch (final NoSuchAlgorithmException e) {
        LogUtil.logError(FlexiProviderPlugin.PLUGIN_ID, "NoSuchAlgorithmException while generating default parameters for " + algorithm.getName(), e, // $NON-NLS-1$
        true);
    } catch (final InvalidAlgorithmParameterException e) {
        LogUtil.logError(FlexiProviderPlugin.PLUGIN_ID, // $NON-NLS-1$
        "InvalidAlgorithmParameterException while generating default parameters for " + algorithm.getName(), e, true);
    }
    return null;
}
Also used : InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException) AlgorithmParameterGenerator(de.flexiprovider.api.parameters.AlgorithmParameterGenerator) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) AlgorithmParameterSpec(de.flexiprovider.api.parameters.AlgorithmParameterSpec)

Aggregations

AlgorithmParameterSpec (de.flexiprovider.api.parameters.AlgorithmParameterSpec)10 InvalidAlgorithmParameterException (de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException)8 NoSuchAlgorithmException (de.flexiprovider.api.exceptions.NoSuchAlgorithmException)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 WizardDialog (org.eclipse.jface.wizard.WizardDialog)5 Wizard (org.eclipse.jface.wizard.Wizard)4 IMetaKeyGenerator (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaKeyGenerator)4 IMetaLength (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaLength)4 INewEntryDescriptor (org.jcryptool.crypto.keystore.descriptors.interfaces.INewEntryDescriptor)4 INewKeyWizard (org.jcryptool.crypto.keystore.descriptors.interfaces.INewKeyWizard)4 InvalidKeyException (de.flexiprovider.api.exceptions.InvalidKeyException)3 PrivateKey (de.flexiprovider.api.keys.PrivateKey)3 PublicKey (de.flexiprovider.api.keys.PublicKey)3 SecretKey (de.flexiprovider.api.keys.SecretKey)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 Job (org.eclipse.core.runtime.jobs.Job)3 NewKeyPairWizard (org.jcryptool.crypto.flexiprovider.keystore.wizards.NewKeyPairWizard)3 NewSymmetricKeyWizard (org.jcryptool.crypto.flexiprovider.keystore.wizards.NewSymmetricKeyWizard)3 Key (de.flexiprovider.api.keys.Key)2 KeyPair (de.flexiprovider.api.keys.KeyPair)2