Search in sources :

Example 1 with CryptoException

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());
}
Also used : SecretKey(javax.crypto.SecretKey) PB(io.bisq.generated.protobuffer.PB) RevealedVote(bisq.core.dao.vote.RevealedVote) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) CryptoException(bisq.common.crypto.CryptoException) BlindVote(bisq.core.dao.vote.BlindVote) ProposalList(bisq.core.dao.proposal.ProposalList)

Example 2 with CryptoException

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 -> {
    }));
}
Also used : CryptoException(bisq.common.crypto.CryptoException) KeyPair(java.security.KeyPair) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Assert.assertTrue(org.junit.Assert.assertTrue) PublicKey(java.security.PublicKey) IOException(java.io.IOException) Test(org.junit.Test) KeyStoreException(java.security.KeyStoreException) CertificateException(java.security.cert.CertificateException) Ignore(org.junit.Ignore) Assert.assertFalse(org.junit.Assert.assertFalse) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) After(org.junit.After) Sig(bisq.common.crypto.Sig) Before(org.junit.Before) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 3 with CryptoException

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();
}
Also used : DecryptedDataTuple(bisq.network.crypto.DecryptedDataTuple) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Ping(bisq.network.p2p.peers.keepalive.messages.Ping) SealedAndSigned(bisq.common.crypto.SealedAndSigned) Popup(bisq.desktop.main.overlays.popups.Popup) CryptoException(bisq.common.crypto.CryptoException) UserThread(bisq.common.UserThread)

Example 4 with CryptoException

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();
            }
        });
    }
}
Also used : WalletException(bisq.core.btc.exceptions.WalletException) Coin(org.bitcoinj.core.Coin) Transaction(org.bitcoinj.core.Transaction) InsufficientBsqException(bisq.core.btc.wallet.InsufficientBsqException) TransactionVerificationException(bisq.core.btc.exceptions.TransactionVerificationException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) InsufficientMoneyException(org.bitcoinj.core.InsufficientMoneyException) CryptoException(bisq.common.crypto.CryptoException) ChangeBelowDustException(bisq.core.btc.wallet.ChangeBelowDustException)

Example 5 with CryptoException

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();
}
Also used : DecryptedDataTuple(bisq.network.crypto.DecryptedDataTuple) Ping(bisq.network.p2p.peers.keepalive.messages.Ping) SealedAndSigned(bisq.common.crypto.SealedAndSigned) CryptoException(bisq.common.crypto.CryptoException) UserThread(bisq.common.UserThread)

Aggregations

CryptoException (bisq.common.crypto.CryptoException)5 UserThread (bisq.common.UserThread)2 SealedAndSigned (bisq.common.crypto.SealedAndSigned)2 DecryptedDataTuple (bisq.network.crypto.DecryptedDataTuple)2 Ping (bisq.network.p2p.peers.keepalive.messages.Ping)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 Sig (bisq.common.crypto.Sig)1 TransactionVerificationException (bisq.core.btc.exceptions.TransactionVerificationException)1 WalletException (bisq.core.btc.exceptions.WalletException)1 ChangeBelowDustException (bisq.core.btc.wallet.ChangeBelowDustException)1 InsufficientBsqException (bisq.core.btc.wallet.InsufficientBsqException)1 ProposalList (bisq.core.dao.proposal.ProposalList)1 BlindVote (bisq.core.dao.vote.BlindVote)1 RevealedVote (bisq.core.dao.vote.RevealedVote)1 Popup (bisq.desktop.main.overlays.popups.Popup)1 PB (io.bisq.generated.protobuffer.PB)1 IOException (java.io.IOException)1 KeyPair (java.security.KeyPair)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1