Search in sources :

Example 26 with KeysetGenerateResponse

use of com.google.crypto.tink.proto.testing.KeysetGenerateResponse in project tink by google.

the class TestingServicesTest method computePrf_success.

@Test
public void computePrf_success() throws Exception {
    byte[] template = KeyTemplateProtoConverter.toByteArray(HmacPrfKeyManager.hmacSha256Template());
    byte[] inputData = "The quick brown fox jumps over the lazy dog".getBytes(UTF_8);
    int outputLength = 15;
    KeysetGenerateResponse keysetResponse = generateKeyset(keysetStub, template);
    assertThat(keysetResponse.getErr()).isEmpty();
    byte[] keyset = keysetResponse.getKeyset().toByteArray();
    PrfSetKeyIdsResponse keyIdsResponse = keyIds(prfSetStub, keyset);
    assertThat(keyIdsResponse.getErr()).isEmpty();
    int primaryKeyId = keyIdsResponse.getOutput().getPrimaryKeyId();
    PrfSetComputeResponse computeResponse = computePrf(prfSetStub, keyset, primaryKeyId, inputData, outputLength);
    assertThat(computeResponse.getErr()).isEmpty();
    assertThat(computeResponse.getOutput().size()).isEqualTo(outputLength);
}
Also used : PrfSetComputeResponse(com.google.crypto.tink.proto.testing.PrfSetComputeResponse) KeysetGenerateResponse(com.google.crypto.tink.proto.testing.KeysetGenerateResponse) PrfSetKeyIdsResponse(com.google.crypto.tink.proto.testing.PrfSetKeyIdsResponse) Test(org.junit.Test)

Example 27 with KeysetGenerateResponse

use of com.google.crypto.tink.proto.testing.KeysetGenerateResponse in project tink by google.

the class TestingServicesTest method computePrf_failsOnBadOutputLength.

@Test
public void computePrf_failsOnBadOutputLength() throws Exception {
    byte[] template = KeyTemplateProtoConverter.toByteArray(HmacPrfKeyManager.hmacSha256Template());
    byte[] inputData = "The quick brown fox jumps over the lazy dog".getBytes(UTF_8);
    int outputLength = 12345;
    KeysetGenerateResponse keysetResponse = generateKeyset(keysetStub, template);
    assertThat(keysetResponse.getErr()).isEmpty();
    byte[] keyset = keysetResponse.getKeyset().toByteArray();
    PrfSetKeyIdsResponse keyIdsResponse = keyIds(prfSetStub, keyset);
    assertThat(keyIdsResponse.getErr()).isEmpty();
    int primaryKeyId = keyIdsResponse.getOutput().getPrimaryKeyId();
    PrfSetComputeResponse computeResponse = computePrf(prfSetStub, keyset, primaryKeyId, inputData, outputLength);
    assertThat(computeResponse.getErr()).isNotEmpty();
}
Also used : PrfSetComputeResponse(com.google.crypto.tink.proto.testing.PrfSetComputeResponse) KeysetGenerateResponse(com.google.crypto.tink.proto.testing.KeysetGenerateResponse) PrfSetKeyIdsResponse(com.google.crypto.tink.proto.testing.PrfSetKeyIdsResponse) Test(org.junit.Test)

Example 28 with KeysetGenerateResponse

use of com.google.crypto.tink.proto.testing.KeysetGenerateResponse in project tink by google.

the class TestingServicesTest method aeadDecrypt_failsOnBadCiphertext.

@Test
public void aeadDecrypt_failsOnBadCiphertext() throws Exception {
    byte[] template = KeyTemplateProtoConverter.toByteArray(KeyTemplates.get("AES128_GCM"));
    byte[] badCiphertext = "bad ciphertext".getBytes(UTF_8);
    byte[] associatedData = "aead_decrypt_fails_on_bad_ciphertext".getBytes(UTF_8);
    KeysetGenerateResponse keysetResponse = generateKeyset(keysetStub, template);
    assertThat(keysetResponse.getErr()).isEmpty();
    byte[] keyset = keysetResponse.getKeyset().toByteArray();
    AeadDecryptResponse decResponse = aeadDecrypt(aeadStub, keyset, badCiphertext, associatedData);
    assertThat(decResponse.getErr()).isNotEmpty();
}
Also used : DeterministicAeadDecryptResponse(com.google.crypto.tink.proto.testing.DeterministicAeadDecryptResponse) StreamingAeadDecryptResponse(com.google.crypto.tink.proto.testing.StreamingAeadDecryptResponse) AeadDecryptResponse(com.google.crypto.tink.proto.testing.AeadDecryptResponse) KeysetGenerateResponse(com.google.crypto.tink.proto.testing.KeysetGenerateResponse) Test(org.junit.Test)

Example 29 with KeysetGenerateResponse

use of com.google.crypto.tink.proto.testing.KeysetGenerateResponse in project tink by google.

the class TestingServicesTest method verifyMac_failsOnBadMacValue.

@Test
public void verifyMac_failsOnBadMacValue() throws Exception {
    byte[] template = KeyTemplateProtoConverter.toByteArray(HmacKeyManager.hmacSha256HalfDigestTemplate());
    byte[] data = "The quick brown fox jumps over the lazy dog".getBytes(UTF_8);
    KeysetGenerateResponse keysetResponse = generateKeyset(keysetStub, template);
    assertThat(keysetResponse.getErr()).isEmpty();
    byte[] keyset = keysetResponse.getKeyset().toByteArray();
    VerifyMacResponse verifyResponse = verifyMac(macStub, keyset, "bad mac_value".getBytes(UTF_8), data);
    assertThat(verifyResponse.getErr()).isNotEmpty();
}
Also used : KeysetGenerateResponse(com.google.crypto.tink.proto.testing.KeysetGenerateResponse) VerifyMacResponse(com.google.crypto.tink.proto.testing.VerifyMacResponse) Test(org.junit.Test)

Example 30 with KeysetGenerateResponse

use of com.google.crypto.tink.proto.testing.KeysetGenerateResponse in project tink by google.

the class TestingServicesTest method generateEncryptDecryptKeysetWithAssociatedData.

@Test
public void generateEncryptDecryptKeysetWithAssociatedData() throws Exception {
    byte[] template = KeyTemplateProtoConverter.toByteArray(KeyTemplates.get("AES128_GCM"));
    byte[] associatedData = "a".getBytes(UTF_8);
    KeysetGenerateResponse keysetResponse = generateKeyset(keysetStub, template);
    assertThat(keysetResponse.getErr()).isEmpty();
    byte[] keyset = keysetResponse.getKeyset().toByteArray();
    KeysetGenerateResponse masterKeysetResponse = generateKeyset(keysetStub, template);
    assertThat(masterKeysetResponse.getErr()).isEmpty();
    byte[] masterKeyset = masterKeysetResponse.getKeyset().toByteArray();
    KeysetWriteEncryptedResponse writeResponse = keysetWriteEncrypted(keysetStub, keyset, masterKeyset, Optional.of(associatedData));
    assertThat(writeResponse.getErr()).isEmpty();
    byte[] encryptedKeyset = writeResponse.getEncryptedKeyset().toByteArray();
    assertThat(encryptedKeyset).isNotEqualTo(keyset);
    KeysetReadEncryptedResponse readResponse = keysetReadEncrypted(keysetStub, encryptedKeyset, masterKeyset, Optional.of(associatedData));
    assertThat(readResponse.getErr()).isEmpty();
    byte[] output = readResponse.getKeyset().toByteArray();
    assertThat(output).isEqualTo(keyset);
}
Also used : KeysetWriteEncryptedResponse(com.google.crypto.tink.proto.testing.KeysetWriteEncryptedResponse) KeysetReadEncryptedResponse(com.google.crypto.tink.proto.testing.KeysetReadEncryptedResponse) KeysetGenerateResponse(com.google.crypto.tink.proto.testing.KeysetGenerateResponse) Test(org.junit.Test)

Aggregations

KeysetGenerateResponse (com.google.crypto.tink.proto.testing.KeysetGenerateResponse)34 Test (org.junit.Test)33 JwtSignRequest (com.google.crypto.tink.proto.testing.JwtSignRequest)7 JwtSignResponse (com.google.crypto.tink.proto.testing.JwtSignResponse)7 JwtToken (com.google.crypto.tink.proto.testing.JwtToken)7 JwtValidator (com.google.crypto.tink.proto.testing.JwtValidator)7 JwtVerifyRequest (com.google.crypto.tink.proto.testing.JwtVerifyRequest)7 JwtVerifyResponse (com.google.crypto.tink.proto.testing.JwtVerifyResponse)7 KeysetPublicResponse (com.google.crypto.tink.proto.testing.KeysetPublicResponse)7 DeterministicAeadDecryptResponse (com.google.crypto.tink.proto.testing.DeterministicAeadDecryptResponse)6 StreamingAeadDecryptResponse (com.google.crypto.tink.proto.testing.StreamingAeadDecryptResponse)6 DeterministicAeadEncryptResponse (com.google.crypto.tink.proto.testing.DeterministicAeadEncryptResponse)4 StreamingAeadEncryptResponse (com.google.crypto.tink.proto.testing.StreamingAeadEncryptResponse)4 AeadDecryptResponse (com.google.crypto.tink.proto.testing.AeadDecryptResponse)3 HybridDecryptResponse (com.google.crypto.tink.proto.testing.HybridDecryptResponse)3 KeysetReadEncryptedResponse (com.google.crypto.tink.proto.testing.KeysetReadEncryptedResponse)3 KeysetWriteEncryptedResponse (com.google.crypto.tink.proto.testing.KeysetWriteEncryptedResponse)3 PrfSetComputeResponse (com.google.crypto.tink.proto.testing.PrfSetComputeResponse)3 SignatureVerifyResponse (com.google.crypto.tink.proto.testing.SignatureVerifyResponse)3 VerifyMacResponse (com.google.crypto.tink.proto.testing.VerifyMacResponse)3