Search in sources :

Example 6 with SecureString

use of com.sparrowwallet.drongo.SecureString in project sparrow by sparrowwallet.

the class HeadersController method signSoftwareKeystores.

private void signSoftwareKeystores() {
    if (headersForm.getSigningWallet().getKeystores().stream().noneMatch(Keystore::hasPrivateKey)) {
        return;
    }
    if (headersForm.getPsbt().isSigned()) {
        return;
    }
    Wallet copy = headersForm.getSigningWallet().copy();
    String walletId = headersForm.getAvailableWallets().get(headersForm.getSigningWallet()).getWalletId(headersForm.getSigningWallet());
    if (copy.isEncrypted()) {
        WalletPasswordDialog dlg = new WalletPasswordDialog(copy.getMasterName(), WalletPasswordDialog.PasswordRequirement.LOAD);
        Optional<SecureString> password = dlg.showAndWait();
        if (password.isPresent()) {
            Storage.DecryptWalletService decryptWalletService = new Storage.DecryptWalletService(copy, password.get());
            decryptWalletService.setOnSucceeded(workerStateEvent -> {
                EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.END, "Done"));
                Wallet decryptedWallet = decryptWalletService.getValue();
                signUnencryptedKeystores(decryptedWallet);
            });
            decryptWalletService.setOnFailed(workerStateEvent -> {
                EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.END, "Failed"));
                AppServices.showErrorDialog("Incorrect Password", decryptWalletService.getException().getMessage());
            });
            EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.START, "Decrypting wallet..."));
            decryptWalletService.start();
        }
    } else {
        signUnencryptedKeystores(copy);
    }
}
Also used : Storage(com.sparrowwallet.sparrow.io.Storage) SecureString(com.sparrowwallet.drongo.SecureString) SecureString(com.sparrowwallet.drongo.SecureString)

Example 7 with SecureString

use of com.sparrowwallet.drongo.SecureString in project sparrow by sparrowwallet.

the class WalletController method unlockWallet.

private void unlockWallet(CustomPasswordField passwordField) {
    if (walletEncryptedProperty.get()) {
        String walletId = walletForm.getWalletId();
        SecureString password = new SecureString(passwordField.getText());
        Storage.KeyDerivationService keyDerivationService = new Storage.KeyDerivationService(walletForm.getStorage(), password, true);
        keyDerivationService.setOnSucceeded(workerStateEvent -> {
            passwordField.clear();
            password.clear();
            EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.END, "Done"));
            unlockWallet();
        });
        keyDerivationService.setOnFailed(workerStateEvent -> {
            EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.END, "Failed"));
            if (keyDerivationService.getException() instanceof InvalidPasswordException) {
                showErrorDialog("Invalid Password", "The wallet password was invalid.");
            } else {
                log.error("Error deriving wallet key", keyDerivationService.getException());
            }
        });
        EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.START, "Decrypting wallet..."));
        keyDerivationService.start();
    } else {
        unlockWallet();
    }
}
Also used : Storage(com.sparrowwallet.sparrow.io.Storage) InvalidPasswordException(com.sparrowwallet.drongo.crypto.InvalidPasswordException) SecureString(com.sparrowwallet.drongo.SecureString) SecureString(com.sparrowwallet.drongo.SecureString)

Example 8 with SecureString

use of com.sparrowwallet.drongo.SecureString in project sparrow by sparrowwallet.

the class UtxosController method previewPremix.

public void previewPremix(Tx0Preview tx0Preview, List<UtxoEntry> utxoEntries) {
    Wallet wallet = getWalletForm().getWallet();
    String walletId = walletForm.getWalletId();
    if (wallet.isMasterWallet() && !wallet.isWhirlpoolMasterWallet() && wallet.isEncrypted()) {
        WalletPasswordDialog dlg = new WalletPasswordDialog(wallet.getMasterName(), WalletPasswordDialog.PasswordRequirement.LOAD);
        Optional<SecureString> password = dlg.showAndWait();
        if (password.isPresent()) {
            Storage.KeyDerivationService keyDerivationService = new Storage.KeyDerivationService(walletForm.getStorage(), password.get(), true);
            keyDerivationService.setOnSucceeded(workerStateEvent -> {
                EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.END, "Done"));
                ECKey encryptionFullKey = keyDerivationService.getValue();
                Key key = new Key(encryptionFullKey.getPrivKeyBytes(), walletForm.getStorage().getKeyDeriver().getSalt(), EncryptionType.Deriver.ARGON2);
                wallet.decrypt(key);
                try {
                    prepareWhirlpoolWallet(wallet);
                } finally {
                    wallet.encrypt(key);
                    for (Wallet childWallet : wallet.getChildWallets()) {
                        if (!childWallet.isNested() && !childWallet.isEncrypted()) {
                            childWallet.encrypt(key);
                        }
                    }
                    key.clear();
                    encryptionFullKey.clear();
                    password.get().clear();
                }
                previewPremix(wallet, tx0Preview, utxoEntries);
            });
            keyDerivationService.setOnFailed(workerStateEvent -> {
                EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.END, "Failed"));
                if (keyDerivationService.getException() instanceof InvalidPasswordException) {
                    Optional<ButtonType> optResponse = showErrorDialog("Invalid Password", "The wallet password was invalid. Try again?", ButtonType.CANCEL, ButtonType.OK);
                    if (optResponse.isPresent() && optResponse.get().equals(ButtonType.OK)) {
                        Platform.runLater(() -> previewPremix(tx0Preview, utxoEntries));
                    }
                } else {
                    log.error("Error deriving wallet key", keyDerivationService.getException());
                }
            });
            EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.START, "Decrypting wallet..."));
            keyDerivationService.start();
        }
    } else {
        if (wallet.isMasterWallet() && !wallet.isWhirlpoolMasterWallet()) {
            prepareWhirlpoolWallet(wallet);
        }
        previewPremix(wallet, tx0Preview, utxoEntries);
    }
}
Also used : SecureString(com.sparrowwallet.drongo.SecureString) Storage(com.sparrowwallet.sparrow.io.Storage) ButtonType(javafx.scene.control.ButtonType) SecureString(com.sparrowwallet.drongo.SecureString)

Example 9 with SecureString

use of com.sparrowwallet.drongo.SecureString in project sparrow by sparrowwallet.

the class PayNymController method broadcastNotificationTransaction.

public void broadcastNotificationTransaction(PayNym payNym) {
    Wallet masterWallet = getMasterWallet();
    WalletTransaction walletTransaction;
    try {
        walletTransaction = getWalletTransaction(masterWallet, payNym, new byte[80], null);
    } catch (InsufficientFundsException e) {
        try {
            Wallet wallet = AppServices.get().getWallet(walletId);
            walletTransaction = getWalletTransaction(wallet, payNym, new byte[80], null);
        } catch (InsufficientFundsException e2) {
            AppServices.showErrorDialog("Insufficient Funds", "There are not enough funds in this wallet to broadcast the notification transaction.");
            followingList.refresh();
            return;
        }
    }
    final WalletTransaction walletTx = walletTransaction;
    final PaymentCode paymentCode = masterWallet.getPaymentCode();
    Wallet wallet = walletTransaction.getWallet();
    Storage storage = AppServices.get().getOpenWallets().get(wallet);
    if (wallet.isEncrypted()) {
        WalletPasswordDialog dlg = new WalletPasswordDialog(wallet.getMasterName(), WalletPasswordDialog.PasswordRequirement.LOAD);
        Optional<SecureString> password = dlg.showAndWait();
        if (password.isPresent()) {
            Storage.DecryptWalletService decryptWalletService = new Storage.DecryptWalletService(wallet.copy(), password.get());
            decryptWalletService.setOnSucceeded(workerStateEvent -> {
                EventManager.get().post(new StorageEvent(storage.getWalletId(wallet), TimedEvent.Action.END, "Done"));
                Wallet decryptedWallet = decryptWalletService.getValue();
                broadcastNotificationTransaction(decryptedWallet, walletTx, paymentCode, payNym);
                decryptedWallet.clearPrivate();
            });
            decryptWalletService.setOnFailed(workerStateEvent -> {
                EventManager.get().post(new StorageEvent(storage.getWalletId(wallet), TimedEvent.Action.END, "Failed"));
                followingList.refresh();
                AppServices.showErrorDialog("Incorrect Password", decryptWalletService.getException().getMessage());
            });
            EventManager.get().post(new StorageEvent(storage.getWalletId(wallet), TimedEvent.Action.START, "Decrypting wallet..."));
            decryptWalletService.start();
        }
    } else {
        broadcastNotificationTransaction(wallet, walletTx, paymentCode, payNym);
    }
}
Also used : PaymentCode(com.sparrowwallet.drongo.bip47.PaymentCode) Storage(com.sparrowwallet.sparrow.io.Storage) SecureString(com.sparrowwallet.drongo.SecureString)

Example 10 with SecureString

use of com.sparrowwallet.drongo.SecureString in project sparrow by sparrowwallet.

the class SendController method broadcastNotification.

public void broadcastNotification(ActionEvent event) {
    Wallet wallet = getWalletForm().getWallet();
    Storage storage = AppServices.get().getOpenWallets().get(wallet);
    if (wallet.isEncrypted()) {
        WalletPasswordDialog dlg = new WalletPasswordDialog(wallet.getMasterName(), WalletPasswordDialog.PasswordRequirement.LOAD);
        Optional<SecureString> password = dlg.showAndWait();
        if (password.isPresent()) {
            Storage.DecryptWalletService decryptWalletService = new Storage.DecryptWalletService(wallet.copy(), password.get());
            decryptWalletService.setOnSucceeded(workerStateEvent -> {
                EventManager.get().post(new StorageEvent(storage.getWalletId(wallet), TimedEvent.Action.END, "Done"));
                Wallet decryptedWallet = decryptWalletService.getValue();
                broadcastNotification(decryptedWallet);
                decryptedWallet.clearPrivate();
            });
            decryptWalletService.setOnFailed(workerStateEvent -> {
                EventManager.get().post(new StorageEvent(storage.getWalletId(wallet), TimedEvent.Action.END, "Failed"));
                AppServices.showErrorDialog("Incorrect Password", decryptWalletService.getException().getMessage());
            });
            EventManager.get().post(new StorageEvent(storage.getWalletId(wallet), TimedEvent.Action.START, "Decrypting wallet..."));
            decryptWalletService.start();
        }
    } else {
        broadcastNotification(wallet);
    }
}
Also used : Storage(com.sparrowwallet.sparrow.io.Storage) SecureString(com.sparrowwallet.drongo.SecureString)

Aggregations

SecureString (com.sparrowwallet.drongo.SecureString)12 Storage (com.sparrowwallet.sparrow.io.Storage)8 StorageEvent (com.sparrowwallet.sparrow.event.StorageEvent)3 PaymentCode (com.sparrowwallet.drongo.bip47.PaymentCode)2 InvalidPasswordException (com.sparrowwallet.drongo.crypto.InvalidPasswordException)2 Wallet (com.sparrowwallet.drongo.wallet.Wallet)2 Subscribe (com.google.common.eventbus.Subscribe)1 WalletPasswordDialog (com.sparrowwallet.sparrow.control.WalletPasswordDialog)1 ButtonType (javafx.scene.control.ButtonType)1