Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add payment account payload safeguards #5621

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ public AccountAgeWitness getNewWitness(PaymentAccountPayload paymentAccountPaylo

Optional<AccountAgeWitness> findWitness(PaymentAccountPayload paymentAccountPayload,
PubKeyRing pubKeyRing) {
if (paymentAccountPayload == null) {
return Optional.empty();
}

byte[] accountInputDataWithSalt = getAccountInputDataWithSalt(paymentAccountPayload);
byte[] hash = Hash.getSha256Ripemd160hash(Utilities.concatenateByteArrays(accountInputDataWithSalt,
pubKeyRing.getSignaturePubKeyBytes()));
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/bisq/core/filter/FilterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ public boolean requireUpdateToNewVersionForDAO() {

public boolean arePeersPaymentAccountDataBanned(PaymentAccountPayload paymentAccountPayload) {
return getFilter() != null &&
paymentAccountPayload != null &&
getFilter().getBannedPaymentAccounts().stream()
.filter(paymentAccountFilter -> paymentAccountFilter.getPaymentMethodId().equals(
paymentAccountPayload.getPaymentMethodId()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -84,14 +86,15 @@ private static boolean isBuyer(Dispute dispute) {
return buyerSigPubKeyHashAsHex.equals(traderSigPubKeyHashAsHex);
}

private static PayloadWithHolderName getPayloadWithHolderName(Dispute dispute) {
return (PayloadWithHolderName) getPaymentAccountPayload(dispute);
private static Optional<PayloadWithHolderName> getPayloadWithHolderName(Dispute dispute) {
Optional<PaymentAccountPayload> paymentAccountPayload = getPaymentAccountPayload(dispute);
return paymentAccountPayload.map(accountPayload -> (PayloadWithHolderName) accountPayload);
}

public static PaymentAccountPayload getPaymentAccountPayload(Dispute dispute) {
return isBuyer(dispute) ?
public static Optional<PaymentAccountPayload> getPaymentAccountPayload(Dispute dispute) {
return Optional.ofNullable(isBuyer(dispute) ?
dispute.getContract().getBuyerPaymentAccountPayload() :
dispute.getContract().getSellerPaymentAccountPayload();
dispute.getContract().getSellerPaymentAccountPayload());
}

public static String getAddress(Dispute dispute) {
Expand Down Expand Up @@ -146,7 +149,11 @@ public void detectMultipleHolderNames() {
String previous = suspiciousDisputesByTraderMap.toString();
getAllDisputesByTraderMap().forEach((key, value) -> {
Set<String> userNames = value.stream()
.map(dispute -> getPayloadWithHolderName(dispute).getHolderName())
.map(dispute -> {
Optional<PayloadWithHolderName> payloadWithHolderName = getPayloadWithHolderName(dispute);
return payloadWithHolderName.map(PayloadWithHolderName::getHolderName).orElse(null);
})
.filter(Objects::nonNull)
.collect(Collectors.toSet());
if (userNames.size() > 1) {
// As we compare previous results we need to make sorting deterministic
Expand Down Expand Up @@ -232,17 +239,20 @@ private String getReport(Collection<List<Dispute>> collectionOfDisputesOfTrader)
if (!DontShowAgainLookup.showAgain(ackKey)) {
ackSubString = "[ACK] ";
}
String holderName = getPayloadWithHolderName(dispute).getHolderName();
Optional<PayloadWithHolderName> payloadWithHolderName = getPayloadWithHolderName(dispute);
String holderName = payloadWithHolderName.isPresent() ? payloadWithHolderName.get().getHolderName() : "NA";
names.add(holderName);
boolean isBuyer = isBuyer(dispute);
isBuyerHashSet.add(isBuyer);
String isBuyerSubString = getIsBuyerSubString(isBuyer);
DisputeResult disputeResult = dispute.disputeResultProperty().get();
String summaryNotes = disputeResult != null ? disputeResult.getSummaryNotesProperty().get().trim() : "Not closed yet";
Optional<PaymentAccountPayload> paymentAccountPayload = getPaymentAccountPayload(dispute);
return ackSubString +
"Trade ID: '" + dispute.getShortTradeId() +
"'\n Account holder name: '" + holderName +
"'\n Payment method: '" + Res.get(getPaymentAccountPayload(dispute).getPaymentMethodId()) +
"'\n Payment method: '" + Res.get(paymentAccountPayload.isPresent() ?
paymentAccountPayload.get().getPaymentMethodId() : "NA") +
isBuyerSubString +
"'\n Summary: '" + summaryNotes;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,11 @@ private void addContent() {
nrOfDisputesAsBuyer + " / " + nrOfDisputesAsSeller);

addConfirmationLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("shared.paymentDetails", Res.get("shared.buyer")),
contract.getBuyerPaymentAccountPayload().getPaymentDetails()).second.setMouseTransparent(false);
contract.getBuyerPaymentAccountPayload() != null ?
contract.getBuyerPaymentAccountPayload().getPaymentDetails() : "NA").second.setMouseTransparent(false);
addConfirmationLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("shared.paymentDetails", Res.get("shared.seller")),
sellerPaymentAccountPayload.getPaymentDetails()).second.setMouseTransparent(false);
sellerPaymentAccountPayload != null ?
sellerPaymentAccountPayload.getPaymentDetails() : "NA").second.setMouseTransparent(false);

String title = "";
String agentKeyBaseUserName = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,10 @@ private void applyFilteredListPredicate(String filterString) {
if (contract != null) {
isBuyerOnion = contract.getBuyerNodeAddress().getFullAddress().contains(filterString);
isSellerOnion = contract.getSellerNodeAddress().getFullAddress().contains(filterString);
matchesBuyersPaymentAccountData = contract.getBuyerPaymentAccountPayload().getPaymentDetails().contains(filterString);
matchesSellersPaymentAccountData = contract.getSellerPaymentAccountPayload().getPaymentDetails().contains(filterString);
matchesBuyersPaymentAccountData = contract.getBuyerPaymentAccountPayload() != null &&
contract.getBuyerPaymentAccountPayload().getPaymentDetails().contains(filterString);
matchesSellersPaymentAccountData = contract.getSellerPaymentAccountPayload() != null &&
contract.getSellerPaymentAccountPayload().getPaymentDetails().contains(filterString);
}
return isBuyerOnion || isSellerOnion ||
matchesBuyersPaymentAccountData || matchesSellersPaymentAccountData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,10 @@ private void applyFilteredListPredicate(String filterString) {
if (contract != null) {
isBuyerOnion = contract.getBuyerNodeAddress().getFullAddress().contains(filterString);
isSellerOnion = contract.getSellerNodeAddress().getFullAddress().contains(filterString);
matchesBuyersPaymentAccountData = contract.getBuyerPaymentAccountPayload().getPaymentDetails().contains(filterString);
matchesSellersPaymentAccountData = contract.getSellerPaymentAccountPayload().getPaymentDetails().contains(filterString);
matchesBuyersPaymentAccountData = contract.getBuyerPaymentAccountPayload() != null &&
contract.getBuyerPaymentAccountPayload().getPaymentDetails().contains(filterString);
matchesSellersPaymentAccountData = contract.getSellerPaymentAccountPayload() != null &&
contract.getSellerPaymentAccountPayload().getPaymentDetails().contains(filterString);
}
return isBuyerOnion || isSellerOnion ||
matchesBuyersPaymentAccountData || matchesSellersPaymentAccountData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,18 @@ protected void addContent() {
// Not expected
myPaymentDetails = ((AssetsAccountPayload) myPaymentAccountPayload).getAddress();
}
peersPaymentDetails = ((AssetsAccountPayload) peersPaymentAccountPayload).getAddress();
peersPaymentDetails = peersPaymentAccountPayload != null ?
((AssetsAccountPayload) peersPaymentAccountPayload).getAddress() : "NA";
myTitle = Res.get("portfolio.pending.step3_seller.yourAddress", currencyName);
peersTitle = Res.get("portfolio.pending.step3_seller.buyersAddress", currencyName);
} else {
if (myPaymentDetails.isEmpty()) {
// Not expected
myPaymentDetails = myPaymentAccountPayload.getPaymentDetails();
myPaymentDetails = myPaymentAccountPayload != null ?
myPaymentAccountPayload.getPaymentDetails() : "NA";
}
peersPaymentDetails = peersPaymentAccountPayload.getPaymentDetails();
peersPaymentDetails = peersPaymentAccountPayload != null ?
peersPaymentAccountPayload.getPaymentDetails() : "NA";
myTitle = Res.get("portfolio.pending.step3_seller.yourAccount");
peersTitle = Res.get("portfolio.pending.step3_seller.buyersAccount");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,13 @@ protected FilterResult getFilterResult(Dispute dispute, String filterTerm) {
return FilterResult.SELLER_NODE_ADDRESS;
}

if (dispute.getContract().getBuyerPaymentAccountPayload().getPaymentDetails().toLowerCase().contains(filter)) {
if (dispute.getContract().getBuyerPaymentAccountPayload() != null &&
dispute.getContract().getBuyerPaymentAccountPayload().getPaymentDetails().toLowerCase().contains(filter)) {
return FilterResult.BUYER_ACCOUNT_DETAILS;
}

if (dispute.getContract().getSellerPaymentAccountPayload().getPaymentDetails().toLowerCase().contains(filter)) {
if (dispute.getContract().getSellerPaymentAccountPayload() != null &&
dispute.getContract().getSellerPaymentAccountPayload().getPaymentDetails().toLowerCase().contains(filter)) {
return FilterResult.SELLER_ACCOUNT_DETAILS;
}

Expand Down Expand Up @@ -780,11 +782,11 @@ private void showCompactReport() {
.append(")\n");

String buyerPaymentAccountPayload = Utilities.toTruncatedString(
contract.getBuyerPaymentAccountPayload().getPaymentDetails().
replace("\n", " ").replace(";", "."), 100);
contract.getBuyerPaymentAccountPayload() != null ? contract.getBuyerPaymentAccountPayload().getPaymentDetails().
replace("\n", " ").replace(";", ".") : "NA", 100);
String sellerPaymentAccountPayload = Utilities.toTruncatedString(
contract.getSellerPaymentAccountPayload().getPaymentDetails()
.replace("\n", " ").replace(";", "."), 100);
contract.getSellerPaymentAccountPayload() != null ? contract.getSellerPaymentAccountPayload().getPaymentDetails()
.replace("\n", " ").replace(";", ".") : "NA", 100);
String buyerNodeAddress = contract.getBuyerNodeAddress().getFullAddress();
String sellerNodeAddress = contract.getSellerNodeAddress().getFullAddress();
csvStringBuilder.append(currency).append(";")
Expand Down