mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-27 00:45:23 -04:00
use byte[] for signatures instead of strings
This commit is contained in:
parent
ead70751dc
commit
4650003838
23 changed files with 265 additions and 255 deletions
|
@ -104,9 +104,9 @@ public final class Dispute implements NetworkPayload, PersistablePayload {
|
|||
private final String payoutTxId;
|
||||
private String contractAsJson;
|
||||
@Nullable
|
||||
private final String makerContractSignature;
|
||||
private final byte[] makerContractSignature;
|
||||
@Nullable
|
||||
private final String takerContractSignature;
|
||||
private final byte[] takerContractSignature;
|
||||
private final PubKeyRing agentPubKeyRing; // dispute agent
|
||||
private final boolean isSupportTicket;
|
||||
private final ObservableList<ChatMessage> chatMessages = FXCollections.observableArrayList();
|
||||
|
@ -179,8 +179,8 @@ public final class Dispute implements NetworkPayload, PersistablePayload {
|
|||
@Nullable String depositTxId,
|
||||
@Nullable String payoutTxId,
|
||||
String contractAsJson,
|
||||
@Nullable String makerContractSignature,
|
||||
@Nullable String takerContractSignature,
|
||||
@Nullable byte[] makerContractSignature,
|
||||
@Nullable byte[] takerContractSignature,
|
||||
@Nullable PaymentAccountPayload makerPaymentAccountPayload,
|
||||
@Nullable PaymentAccountPayload takerPaymentAccountPayload,
|
||||
PubKeyRing agentPubKeyRing,
|
||||
|
@ -251,8 +251,8 @@ public final class Dispute implements NetworkPayload, PersistablePayload {
|
|||
Optional.ofNullable(depositTxId).ifPresent(builder::setDepositTxId);
|
||||
Optional.ofNullable(payoutTxId).ifPresent(builder::setPayoutTxId);
|
||||
Optional.ofNullable(disputePayoutTxId).ifPresent(builder::setDisputePayoutTxId);
|
||||
Optional.ofNullable(makerContractSignature).ifPresent(builder::setMakerContractSignature);
|
||||
Optional.ofNullable(takerContractSignature).ifPresent(builder::setTakerContractSignature);
|
||||
Optional.ofNullable(makerContractSignature).ifPresent(e -> builder.setMakerContractSignature(ByteString.copyFrom(e)));
|
||||
Optional.ofNullable(takerContractSignature).ifPresent(e -> builder.setTakerContractSignature(ByteString.copyFrom(e)));
|
||||
Optional.ofNullable(makerPaymentAccountPayload).ifPresent(e -> builder.setMakerPaymentAccountPayload((protobuf.PaymentAccountPayload) makerPaymentAccountPayload.toProtoMessage()));
|
||||
Optional.ofNullable(takerPaymentAccountPayload).ifPresent(e -> builder.setTakerPaymentAccountPayload((protobuf.PaymentAccountPayload) takerPaymentAccountPayload.toProtoMessage()));
|
||||
Optional.ofNullable(disputeResultProperty.get()).ifPresent(result -> builder.setDisputeResult(disputeResultProperty.get().toProtoMessage()));
|
||||
|
@ -281,8 +281,8 @@ public final class Dispute implements NetworkPayload, PersistablePayload {
|
|||
ProtoUtil.stringOrNullFromProto(proto.getDepositTxId()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getPayoutTxId()),
|
||||
proto.getContractAsJson(),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getMakerContractSignature()),
|
||||
ProtoUtil.stringOrNullFromProto(proto.getTakerContractSignature()),
|
||||
ProtoUtil.byteArrayOrNullFromProto(proto.getMakerContractSignature()),
|
||||
ProtoUtil.byteArrayOrNullFromProto(proto.getTakerContractSignature()),
|
||||
proto.hasMakerPaymentAccountPayload() ? coreProtoResolver.fromProto(proto.getMakerPaymentAccountPayload()) : null,
|
||||
proto.hasTakerPaymentAccountPayload() ? coreProtoResolver.fromProto(proto.getTakerPaymentAccountPayload()) : null,
|
||||
PubKeyRing.fromProto(proto.getAgentPubKeyRing()),
|
||||
|
@ -524,8 +524,8 @@ public final class Dispute implements NetworkPayload, PersistablePayload {
|
|||
",\n depositTxId='" + depositTxId + '\'' +
|
||||
",\n payoutTxId='" + payoutTxId + '\'' +
|
||||
",\n contractAsJson='" + contractAsJson + '\'' +
|
||||
",\n makerContractSignature='" + makerContractSignature + '\'' +
|
||||
",\n takerContractSignature='" + takerContractSignature + '\'' +
|
||||
",\n makerContractSignature='" + Utilities.bytesAsHexString(makerContractSignature) + '\'' +
|
||||
",\n takerContractSignature='" + Utilities.bytesAsHexString(takerContractSignature) + '\'' +
|
||||
",\n agentPubKeyRing=" + agentPubKeyRing +
|
||||
",\n isSupportTicket=" + isSupportTicket +
|
||||
",\n chatMessages=" + chatMessages +
|
||||
|
|
|
@ -17,16 +17,14 @@
|
|||
|
||||
package haveno.core.support.dispute;
|
||||
|
||||
import haveno.common.crypto.CryptoException;
|
||||
import haveno.common.crypto.Hash;
|
||||
import haveno.common.crypto.Sig;
|
||||
import haveno.common.util.Utilities;
|
||||
import haveno.core.locale.Res;
|
||||
import haveno.core.support.dispute.agent.DisputeAgent;
|
||||
import haveno.core.support.dispute.arbitration.arbitrator.ArbitratorManager;
|
||||
import haveno.core.trade.HavenoUtils;
|
||||
import haveno.network.p2p.NodeAddress;
|
||||
import java.security.KeyPair;
|
||||
import java.security.PublicKey;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
@ -46,10 +44,10 @@ public class DisputeSummaryVerification {
|
|||
KeyPair signatureKeyPair = disputeManager.getSignatureKeyPair();
|
||||
String sigAsHex;
|
||||
try {
|
||||
byte[] signature = Sig.sign(signatureKeyPair.getPrivate(), hash);
|
||||
byte[] signature = HavenoUtils.sign(signatureKeyPair.getPrivate(), hash);
|
||||
sigAsHex = Utilities.encodeToHex(signature);
|
||||
disputeResult.setArbitratorSignature(signature);
|
||||
} catch (CryptoException e) {
|
||||
} catch (Exception e) {
|
||||
sigAsHex = "Signing failed";
|
||||
}
|
||||
|
||||
|
@ -69,19 +67,13 @@ public class DisputeSummaryVerification {
|
|||
NodeAddress nodeAddress = new NodeAddress(fullAddress);
|
||||
DisputeAgent disputeAgent = arbitratorMediator.getDisputeAgentByNodeAddress(nodeAddress).orElse(null);
|
||||
checkNotNull(disputeAgent, "Dispute agent is null");
|
||||
PublicKey pubKey = disputeAgent.getPubKeyRing().getSignaturePubKey();
|
||||
|
||||
String sigString = parts[1].split(SEPARATOR2)[0];
|
||||
byte[] sig = Utilities.decodeFromHex(sigString);
|
||||
byte[] hash = Hash.getSha256Hash(textToSign);
|
||||
try {
|
||||
boolean result = Sig.verify(pubKey, hash, sig);
|
||||
if (result) {
|
||||
return;
|
||||
} else {
|
||||
throw new IllegalArgumentException(Res.get("support.sigCheck.popup.failed"));
|
||||
}
|
||||
} catch (CryptoException e) {
|
||||
HavenoUtils.verifySignature(disputeAgent.getPubKeyRing(), hash, sig);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException(Res.get("support.sigCheck.popup.failed"));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
|
|
|
@ -18,12 +18,11 @@
|
|||
package haveno.core.support.dispute;
|
||||
|
||||
import haveno.common.config.Config;
|
||||
import haveno.common.crypto.CryptoException;
|
||||
import haveno.common.crypto.Hash;
|
||||
import haveno.common.crypto.Sig;
|
||||
import haveno.common.util.Tuple3;
|
||||
import haveno.core.support.SupportType;
|
||||
import haveno.core.trade.Contract;
|
||||
import haveno.core.trade.HavenoUtils;
|
||||
import haveno.core.trade.Trade;
|
||||
import haveno.core.util.JsonUtil;
|
||||
import haveno.core.util.validation.RegexValidatorFactory;
|
||||
|
@ -64,23 +63,11 @@ public class DisputeValidation {
|
|||
checkArgument(Arrays.equals(Objects.requireNonNull(dispute.getContractHash()), Hash.getSha256Hash(checkNotNull(dispute.getContractAsJson()))),
|
||||
"Invalid contractHash");
|
||||
|
||||
try {
|
||||
// Only the dispute opener has set the signature
|
||||
String makerContractSignature = dispute.getMakerContractSignature();
|
||||
if (makerContractSignature != null) {
|
||||
Sig.verify(contract.getMakerPubKeyRing().getSignaturePubKey(),
|
||||
dispute.getContractAsJson(),
|
||||
makerContractSignature);
|
||||
}
|
||||
String takerContractSignature = dispute.getTakerContractSignature();
|
||||
if (takerContractSignature != null) {
|
||||
Sig.verify(contract.getTakerPubKeyRing().getSignaturePubKey(),
|
||||
dispute.getContractAsJson(),
|
||||
takerContractSignature);
|
||||
}
|
||||
} catch (CryptoException e) {
|
||||
throw new ValidationException(dispute, e.getMessage());
|
||||
}
|
||||
// Only the dispute opener has set the signature
|
||||
byte[] makerContractSignature = dispute.getMakerContractSignature();
|
||||
if (makerContractSignature != null) HavenoUtils.verifySignature(contract.getMakerPubKeyRing(), dispute.getContractAsJson(), makerContractSignature);
|
||||
byte[] takerContractSignature = dispute.getTakerContractSignature();
|
||||
if (takerContractSignature != null) HavenoUtils.verifySignature(contract.getTakerPubKeyRing(), dispute.getContractAsJson(), takerContractSignature);
|
||||
} catch (Throwable t) {
|
||||
throw new ValidationException(dispute, t.getMessage());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue