Search in sources :

Example 1 with PasswordKeyProxyFactoryTestImpl

use of org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl in project credhub by cloudfoundry-incubator.

the class LunaKeyProxyTest method isMatchingCanary_whenDecryptThrowsRelevantIllegalBlockSizeException_returnsFalse.

@Test
public void isMatchingCanary_whenDecryptThrowsRelevantIllegalBlockSizeException_returnsFalse() throws Exception {
    subject = new LunaKeyProxy(encryptionKey, new InternalEncryptionService(new PasswordKeyProxyFactoryTestImpl()) {

        @Override
        public String decrypt(Key key, byte[] encryptedValue, byte[] nonce) throws Exception {
            throw new IllegalBlockSizeException("returns 0x40");
        }
    });
    assertThat(subject.matchesCanary(mock(EncryptionKeyCanary.class)), equalTo(false));
}
Also used : IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) Key(java.security.Key) PasswordKeyProxyFactoryTestImpl(org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl) Test(org.junit.Test)

Example 2 with PasswordKeyProxyFactoryTestImpl

use of org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl in project credhub by cloudfoundry-incubator.

the class LunaKeyProxyTest method isMatchingCanary_whenDecryptThrowsOtherException_throwsIncorrectKeyException.

@Test(expected = IncorrectKeyException.class)
public void isMatchingCanary_whenDecryptThrowsOtherException_throwsIncorrectKeyException() throws Exception {
    subject = new LunaKeyProxy(encryptionKey, new InternalEncryptionService(new PasswordKeyProxyFactoryTestImpl()) {

        @Override
        public String decrypt(Key key, byte[] encryptedValue, byte[] nonce) throws Exception {
            throw new Exception("");
        }
    });
    subject.matchesCanary(mock(EncryptionKeyCanary.class));
}
Also used : EncryptionKeyCanary(org.cloudfoundry.credhub.entity.EncryptionKeyCanary) Key(java.security.Key) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) AEADBadTagException(javax.crypto.AEADBadTagException) BadPaddingException(javax.crypto.BadPaddingException) IncorrectKeyException(org.cloudfoundry.credhub.exceptions.IncorrectKeyException) PasswordKeyProxyFactoryTestImpl(org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl) Test(org.junit.Test)

Example 3 with PasswordKeyProxyFactoryTestImpl

use of org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl in project credhub by cloudfoundry-incubator.

the class LunaKeyProxyTest method isMatchingCanary_whenCanaryMatches_returnsTrue.

@Test
public void isMatchingCanary_whenCanaryMatches_returnsTrue() throws Exception {
    subject = new LunaKeyProxy(encryptionKey, new InternalEncryptionService(new PasswordKeyProxyFactoryTestImpl()));
    assertThat(subject.matchesCanary(canary), equalTo(true));
}
Also used : PasswordKeyProxyFactoryTestImpl(org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl) Test(org.junit.Test)

Example 4 with PasswordKeyProxyFactoryTestImpl

use of org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl in project credhub by cloudfoundry-incubator.

the class LunaKeyProxyTest method isMatchingCanary_whenDecryptThrowsIllegalBlockSizeException_throwsIncorrectKeyException.

@Test(expected = IncorrectKeyException.class)
public void isMatchingCanary_whenDecryptThrowsIllegalBlockSizeException_throwsIncorrectKeyException() throws Exception {
    subject = new LunaKeyProxy(encryptionKey, new InternalEncryptionService(new PasswordKeyProxyFactoryTestImpl()) {

        @Override
        public String decrypt(Key key, byte[] encryptedValue, byte[] nonce) throws Exception {
            throw new IllegalBlockSizeException("");
        }
    });
    subject.matchesCanary(mock(EncryptionKeyCanary.class));
}
Also used : EncryptionKeyCanary(org.cloudfoundry.credhub.entity.EncryptionKeyCanary) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) Key(java.security.Key) PasswordKeyProxyFactoryTestImpl(org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl) Test(org.junit.Test)

Example 5 with PasswordKeyProxyFactoryTestImpl

use of org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl in project credhub by cloudfoundry-incubator.

the class LunaKeyProxyTest method beforeEach.

@Before
public void beforeEach() throws Exception {
    final InternalEncryptionService encryptionService = new InternalEncryptionService(new PasswordKeyProxyFactoryTestImpl());
    EncryptionKeyMetadata keyMetadata = new EncryptionKeyMetadata();
    keyMetadata.setEncryptionPassword("p@ssword");
    encryptionKey = encryptionService.createKeyProxy(keyMetadata).getKey();
    canary = new EncryptionKeyCanary();
    EncryptedValue encryptionData = encryptionService.encrypt(null, encryptionKey, CANARY_VALUE);
    canary.setEncryptedCanaryValue(encryptionData.getEncryptedValue());
    canary.setNonce(encryptionData.getNonce());
    deprecatedCanary = new EncryptionKeyCanary();
    EncryptedValue deprecatedEncryptionData = encryptionService.encrypt(null, encryptionKey, DEPRECATED_CANARY_VALUE);
    deprecatedCanary.setEncryptedCanaryValue(deprecatedEncryptionData.getEncryptedValue());
    deprecatedCanary.setNonce(deprecatedEncryptionData.getNonce());
}
Also used : EncryptionKeyCanary(org.cloudfoundry.credhub.entity.EncryptionKeyCanary) EncryptionKeyMetadata(org.cloudfoundry.credhub.config.EncryptionKeyMetadata) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) PasswordKeyProxyFactoryTestImpl(org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl) Before(org.junit.Before)

Aggregations

PasswordKeyProxyFactoryTestImpl (org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl)9 Test (org.junit.Test)8 Key (java.security.Key)5 EncryptionKeyCanary (org.cloudfoundry.credhub.entity.EncryptionKeyCanary)4 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)3 AEADBadTagException (javax.crypto.AEADBadTagException)2 BadPaddingException (javax.crypto.BadPaddingException)2 EncryptionKeyMetadata (org.cloudfoundry.credhub.config.EncryptionKeyMetadata)2 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)1 IncorrectKeyException (org.cloudfoundry.credhub.exceptions.IncorrectKeyException)1 Before (org.junit.Before)1