mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 23:18:17 +01:00
Refactorings, add decryption to crypt test at startup
This commit is contained in:
parent
8037c33e79
commit
6721131ccf
9 changed files with 30 additions and 19 deletions
|
@ -32,12 +32,13 @@ public final class DepositTxPublishedMessage extends TradeMessage implements Mai
|
||||||
|
|
||||||
public final byte[] depositTx;
|
public final byte[] depositTx;
|
||||||
private final NodeAddress senderNodeAddress;
|
private final NodeAddress senderNodeAddress;
|
||||||
private final String uid = UUID.randomUUID().toString();
|
private final String uid;
|
||||||
|
|
||||||
public DepositTxPublishedMessage(String tradeId, byte[] depositTx, NodeAddress senderNodeAddress) {
|
public DepositTxPublishedMessage(String tradeId, byte[] depositTx, NodeAddress senderNodeAddress) {
|
||||||
super(tradeId);
|
super(tradeId);
|
||||||
this.depositTx = depositTx;
|
this.depositTx = depositTx;
|
||||||
this.senderNodeAddress = senderNodeAddress;
|
this.senderNodeAddress = senderNodeAddress;
|
||||||
|
uid = UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -31,12 +31,13 @@ public final class FiatTransferStartedMessage extends TradeMessage implements Ma
|
||||||
|
|
||||||
public final String buyerPayoutAddress;
|
public final String buyerPayoutAddress;
|
||||||
private final NodeAddress senderNodeAddress;
|
private final NodeAddress senderNodeAddress;
|
||||||
private final String uid = UUID.randomUUID().toString();
|
private final String uid;
|
||||||
|
|
||||||
public FiatTransferStartedMessage(String tradeId, String buyerPayoutAddress, NodeAddress senderNodeAddress) {
|
public FiatTransferStartedMessage(String tradeId, String buyerPayoutAddress, NodeAddress senderNodeAddress) {
|
||||||
super(tradeId);
|
super(tradeId);
|
||||||
this.buyerPayoutAddress = buyerPayoutAddress;
|
this.buyerPayoutAddress = buyerPayoutAddress;
|
||||||
this.senderNodeAddress = senderNodeAddress;
|
this.senderNodeAddress = senderNodeAddress;
|
||||||
|
uid = UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -34,7 +34,7 @@ public final class FinalizePayoutTxRequest extends TradeMessage implements Mailb
|
||||||
public final String sellerPayoutAddress;
|
public final String sellerPayoutAddress;
|
||||||
public final long lockTimeAsBlockHeight;
|
public final long lockTimeAsBlockHeight;
|
||||||
private final NodeAddress senderNodeAddress;
|
private final NodeAddress senderNodeAddress;
|
||||||
private final String uid = UUID.randomUUID().toString();
|
private final String uid;
|
||||||
|
|
||||||
public FinalizePayoutTxRequest(String tradeId,
|
public FinalizePayoutTxRequest(String tradeId,
|
||||||
byte[] sellerSignature,
|
byte[] sellerSignature,
|
||||||
|
@ -46,6 +46,7 @@ public final class FinalizePayoutTxRequest extends TradeMessage implements Mailb
|
||||||
this.sellerPayoutAddress = sellerPayoutAddress;
|
this.sellerPayoutAddress = sellerPayoutAddress;
|
||||||
this.lockTimeAsBlockHeight = lockTimeAsBlockHeight;
|
this.lockTimeAsBlockHeight = lockTimeAsBlockHeight;
|
||||||
this.senderNodeAddress = senderNodeAddress;
|
this.senderNodeAddress = senderNodeAddress;
|
||||||
|
uid = UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -47,7 +47,7 @@ public final class PayDepositRequest extends TradeMessage implements MailboxMess
|
||||||
public final ArrayList<NodeAddress> acceptedArbitratorNodeAddresses;
|
public final ArrayList<NodeAddress> acceptedArbitratorNodeAddresses;
|
||||||
public final NodeAddress arbitratorNodeAddress;
|
public final NodeAddress arbitratorNodeAddress;
|
||||||
private final NodeAddress senderNodeAddress;
|
private final NodeAddress senderNodeAddress;
|
||||||
private final String uid = UUID.randomUUID().toString();
|
private final String uid;
|
||||||
|
|
||||||
public PayDepositRequest(NodeAddress senderNodeAddress,
|
public PayDepositRequest(NodeAddress senderNodeAddress,
|
||||||
String tradeId,
|
String tradeId,
|
||||||
|
@ -77,6 +77,7 @@ public final class PayDepositRequest extends TradeMessage implements MailboxMess
|
||||||
this.takeOfferFeeTxId = takeOfferFeeTxId;
|
this.takeOfferFeeTxId = takeOfferFeeTxId;
|
||||||
this.acceptedArbitratorNodeAddresses = acceptedArbitratorNodeAddresses;
|
this.acceptedArbitratorNodeAddresses = acceptedArbitratorNodeAddresses;
|
||||||
this.arbitratorNodeAddress = arbitratorNodeAddress;
|
this.arbitratorNodeAddress = arbitratorNodeAddress;
|
||||||
|
uid = UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,12 +32,13 @@ public final class PayoutTxFinalizedMessage extends TradeMessage implements Mail
|
||||||
|
|
||||||
public final byte[] payoutTx;
|
public final byte[] payoutTx;
|
||||||
private final NodeAddress senderNodeAddress;
|
private final NodeAddress senderNodeAddress;
|
||||||
private final String uid = UUID.randomUUID().toString();
|
private final String uid;
|
||||||
|
|
||||||
public PayoutTxFinalizedMessage(String tradeId, byte[] payoutTx, NodeAddress senderNodeAddress) {
|
public PayoutTxFinalizedMessage(String tradeId, byte[] payoutTx, NodeAddress senderNodeAddress) {
|
||||||
super(tradeId);
|
super(tradeId);
|
||||||
this.payoutTx = payoutTx;
|
this.payoutTx = payoutTx;
|
||||||
this.senderNodeAddress = senderNodeAddress;
|
this.senderNodeAddress = senderNodeAddress;
|
||||||
|
uid = UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -35,9 +35,7 @@ import io.bitsquare.btc.pricefeed.PriceFeed;
|
||||||
import io.bitsquare.common.Clock;
|
import io.bitsquare.common.Clock;
|
||||||
import io.bitsquare.common.Timer;
|
import io.bitsquare.common.Timer;
|
||||||
import io.bitsquare.common.UserThread;
|
import io.bitsquare.common.UserThread;
|
||||||
import io.bitsquare.common.crypto.CryptoException;
|
import io.bitsquare.common.crypto.*;
|
||||||
import io.bitsquare.common.crypto.Encryption;
|
|
||||||
import io.bitsquare.common.crypto.KeyRing;
|
|
||||||
import io.bitsquare.common.util.Utilities;
|
import io.bitsquare.common.util.Utilities;
|
||||||
import io.bitsquare.gui.Navigation;
|
import io.bitsquare.gui.Navigation;
|
||||||
import io.bitsquare.gui.common.model.ViewModel;
|
import io.bitsquare.gui.common.model.ViewModel;
|
||||||
|
@ -56,6 +54,7 @@ import io.bitsquare.p2p.P2PServiceListener;
|
||||||
import io.bitsquare.p2p.network.CloseConnectionReason;
|
import io.bitsquare.p2p.network.CloseConnectionReason;
|
||||||
import io.bitsquare.p2p.network.Connection;
|
import io.bitsquare.p2p.network.Connection;
|
||||||
import io.bitsquare.p2p.network.ConnectionListener;
|
import io.bitsquare.p2p.network.ConnectionListener;
|
||||||
|
import io.bitsquare.p2p.peers.keepalive.messages.Ping;
|
||||||
import io.bitsquare.payment.OKPayAccount;
|
import io.bitsquare.payment.OKPayAccount;
|
||||||
import io.bitsquare.trade.Trade;
|
import io.bitsquare.trade.Trade;
|
||||||
import io.bitsquare.trade.TradeManager;
|
import io.bitsquare.trade.TradeManager;
|
||||||
|
@ -467,9 +466,16 @@ public class MainViewModel implements ViewModel {
|
||||||
try {
|
try {
|
||||||
log.trace("Run crypto test");
|
log.trace("Run crypto test");
|
||||||
// just use any simple dummy msg
|
// just use any simple dummy msg
|
||||||
Encryption.encryptHybridWithSignature(new io.bitsquare.p2p.peers.keepalive.messages.Ping(0, 0),
|
io.bitsquare.p2p.peers.keepalive.messages.Ping payload = new Ping(1, 1);
|
||||||
|
SealedAndSigned sealedAndSigned = Encryption.encryptHybridWithSignature(payload,
|
||||||
keyRing.getSignatureKeyPair(), keyRing.getPubKeyRing().getEncryptionPubKey());
|
keyRing.getSignatureKeyPair(), keyRing.getPubKeyRing().getEncryptionPubKey());
|
||||||
log.trace("Crypto test succeeded");
|
DecryptedDataTuple tuple = Encryption.decryptHybridWithSignature(sealedAndSigned, keyRing.getEncryptionKeyPair().getPrivate());
|
||||||
|
if (tuple.payload instanceof Ping &&
|
||||||
|
((Ping) tuple.payload).nonce == payload.nonce &&
|
||||||
|
((Ping) tuple.payload).lastRoundTripTime == payload.lastRoundTripTime)
|
||||||
|
log.trace("Crypto test succeeded");
|
||||||
|
else
|
||||||
|
throw new CryptoException("Payload not correct after decryption");
|
||||||
} catch (CryptoException e) {
|
} catch (CryptoException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
String msg = "Seems that you use a self compiled binary and have not following the build " +
|
String msg = "Seems that you use a self compiled binary and have not following the build " +
|
||||||
|
|
|
@ -21,7 +21,6 @@ import io.bitsquare.common.crypto.*;
|
||||||
import io.bitsquare.p2p.Message;
|
import io.bitsquare.p2p.Message;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.security.KeyPair;
|
|
||||||
|
|
||||||
public class EncryptionService {
|
public class EncryptionService {
|
||||||
private final KeyRing keyRing;
|
private final KeyRing keyRing;
|
||||||
|
@ -32,8 +31,7 @@ public class EncryptionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SealedAndSigned encryptAndSign(PubKeyRing pubKeyRing, Message message) throws CryptoException {
|
public SealedAndSigned encryptAndSign(PubKeyRing pubKeyRing, Message message) throws CryptoException {
|
||||||
KeyPair signatureKeyPair = keyRing.getSignatureKeyPair();
|
return Encryption.encryptHybridWithSignature(message, keyRing.getSignatureKeyPair(), pubKeyRing.getEncryptionPubKey());
|
||||||
return Encryption.encryptHybridWithSignature(message, signatureKeyPair, pubKeyRing.getEncryptionPubKey());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DecryptedMsgWithPubKey decryptAndVerify(SealedAndSigned sealedAndSigned) throws CryptoException {
|
public DecryptedMsgWithPubKey decryptAndVerify(SealedAndSigned sealedAndSigned) throws CryptoException {
|
||||||
|
|
|
@ -348,9 +348,9 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||||
log.info("Wrong receiverAddressMaskHash. The message is not intended for us.");
|
log.info("Wrong receiverAddressMaskHash. The message is not intended for us.");
|
||||||
}
|
}
|
||||||
} catch (CryptoException e) {
|
} catch (CryptoException e) {
|
||||||
log.warn(message.toString());
|
log.info(message.toString());
|
||||||
log.warn(e.toString());
|
log.info(e.toString());
|
||||||
log.warn("Decryption of SealedAndSignedMessage failed. " +
|
log.info("Decryption of prefixedSealedAndSignedMessage.sealedAndSigned failed. " +
|
||||||
"That is expected if the message is not intended for us.");
|
"That is expected if the message is not intended for us.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -416,6 +416,8 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||||
});
|
});
|
||||||
} catch (CryptoException e) {
|
} catch (CryptoException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error(message.toString());
|
||||||
|
log.error(e.toString());
|
||||||
sendDirectMessageListener.onFault();
|
sendDirectMessageListener.onFault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -450,8 +452,9 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
|
||||||
"decryptedMsgWithPubKey.message=", decryptedMsgWithPubKey.message);
|
"decryptedMsgWithPubKey.message=", decryptedMsgWithPubKey.message);
|
||||||
}
|
}
|
||||||
} catch (CryptoException e) {
|
} catch (CryptoException e) {
|
||||||
log.trace("Decryption of SealedAndSignedMessage failed. " +
|
log.info(e.toString());
|
||||||
"That is expected if the message is not intended for us. " + e.getMessage());
|
log.info("Decryption of prefixedSealedAndSignedMessage.sealedAndSigned failed. " +
|
||||||
|
"That is expected if the message is not intended for us.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.info("Wrong blurredAddressHash. The message is not intended for us.");
|
log.info("Wrong blurredAddressHash. The message is not intended for us.");
|
||||||
|
|
|
@ -20,5 +20,4 @@ package io.bitsquare.p2p.messaging;
|
||||||
import io.bitsquare.p2p.Message;
|
import io.bitsquare.p2p.Message;
|
||||||
|
|
||||||
public interface DirectMessage extends Message {
|
public interface DirectMessage extends Message {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue