Search in sources :

Example 16 with KeysetGenerateResponse

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

the class JwtServiceImplTest method verifyFailsWithWrongKey.

@Test
public void verifyFailsWithWrongKey() throws Exception {
    byte[] template = KeyTemplateProtoConverter.toByteArray(JwtHmacKeyManager.hs256Template());
    KeysetGenerateResponse keysetResponse = generateKeyset(keysetStub, template);
    assertThat(keysetResponse.getErr()).isEmpty();
    byte[] keyset = keysetResponse.getKeyset().toByteArray();
    JwtToken token = generateToken("audience", 1234 + 100, 0);
    JwtSignRequest signRequest = JwtSignRequest.newBuilder().setKeyset(ByteString.copyFrom(keyset)).setRawJwt(token).build();
    JwtSignResponse signResponse = jwtStub.computeMacAndEncode(signRequest);
    assertThat(signResponse.getErr()).isEmpty();
    KeysetGenerateResponse wrongKeysetResponse = generateKeyset(keysetStub, template);
    assertThat(wrongKeysetResponse.getErr()).isEmpty();
    byte[] wrongKeyset = wrongKeysetResponse.getKeyset().toByteArray();
    JwtValidator validator = JwtValidator.newBuilder().setExpectedTypeHeader(StringValue.newBuilder().setValue("typeHeader")).setExpectedIssuer(StringValue.newBuilder().setValue("issuer")).setExpectedAudience(StringValue.newBuilder().setValue("audience")).setNow(Timestamp.newBuilder().setSeconds(1234)).build();
    JwtVerifyRequest verifyRequest = JwtVerifyRequest.newBuilder().setKeyset(ByteString.copyFrom(wrongKeyset)).setSignedCompactJwt(signResponse.getSignedCompactJwt()).setValidator(validator).build();
    JwtVerifyResponse verifyResponse = jwtStub.verifyMacAndDecode(verifyRequest);
    assertThat(verifyResponse.getErr()).isNotEmpty();
}
Also used : JwtToken(com.google.crypto.tink.proto.testing.JwtToken) JwtSignRequest(com.google.crypto.tink.proto.testing.JwtSignRequest) JwtValidator(com.google.crypto.tink.proto.testing.JwtValidator) JwtSignResponse(com.google.crypto.tink.proto.testing.JwtSignResponse) KeysetGenerateResponse(com.google.crypto.tink.proto.testing.KeysetGenerateResponse) JwtVerifyRequest(com.google.crypto.tink.proto.testing.JwtVerifyRequest) JwtVerifyResponse(com.google.crypto.tink.proto.testing.JwtVerifyResponse) Test(org.junit.Test)

Example 17 with KeysetGenerateResponse

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

the class AsymmetricTestingServicesTest method hybridGenerateEncryptDecrypt_success.

@Test
public void hybridGenerateEncryptDecrypt_success() throws Exception {
    byte[] template = KeyTemplateProtoConverter.toByteArray(EciesAeadHkdfPrivateKeyManager.eciesP256HkdfHmacSha256Aes128GcmTemplate());
    byte[] plaintext = "The quick brown fox jumps over the lazy dog".getBytes(UTF_8);
    byte[] associatedData = "generate_encrypt_decrypt".getBytes(UTF_8);
    KeysetGenerateResponse genResponse = generateKeyset(keysetStub, template);
    assertThat(genResponse.getErr()).isEmpty();
    byte[] privateKeyset = genResponse.getKeyset().toByteArray();
    KeysetPublicResponse pubResponse = publicKeyset(keysetStub, privateKeyset);
    assertThat(pubResponse.getErr()).isEmpty();
    byte[] publicKeyset = pubResponse.getPublicKeyset().toByteArray();
    HybridEncryptResponse encResponse = hybridEncrypt(hybridStub, publicKeyset, plaintext, associatedData);
    assertThat(encResponse.getErr()).isEmpty();
    byte[] ciphertext = encResponse.getCiphertext().toByteArray();
    HybridDecryptResponse decResponse = hybridDecrypt(hybridStub, privateKeyset, ciphertext, associatedData);
    assertThat(decResponse.getErr()).isEmpty();
    byte[] output = decResponse.getPlaintext().toByteArray();
    assertThat(output).isEqualTo(plaintext);
}
Also used : HybridEncryptResponse(com.google.crypto.tink.proto.testing.HybridEncryptResponse) HybridDecryptResponse(com.google.crypto.tink.proto.testing.HybridDecryptResponse) KeysetGenerateResponse(com.google.crypto.tink.proto.testing.KeysetGenerateResponse) KeysetPublicResponse(com.google.crypto.tink.proto.testing.KeysetPublicResponse) Test(org.junit.Test)

Example 18 with KeysetGenerateResponse

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

the class AsymmetricTestingServicesTest method signatureVerify_failsOnBadSignature.

@Test
public void signatureVerify_failsOnBadSignature() throws Exception {
    byte[] template = KeyTemplateProtoConverter.toByteArray(EcdsaSignKeyManager.ecdsaP256Template());
    byte[] data = "The quick brown fox jumps over the lazy dog".getBytes(UTF_8);
    KeysetGenerateResponse genResponse = generateKeyset(keysetStub, template);
    assertThat(genResponse.getErr()).isEmpty();
    byte[] privateKeyset = genResponse.getKeyset().toByteArray();
    KeysetPublicResponse pubResponse = publicKeyset(keysetStub, privateKeyset);
    assertThat(pubResponse.getErr()).isEmpty();
    byte[] publicKeyset = pubResponse.getPublicKeyset().toByteArray();
    SignatureVerifyResponse verifyResponse = signatureVerify(signatureStub, publicKeyset, "bad signature".getBytes(UTF_8), data);
    assertThat(verifyResponse.getErr()).isNotEmpty();
}
Also used : KeysetGenerateResponse(com.google.crypto.tink.proto.testing.KeysetGenerateResponse) SignatureVerifyResponse(com.google.crypto.tink.proto.testing.SignatureVerifyResponse) KeysetPublicResponse(com.google.crypto.tink.proto.testing.KeysetPublicResponse) Test(org.junit.Test)

Example 19 with KeysetGenerateResponse

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

the class AsymmetricTestingServicesTest method hybridDecrypt_failsOnBadCiphertext.

@Test
public void hybridDecrypt_failsOnBadCiphertext() throws Exception {
    byte[] template = KeyTemplateProtoConverter.toByteArray(EciesAeadHkdfPrivateKeyManager.eciesP256HkdfHmacSha256Aes128GcmTemplate());
    byte[] badCiphertext = "bad ciphertext".getBytes(UTF_8);
    byte[] contextInfo = "hybrid_decrypt_bad_ciphertext".getBytes(UTF_8);
    KeysetGenerateResponse keysetResponse = generateKeyset(keysetStub, template);
    assertThat(keysetResponse.getErr()).isEmpty();
    byte[] privateKeyset = keysetResponse.getKeyset().toByteArray();
    KeysetPublicResponse pubResponse = publicKeyset(keysetStub, privateKeyset);
    assertThat(pubResponse.getErr()).isEmpty();
    byte[] publicKeyset = pubResponse.getPublicKeyset().toByteArray();
    HybridDecryptResponse decResponse = hybridDecrypt(hybridStub, publicKeyset, badCiphertext, contextInfo);
    assertThat(decResponse.getErr()).isNotEmpty();
}
Also used : HybridDecryptResponse(com.google.crypto.tink.proto.testing.HybridDecryptResponse) KeysetGenerateResponse(com.google.crypto.tink.proto.testing.KeysetGenerateResponse) KeysetPublicResponse(com.google.crypto.tink.proto.testing.KeysetPublicResponse) Test(org.junit.Test)

Example 20 with KeysetGenerateResponse

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

the class AsymmetricTestingServicesTest method signatureVerify_failsOnBadKeyset.

@Test
public void signatureVerify_failsOnBadKeyset() throws Exception {
    byte[] template = KeyTemplateProtoConverter.toByteArray(EcdsaSignKeyManager.ecdsaP256Template());
    byte[] data = "The quick brown fox jumps over the lazy dog".getBytes(UTF_8);
    KeysetGenerateResponse genResponse = generateKeyset(keysetStub, template);
    assertThat(genResponse.getErr()).isEmpty();
    byte[] privateKeyset = genResponse.getKeyset().toByteArray();
    SignatureSignResponse signResponse = signatureSign(signatureStub, privateKeyset, data);
    assertThat(signResponse.getErr()).isEmpty();
    byte[] signature = signResponse.getSignature().toByteArray();
    byte[] badKeyset = "bad keyset".getBytes(UTF_8);
    SignatureVerifyResponse verifyResponse = signatureVerify(signatureStub, badKeyset, signature, data);
    assertThat(verifyResponse.getErr()).isNotEmpty();
}
Also used : SignatureSignResponse(com.google.crypto.tink.proto.testing.SignatureSignResponse) KeysetGenerateResponse(com.google.crypto.tink.proto.testing.KeysetGenerateResponse) SignatureVerifyResponse(com.google.crypto.tink.proto.testing.SignatureVerifyResponse) 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