use of com.google.crypto.tink.proto.testing.SignatureVerifyResponse in project tink by google.
the class SignatureServiceImpl method verify.
/**
* Verifies a signature.
*/
@Override
public void verify(SignatureVerifyRequest request, StreamObserver<SignatureVerifyResponse> responseObserver) {
SignatureVerifyResponse response;
try {
KeysetHandle publicKeysetHandle = CleartextKeysetHandle.read(BinaryKeysetReader.withBytes(request.getPublicKeyset().toByteArray()));
PublicKeyVerify verifier = publicKeysetHandle.getPrimitive(PublicKeyVerify.class);
verifier.verify(request.getSignature().toByteArray(), request.getData().toByteArray());
response = SignatureVerifyResponse.getDefaultInstance();
} catch (GeneralSecurityException | InvalidProtocolBufferException e) {
response = SignatureVerifyResponse.newBuilder().setErr(e.toString()).build();
} catch (IOException e) {
responseObserver.onError(Status.UNKNOWN.withDescription(e.getMessage()).asException());
return;
}
responseObserver.onNext(response);
responseObserver.onCompleted();
}
use of com.google.crypto.tink.proto.testing.SignatureVerifyResponse 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();
}
use of com.google.crypto.tink.proto.testing.SignatureVerifyResponse 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();
}
use of com.google.crypto.tink.proto.testing.SignatureVerifyResponse in project tink by google.
the class AsymmetricTestingServicesTest method signatureSignVerify_success.
@Test
public void signatureSignVerify_success() 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();
SignatureSignResponse signResponse = signatureSign(signatureStub, privateKeyset, data);
assertThat(signResponse.getErr()).isEmpty();
byte[] signature = signResponse.getSignature().toByteArray();
SignatureVerifyResponse verifyResponse = signatureVerify(signatureStub, publicKeyset, signature, data);
assertThat(verifyResponse.getErr()).isEmpty();
}
Aggregations