Search in sources :

Example 91 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class TableUserFilterManager method setSerializedData.

/**
 * Import the serialized data, e.g. after restoring from a bookmark
 */
public void setSerializedData(byte[] data) {
    try {
        reset();
        Collection<IUserFilterState> filterStates = SerializationUtility.createObjectSerializer().deserialize(data, null);
        for (IUserFilterState filterState : filterStates) {
            boolean success = filterState.notifyDeserialized(m_table);
            if (success) {
                addFilter(filterState);
            } else {
                LOG.info("User filter state of table '{}' cannot be deserialized because the column could not be found. Ignoring element.", m_table.getClass().getName());
            }
        }
    } catch (IOException | ClassNotFoundException e) {
        throw new ProcessingException("Failed reading user filter data.", e);
    }
}
Also used : IUserFilterState(org.eclipse.scout.rt.client.ui.basic.userfilter.IUserFilterState) IOException(java.io.IOException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 92 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class SunSecurityProvider method verifySignature.

@Override
public boolean verifySignature(byte[] publicKey, InputStream data, byte[] signatureToVerify) {
    Assertions.assertGreater(Assertions.assertNotNull(publicKey, "no public key provided").length, 0, "empty public key not allowed");
    Assertions.assertGreater(Assertions.assertNotNull(signatureToVerify, "no signature provided").length, 0, "empty signature not allowed");
    if (data == null) {
        throw new AssertionException("no data provided");
    }
    try {
        // create public key from bytes
        KeyFactory keyFactory = KeyFactory.getInstance(getKeyPairGenerationAlgorithm(), getSignatureProvider());
        X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(publicKey);
        PublicKey pubKey = keyFactory.generatePublic(pubKeySpec);
        // verify signature
        Signature sig = Signature.getInstance(getSignatureAlgorithm(), getSignatureProvider());
        sig.initVerify(pubKey);
        int n;
        byte[] buf = new byte[BUF_SIZE];
        while ((n = data.read(buf)) >= 0) {
            sig.update(buf, 0, n);
        }
        return sig.verify(signatureToVerify);
    } catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidKeySpecException | InvalidKeyException | SignatureException | IOException t) {
        throw new ProcessingException("unable to verify signature", t);
    }
}
Also used : PublicKey(java.security.PublicKey) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) Signature(java.security.Signature) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) NoSuchProviderException(java.security.NoSuchProviderException) SecretKeyFactory(javax.crypto.SecretKeyFactory) KeyFactory(java.security.KeyFactory) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 93 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class SunSecurityProvider method createKeyPair.

