use of keywhiz.api.model.SecretSeriesAndContent in project keywhiz by square.
the class SecretResource method backfillHmac.
/**
* Backfill content hmac for this secret.
*/
@Timed
@ExceptionMetered
@Path("{name}/backfill-hmac")
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public boolean backfillHmac(@Auth AutomationClient automationClient, @PathParam("name") String name) {
Optional<SecretSeriesAndContent> secret = secretDAO.getSecretByName(name);
if (!secret.isPresent()) {
return false;
}
logger.info("backfill-hmac {}: processing secret", name);
SecretContent secretContent = secret.get().content();
if (!secretContent.hmac().isEmpty()) {
// No need to backfill
return true;
}
String hmac = cryptographer.computeHmac(cryptographer.decrypt(secretContent.encryptedContent()).getBytes(UTF_8), "hmackey");
// We expect only one row to be changed
return secretSeriesDAO.setHmac(secretContent.id(), hmac) == 1;
}
use of keywhiz.api.model.SecretSeriesAndContent in project keywhiz by square.
the class SecretTransformerTest method transformsOwner.
@Test
public void transformsOwner() {
String ownerName = "foo";
SecretSeries series = validSeries().toBuilder().owner(ownerName).build();
SecretContent content = validContent();
SecretSeriesAndContent seriesAndContent = SecretSeriesAndContent.of(series, content);
Secret secret = transformer.transform(seriesAndContent);
assertEquals(ownerName, secret.getOwner());
}
use of keywhiz.api.model.SecretSeriesAndContent in project keywhiz by square.
the class GroupDAOTest method deleteSetsSecretOwnerToNull.
@Test
public void deleteSetsSecretOwnerToNull() {
String groupName = randomName();
long groupId = groupDAO.createGroup(groupName, "creator", "description", ImmutableMap.of());
long secretId = secretDAO.createSecret(randomName(), groupName, "encryptedSecret", "hmac", "creator", Collections.emptyMap(), 0, "description", null, null);
SecretSeriesAndContent original = secretDAO.getSecretById(secretId).get();
assertEquals(groupName, original.series().owner());
groupDAO.deleteGroup(groupDAO.getGroupById(groupId).get());
SecretSeriesAndContent updated = secretDAO.getSecretById(secretId).get();
assertNull(updated.series().owner());
}
use of keywhiz.api.model.SecretSeriesAndContent in project keywhiz by square.
the class SecretDAOTest method createSecret.
@Test
public void createSecret() {
int secretsBefore = tableSize(SECRETS);
int secretContentsBefore = tableSize(SECRETS_CONTENT);
String name = "newSecret";
String content = "c2VjcmV0MQ==";
String hmac = cryptographer.computeHmac(content.getBytes(UTF_8), "hmackey");
String encryptedContent = cryptographer.encryptionKeyDerivedFrom(name).encrypt(content);
long newId = secretDAO.createSecret(name, null, encryptedContent, hmac, "creator", ImmutableMap.of(), 0, "", null, ImmutableMap.of());
SecretSeriesAndContent newSecret = secretDAO.getSecretById(newId).get();
assertThat(tableSize(SECRETS)).isEqualTo(secretsBefore + 1);
assertThat(tableSize(SECRETS_CONTENT)).isEqualTo(secretContentsBefore + 1);
newSecret = secretDAO.getSecretByName(newSecret.series().name()).get();
assertThat(secretDAO.getSecrets(null, null, null, null, null)).containsOnly(secret1, secret2b, newSecret);
}
use of keywhiz.api.model.SecretSeriesAndContent in project keywhiz by square.
the class SecretDAOTest method createOrUpdateExistingSecretUpdatesOwner.
@Test
public void createOrUpdateExistingSecretUpdatesOwner() {
String ownerName1 = createGroup();
String ownerName2 = createGroup();
String secretName = randomName();
long secretId1 = createOrUpdateSecretWithOwner(secretName, ownerName1);
long secretId2 = createOrUpdateSecretWithOwner(secretName, ownerName2);
assertEquals(secretId1, secretId2);
SecretSeriesAndContent secret = secretDAO.getSecretById(secretId1).get();
assertEquals(ownerName2, secret.series().owner());
}
Aggregations