Search in sources :

Example 6 with InvalidKeyException

use of de.flexiprovider.api.exceptions.InvalidKeyException in project core by jcryptool.

the class MacEngine method init.

@Override
public KeyObject init(IFlexiProviderOperation operation) {
    // $NON-NLS-1$
    LogUtil.logInfo("initializing mac engine");
    this.operation = operation;
    char[] password = null;
    Key key = null;
    // password may be contained in the ActionItem, otherwise prompt
    if (operation.getPassword() != null) {
        password = operation.getPassword();
    } else if (!operation.useCustomKey()) {
        // farndt - prompt only if custom key is not to be used
        password = promptPassword();
    }
    if (password != null && !operation.useCustomKey()) {
        try {
            key = (Key) KeyStoreManager.getInstance().getSecretKey(operation.getKeyStoreAlias(), password);
            // save in the operation if no exception occurred
            operation.setPassword(password);
        } catch (UnrecoverableEntryException e) {
            JCTMessageDialog.showInfoDialog(new Status(IStatus.INFO, FlexiProviderEnginesPlugin.PLUGIN_ID, Messages.ExAccessKeystorePassword, e));
            return null;
        } catch (Exception e) {
            LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "Exception while accessing a secret key", e, // $NON-NLS-1$
            true);
            return null;
        }
    } else {
        // farndt - use custom key
        key = new CustomKey(operation.getKeyBytes());
    }
    if (key != null) {
        try {
            mac = Registry.getMAC(operation.getAlgorithmDescriptor().getAlgorithmName());
            AlgorithmParameterSpec spec = operation.getAlgorithmDescriptor().getAlgorithmParameterSpec();
            if (spec != null) {
                mac.init((SecretKey) key, spec);
            } else {
                mac.init((SecretKey) key);
            }
            initialized = true;
        } catch (NoSuchAlgorithmException e) {
            LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "NoSuchAlgorithmException while initializing a mac", e, // $NON-NLS-1$
            true);
            return null;
        } catch (InvalidKeyException e) {
            LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, Messages.MacEngine_2, e, true);
            return null;
        } catch (InvalidAlgorithmParameterException e) {
            LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "InvalidAlgorithmParameterException while initializing a mac", e, // $NON-NLS-1$
            true);
            return null;
        }
    }
    return new KeyObject(key, password);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException) UnrecoverableEntryException(java.security.UnrecoverableEntryException) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) InvalidKeyException(de.flexiprovider.api.exceptions.InvalidKeyException) AlgorithmParameterSpec(de.flexiprovider.api.parameters.AlgorithmParameterSpec) SecretKey(de.flexiprovider.api.keys.SecretKey) Key(de.flexiprovider.api.keys.Key) HMacKey(de.flexiprovider.core.mac.HMacKey) PartInitException(org.eclipse.ui.PartInitException) UnrecoverableEntryException(java.security.UnrecoverableEntryException) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) IOException(java.io.IOException) InvalidKeyException(de.flexiprovider.api.exceptions.InvalidKeyException) InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException)

Example 7 with InvalidKeyException

use of de.flexiprovider.api.exceptions.InvalidKeyException in project core by jcryptool.

the class SignatureEngine method init.

@Override
public KeyObject init(IFlexiProviderOperation operation) {
    // $NON-NLS-1$
    LogUtil.logInfo("initializing signature engine");
    this.operation = operation;
    char[] password = null;
    KeyObject usedKey = null;
    try {
        signature = Registry.getSignature(operation.getAlgorithmDescriptor().getAlgorithmName());
        AlgorithmParameterSpec spec = operation.getAlgorithmDescriptor().getAlgorithmParameterSpec();
        if (spec != null) {
            signature.setParameters(spec);
        }
        if (operation.getOperation().equals(OperationType.SIGN)) {
            if (operation.getPassword() != null) {
                password = operation.getPassword();
            } else {
                password = promptPassword();
            }
            if (password == null) {
                return null;
            }
            Key privateKey = (Key) KeyStoreManager.getInstance().getPrivateKey(operation.getKeyStoreAlias(), password);
            signature.initSign((PrivateKey) privateKey, FlexiProviderEnginesPlugin.getSecureRandom());
            usedKey = new KeyObject(privateKey, password);
            // save in the operation if no exception occurred
            operation.setPassword(password);
        } else {
            Certificate certificate = KeyStoreManager.getInstance().getCertificate(operation.getKeyStoreAlias());
            Key publicKey = (Key) certificate.getPublicKey();
            signature.initVerify((PublicKey) publicKey);
            usedKey = new KeyObject(publicKey, password);
        }
        initialized = true;
    } catch (NoSuchAlgorithmException e) {
        LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "NoSuchAlgorithmException while initializing a signature", e, // $NON-NLS-1$
        true);
        return null;
    } catch (InvalidAlgorithmParameterException e) {
        LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "InvalidAlgorithmParameterException while initializing a signature", e, // $NON-NLS-1$
        true);
        return null;
    } catch (InvalidKeyException e) {
        LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, Messages.SignatureEngine_5, e, true);
        return null;
    } catch (UnrecoverableEntryException e) {
        JCTMessageDialog.showInfoDialog(new Status(IStatus.INFO, FlexiProviderEnginesPlugin.PLUGIN_ID, Messages.ExAccessKeystorePassword, e));
        return null;
    } catch (Exception e) {
        // $NON-NLS-1$
        LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "Exception while initializing a signature", e, true);
        return null;
    }
    return usedKey;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException) UnrecoverableEntryException(java.security.UnrecoverableEntryException) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) InvalidKeyException(de.flexiprovider.api.exceptions.InvalidKeyException) AlgorithmParameterSpec(de.flexiprovider.api.parameters.AlgorithmParameterSpec) PublicKey(de.flexiprovider.api.keys.PublicKey) Key(de.flexiprovider.api.keys.Key) PrivateKey(de.flexiprovider.api.keys.PrivateKey) SignatureException(de.flexiprovider.api.exceptions.SignatureException) UnrecoverableEntryException(java.security.UnrecoverableEntryException) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) IOException(java.io.IOException) InvalidKeyException(de.flexiprovider.api.exceptions.InvalidKeyException) InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException) Certificate(java.security.cert.Certificate)