@Override
public KeyPairBytes createKeyPair() {
    try {
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance(getKeyPairGenerationAlgorithm(), getSignatureProvider());
        ECGenParameterSpec spec = new ECGenParameterSpec(getEllipticCurveName());
        keyGen.initialize(spec, createSecureRandom());
        KeyPair keyPair = keyGen.generateKeyPair();
        X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(keyPair.getPublic().getEncoded());
        PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(keyPair.getPrivate().getEncoded());
        return new KeyPairBytes(pkcs8EncodedKeySpec.getEncoded(), x509EncodedKeySpec.getEncoded());
    } catch (NoSuchProviderException | InvalidAlgorithmParameterException | NoSuchAlgorithmException e) {
        throw new ProcessingException("unable to create a new key-pair", e);
    }
}
Also used : KeyPair(java.security.KeyPair) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) ECGenParameterSpec(java.security.spec.ECGenParameterSpec) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) KeyPairGenerator(java.security.KeyPairGenerator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 94 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class SunSecurityProvider method doCrypt.

protected void doCrypt(InputStream input, OutputStream output, EncryptionKey key, int mode) {
    Assertions.assertNotNull(key, "key must not be null.");
    if (input == null) {
        throw new AssertionException("input must not be null.");
    }
    if (output == null) {
        throw new AssertionException("output must not be null.");
    }
    try {
        Cipher cipher = Cipher.getInstance(getCipherAlgorithm() + "/" + getCipherAlgorithmMode() + "/" + getCipherAlgorithmPadding(), getCipherAlgorithmProvider());
        cipher.init(mode, key.get(), key.params());
        try (OutputStream out = new CipherOutputStream(output, cipher)) {
            int n;
            byte[] buf = new byte[BUF_SIZE];
            while ((n = input.read(buf)) >= 0) {
                out.write(buf, 0, n);
            }
        }
    } catch (NoSuchAlgorithmException e) {
        throw new ProcessingException("Unable to crypt data. Algorithm could not be found. Make sure to use JRE 1.8 or newer.", e);
    } catch (NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | NoSuchProviderException | IOException e) {
        throw new ProcessingException("Unable to crypt data.", e);
    }
}
Also used : CipherOutputStream(javax.crypto.CipherOutputStream) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) CipherOutputStream(javax.crypto.CipherOutputStream) OutputStream(java.io.OutputStream) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) Cipher(javax.crypto.Cipher) NoSuchProviderException(java.security.NoSuchProviderException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 95 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class SunSecurityProvider method createEncryptionKey.

@Override
public EncryptionKey createEncryptionKey(char[] password, byte[] salt, int keyLen) {
    Assertions.assertGreater(Assertions.assertNotNull(password, "password must not be null.").length, 0, "empty password is not allowed.");
    Assertions.assertGreater(Assertions.assertNotNull(salt, "salt must be provided.").length, 0, "empty salt is not allowed.");
    Assertions.assertTrue(keyLen == 128 || keyLen == 192 || keyLen == 256, "key length must be 128, 192 or 256.");
    try {
        SecretKeyFactory factory = SecretKeyFactory.getInstance(getSecretKeyAlgorithm(), getCipherAlgorithmProvider());
        KeySpec spec = new PBEKeySpec(password, salt, getKeyDerivationIterationCount(), keyLen + (GCM_INITIALIZATION_VECTOR_LEN * 8));
        SecretKey tmpSecret = factory.generateSecret(spec);
        // derive Key and Initialization Vector
        byte[] encoded = tmpSecret.getEncoded();
        byte[] iv = new byte[GCM_INITIALIZATION_VECTOR_LEN];
        byte[] key = new byte[keyLen / 8];
        System.arraycopy(encoded, 0, key, 0, key.length);
        System.arraycopy(encoded, key.length, iv, 0, GCM_INITIALIZATION_VECTOR_LEN);
        SecretKey secretKey = new SecretKeySpec(key, getCipherAlgorithm());
        GCMParameterSpec parameters = new GCMParameterSpec(GCM_AUTH_TAG_BIT_LEN, iv);
        return new EncryptionKey(secretKey, parameters);
    } catch (NoSuchAlgorithmException e) {
        throw new ProcessingException("Unable to create secret. Algorithm could not be found. Make sure to use JRE 1.8 or newer.", e);
    } catch (InvalidKeySpecException | NoSuchProviderException e) {
        throw new ProcessingException("Unable to create secret.", e);
    }
}
Also used : PBEKeySpec(javax.crypto.spec.PBEKeySpec) SecretKeySpec(javax.crypto.spec.SecretKeySpec) KeySpec(java.security.spec.KeySpec) PBEKeySpec(javax.crypto.spec.PBEKeySpec) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) GCMParameterSpec(javax.crypto.spec.GCMParameterSpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SecretKey(javax.crypto.SecretKey) SecretKeySpec(javax.crypto.spec.SecretKeySpec) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) NoSuchProviderException(java.security.NoSuchProviderException) SecretKeyFactory(javax.crypto.SecretKeyFactory) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Aggregations

ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)142 IOException (java.io.IOException)48 MessagingException (javax.mail.MessagingException)21 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)17 File (java.io.File)14 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)12 Folder (javax.mail.Folder)10 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)9 RemoteFile (org.eclipse.scout.rt.shared.services.common.file.RemoteFile)9 NoSuchProviderException (java.security.NoSuchProviderException)8 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)8 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 FileOutputStream (java.io.FileOutputStream)6 Message (javax.mail.Message)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStream (java.io.OutputStream)5 HashMap (java.util.HashMap)5