Remove accountSalt from trade messages and TradePeer

This commit is contained in:
Manfred Karrer 2017-09-25 12:47:09 -05:00
parent 952c0d00ad
commit efcc7ff05c
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46
11 changed files with 11 additions and 45 deletions

View File

@ -186,7 +186,6 @@ message PayDepositRequest {
NodeAddress arbitrator_node_address = 19;
NodeAddress mediator_node_address = 20;
string uid = 21;
bytes account_salt = 22;
}
message PublishDepositTxRequest {
@ -201,7 +200,6 @@ message PublishDepositTxRequest {
bytes maker_multi_sig_pub_key = 9;
NodeAddress sender_node_address = 10;
string uid = 11;
bytes account_salt = 12;
}
message DepositTxPublishedMessage {
@ -1167,7 +1165,6 @@ message TradingPeer {
repeated RawTransactionInput raw_transaction_inputs = 9;
int64 change_output_value = 10;
string change_output_address = 11;
bytes account_salt = 12;
}

View File

@ -46,8 +46,8 @@ public class AccountAgeWitnessService {
this.keyRing = keyRing;
}
public AccountAgeWitness getPaymentAccountWitness(PaymentAccount paymentAccount, Trade trade) throws CryptoException {
byte[] hash = getWitnessHash(paymentAccount);
public AccountAgeWitness getPaymentAccountWitness(PaymentAccountPayload paymentAccountPayload, Trade trade) throws CryptoException {
byte[] hash = getWitnessHash(paymentAccountPayload);
byte[] signature = Sig.sign(keyRing.getSignatureKeyPair().getPrivate(), hash);
long tradeDate = trade.getTakeOfferDate().getTime();
byte[] hashOfPubKey = Sha256Hash.hash(keyRing.getPubKeyRing().getSignaturePubKeyBytes());
@ -57,8 +57,8 @@ public class AccountAgeWitnessService {
tradeDate);
}
public byte[] getWitnessHash(PaymentAccount paymentAccount) {
return getWitnessHash(paymentAccount.getPaymentAccountPayload(), paymentAccount.getSalt());
public byte[] getWitnessHash(PaymentAccountPayload paymentAccountPayload) {
return getWitnessHash(paymentAccountPayload, paymentAccountPayload.getSalt());
}
public byte[] getWitnessHash(PaymentAccountPayload paymentAccountPayload, byte[] salt) {
@ -151,9 +151,8 @@ public class AccountAgeWitnessService {
}
public boolean verifyOffersAccountAgeWitness(PaymentAccountPayload paymentAccountPayload,
byte[] peersSalt,
byte[] offersWitness) {
byte[] witnessHash = getWitnessHash(paymentAccountPayload, peersSalt);
byte[] witnessHash = getWitnessHash(paymentAccountPayload, paymentAccountPayload.getSalt());
final boolean result = Arrays.equals(witnessHash, offersWitness);
if (!result)
log.warn("witnessHash is not matching peers offersWitness. " +

View File

@ -59,7 +59,6 @@ public final class PayDepositRequest extends TradeMessage {
private final NodeAddress arbitratorNodeAddress;
private final NodeAddress mediatorNodeAddress;
private final String uid;
private final byte[] accountSalt;
public PayDepositRequest(String tradeId,
NodeAddress senderNodeAddress,
@ -82,7 +81,6 @@ public final class PayDepositRequest extends TradeMessage {
NodeAddress arbitratorNodeAddress,
NodeAddress mediatorNodeAddress,
String uid,
byte[] accountSalt,
int messageVersion) {
super(messageVersion, tradeId);
this.senderNodeAddress = senderNodeAddress;
@ -105,7 +103,6 @@ public final class PayDepositRequest extends TradeMessage {
this.arbitratorNodeAddress = arbitratorNodeAddress;
this.mediatorNodeAddress = mediatorNodeAddress;
this.uid = uid;
this.accountSalt = accountSalt;
}
@ -138,8 +135,7 @@ public final class PayDepositRequest extends TradeMessage {
.map(NodeAddress::toProtoMessage).collect(Collectors.toList()))
.setArbitratorNodeAddress(arbitratorNodeAddress.toProtoMessage())
.setMediatorNodeAddress(mediatorNodeAddress.toProtoMessage())
.setUid(uid)
.setAccountSalt(ByteString.copyFrom(accountSalt));
.setUid(uid);
Optional.ofNullable(changeOutputAddress).ifPresent(builder::setChangeOutputAddress);
return getNetworkEnvelopeBuilder().setPayDepositRequest(builder).build();
}
@ -175,7 +171,6 @@ public final class PayDepositRequest extends TradeMessage {
NodeAddress.fromProto(proto.getArbitratorNodeAddress()),
NodeAddress.fromProto(proto.getMediatorNodeAddress()),
proto.getUid(),
proto.getAccountSalt().toByteArray(),
messageVersion);
}
@ -203,7 +198,6 @@ public final class PayDepositRequest extends TradeMessage {
",\n arbitratorNodeAddress=" + arbitratorNodeAddress +
",\n mediatorNodeAddress=" + mediatorNodeAddress +
",\n uid='" + uid + '\'' +
",\n accountSalt='" + Utilities.bytesAsHexString(accountSalt) + '\'' +
"\n} " + super.toString();
}
}

View File

@ -49,7 +49,6 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
private final List<RawTransactionInput> makerInputs;
private final NodeAddress senderNodeAddress;
private final String uid;
private final byte[] accountSalt;
public PublishDepositTxRequest(String tradeId,
PaymentAccountPayload makerPaymentAccountPayload,
@ -61,8 +60,7 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
byte[] preparedDepositTx,
List<RawTransactionInput> makerInputs,
NodeAddress senderNodeAddress,
String uid,
byte[] accountSalt) {
String uid) {
this(tradeId,
makerPaymentAccountPayload,
makerAccountId,
@ -74,7 +72,6 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
makerInputs,
senderNodeAddress,
uid,
accountSalt,
Version.getP2PMessageVersion());
}
@ -94,7 +91,6 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
List<RawTransactionInput> makerInputs,
NodeAddress senderNodeAddress,
String uid,
byte[] accountSalt,
int messageVersion) {
super(messageVersion, tradeId);
this.makerPaymentAccountPayload = makerPaymentAccountPayload;
@ -107,7 +103,6 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
this.makerInputs = makerInputs;
this.senderNodeAddress = senderNodeAddress;
this.uid = uid;
this.accountSalt = accountSalt;
}
@Override
@ -124,8 +119,7 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
.setPreparedDepositTx(ByteString.copyFrom(preparedDepositTx))
.addAllMakerInputs(makerInputs.stream().map(RawTransactionInput::toProtoMessage).collect(Collectors.toList()))
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
.setUid(uid)
.setAccountSalt(ByteString.copyFrom(accountSalt)))
.setUid(uid))
.build();
}
@ -145,7 +139,6 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
makerInputs,
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid(),
proto.getAccountSalt().toByteArray(),
messageVersion);
}
@ -163,7 +156,6 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
",\n makerInputs=" + makerInputs +
",\n senderNodeAddress=" + senderNodeAddress +
",\n uid='" + uid + '\'' +
",\n accountSalt='" + Utilities.bytesAsHexString(accountSalt) + '\'' +
"\n} " + super.toString();
}
}