Example 8 with InvalidKeyException

use of de.flexiprovider.api.exceptions.InvalidKeyException 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 9 with InvalidKeyException

use of de.flexiprovider.api.exceptions.InvalidKeyException in project core by jcryptool.

the class CipherEngine method init.

@Override
public KeyObject init(IFlexiProviderOperation operation) {
    // $NON-NLS-1$
    LogUtil.logInfo("initializing cipher engine");
    this.operation = operation;
    char[] password = null;
    Key key = null;
    // password may be contained in the ActionItem, otherwise prompt
    if (operation.getPassword() != null) {
        password = operation.getPassword();
    } else {
        password = promptPassword();
    }
    if (password != null) {
        try {
            key = (Key) KeyStoreManager.getInstance().getSecretKey(operation.getKeyStoreAlias(), password);
            // save in the operation if no exception occurred
            operation.setPassword(password);
        } catch (UnrecoverableEntryException e) {
            JCTMessageDialog.showInfoDialog(new Status(IStatus.INFO, FlexiProviderEnginesPlugin.PLUGIN_ID, Messages.ExAccessKeystorePassword, e));
            return null;
        } catch (Exception e) {
            LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "Exception while accessing a secret key", e, // $NON-NLS-1$
            true);
            return null;
        }
    }
    if (key != null) {
        try {
            cipher = Registry.getCipher(operation.getAlgorithmDescriptor().getAlgorithmName());
            if (operation.getOperation().equals(OperationType.ENCRYPT)) {
                cipher.initEncrypt(key, operation.getAlgorithmDescriptor().getAlgorithmParameterSpec(), FlexiProviderEnginesPlugin.getSecureRandom());
            } else {
                cipher.initDecrypt(key, operation.getAlgorithmDescriptor().getAlgorithmParameterSpec());
            }
            initialized = true;
        } catch (NoSuchAlgorithmException e) {
            LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "NoSuchAlgorithmException while initializing a cipher engine", e, // $NON-NLS-1$
            true);
            return null;
        } catch (InvalidKeyException e) {
            LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, Messages.CipherEngine_2, e, true);
            return null;
        } catch (InvalidAlgorithmParameterException e) {
            LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "InvalidAlgorithmParameterException while initializing a cipher engine", e, // $NON-NLS-1$
            true);
            return null;
        }
    }
    return new KeyObject(key, password);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException) UnrecoverableEntryException(java.security.UnrecoverableEntryException) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) InvalidKeyException(de.flexiprovider.api.exceptions.InvalidKeyException) Key(de.flexiprovider.api.keys.Key) BadPaddingException(de.flexiprovider.api.exceptions.BadPaddingException) IllegalBlockSizeException(de.flexiprovider.api.exceptions.IllegalBlockSizeException) PartInitException(org.eclipse.ui.PartInitException) UnrecoverableEntryException(java.security.UnrecoverableEntryException) NoSuchAlgorithmException(de.flexiprovider.api.exceptions.NoSuchAlgorithmException) IOException(java.io.IOException) InvalidKeyException(de.flexiprovider.api.exceptions.InvalidKeyException) InvalidAlgorithmParameterException(de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException)

Aggregations

InvalidKeyException (de.flexiprovider.api.exceptions.InvalidKeyException)9 NoSuchAlgorithmException (de.flexiprovider.api.exceptions.NoSuchAlgorithmException)8 InvalidAlgorithmParameterException (de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException)7 Key (de.flexiprovider.api.keys.Key)7 UnrecoverableEntryException (java.security.UnrecoverableEntryException)6 IStatus (org.eclipse.core.runtime.IStatus)6 Status (org.eclipse.core.runtime.Status)6 IOException (java.io.IOException)4 AlgorithmParameterSpec (de.flexiprovider.api.parameters.AlgorithmParameterSpec)3 Certificate (java.security.cert.Certificate)3 BlockCipher (de.flexiprovider.api.BlockCipher)2 BadPaddingException (de.flexiprovider.api.exceptions.BadPaddingException)2 IllegalBlockSizeException (de.flexiprovider.api.exceptions.IllegalBlockSizeException)2 NoSuchPaddingException (de.flexiprovider.api.exceptions.NoSuchPaddingException)2 ArrayList (java.util.ArrayList)2 PartInitException (org.eclipse.ui.PartInitException)2 TableEntry (org.jcryptool.crypto.keystore.ui.dialogs.TableEntry)2 Cipher (de.flexiprovider.api.Cipher)1 SignatureException (de.flexiprovider.api.exceptions.SignatureException)1 PrivateKey (de.flexiprovider.api.keys.PrivateKey)1