Search in sources :

Example 1 with Decryptor

use of org.c02e.jpgpj.Decryptor in project keywhiz by square.

the class BackupResourceTest method backupSuccess.

@Test
public void backupSuccess() throws Exception {
    Response httpResponse = backup("test", "Blackops");
    assertThat(httpResponse.code()).isEqualTo(200);
    InputStream ciphertext = httpResponse.body().byteStream();
    ByteArrayOutputStream plaintext = new ByteArrayOutputStream();
    Key key = new Key(TEST_EXPORT_KEY_PRIVATE, "password");
    // Decrypt and make sure we have expected data in the encrypted backup
    Decryptor decryptor = new Decryptor(key);
    decryptor.setVerificationRequired(false);
    decryptor.decrypt(ciphertext, plaintext);
    List<SecretDeliveryResponse> output = mapper.readValue(plaintext.toByteArray(), new TypeReference<List<SecretDeliveryResponse>>() {
    });
    assertThat(output).extracting(SecretDeliveryResponse::getName).containsExactlyInAnyOrder("Hacking_Password", "General_Password");
    assertThat(output).extracting(SecretDeliveryResponse::getSecret).allMatch(s -> !Strings.isNullOrEmpty(s));
}
Also used : SecretDeliveryResponse(keywhiz.api.SecretDeliveryResponse) Response(okhttp3.Response) Decryptor(org.c02e.jpgpj.Decryptor) InputStream(java.io.InputStream) List(java.util.List) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Key(org.c02e.jpgpj.Key) SecretDeliveryResponse(keywhiz.api.SecretDeliveryResponse) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 List (java.util.List)1 SecretDeliveryResponse (keywhiz.api.SecretDeliveryResponse)1 Response (okhttp3.Response)1 Decryptor (org.c02e.jpgpj.Decryptor)1 Key (org.c02e.jpgpj.Key)1 Test (org.junit.Test)1