Search in sources :

Example 1 with DecryptedDataTuple

use of bisq.network.crypto.DecryptedDataTuple 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 2 with DecryptedDataTuple

use of bisq.network.crypto.DecryptedDataTuple 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

UserThread (bisq.common.UserThread)2 CryptoException (bisq.common.crypto.CryptoException)2 SealedAndSigned (bisq.common.crypto.SealedAndSigned)2 DecryptedDataTuple (bisq.network.crypto.DecryptedDataTuple)2 Ping (bisq.network.p2p.peers.keepalive.messages.Ping)2 Popup (bisq.desktop.main.overlays.popups.Popup)1 BooleanProperty (javafx.beans.property.BooleanProperty)1 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)1