View File

@ -60,8 +60,6 @@ public final class TradingPeer implements PersistablePayload {
private long changeOutputValue;
@Nullable
private String changeOutputAddress;
@Nullable
private byte[] accountSalt;
public TradingPeer() {
}
@ -80,7 +78,6 @@ public final class TradingPeer implements PersistablePayload {
Optional.ofNullable(multiSigPubKey).ifPresent(e -> builder.setMultiSigPubKey(ByteString.copyFrom(multiSigPubKey)));
Optional.ofNullable(rawTransactionInputs).ifPresent(e -> builder.addAllRawTransactionInputs(ProtoUtil.collectionToProto(rawTransactionInputs)));
Optional.ofNullable(changeOutputAddress).ifPresent(builder::setChangeOutputAddress);
Optional.ofNullable(accountSalt).ifPresent(e -> builder.setAccountSalt(ByteString.copyFrom(accountSalt)));
return builder.build();
}
@ -105,7 +102,6 @@ public final class TradingPeer implements PersistablePayload {
.collect(Collectors.toList());
tradingPeer.setRawTransactionInputs(rawTransactionInputs);
tradingPeer.setChangeOutputAddress(ProtoUtil.stringOrNullFromProto(proto.getChangeOutputAddress()));
tradingPeer.setAccountSalt(ProtoUtil.byteArrayOrNullFromProto(proto.getAccountSalt()));
return tradingPeer;
}
}

View File

