Search in sources :

Example 1 with EncryptionKey

use of org.cloudfoundry.credhub.service.EncryptionKey in project credhub by cloudfoundry-incubator.

the class EncryptionKeyRotatorTest method createOldKey.

private Key createOldKey() throws Exception {
    final PasswordBasedKeyProxy keyProxy = new PasswordBasedKeyProxy("old-password", 1, encryptionService);
    Key oldKey = keyProxy.deriveKey();
    oldCanary = new EncryptionKeyCanary();
    final EncryptedValue canaryEncryption = encryptionService.encrypt(null, oldKey, CANARY_VALUE);
    oldCanary.setEncryptedCanaryValue(canaryEncryption.getEncryptedValue());
    oldCanary.setNonce(canaryEncryption.getNonce());
    oldCanary = encryptionKeyCanaryDataService.save(oldCanary);
    keySet.add(new EncryptionKey(encryptionService, oldCanary.getUuid(), oldKey));
    return oldKey;
}
Also used : EncryptionKeyCanary(org.cloudfoundry.credhub.entity.EncryptionKeyCanary) EncryptionKey(org.cloudfoundry.credhub.service.EncryptionKey) PasswordBasedKeyProxy(org.cloudfoundry.credhub.service.PasswordBasedKeyProxy) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) EncryptionKey(org.cloudfoundry.credhub.service.EncryptionKey) Key(java.security.Key)

Example 2 with EncryptionKey

use of org.cloudfoundry.credhub.service.EncryptionKey in project credhub by cloudfoundry-incubator.

the class KeyUsageControllerTest method getKeyUsages_getsKeyDistributionAcrossActiveInactiveAndUnknownEncryptionKeys.

@Test
public void getKeyUsages_getsKeyDistributionAcrossActiveInactiveAndUnknownEncryptionKeys() throws Exception {
    final UUID activeKey = UUID.randomUUID();
    final UUID knownKey = UUID.randomUUID();
    final UUID unknownKey = UUID.randomUUID();
    HashMap<UUID, Long> countByEncryptionKey = new HashMap<>();
    countByEncryptionKey.put(activeKey, 200L);
    countByEncryptionKey.put(knownKey, 10L);
    countByEncryptionKey.put(unknownKey, 5L);
    keySet.add(new EncryptionKey(mock(EncryptionService.class), activeKey, mock(Key.class)));
    keySet.add(new EncryptionKey(mock(EncryptionService.class), knownKey, mock(Key.class)));
    keySet.setActive(activeKey);
    when(credentialVersionDataService.countByEncryptionKey()).thenReturn(countByEncryptionKey);
    mockMvc.perform(get("/api/v1/key-usage")).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.active_key").value(200)).andExpect(jsonPath("$.inactive_keys").value(10)).andExpect(jsonPath("$.unknown_keys").value(5));
}
Also used : HashMap(java.util.HashMap) EncryptionKey(org.cloudfoundry.credhub.service.EncryptionKey) UUID(java.util.UUID) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

EncryptionKey (org.cloudfoundry.credhub.service.EncryptionKey)2 Key (java.security.Key)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)1 EncryptionKeyCanary (org.cloudfoundry.credhub.entity.EncryptionKeyCanary)1 PasswordBasedKeyProxy (org.cloudfoundry.credhub.service.PasswordBasedKeyProxy)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1