Search in sources :

Example 1 with DecryptedDataTuple

use of io.bisq.network.crypto.DecryptedDataTuple in project bisq-api by mrosseel.

the class MainViewModelHeadless 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);
            // TODO API probably should quit on this error
            // UserThread.execute(() -> new Popup<>().warning(msg)
            // .useShutDownButton()
            // .useReportBugButton()
            // .show());
            }
        }
    };
    checkCryptoThread.start();
}
Also used : DecryptedDataTuple(io.bisq.network.crypto.DecryptedDataTuple) Ping(io.bisq.network.p2p.peers.keepalive.messages.Ping) SealedAndSigned(io.bisq.common.crypto.SealedAndSigned) CryptoException(io.bisq.common.crypto.CryptoException) UserThread(io.bisq.common.UserThread)

Aggregations

UserThread (io.bisq.common.UserThread)1 CryptoException (io.bisq.common.crypto.CryptoException)1 SealedAndSigned (io.bisq.common.crypto.SealedAndSigned)1 DecryptedDataTuple (io.bisq.network.crypto.DecryptedDataTuple)1 Ping (io.bisq.network.p2p.peers.keepalive.messages.Ping)1