Search in sources :

Example 6 with PasswordException

use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.

the class CoreSecurityService method initService.

@Override
protected final void initService() throws CoreException {
    try {
        pkPassword = getPrivateKeyPasswordProvider().retrievePrivateKeyPassword();
    } catch (PasswordException e) {
        throw new CoreException("Could not get password using " + getPrivateKeyPasswordProvider().getClass().getCanonicalName(), e);
    }
    try {
        if (isEmpty(localPartner)) {
            throw new CoreException("No Local Partner configured");
        }
        localPartnerAlias = new Alias(localPartner, pkPassword);
        if (isEmpty(remotePartner)) {
            log.warn("Remote partner not configured,  " + "must be set individually as message metadata");
        } else {
            remotePartnerAlias = new Alias(remotePartner);
        }
        SecurityServiceFactory factory = securityFactory;
        if (factory == null) {
            factory = SecurityServiceFactory.defaultInstance();
        }
        service = factory.createService();
        for (Iterator i = keystoreUrls.iterator(); i.hasNext(); ) {
            ConfiguredKeystore url = (ConfiguredKeystore) i.next();
            service.registerKeystore(url);
        }
        service.setEncryptionAlgorithm(encryptionAlgorithm);
        if (successId != null && failId != null) {
            branchingEnabled = true;
        } else {
            log.debug("No Success Id or Fail Id, branching disabled");
        }
    } catch (AdaptrisSecurityException e) {
        throw new CoreException(e);
    }
}
Also used : PasswordException(com.adaptris.security.exc.PasswordException) CoreException(com.adaptris.core.CoreException) Alias(com.adaptris.security.keystore.Alias) Iterator(java.util.Iterator) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException) ConfiguredKeystore(com.adaptris.security.keystore.ConfiguredKeystore) SecurityServiceFactory(com.adaptris.security.SecurityServiceFactory)

Example 7 with PasswordException

use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.

the class FtpPasswordConnectionCase method testConnect_BadEncodedPassword.

@Test
public void testConnect_BadEncodedPassword() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    FileTransferConnectionUsingPassword connection = (FileTransferConnectionUsingPassword) createConnection();
    connection.setDefaultPassword("PW:BHFYENGMWEYQ");
    try {
        start(connection);
        FileTransferClient client = connection.connect(getDestinationString());
        fail();
    } catch (IOException | PasswordException expected) {
    } finally {
        stop(connection);
    }
}
Also used : PasswordException(com.adaptris.security.exc.PasswordException) FileTransferClient(com.adaptris.filetransfer.FileTransferClient) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with PasswordException

use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.

the class AesCrypto method encode.

@Override
@SuppressWarnings({ "lgtm [java/weak-cryptographic-algorithm]" })
public String encode(String plainText, String charset) throws PasswordException {
    String result = null;
    try {
        KeyGenerator kg = KeyGenerator.getInstance(ALG);
        kg.init(KEY_LEN, SecurityUtil.getSecureRandom());
        SecretKey sessionKey = kg.generateKey();
        Cipher dataCipher = Cipher.getInstance(CIPHER);
        dataCipher.init(Cipher.ENCRYPT_MODE, sessionKey);
        byte[] encryptedBody = dataCipher.doFinal(seed(plainText, charset));
        Output output = new Output();
        output.setSessionKey(sessionKey.getEncoded());
        output.setSessionVector(dataCipher.getIV());
        output.setEncryptedData(encryptedBody);
        result = PORTABLE_PASSWORD + output.write();
    } catch (Exception e) {
        throw new PasswordException(e);
    }
    return result;
}
Also used : PasswordException(com.adaptris.security.exc.PasswordException) SecretKey(javax.crypto.SecretKey) Cipher(javax.crypto.Cipher) KeyGenerator(javax.crypto.KeyGenerator) IOException(java.io.IOException) PasswordException(com.adaptris.security.exc.PasswordException)

Example 9 with PasswordException

use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.

the class MicrosoftCrypto method decode.

public String decode(String encrypted, String charset) throws PasswordException {
    String encryptedString = encrypted;
    String result;
    if (encrypted.startsWith(MSCAPI_STYLE)) {
        encryptedString = encrypted.substring(MSCAPI_STYLE.length());
    }
    try {
        Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.DECRYPT_MODE, getPrivateKey());
        byte[] encryptedBytes = base64.translate(encryptedString);
        byte[] decrypted = cipher.doFinal(encryptedBytes);
        result = new String(decrypted, getEncodingToUse(charset));
    } catch (Exception e) {
        throw new PasswordException(e);
    }
    return result;
}
Also used : PasswordException(com.adaptris.security.exc.PasswordException) Cipher(javax.crypto.Cipher) PasswordException(com.adaptris.security.exc.PasswordException)

Example 10 with PasswordException

use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.

the class PbeCrypto method encode.

@Override
@SuppressWarnings({ "lgtm [java/weak-cryptographic-algorithm]" })
public String encode(String plainText, String charset) throws PasswordException {
    byte[] encrypted = new byte[0];
    try {
        PBEParameterSpec pbeParamSpec = new PBEParameterSpec(SALT, ITERATIONS);
        PBEKeySpec pbeKeySpec = new PBEKeySpec(hostname.toCharArray());
        SecretKeyFactory keyFac = SecretKeyFactory.getInstance(ALGORITHM);
        SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
        Cipher pbeCipher = Cipher.getInstance(ALGORITHM);
        pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
        encrypted = pbeCipher.doFinal(seed(plainText, charset));
    } catch (Exception e) {
        throw new PasswordException(e);
    }
    return NON_PORTABLE_PASSWORD + base64.translate(encrypted);
}
Also used : PBEKeySpec(javax.crypto.spec.PBEKeySpec) PasswordException(com.adaptris.security.exc.PasswordException) SecretKey(javax.crypto.SecretKey) Cipher(javax.crypto.Cipher) SecretKeyFactory(javax.crypto.SecretKeyFactory) PBEParameterSpec(javax.crypto.spec.PBEParameterSpec) PasswordException(com.adaptris.security.exc.PasswordException)

Aggregations

PasswordException (com.adaptris.security.exc.PasswordException)15 Cipher (javax.crypto.Cipher)8 IOException (java.io.IOException)6 SecretKey (javax.crypto.SecretKey)6 Properties (java.util.Properties)3 FileTransferClient (com.adaptris.filetransfer.FileTransferClient)2 InputStream (java.io.InputStream)2 KeyGenerator (javax.crypto.KeyGenerator)2 SecretKeyFactory (javax.crypto.SecretKeyFactory)2 GCMParameterSpec (javax.crypto.spec.GCMParameterSpec)2 PBEKeySpec (javax.crypto.spec.PBEKeySpec)2 PBEParameterSpec (javax.crypto.spec.PBEParameterSpec)2 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 Test (org.junit.Test)2 CoreException (com.adaptris.core.CoreException)1 SecurityServiceFactory (com.adaptris.security.SecurityServiceFactory)1 AdaptrisSecurityException (com.adaptris.security.exc.AdaptrisSecurityException)1 Alias (com.adaptris.security.keystore.Alias)1 ConfiguredKeystore (com.adaptris.security.keystore.ConfiguredKeystore)1 Base64ByteTranslator (com.adaptris.util.text.Base64ByteTranslator)1