Search in sources :

Example 26 with InvalidCipherTextException

use of org.bouncycastle.crypto.InvalidCipherTextException in project gocd by gocd.

the class SvnMaterialTest method shouldErrorOutIfEncryptionFails.

@Test
public void shouldErrorOutIfEncryptionFails() throws Exception {
    GoCipher mockGoCipher = mock(GoCipher.class);
    when(mockGoCipher.encrypt("password")).thenThrow(new InvalidCipherTextException("exception"));
    try {
        new SvnMaterial("/foo", "username", "password", false, mockGoCipher);
        fail("Should have thrown up");
    } catch (Exception e) {
        assertThat(e.getMessage(), is("Password encryption failed. Please verify your cipher key."));
    }
}
Also used : InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) GoCipher(com.thoughtworks.go.security.GoCipher) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) Test(org.junit.Test)

Example 27 with InvalidCipherTextException

use of org.bouncycastle.crypto.InvalidCipherTextException in project gocd by gocd.

the class TfsMaterialConfigUpdateTest method shouldErrorOutIfEncryptionFails.

@Test
public void shouldErrorOutIfEncryptionFails() throws Exception {
    GoCipher mockGoCipher = mock(GoCipher.class);
    when(mockGoCipher.encrypt("password")).thenThrow(new InvalidCipherTextException("exception"));
    try {
        new TfsMaterialConfig(mockGoCipher, new UrlArgument("http://10.4.4.101:8080/tfs/Sample"), "loser", "CORPORATE", "password", "walk_this_path");
        fail("Should have thrown up");
    } catch (Exception e) {
        assertThat(e.getMessage(), is("Password encryption failed. Please verify your cipher key."));
    }
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) GoCipher(com.thoughtworks.go.security.GoCipher) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) Test(org.junit.Test)

Example 28 with InvalidCipherTextException

use of org.bouncycastle.crypto.InvalidCipherTextException in project gocd by gocd.

the class TfsMaterialTest method shouldErrorOutIfEncryptionFails.

@Test
public void shouldErrorOutIfEncryptionFails() throws Exception {
    GoCipher mockGoCipher = mock(GoCipher.class);
    when(mockGoCipher.encrypt("password")).thenThrow(new InvalidCipherTextException("exception"));
    try {
        new TfsMaterial(mockGoCipher, new UrlArgument("/foo"), "username", DOMAIN, "password", "");
        fail("Should have thrown up");
    } catch (Exception e) {
        assertThat(e.getMessage(), is("Password encryption failed. Please verify your cipher key."));
    }
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) GoCipher(com.thoughtworks.go.security.GoCipher) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) IOException(java.io.IOException) Test(org.junit.Test)

Example 29 with InvalidCipherTextException

use of org.bouncycastle.crypto.InvalidCipherTextException in project gocd by gocd.

the class TfsMaterialTest method shouldErrorOutIfDecryptionFails.

@Test
public void shouldErrorOutIfDecryptionFails() throws InvalidCipherTextException {
    GoCipher mockGoCipher = mock(GoCipher.class);
    String fakeCipherText = "fake cipher text";
    when(mockGoCipher.decrypt(fakeCipherText)).thenThrow(new InvalidCipherTextException("exception"));
    TfsMaterial material = new TfsMaterial(mockGoCipher, new UrlArgument("/foo"), "username", DOMAIN, "password", "");
    ReflectionUtil.setField(material, "encryptedPassword", fakeCipherText);
    try {
        material.getPassword();
        fail("Should have thrown up");
    } catch (Exception e) {
        assertThat(e.getMessage(), is("Could not decrypt the password to get the real password"));
    }
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) GoCipher(com.thoughtworks.go.security.GoCipher) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) IOException(java.io.IOException) Test(org.junit.Test)

Example 30 with InvalidCipherTextException

use of org.bouncycastle.crypto.InvalidCipherTextException in project gocd by gocd.

the class EnvrionmentVariableRepresenter method fromJSON.

public static EnvironmentVariableConfig fromJSON(JsonReader jsonReader) {
    String name = jsonReader.getString("name");
    Boolean secure = jsonReader.optBoolean("secure").orElse(false);
    String value = secure ? jsonReader.optString("value").orElse(null) : jsonReader.getString("value");
    String encryptedValue = jsonReader.optString("encrypted_value").orElse(null);
    try {
        EnvironmentVariableConfig environmentVariableConfig = new EnvironmentVariableConfig();
        environmentVariableConfig.deserialize(name, value, secure, encryptedValue);
        return environmentVariableConfig;
    } catch (InvalidCipherTextException e) {
        throw new InvalidGoCipherTextException(e.getMessage(), e);
    }
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) InvalidGoCipherTextException(com.thoughtworks.go.apiv1.pipelineoperations.exceptions.InvalidGoCipherTextException)

Aggregations

InvalidCipherTextException (org.bouncycastle.crypto.InvalidCipherTextException)46 KeyParameter (org.bouncycastle.crypto.params.KeyParameter)13 ParametersWithIV (org.bouncycastle.crypto.params.ParametersWithIV)13 AESEngine (org.bouncycastle.crypto.engines.AESEngine)12 CipherParameters (org.bouncycastle.crypto.CipherParameters)11 PaddedBufferedBlockCipher (org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher)9 IOException (java.io.IOException)7 DataLengthException (org.bouncycastle.crypto.DataLengthException)7 CBCBlockCipher (org.bouncycastle.crypto.modes.CBCBlockCipher)7 GCMBlockCipher (org.bouncycastle.crypto.modes.GCMBlockCipher)7 GoCipher (com.thoughtworks.go.security.GoCipher)6 Test (org.junit.Test)6 BadPaddingException (javax.crypto.BadPaddingException)5 BlockCipher (org.bouncycastle.crypto.BlockCipher)5 BufferedBlockCipher (org.bouncycastle.crypto.BufferedBlockCipher)5 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ExtendedInvalidCipherTextException (org.openremote.agent.protocol.bluetooth.mesh.utils.ExtendedInvalidCipherTextException)4 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)3 SecretKeySpec (javax.crypto.spec.SecretKeySpec)3