@ -47,8 +47,6 @@ public class MakerProcessPayDepositRequest extends TradeTask {
checkTradeId(processModel.getOfferId(), payDepositRequest);
processModel.getTradingPeer().setPaymentAccountPayload(checkNotNull(payDepositRequest.getTakerPaymentAccountPayload()));
processModel.getTradingPeer().setAccountSalt(checkNotNull(payDepositRequest.getAccountSalt()));
processModel.getTradingPeer().setRawTransactionInputs(checkNotNull(payDepositRequest.getRawTransactionInputs()));
checkArgument(payDepositRequest.getRawTransactionInputs().size() > 0);

View File

@ -54,8 +54,6 @@ public class MakerSendPublishDepositTxRequest extends TradeTask {
addressEntryOptional.get().getPubKey()),
"makerMultiSigPubKey from AddressEntry must match the one from the trade data. trade id =" + id);
byte[] accountSalt = processModel.getPaymentAccountPayload(trade).getSalt();
PublishDepositTxRequest message = new PublishDepositTxRequest(
processModel.getOfferId(),
processModel.getPaymentAccountPayload(trade),
@ -67,8 +65,7 @@ public class MakerSendPublishDepositTxRequest extends TradeTask {
processModel.getPreparedDepositTx(),
processModel.getRawTransactionInputs(),
processModel.getMyNodeAddress(),
UUID.randomUUID().toString(),
accountSalt
UUID.randomUUID().toString()
);
trade.setState(Trade.State.MAKER_SENT_PUBLISH_DEPOSIT_TX_REQUEST);

View File

@ -45,7 +45,6 @@ public class TakerProcessPublishDepositTxRequest extends TradeTask {
checkNotNull(publishDepositTxRequest);
processModel.getTradingPeer().setPaymentAccountPayload(checkNotNull(publishDepositTxRequest.getMakerPaymentAccountPayload()));
processModel.getTradingPeer().setAccountSalt(checkNotNull(publishDepositTxRequest.getAccountSalt()));
processModel.getTradingPeer().setAccountId(nonEmptyStringOf(publishDepositTxRequest.getMakerAccountId()));
processModel.getTradingPeer().setMultiSigPubKey(checkNotNull(publishDepositTxRequest.getMakerMultiSigPubKey()));
processModel.getTradingPeer().setContractAsJson(nonEmptyStringOf(publishDepositTxRequest.getMakerContractAsJson()));

View File

@ -68,8 +68,6 @@ public class TakerSendPayDepositRequest extends TradeTask {
AddressEntry takerPayoutAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT);
String takerPayoutAddressString = takerPayoutAddressEntry.getAddressString();
byte[] accountSalt = processModel.getPaymentAccountPayload(trade).getSalt();
PayDepositRequest message = new PayDepositRequest(
processModel.getOfferId(),
processModel.getMyNodeAddress(),
@ -92,7 +90,6 @@ public class TakerSendPayDepositRequest extends TradeTask {
trade.getArbitratorNodeAddress(),
trade.getMediatorNodeAddress(),
UUID.randomUUID().toString(),
accountSalt,
Version.getP2PMessageVersion());
processModel.getP2PService().sendEncryptedDirectMessage(

View File

@ -44,16 +44,13 @@ public class TakerVerifyOffersAgeWitnessHash extends TradeTask {
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) {
extraDataMap.containsKey(OfferPayload.ACCOUNT_AGE_WITNESS)) {
final String offersWitness = extraDataMap.get(OfferPayload.ACCOUNT_AGE_WITNESS);
final PaymentAccountPayload paymentAccountPayload = checkNotNull(processModel.getTradingPeer().getPaymentAccountPayload()
, "Peers paymentAccountPayload must nto be null");
checkArgument(processModel.getAccountAgeWitnessService()
.verifyOffersAccountAgeWitness(paymentAccountPayload,
accountSalt,
Utilities.decodeFromHex(offersWitness)), "");
}
complete();

View File

@ -348,7 +348,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
String hashOfChallenge = null;
HashMap<String, String> extraDataMap = new HashMap<>();
byte[] hashOfPaymentAccount = accountAgeWitnessService.getWitnessHash(paymentAccount);
byte[] hashOfPaymentAccount = accountAgeWitnessService.getWitnessHash(paymentAccount.getPaymentAccountPayload());
extraDataMap.put(OfferPayload.ACCOUNT_AGE_WITNESS, Utilities.bytesAsHexString(hashOfPaymentAccount));
Coin buyerSecurityDepositAsCoin = buyerSecurityDeposit.get();