mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 13:16:44 +00:00
maintain strong reference to key derivation service until action completion
This commit is contained in:
parent
8ddc494b53
commit
c6b6e74515
3 changed files with 16 additions and 5 deletions
|
@ -215,6 +215,8 @@ public class AppController implements Initializable {
|
||||||
@FXML
|
@FXML
|
||||||
private UnlabeledToggleSwitch serverToggle;
|
private UnlabeledToggleSwitch serverToggle;
|
||||||
|
|
||||||
|
private Storage.KeyDerivationService keyDerivationService;
|
||||||
|
|
||||||
private PauseTransition wait;
|
private PauseTransition wait;
|
||||||
|
|
||||||
private Timeline statusTimeline;
|
private Timeline statusTimeline;
|
||||||
|
@ -1322,7 +1324,7 @@ public class AppController implements Initializable {
|
||||||
log.error("Error saving imported wallet", e);
|
log.error("Error saving imported wallet", e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Storage.KeyDerivationService keyDerivationService = new Storage.KeyDerivationService(storage, password.get());
|
keyDerivationService = new Storage.KeyDerivationService(storage, password.get());
|
||||||
keyDerivationService.setOnSucceeded(workerStateEvent -> {
|
keyDerivationService.setOnSucceeded(workerStateEvent -> {
|
||||||
EventManager.get().post(new StorageEvent(Storage.getWalletFile(wallet.getName()).getAbsolutePath(), TimedEvent.Action.END, "Done"));
|
EventManager.get().post(new StorageEvent(Storage.getWalletFile(wallet.getName()).getAbsolutePath(), TimedEvent.Action.END, "Done"));
|
||||||
ECKey encryptionFullKey = keyDerivationService.getValue();
|
ECKey encryptionFullKey = keyDerivationService.getValue();
|
||||||
|
@ -1353,11 +1355,13 @@ public class AppController implements Initializable {
|
||||||
if(key != null) {
|
if(key != null) {
|
||||||
key.clear();
|
key.clear();
|
||||||
}
|
}
|
||||||
|
keyDerivationService = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
keyDerivationService.setOnFailed(workerStateEvent -> {
|
keyDerivationService.setOnFailed(workerStateEvent -> {
|
||||||
EventManager.get().post(new StorageEvent(Storage.getWalletFile(wallet.getName()).getAbsolutePath(), TimedEvent.Action.END, "Failed"));
|
EventManager.get().post(new StorageEvent(Storage.getWalletFile(wallet.getName()).getAbsolutePath(), TimedEvent.Action.END, "Failed"));
|
||||||
showErrorDialog("Error encrypting wallet", keyDerivationService.getException().getMessage());
|
showErrorDialog("Error encrypting wallet", keyDerivationService.getException().getMessage());
|
||||||
|
keyDerivationService = null;
|
||||||
});
|
});
|
||||||
EventManager.get().post(new StorageEvent(Storage.getWalletFile(wallet.getName()).getAbsolutePath(), TimedEvent.Action.START, "Encrypting wallet..."));
|
EventManager.get().post(new StorageEvent(Storage.getWalletFile(wallet.getName()).getAbsolutePath(), TimedEvent.Action.START, "Encrypting wallet..."));
|
||||||
keyDerivationService.start();
|
keyDerivationService.start();
|
||||||
|
@ -1468,7 +1472,7 @@ public class AppController implements Initializable {
|
||||||
Optional<SecureString> password = dlg.showAndWait();
|
Optional<SecureString> password = dlg.showAndWait();
|
||||||
if(password.isPresent()) {
|
if(password.isPresent()) {
|
||||||
Storage storage = selectedWalletForm.getStorage();
|
Storage storage = selectedWalletForm.getStorage();
|
||||||
Storage.KeyDerivationService keyDerivationService = new Storage.KeyDerivationService(storage, password.get(), true);
|
keyDerivationService = new Storage.KeyDerivationService(storage, password.get(), true);
|
||||||
keyDerivationService.setOnSucceeded(workerStateEvent -> {
|
keyDerivationService.setOnSucceeded(workerStateEvent -> {
|
||||||
EventManager.get().post(new StorageEvent(selectedWalletForm.getWalletId(), TimedEvent.Action.END, "Done"));
|
EventManager.get().post(new StorageEvent(selectedWalletForm.getWalletId(), TimedEvent.Action.END, "Done"));
|
||||||
ECKey encryptionFullKey = keyDerivationService.getValue();
|
ECKey encryptionFullKey = keyDerivationService.getValue();
|
||||||
|
@ -1486,7 +1490,7 @@ public class AppController implements Initializable {
|
||||||
} finally {
|
} finally {
|
||||||
key.clear();
|
key.clear();
|
||||||
encryptionFullKey.clear();
|
encryptionFullKey.clear();
|
||||||
password.get().clear();
|
keyDerivationService = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
keyDerivationService.setOnFailed(workerStateEvent -> {
|
keyDerivationService.setOnFailed(workerStateEvent -> {
|
||||||
|
@ -1499,6 +1503,7 @@ public class AppController implements Initializable {
|
||||||
} else {
|
} else {
|
||||||
log.error("Error deriving wallet key", keyDerivationService.getException());
|
log.error("Error deriving wallet key", keyDerivationService.getException());
|
||||||
}
|
}
|
||||||
|
keyDerivationService = null;
|
||||||
});
|
});
|
||||||
EventManager.get().post(new StorageEvent(selectedWalletForm.getWalletId(), TimedEvent.Action.START, "Decrypting wallet..."));
|
EventManager.get().post(new StorageEvent(selectedWalletForm.getWalletId(), TimedEvent.Action.START, "Decrypting wallet..."));
|
||||||
keyDerivationService.start();
|
keyDerivationService.start();
|
||||||
|
@ -2223,7 +2228,7 @@ public class AppController implements Initializable {
|
||||||
dlg.initOwner(rootStack.getScene().getWindow());
|
dlg.initOwner(rootStack.getScene().getWindow());
|
||||||
Optional<SecureString> password = dlg.showAndWait();
|
Optional<SecureString> password = dlg.showAndWait();
|
||||||
if(password.isPresent()) {
|
if(password.isPresent()) {
|
||||||
Storage.KeyDerivationService keyDerivationService = new Storage.KeyDerivationService(storage, password.get(), true);
|
keyDerivationService = new Storage.KeyDerivationService(storage, password.get(), true);
|
||||||
keyDerivationService.setOnSucceeded(workerStateEvent -> {
|
keyDerivationService.setOnSucceeded(workerStateEvent -> {
|
||||||
EventManager.get().post(new StorageEvent(selectedWalletForm.getWalletId(), TimedEvent.Action.END, "Done"));
|
EventManager.get().post(new StorageEvent(selectedWalletForm.getWalletId(), TimedEvent.Action.END, "Done"));
|
||||||
ECKey encryptionFullKey = keyDerivationService.getValue();
|
ECKey encryptionFullKey = keyDerivationService.getValue();
|
||||||
|
@ -2233,7 +2238,7 @@ public class AppController implements Initializable {
|
||||||
deleteStorage(storage, true);
|
deleteStorage(storage, true);
|
||||||
} finally {
|
} finally {
|
||||||
encryptionFullKey.clear();
|
encryptionFullKey.clear();
|
||||||
password.get().clear();
|
keyDerivationService = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
keyDerivationService.setOnFailed(workerStateEvent -> {
|
keyDerivationService.setOnFailed(workerStateEvent -> {
|
||||||
|
@ -2246,6 +2251,7 @@ public class AppController implements Initializable {
|
||||||
} else {
|
} else {
|
||||||
log.error("Error deriving wallet key", keyDerivationService.getException());
|
log.error("Error deriving wallet key", keyDerivationService.getException());
|
||||||
}
|
}
|
||||||
|
keyDerivationService = null;
|
||||||
});
|
});
|
||||||
EventManager.get().post(new StorageEvent(selectedWalletForm.getWalletId(), TimedEvent.Action.START, "Decrypting wallet..."));
|
EventManager.get().post(new StorageEvent(selectedWalletForm.getWalletId(), TimedEvent.Action.START, "Decrypting wallet..."));
|
||||||
keyDerivationService.start();
|
keyDerivationService.start();
|
||||||
|
|
|
@ -240,6 +240,8 @@ public abstract class FileImportPane extends TitledDescriptionPane {
|
||||||
contentBox.setPadding(new Insets(10, 30, 10, 30));
|
contentBox.setPadding(new Insets(10, 30, 10, 30));
|
||||||
contentBox.setPrefHeight(60);
|
contentBox.setPrefHeight(60);
|
||||||
|
|
||||||
|
javafx.application.Platform.runLater(passwordField::requestFocus);
|
||||||
|
|
||||||
return contentBox;
|
return contentBox;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import com.sparrowwallet.sparrow.EventManager;
|
||||||
import com.sparrowwallet.sparrow.event.WalletImportEvent;
|
import com.sparrowwallet.sparrow.event.WalletImportEvent;
|
||||||
import com.sparrowwallet.sparrow.io.ImportException;
|
import com.sparrowwallet.sparrow.io.ImportException;
|
||||||
import com.sparrowwallet.sparrow.io.KeystoreFileImport;
|
import com.sparrowwallet.sparrow.io.KeystoreFileImport;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
|
@ -153,6 +154,8 @@ public class FileWalletKeystoreImportPane extends FileImportPane {
|
||||||
contentBox.setPadding(new Insets(10, 30, 10, 30));
|
contentBox.setPadding(new Insets(10, 30, 10, 30));
|
||||||
contentBox.setPrefHeight(60);
|
contentBox.setPrefHeight(60);
|
||||||
|
|
||||||
|
Platform.runLater(scriptTypeComboBox::requestFocus);
|
||||||
|
|
||||||
return contentBox;
|
return contentBox;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue