Search in sources :

Example 1 with InvalidPasswordException

use of com.sparrowwallet.drongo.crypto.InvalidPasswordException in project sparrow by sparrowwallet.

the class DbPersistence method createDataSource.

private HikariDataSource createDataSource(File walletFile, String password) throws StorageException {
    try {
        Class.forName("org.h2.Driver");
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl(getUrl(walletFile, password));
        config.setUsername(H2_USER);
        config.setPassword(password == null ? H2_PASSWORD : password + " " + H2_PASSWORD);
        return new HikariDataSource(config);
    } catch (ClassNotFoundException e) {
        log.error("Cannot find H2 driver", e);
        throw new StorageException("Cannot find H2 driver", e);
    } catch (HikariPool.PoolInitializationException e) {
        if (e.getMessage() != null && e.getMessage().contains("Database may be already in use")) {
            log.error("Wallet file may already be in use. Make sure the application is not running elsewhere.", e);
            throw new StorageException("Wallet file may already be in use. Make sure the application is not running elsewhere.", e);
        } else if (e.getMessage() != null && (e.getMessage().contains("Wrong user name or password") || e.getMessage().contains("Encryption error in file"))) {
            throw new InvalidPasswordException("Incorrect password for wallet file " + walletFile.getAbsolutePath(), e);
        } else {
            log.error("Failed to open database file", e);
            throw new StorageException("Failed to open database file.\n" + e.getMessage(), e);
        }
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariPool(com.zaxxer.hikari.pool.HikariPool) InvalidPasswordException(com.sparrowwallet.drongo.crypto.InvalidPasswordException) HikariConfig(com.zaxxer.hikari.HikariConfig)

Example 2 with InvalidPasswordException

use of com.sparrowwallet.drongo.crypto.InvalidPasswordException in project sparrow by sparrowwallet.

the class InitiatorDialog method acceptAndBroadcast.

private void acceptAndBroadcast(InitiatorController initiatorController, String walletId, Wallet wallet) {
    if (confirmationRequired && wallet.isEncrypted()) {
        WalletPasswordDialog dlg = new WalletPasswordDialog(wallet.getMasterName(), WalletPasswordDialog.PasswordRequirement.LOAD);
        Optional<SecureString> password = dlg.showAndWait();
        if (password.isPresent()) {
            Storage storage = AppServices.get().getOpenWallets().get(wallet);
            Storage.KeyDerivationService keyDerivationService = new Storage.KeyDerivationService(storage, password.get(), true);
            keyDerivationService.setOnSucceeded(workerStateEvent -> {
                EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.END, "Done"));
                initiatorController.accept();
                password.get().clear();
            });
            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(() -> acceptAndBroadcast(initiatorController, walletId, wallet));
                    }
                } else {
                    log.error("Error deriving wallet key", keyDerivationService.getException());
                }
            });
            EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.START, "Decrypting wallet..."));
            keyDerivationService.start();
        }
    } else {
        initiatorController.accept();
    }
}
Also used : WalletPasswordDialog(com.sparrowwallet.sparrow.control.WalletPasswordDialog) Storage(com.sparrowwallet.sparrow.io.Storage) StorageEvent(com.sparrowwallet.sparrow.event.StorageEvent) InvalidPasswordException(com.sparrowwallet.drongo.crypto.InvalidPasswordException) SecureString(com.sparrowwallet.drongo.SecureString)

Example 3 with InvalidPasswordException

use of com.sparrowwallet.drongo.crypto.InvalidPasswordException 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)

Aggregations

InvalidPasswordException (com.sparrowwallet.drongo.crypto.InvalidPasswordException)3 SecureString (com.sparrowwallet.drongo.SecureString)2 Storage (com.sparrowwallet.sparrow.io.Storage)2 WalletPasswordDialog (com.sparrowwallet.sparrow.control.WalletPasswordDialog)1 StorageEvent (com.sparrowwallet.sparrow.event.StorageEvent)1 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 HikariPool (com.zaxxer.hikari.pool.HikariPool)1