From 1b8ccd6271ad73c16471e739f4481af7923b8ff3 Mon Sep 17 00:00:00 2001 From: Daniel Akhterov Date: Mon, 20 Dec 2021 18:15:57 -0800 Subject: [PATCH] fix: `PublicKey.verifyTransaction()` should use the right field in the protobufs Signed-off-by: Daniel Akhterov --- sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKey.java | 4 +++- .../main/java/com/hedera/hashgraph/sdk/PublicKeyECDSA.java | 5 +++++ .../main/java/com/hedera/hashgraph/sdk/PublicKeyED25519.java | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKey.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKey.java index a392f9362..8e7bd85ab 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKey.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKey.java @@ -84,6 +84,8 @@ static PublicKey fromAliasBytes(ByteString aliasBytes) { */ public abstract boolean verify(byte[] message, byte[] signature); + abstract ByteString extractSignatureFromProtobuf(SignaturePair pair); + public boolean verifyTransaction(Transaction transaction) { if (!transaction.isFrozen()) { transaction.freeze(); @@ -95,7 +97,7 @@ public boolean verifyTransaction(Transaction transaction) { if (sigPair.getPubKeyPrefix().equals(ByteString.copyFrom(toBytes()))) { found = true; - if (!verify(signedTransaction.getBodyBytes().toByteArray(), sigPair.getEd25519().toByteArray())) { + if (!verify(signedTransaction.getBodyBytes().toByteArray(), extractSignatureFromProtobuf(sigPair).toByteArray())) { return false; } } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKeyECDSA.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKeyECDSA.java index b9bf91630..57f662189 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKeyECDSA.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKeyECDSA.java @@ -39,6 +39,11 @@ static PublicKeyECDSA fromSubjectKeyInfoInternal(SubjectPublicKeyInfo subjectPub return new PublicKeyECDSA(subjectPublicKeyInfo.getPublicKeyData().getBytes()); } + @Override + ByteString extractSignatureFromProtobuf(SignaturePair pair) { + return pair.getECDSA384(); + } + @Override public boolean verify(byte[] message, byte[] signature) { var hash = Crypto.calcKeccak256(message); diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKeyED25519.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKeyED25519.java index 89c8bcc22..ea0c4e18d 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKeyED25519.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKeyED25519.java @@ -31,6 +31,11 @@ static PublicKeyED25519 fromSubjectKeyInfoInternal(SubjectPublicKeyInfo subjectP return new PublicKeyED25519(subjectPublicKeyInfo.getPublicKeyData().getBytes()); } + @Override + ByteString extractSignatureFromProtobuf(SignaturePair pair) { + return pair.getEd25519(); + } + @Override public boolean verify(byte[] message, byte[] signature) { return Ed25519.verify(signature, 0, keyData, 0, message, 0, message.length);