use of bisq.common.crypto.CryptoException in project bisq-core by bisq-network.
the class IssuanceService method getRevealedVotes.
private Set<RevealedVote> getRevealedVotes(Map<String, SecretKey> secretKeysByTxIdMap, Set<BlindVoteWithRevealTxId> blindVoteWithRevealTxIdSet) {
return blindVoteWithRevealTxIdSet.stream().map(blindVoteWithRevealTxId -> {
try {
// TODO check if cloning here is needed (we might want to keep the blindVote separated from the
// blindVoteList to the RevealedVote...)
final BlindVote blindVote = BlindVote.clone(blindVoteWithRevealTxId.getBlindVote());
final byte[] encryptedProposalList = blindVote.getEncryptedProposalList();
final SecretKey secretKey = secretKeysByTxIdMap.get(blindVoteWithRevealTxId.getTxId());
final byte[] decrypted = Encryption.decrypt(encryptedProposalList, secretKey);
// TODO move to ProposalList
final PB.PersistableEnvelope envelope = PB.PersistableEnvelope.parseFrom(decrypted);
ProposalList proposalList = ProposalList.fromProto(envelope.getProposalList());
return new RevealedVote(proposalList, blindVote);
} catch (CryptoException e) {
e.printStackTrace();
return null;
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toSet());
}
use of bisq.common.crypto.CryptoException in project bisq-core by bisq-network.
the class AccountAgeWitnessServiceTest method testIsTradeDateAfterReleaseDate.
@Test
public void testIsTradeDateAfterReleaseDate() throws CryptoException {
Date ageWitnessReleaseDate = new GregorianCalendar(2017, 9, 23).getTime();
Date tradeDate = new GregorianCalendar(2017, 10, 1).getTime();
assertTrue(service.isDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {
}));
tradeDate = new GregorianCalendar(2017, 9, 23).getTime();
assertTrue(service.isDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {
}));
tradeDate = new GregorianCalendar(2017, 9, 22, 0, 0, 1).getTime();
assertTrue(service.isDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {
}));
tradeDate = new GregorianCalendar(2017, 9, 22).getTime();
assertFalse(service.isDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {
}));
tradeDate = new GregorianCalendar(2017, 9, 21).getTime();
assertFalse(service.isDateAfterReleaseDate(tradeDate.getTime(), ageWitnessReleaseDate, errorMessage -> {
}));
}
use of bisq.common.crypto.CryptoException in project bisq-desktop by bisq-network.
the class MainViewModel method checkCryptoSetup.
private void checkCryptoSetup() {
BooleanProperty result = new SimpleBooleanProperty();
// We want to test if the client is compiled with the correct crypto provider (BountyCastle)
// and if the unlimited Strength for cryptographic keys is set.
// If users compile themselves they might miss that step and then would get an exception in the trade.
// To avoid that we add here at startup a sample encryption and signing to see if it don't causes an exception.
// See: https://github.com/bisq-network/exchange/blob/master/doc/build.md#7-enable-unlimited-strength-for-cryptographic-keys
Thread checkCryptoThread = new Thread() {
@Override
public void run() {
try {
Thread.currentThread().setName("checkCryptoThread");
log.trace("Run crypto test");
// just use any simple dummy msg
Ping payload = new Ping(1, 1);
SealedAndSigned sealedAndSigned = EncryptionService.encryptHybridWithSignature(payload, keyRing.getSignatureKeyPair(), keyRing.getPubKeyRing().getEncryptionPubKey());
DecryptedDataTuple tuple = encryptionService.decryptHybridWithSignature(sealedAndSigned, keyRing.getEncryptionKeyPair().getPrivate());
if (tuple.getNetworkEnvelope() instanceof Ping && ((Ping) tuple.getNetworkEnvelope()).getNonce() == payload.getNonce() && ((Ping) tuple.getNetworkEnvelope()).getLastRoundTripTime() == payload.getLastRoundTripTime()) {
log.debug("Crypto test succeeded");
if (Security.getProvider("BC") != null) {
UserThread.execute(() -> result.set(true));
} else {
throw new CryptoException("Security provider BountyCastle is not available.");
}
} else {
throw new CryptoException("Payload not correct after decryption");
}
} catch (CryptoException e) {
e.printStackTrace();
String msg = Res.get("popup.warning.cryptoTestFailed", e.getMessage());
log.error(msg);
UserThread.execute(() -> new Popup<>().warning(msg).useShutDownButton().useReportBugButton().show());
}
}
};
checkCryptoThread.start();
}
use of bisq.common.crypto.CryptoException in project bisq-desktop by bisq-network.
the class ActiveProposalsView method activate.
@Override
protected void activate() {
super.activate();
bsqWalletService.addBsqBalanceListener(this);
onUpdateBalances(bsqWalletService.getAvailableBalance(), bsqWalletService.getPendingBalance(), bsqWalletService.getLockedForVotingBalance(), bsqWalletService.getLockedInBondsBalance());
if (voteButton != null) {
voteButton.setOnAction(e -> {
Coin stake = bsqFormatter.parseToCoin(stakeInputTextField.getText());
// TODO show popup
try {
voteService.publishBlindVote(stake, new FutureCallback<Transaction>() {
@Override
public void onSuccess(@Nullable Transaction result) {
// TODO
}
@Override
public void onFailure(@NotNull Throwable t) {
// TODO
}
});
} catch (CryptoException e1) {
// TODO show error popup
e1.printStackTrace();
} catch (InsufficientBsqException e1) {
e1.printStackTrace();
} catch (WalletException e1) {
e1.printStackTrace();
} catch (TransactionVerificationException e1) {
e1.printStackTrace();
} catch (InsufficientMoneyException e1) {
e1.printStackTrace();
} catch (ChangeBelowDustException e1) {
e1.printStackTrace();
} catch (InvalidProtocolBufferException e1) {
e1.printStackTrace();
}
});
}
}
use of bisq.common.crypto.CryptoException in project bisq-core by bisq-network.
the class SetupUtils method checkCryptoSetup.
public static void checkCryptoSetup(KeyRing keyRing, EncryptionService encryptionService, ResultHandler resultHandler, Consumer<Throwable> errorHandler) {
// We want to test if the client is compiled with the correct crypto provider (BountyCastle)
// and if the unlimited Strength for cryptographic keys is set.
// If users compile themselves they might miss that step and then would get an exception in the trade.
// To avoid that we add here at startup a sample encryption and signing to see if it don't causes an exception.
// See: https://github.com/bisq-network/exchange/blob/master/doc/build.md#7-enable-unlimited-strength-for-cryptographic-keys
Thread checkCryptoThread = new Thread() {
@Override
public void run() {
try {
Thread.currentThread().setName("checkCryptoThread");
log.trace("Run crypto test");
// just use any simple dummy msg
Ping payload = new Ping(1, 1);
SealedAndSigned sealedAndSigned = EncryptionService.encryptHybridWithSignature(payload, keyRing.getSignatureKeyPair(), keyRing.getPubKeyRing().getEncryptionPubKey());
DecryptedDataTuple tuple = encryptionService.decryptHybridWithSignature(sealedAndSigned, keyRing.getEncryptionKeyPair().getPrivate());
if (tuple.getNetworkEnvelope() instanceof Ping && ((Ping) tuple.getNetworkEnvelope()).getNonce() == payload.getNonce() && ((Ping) tuple.getNetworkEnvelope()).getLastRoundTripTime() == payload.getLastRoundTripTime()) {
log.debug("Crypto test succeeded");
if (Security.getProvider("BC") != null) {
UserThread.execute(resultHandler::handleResult);
} else {
errorHandler.accept(new CryptoException("Security provider BountyCastle is not available."));
}
} else {
errorHandler.accept(new CryptoException("Payload not correct after decryption"));
}
} catch (CryptoException e) {
log.error(e.toString());
e.printStackTrace();
errorHandler.accept(e);
}
}
};
checkCryptoThread.start();
}
Aggregations