mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-25 15:29:23 -05:00
check peer date while initializing trade instead of deposits confirmed
This commit is contained in:
parent
a49611a234
commit
7f26119515
@ -526,17 +526,15 @@ public class AccountAgeWitnessService {
|
|||||||
|
|
||||||
public boolean verifyAccountAgeWitness(Trade trade,
|
public boolean verifyAccountAgeWitness(Trade trade,
|
||||||
PaymentAccountPayload peersPaymentAccountPayload,
|
PaymentAccountPayload peersPaymentAccountPayload,
|
||||||
Date peersCurrentDate,
|
|
||||||
PubKeyRing peersPubKeyRing,
|
PubKeyRing peersPubKeyRing,
|
||||||
byte[] nonce,
|
byte[] nonce,
|
||||||
byte[] signature,
|
byte[] signature,
|
||||||
ErrorMessageHandler errorMessageHandler) {
|
ErrorMessageHandler errorMessageHandler) {
|
||||||
|
|
||||||
log.info("Verifying account age witness for {} {}, payment account payload hash={}, peers current date={}, nonce={}, signature={}",
|
log.info("Verifying account age witness for {} {}, payment account payload hash={}, nonce={}, signature={}",
|
||||||
trade.getClass().getSimpleName(),
|
trade.getClass().getSimpleName(),
|
||||||
trade.getId(),
|
trade.getId(),
|
||||||
Utilities.bytesAsHexString(peersPaymentAccountPayload.getHash()),
|
Utilities.bytesAsHexString(peersPaymentAccountPayload.getHash()),
|
||||||
peersCurrentDate,
|
|
||||||
Utilities.bytesAsHexString(nonce),
|
Utilities.bytesAsHexString(nonce),
|
||||||
Utilities.bytesAsHexString(signature));
|
Utilities.bytesAsHexString(signature));
|
||||||
|
|
||||||
@ -558,10 +556,6 @@ public class AccountAgeWitnessService {
|
|||||||
if (!isDateAfterReleaseDate(peersWitness.getDate(), RELEASE, errorMessageHandler))
|
if (!isDateAfterReleaseDate(peersWitness.getDate(), RELEASE, errorMessageHandler))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check if peer current date is in tolerance range
|
|
||||||
if (!verifyPeersCurrentDate(peersCurrentDate, errorMessageHandler))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
final byte[] peersAccountInputDataWithSalt = Utilities.concatenateByteArrays(
|
final byte[] peersAccountInputDataWithSalt = Utilities.concatenateByteArrays(
|
||||||
peersPaymentAccountPayload.getAgeWitnessInputData(), peersPaymentAccountPayload.getSalt());
|
peersPaymentAccountPayload.getAgeWitnessInputData(), peersPaymentAccountPayload.getSalt());
|
||||||
byte[] hash = Hash.getSha256Ripemd160hash(Utilities.concatenateByteArrays(peersAccountInputDataWithSalt,
|
byte[] hash = Hash.getSha256Ripemd160hash(Utilities.concatenateByteArrays(peersAccountInputDataWithSalt,
|
||||||
@ -573,8 +567,7 @@ public class AccountAgeWitnessService {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check if the peers trade limit is not less than the trade amount
|
// Check if the peers trade limit is not less than the trade amount
|
||||||
if (!verifyPeersTradeLimit(trade.getOffer(), trade.getAmount(), peersWitness, peersCurrentDate,
|
if (!verifyPeersTradeLimit(trade.getOffer(), trade.getAmount(), peersWitness, new Date(), errorMessageHandler)) {
|
||||||
errorMessageHandler)) {
|
|
||||||
log.error("verifyPeersTradeLimit failed: peersPaymentAccountPayload {}", peersPaymentAccountPayload);
|
log.error("verifyPeersTradeLimit failed: peersPaymentAccountPayload {}", peersPaymentAccountPayload);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -619,13 +612,12 @@ public class AccountAgeWitnessService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean verifyPeersCurrentDate(Date peersCurrentDate, ErrorMessageHandler errorMessageHandler) {
|
public boolean verifyPeersCurrentDate(Date peersCurrentDate) {
|
||||||
boolean result = Math.abs(peersCurrentDate.getTime() - new Date().getTime()) <= TimeUnit.DAYS.toMillis(1);
|
boolean result = Math.abs(peersCurrentDate.getTime() - new Date().getTime()) <= TimeUnit.DAYS.toMillis(1);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
String msg = "Peers current date is further than 1 day off to our current date. " +
|
String msg = "Peers current date is further than 1 day off to our current date. " +
|
||||||
"PeersCurrentDate=" + peersCurrentDate + "; myCurrentDate=" + new Date();
|
"PeersCurrentDate=" + peersCurrentDate + "; myCurrentDate=" + new Date();
|
||||||
log.warn(msg);
|
throw new RuntimeException(msg);
|
||||||
errorMessageHandler.handleErrorMessage(msg);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,8 @@ import static bisq.core.util.Validator.nonEmptyStringOf;
|
|||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ProcessInitTradeRequest extends TradeTask {
|
public class ProcessInitTradeRequest extends TradeTask {
|
||||||
@SuppressWarnings({"unused"})
|
@SuppressWarnings({"unused"})
|
||||||
@ -128,6 +130,9 @@ public class ProcessInitTradeRequest extends TradeTask {
|
|||||||
multisigParticipant.setAccountAgeWitnessSignature(request.getAccountAgeWitnessSignatureOfOfferId());
|
multisigParticipant.setAccountAgeWitnessSignature(request.getAccountAgeWitnessSignatureOfOfferId());
|
||||||
multisigParticipant.setCurrentDate(request.getCurrentDate());
|
multisigParticipant.setCurrentDate(request.getCurrentDate());
|
||||||
|
|
||||||
|
// check peer's current date
|
||||||
|
processModel.getAccountAgeWitnessService().verifyPeersCurrentDate(new Date(multisigParticipant.getCurrentDate()));
|
||||||
|
|
||||||
// check trade amount
|
// check trade amount
|
||||||
checkArgument(request.getTradeAmount() > 0);
|
checkArgument(request.getTradeAmount() > 0);
|
||||||
trade.setAmount(Coin.valueOf(request.getTradeAmount()));
|
trade.setAmount(Coin.valueOf(request.getTradeAmount()));
|
||||||
|
@ -74,12 +74,8 @@ public class VerifyPeersAccountAgeWitness extends TradeTask {
|
|||||||
byte[] nonce = checkNotNull(tradingPeer.getAccountAgeWitnessNonce());
|
byte[] nonce = checkNotNull(tradingPeer.getAccountAgeWitnessNonce());
|
||||||
byte[] signature = checkNotNull(tradingPeer.getAccountAgeWitnessSignature());
|
byte[] signature = checkNotNull(tradingPeer.getAccountAgeWitnessSignature());
|
||||||
AtomicReference<String> errorMsg = new AtomicReference<>();
|
AtomicReference<String> errorMsg = new AtomicReference<>();
|
||||||
long currentDateAsLong = tradingPeer.getCurrentDate();
|
|
||||||
// In case the peer has an older version we get 0, so we use our time instead
|
|
||||||
Date peersCurrentDate = currentDateAsLong > 0 ? new Date(currentDateAsLong) : new Date();
|
|
||||||
boolean isValid = accountAgeWitnessService.verifyAccountAgeWitness(trade,
|
boolean isValid = accountAgeWitnessService.verifyAccountAgeWitness(trade,
|
||||||
peersPaymentAccountPayload,
|
peersPaymentAccountPayload,
|
||||||
peersCurrentDate,
|
|
||||||
peersPubKeyRing,
|
peersPubKeyRing,
|
||||||
nonce,
|
nonce,
|
||||||
signature,
|
signature,
|
||||||
|
Loading…
Reference in New Issue
Block a user