Update bouncycastle, cleanup, renamings

This commit is contained in:
Manfred Karrer 2015-11-02 01:57:00 +01:00
parent 07a9c7fd52
commit 3711519e3a
26 changed files with 267 additions and 210 deletions

View file

@ -30,7 +30,7 @@ import io.bitsquare.p2p.Address;
import io.bitsquare.p2p.Message;
import io.bitsquare.p2p.P2PService;
import io.bitsquare.p2p.P2PServiceListener;
import io.bitsquare.p2p.messaging.DecryptedMessageWithPubKey;
import io.bitsquare.p2p.messaging.DecryptedMsgWithPubKey;
import io.bitsquare.p2p.messaging.SendMailboxMessageListener;
import io.bitsquare.storage.Storage;
import io.bitsquare.trade.Contract;
@ -68,8 +68,8 @@ public class DisputeManager {
transient private final ObservableList<Dispute> disputesObservableList;
private final String disputeInfo;
private final P2PServiceListener p2PServiceListener;
private final List<DecryptedMessageWithPubKey> decryptedMailboxMessageWithPubKeys = new CopyOnWriteArrayList<>();
private final List<DecryptedMessageWithPubKey> decryptedMailMessageWithPubKeys = new CopyOnWriteArrayList<>();
private final List<DecryptedMsgWithPubKey> decryptedMailboxMessageWithPubKeys = new CopyOnWriteArrayList<>();
private final List<DecryptedMsgWithPubKey> decryptedMailMessageWithPubKeys = new CopyOnWriteArrayList<>();
///////////////////////////////////////////////////////////////////////////////////////////

View file

@ -8,25 +8,25 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.crypto.params.KeyParameter;
//TODO
//TODO: Borrowed form BitcoinJ/Lighthouse. Remove Protos dependency, check complete code logic.
public class ScryptUtil {
private static final Logger log = LoggerFactory.getLogger(ScryptUtil.class);
public ScryptUtil() {
}
public static final Protos.ScryptParameters SCRYPT_PARAMETERS = Protos.ScryptParameters.newBuilder()
.setP(6)
.setR(8)
.setN(32768)
.setSalt(ByteString.copyFrom(KeyCrypterScrypt.randomSalt()))
.build();
public interface ScryptKeyDerivationResultHandler {
public interface DeriveKeyResultHandler {
void handleResult(KeyParameter aesKey);
}
public static void deriveKeyWithScrypt(KeyCrypterScrypt keyCrypterScrypt, String password, ScryptKeyDerivationResultHandler resultHandler) {
public static KeyCrypterScrypt getKeyCrypterScrypt() {
Protos.ScryptParameters scryptParameters = Protos.ScryptParameters.newBuilder()
.setP(6)
.setR(8)
.setN(32768)
.setSalt(ByteString.copyFrom(KeyCrypterScrypt.randomSalt()))
.build();
return new KeyCrypterScrypt(scryptParameters);
}
public static void deriveKeyWithScrypt(KeyCrypterScrypt keyCrypterScrypt, String password, DeriveKeyResultHandler resultHandler) {
new Thread(() -> {
log.info("Doing key derivation");

View file

@ -30,7 +30,7 @@ import io.bitsquare.common.crypto.KeyRing;
import io.bitsquare.common.taskrunner.Model;
import io.bitsquare.p2p.Address;
import io.bitsquare.p2p.P2PService;
import io.bitsquare.p2p.messaging.DecryptedMessageWithPubKey;
import io.bitsquare.p2p.messaging.DecryptedMsgWithPubKey;
import io.bitsquare.storage.Storage;
import io.bitsquare.trade.offer.Offer;
import io.bitsquare.trade.offer.OpenOfferManager;
@ -149,7 +149,7 @@ abstract public class Trade implements Tradable, Model, Serializable {
private final ProcessModel processModel;
// Mutable
private DecryptedMessageWithPubKey decryptedMessageWithPubKey;
private DecryptedMsgWithPubKey decryptedMsgWithPubKey;
private Date takeOfferDate = new Date(0); // in some error cases the date is not set and cause null pointers, so we set a default
protected State state;
@ -236,8 +236,8 @@ abstract public class Trade implements Tradable, Model, Serializable {
tradeProtocol.checkPayoutTxTimeLock(this);
if (decryptedMessageWithPubKey != null) {
tradeProtocol.applyMailboxMessage(decryptedMessageWithPubKey, this);
if (decryptedMsgWithPubKey != null) {
tradeProtocol.applyMailboxMessage(decryptedMsgWithPubKey, this);
}
}
@ -280,13 +280,13 @@ abstract public class Trade implements Tradable, Model, Serializable {
return depositTx;
}
public void setMailboxMessage(DecryptedMessageWithPubKey decryptedMessageWithPubKey) {
log.trace("setMailboxMessage " + decryptedMessageWithPubKey);
this.decryptedMessageWithPubKey = decryptedMessageWithPubKey;
public void setMailboxMessage(DecryptedMsgWithPubKey decryptedMsgWithPubKey) {
log.trace("setMailboxMessage " + decryptedMsgWithPubKey);
this.decryptedMsgWithPubKey = decryptedMsgWithPubKey;
}
public DecryptedMessageWithPubKey getMailboxMessage() {
return decryptedMessageWithPubKey;
public DecryptedMsgWithPubKey getMailboxMessage() {
return decryptedMsgWithPubKey;
}
public void setStorage(Storage<? extends TradableList> storage) {
@ -618,7 +618,7 @@ abstract public class Trade implements Tradable, Model, Serializable {
", date=" + takeOfferDate +
", processModel=" + processModel +
", processState=" + state +
", messageWithPubKey=" + decryptedMessageWithPubKey +
", messageWithPubKey=" + decryptedMsgWithPubKey +
", depositTx=" + depositTx +
/* ", contract=" + contract +
", contractAsJson='" + contractAsJson + '\'' +*/

View file

@ -31,7 +31,7 @@ import io.bitsquare.p2p.P2PService;
import io.bitsquare.p2p.P2PServiceListener;
import io.bitsquare.p2p.messaging.DecryptedMailListener;
import io.bitsquare.p2p.messaging.DecryptedMailboxListener;
import io.bitsquare.p2p.messaging.DecryptedMessageWithPubKey;
import io.bitsquare.p2p.messaging.DecryptedMsgWithPubKey;
import io.bitsquare.storage.Storage;
import io.bitsquare.trade.closed.ClosedTradableManager;
import io.bitsquare.trade.failed.FailedTradesManager;
@ -114,8 +114,8 @@ public class TradeManager {
p2PService.addDecryptedMailListener(new DecryptedMailListener() {
@Override
public void onMailMessage(DecryptedMessageWithPubKey decryptedMessageWithPubKey, Address peerAddress) {
Message message = decryptedMessageWithPubKey.message;
public void onMailMessage(DecryptedMsgWithPubKey decryptedMsgWithPubKey, Address peerAddress) {
Message message = decryptedMsgWithPubKey.message;
// Handler for incoming initial messages from taker
if (message instanceof PayDepositRequest) {
@ -126,10 +126,10 @@ public class TradeManager {
});
p2PService.addDecryptedMailboxListener(new DecryptedMailboxListener() {
@Override
public void onMailboxMessageAdded(DecryptedMessageWithPubKey decryptedMessageWithPubKey, Address senderAddress) {
log.trace("onMailboxMessageAdded decryptedMessageWithPubKey: " + decryptedMessageWithPubKey);
public void onMailboxMessageAdded(DecryptedMsgWithPubKey decryptedMsgWithPubKey, Address senderAddress) {
log.trace("onMailboxMessageAdded decryptedMessageWithPubKey: " + decryptedMsgWithPubKey);
log.trace("onMailboxMessageAdded senderAddress: " + senderAddress);
Message message = decryptedMessageWithPubKey.message;
Message message = decryptedMsgWithPubKey.message;
if (message instanceof PayDepositRequest) {
//TODO is that used????
PayDepositRequest payDepositRequest = (PayDepositRequest) message;
@ -143,7 +143,7 @@ public class TradeManager {
String tradeId = ((TradeMessage) message).tradeId;
Optional<Trade> tradeOptional = trades.stream().filter(e -> e.getId().equals(tradeId)).findAny();
if (tradeOptional.isPresent())
tradeOptional.get().setMailboxMessage(decryptedMessageWithPubKey);
tradeOptional.get().setMailboxMessage(decryptedMsgWithPubKey);
}
}
});
@ -203,7 +203,7 @@ public class TradeManager {
initTrade(trade);
// after we are authenticated we remove mailbox messages.
DecryptedMessageWithPubKey mailboxMessage = trade.getMailboxMessage();
DecryptedMsgWithPubKey mailboxMessage = trade.getMailboxMessage();
if (mailboxMessage != null) {
p2PService.removeEntryFromMailbox(mailboxMessage);
trade.setMailboxMessage(null);

View file

@ -22,7 +22,7 @@ import io.bitsquare.common.crypto.PubKeyRing;
import io.bitsquare.p2p.Address;
import io.bitsquare.p2p.Message;
import io.bitsquare.p2p.messaging.DecryptedMailListener;
import io.bitsquare.p2p.messaging.DecryptedMessageWithPubKey;
import io.bitsquare.p2p.messaging.DecryptedMsgWithPubKey;
import io.bitsquare.trade.OffererTrade;
import io.bitsquare.trade.TakerTrade;
import io.bitsquare.trade.Trade;
@ -94,10 +94,10 @@ public abstract class TradeProtocol {
}
public void applyMailboxMessage(DecryptedMessageWithPubKey decryptedMessageWithPubKey, Trade trade) {
log.debug("applyMailboxMessage " + decryptedMessageWithPubKey.message);
if (decryptedMessageWithPubKey.signaturePubKey.equals(processModel.tradingPeer.getPubKeyRing().getSignaturePubKey()))
doApplyMailboxMessage(decryptedMessageWithPubKey.message, trade);
public void applyMailboxMessage(DecryptedMsgWithPubKey decryptedMsgWithPubKey, Trade trade) {
log.debug("applyMailboxMessage " + decryptedMsgWithPubKey.message);
if (decryptedMsgWithPubKey.signaturePubKey.equals(processModel.tradingPeer.getPubKeyRing().getSignaturePubKey()))
doApplyMailboxMessage(decryptedMsgWithPubKey.message, trade);
else
log.error("SignaturePubKey in message does not match the SignaturePubKey we have stored to that trading peer.");
}