use of com.google.crypto.tink.proto.testing.SignatureSignResponse in project tink by google.
the class SignatureServiceImpl method sign.
/**
* Signs a message.
*/
@Override
public void sign(SignatureSignRequest request, StreamObserver<SignatureSignResponse> responseObserver) {
SignatureSignResponse response;
try {
KeysetHandle privateKeysetHandle = CleartextKeysetHandle.read(BinaryKeysetReader.withBytes(request.getPrivateKeyset().toByteArray()));
PublicKeySign signer = privateKeysetHandle.getPrimitive(PublicKeySign.class);
byte[] signatureValue = signer.sign(request.getData().toByteArray());
response = SignatureSignResponse.newBuilder().setSignature(ByteString.copyFrom(signatureValue)).build();
} catch (GeneralSecurityException | InvalidProtocolBufferException e) {
response = SignatureSignResponse.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.SignatureSignResponse 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.SignatureSignResponse 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();
}
use of com.google.crypto.tink.proto.testing.SignatureSignResponse in project tink by google.
the class AsymmetricTestingServicesTest method signatureSign_failsOnBadKeyset.
@Test
public void signatureSign_failsOnBadKeyset() throws Exception {
byte[] badKeyset = "bad keyset".getBytes(UTF_8);
byte[] data = "The quick brown fox jumps over the lazy dog".getBytes(UTF_8);
SignatureSignResponse response = signatureSign(signatureStub, badKeyset, data);
assertThat(response.getErr()).isNotEmpty();
}
Aggregations