mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 15:10:44 +01:00
Add TakerVerifyOffersAgeWitnessHash to taker protocols
This commit is contained in:
parent
6d1a40dbd5
commit
4ef8309153
5 changed files with 93 additions and 5 deletions
|
@ -22,6 +22,7 @@ import io.bisq.common.crypto.Hash;
|
|||
import io.bisq.common.crypto.KeyRing;
|
||||
import io.bisq.common.crypto.Sig;
|
||||
import io.bisq.common.util.Utilities;
|
||||
import io.bisq.core.payment.payload.PaymentAccountPayload;
|
||||
import io.bisq.core.trade.Trade;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
@ -46,10 +47,7 @@ public class PaymentAccountAgeWitnessService {
|
|||
}
|
||||
|
||||
public PaymentAccountAgeWitness getPaymentAccountWitness(PaymentAccount paymentAccount, Trade trade) throws CryptoException {
|
||||
byte[] ageWitnessInputData = paymentAccount.getAgeWitnessInputData();
|
||||
byte[] salt = paymentAccount.getSalt();
|
||||
final byte[] combined = ArrayUtils.addAll(ageWitnessInputData, salt);
|
||||
byte[] hash = Sha256Hash.hash(combined);
|
||||
byte[] hash = getWitnessHash(paymentAccount);
|
||||
byte[] signature = Sig.sign(keyRing.getSignatureKeyPair().getPrivate(), hash);
|
||||
long tradeDate = trade.getTakeOfferDate().getTime();
|
||||
byte[] hashOfPubKey = Sha256Hash.hash(keyRing.getPubKeyRing().getSignaturePubKeyBytes());
|
||||
|
@ -59,6 +57,16 @@ public class PaymentAccountAgeWitnessService {
|
|||
tradeDate);
|
||||
}
|
||||
|
||||
public byte[] getWitnessHash(PaymentAccount paymentAccount) {
|
||||
return getWitnessHash(paymentAccount.getPaymentAccountPayload(), paymentAccount.getSalt());
|
||||
}
|
||||
|
||||
public byte[] getWitnessHash(PaymentAccountPayload paymentAccountPayload, byte[] salt) {
|
||||
byte[] ageWitnessInputData = paymentAccountPayload.getAgeWitnessInputData();
|
||||
final byte[] combined = ArrayUtils.addAll(ageWitnessInputData, salt);
|
||||
return Sha256Hash.hash(combined);
|
||||
}
|
||||
|
||||
boolean verifyAgeWitness(byte[] peersAgeWitnessInputData,
|
||||
PaymentAccountAgeWitness witness,
|
||||
byte[] peersSalt,
|
||||
|
@ -141,4 +149,16 @@ public class PaymentAccountAgeWitnessService {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean verifyOffersAccountAgeWitness(PaymentAccountPayload paymentAccountPayload,
|
||||
byte[] peersSalt,
|
||||
byte[] offersWitness) {
|
||||
byte[] witnessHash = getWitnessHash(paymentAccountPayload, peersSalt);
|
||||
final boolean result = Arrays.equals(witnessHash, offersWitness);
|
||||
if (!result)
|
||||
log.warn("witnessHash is not matching peers offersWitness. " +
|
||||
"witnessHash={}, offersWitness={}", Utilities.bytesAsHexString(witnessHash),
|
||||
Utilities.bytesAsHexString(offersWitness));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import io.bisq.core.trade.messages.PayoutTxPublishedMessage;
|
|||
import io.bisq.core.trade.messages.PublishDepositTxRequest;
|
||||
import io.bisq.core.trade.messages.TradeMessage;
|
||||
import io.bisq.core.trade.protocol.tasks.CheckIfPeerIsBanned;
|
||||
import io.bisq.core.trade.protocol.tasks.taker.TakerVerifyOffersAgeWitnessHash;
|
||||
import io.bisq.core.trade.protocol.tasks.buyer.BuyerProcessPayoutTxPublishedMessage;
|
||||
import io.bisq.core.trade.protocol.tasks.buyer.BuyerSendCounterCurrencyTransferStartedMessage;
|
||||
import io.bisq.core.trade.protocol.tasks.buyer.BuyerSetupPayoutTxListener;
|
||||
|
@ -125,6 +126,7 @@ public class BuyerAsTakerProtocol extends TradeProtocol implements BuyerProtocol
|
|||
TakerProcessPublishDepositTxRequest.class,
|
||||
CheckIfPeerIsBanned.class,
|
||||
TakerVerifyMakerAccount.class,
|
||||
TakerVerifyOffersAgeWitnessHash.class,
|
||||
TakerVerifyMakerFeePayment.class,
|
||||
TakerVerifyAndSignContract.class,
|
||||
BuyerAsTakerSignAndPublishDepositTx.class,
|
||||
|
|
|
@ -27,6 +27,7 @@ import io.bisq.core.trade.messages.CounterCurrencyTransferStartedMessage;
|
|||
import io.bisq.core.trade.messages.PublishDepositTxRequest;
|
||||
import io.bisq.core.trade.messages.TradeMessage;
|
||||
import io.bisq.core.trade.protocol.tasks.CheckIfPeerIsBanned;
|
||||
import io.bisq.core.trade.protocol.tasks.taker.TakerVerifyOffersAgeWitnessHash;
|
||||
import io.bisq.core.trade.protocol.tasks.seller.SellerBroadcastPayoutTx;
|
||||
import io.bisq.core.trade.protocol.tasks.seller.SellerProcessCounterCurrencyTransferStartedMessage;
|
||||
import io.bisq.core.trade.protocol.tasks.seller.SellerSendPayoutTxPublishedMessage;
|
||||
|
@ -120,6 +121,7 @@ public class SellerAsTakerProtocol extends TradeProtocol implements SellerProtoc
|
|||
TakerProcessPublishDepositTxRequest.class,
|
||||
CheckIfPeerIsBanned.class,
|
||||
TakerVerifyMakerAccount.class,
|
||||
TakerVerifyOffersAgeWitnessHash.class,
|
||||
TakerVerifyMakerFeePayment.class,
|
||||
TakerVerifyAndSignContract.class,
|
||||
SellerAsTakerSignAndPublishDepositTx.class,
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bisq.core.trade.protocol.tasks.taker;
|
||||
|
||||
import io.bisq.common.taskrunner.TaskRunner;
|
||||
import io.bisq.common.util.Utilities;
|
||||
import io.bisq.core.offer.OfferPayload;
|
||||
import io.bisq.core.payment.payload.PaymentAccountPayload;
|
||||
import io.bisq.core.trade.Trade;
|
||||
import io.bisq.core.trade.protocol.tasks.TradeTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@Slf4j
|
||||
public class TakerVerifyOffersAgeWitnessHash extends TradeTask {
|
||||
|
||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||
public TakerVerifyOffersAgeWitnessHash(TaskRunner taskHandler, Trade trade) {
|
||||
super(taskHandler, trade);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run() {
|
||||
try {
|
||||
runInterceptHook();
|
||||
|
||||
final Map<String, String> extraDataMap = trade.getOffer().getExtraDataMap();
|
||||
final byte[] accountSalt = processModel.getTradingPeer().getAccountSalt();
|
||||
if (extraDataMap != null &&
|
||||
extraDataMap.containsKey(OfferPayload.ACCOUNT_AGE_WITNESS) &&
|
||||
accountSalt != null) {
|
||||
final String offersWitness = extraDataMap.get(OfferPayload.ACCOUNT_AGE_WITNESS);
|
||||
final PaymentAccountPayload paymentAccountPayload = checkNotNull(processModel.getTradingPeer().getPaymentAccountPayload()
|
||||
, "Peers paymentAccountPayload must nto be null");
|
||||
checkArgument(processModel.getPaymentAccountAgeWitnessService()
|
||||
.verifyOffersAccountAgeWitness(paymentAccountPayload,
|
||||
accountSalt,
|
||||
Utilities.decodeFromHex(offersWitness)), "");
|
||||
}
|
||||
complete();
|
||||
} catch (Throwable t) {
|
||||
failed(t);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -41,7 +41,7 @@ import static org.junit.Assert.assertTrue;
|
|||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
@Slf4j
|
||||
public class PaymentAccountAgeWitnessServiceTest {
|
||||
public class PaymentPaymentAccountAgeWitnessServiceTest {
|
||||
|
||||
private PublicKey publicKey;
|
||||
private KeyPair keypair;
|
Loading…
Add table
Reference in a new issue