use of bisq.common.crypto.SealedAndSigned 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.SealedAndSigned 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