Search in sources :

Example 6 with PasswordKeyProxyFactoryTestImpl

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

the class LunaKeyProxyTest method isMatchingCanary_usingOldCanaryValue_returnsTrue.

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

Example 7 with PasswordKeyProxyFactoryTestImpl

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

the class LunaKeyProxyTest method isMatchingCanary_whenDecryptThrowsAEADBadTagException_returnsFalse.

@Test
public void isMatchingCanary_whenDecryptThrowsAEADBadTagException_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 AEADBadTagException();
        }
    });
    assertThat(subject.matchesCanary(mock(EncryptionKeyCanary.class)), equalTo(false));
}
Also used : AEADBadTagException(javax.crypto.AEADBadTagException) Key(java.security.Key) PasswordKeyProxyFactoryTestImpl(org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl) Test(org.junit.Test)

Example 8 with PasswordKeyProxyFactoryTestImpl

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

the class LunaKeyProxyTest method isMatchingCanary_whenDecryptThrowsBadPaddingException_throwsIncorrectKeyException.

@Test(expected = IncorrectKeyException.class)
public void isMatchingCanary_whenDecryptThrowsBadPaddingException_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 BadPaddingException("");
        }
    });
    subject.matchesCanary(mock(EncryptionKeyCanary.class));
}
Also used : EncryptionKeyCanary(org.cloudfoundry.credhub.entity.EncryptionKeyCanary) BadPaddingException(javax.crypto.BadPaddingException) Key(java.security.Key) PasswordKeyProxyFactoryTestImpl(org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl) Test(org.junit.Test)

Example 9 with PasswordKeyProxyFactoryTestImpl

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

the class InternalEncryptionServiceTest method createsPasswordBasedKeyProxy.

@Test
public void createsPasswordBasedKeyProxy() throws Exception {
    InternalEncryptionService subject = new InternalEncryptionService(new PasswordKeyProxyFactoryTestImpl());
    EncryptionKeyMetadata keyMetadata = new EncryptionKeyMetadata();
    keyMetadata.setEncryptionPassword("foobar");
    final KeyProxy keyProxy = subject.createKeyProxy(keyMetadata);
    assertThat(keyProxy, instanceOf(PasswordBasedKeyProxy.class));
}
Also used : EncryptionKeyMetadata(org.cloudfoundry.credhub.config.EncryptionKeyMetadata) PasswordKeyProxyFactoryTestImpl(org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl) Test(org.junit.Test)

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