mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-24 20:56:45 +00:00
refactor to prepare for keystore encryption
This commit is contained in:
parent
d7c6f5d587
commit
84888b4a43
4 changed files with 16 additions and 15 deletions
2
drongo
2
drongo
|
@ -1 +1 @@
|
||||||
Subproject commit 242c83735a24456a4bd23fd556a56122c9b259ab
|
Subproject commit b951f79cfded507112cc7f213567c6a43c00e7e8
|
|
@ -3,9 +3,10 @@ package com.sparrowwallet.sparrow;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.google.common.io.ByteSource;
|
import com.google.common.io.ByteSource;
|
||||||
import com.google.gson.JsonSyntaxException;
|
|
||||||
import com.sparrowwallet.drongo.Utils;
|
import com.sparrowwallet.drongo.Utils;
|
||||||
|
import com.sparrowwallet.drongo.crypto.ECIESKeyCrypter;
|
||||||
import com.sparrowwallet.drongo.crypto.ECKey;
|
import com.sparrowwallet.drongo.crypto.ECKey;
|
||||||
|
import com.sparrowwallet.drongo.crypto.InvalidPasswordException;
|
||||||
import com.sparrowwallet.drongo.policy.PolicyType;
|
import com.sparrowwallet.drongo.policy.PolicyType;
|
||||||
import com.sparrowwallet.drongo.protocol.ScriptType;
|
import com.sparrowwallet.drongo.protocol.ScriptType;
|
||||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||||
|
@ -14,6 +15,7 @@ import com.sparrowwallet.drongo.psbt.PSBTParseException;
|
||||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||||
import com.sparrowwallet.sparrow.control.TextAreaDialog;
|
import com.sparrowwallet.sparrow.control.TextAreaDialog;
|
||||||
import com.sparrowwallet.sparrow.control.WalletNameDialog;
|
import com.sparrowwallet.sparrow.control.WalletNameDialog;
|
||||||
|
import com.sparrowwallet.sparrow.control.WalletPasswordDialog;
|
||||||
import com.sparrowwallet.sparrow.event.TabEvent;
|
import com.sparrowwallet.sparrow.event.TabEvent;
|
||||||
import com.sparrowwallet.sparrow.event.TransactionTabChangedEvent;
|
import com.sparrowwallet.sparrow.event.TransactionTabChangedEvent;
|
||||||
import com.sparrowwallet.sparrow.event.TransactionTabSelectedEvent;
|
import com.sparrowwallet.sparrow.event.TransactionTabSelectedEvent;
|
||||||
|
@ -21,7 +23,6 @@ import com.sparrowwallet.sparrow.io.FileType;
|
||||||
import com.sparrowwallet.sparrow.io.IOUtils;
|
import com.sparrowwallet.sparrow.io.IOUtils;
|
||||||
import com.sparrowwallet.sparrow.io.Storage;
|
import com.sparrowwallet.sparrow.io.Storage;
|
||||||
import com.sparrowwallet.sparrow.transaction.TransactionController;
|
import com.sparrowwallet.sparrow.transaction.TransactionController;
|
||||||
import com.sparrowwallet.sparrow.wallet.SettingsController;
|
|
||||||
import com.sparrowwallet.sparrow.wallet.WalletController;
|
import com.sparrowwallet.sparrow.wallet.WalletController;
|
||||||
import com.sparrowwallet.sparrow.wallet.WalletForm;
|
import com.sparrowwallet.sparrow.wallet.WalletForm;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
|
@ -233,12 +234,13 @@ public class AppController implements Initializable {
|
||||||
if(FileType.JSON.equals(fileType)) {
|
if(FileType.JSON.equals(fileType)) {
|
||||||
wallet = Storage.getStorage().loadWallet(file);
|
wallet = Storage.getStorage().loadWallet(file);
|
||||||
} else if(FileType.BINARY.equals(fileType)) {
|
} else if(FileType.BINARY.equals(fileType)) {
|
||||||
Optional<ECKey> optionalFullKey = SettingsController.askForWalletPassword(null, true);
|
WalletPasswordDialog dlg = new WalletPasswordDialog(WalletPasswordDialog.PasswordRequirement.LOAD);
|
||||||
if(!optionalFullKey.isPresent()) {
|
Optional<String> password = dlg.showAndWait();
|
||||||
|
if(!password.isPresent()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ECKey encryptionFullKey = optionalFullKey.get();
|
ECKey encryptionFullKey = ECIESKeyCrypter.deriveECKey(password.get());
|
||||||
wallet = Storage.getStorage().loadWallet(file, encryptionFullKey);
|
wallet = Storage.getStorage().loadWallet(file, encryptionFullKey);
|
||||||
encryptionPubKey = ECKey.fromPublicOnly(encryptionFullKey);
|
encryptionPubKey = ECKey.fromPublicOnly(encryptionFullKey);
|
||||||
} else {
|
} else {
|
||||||
|
@ -247,8 +249,9 @@ public class AppController implements Initializable {
|
||||||
|
|
||||||
Tab tab = addWalletTab(file, encryptionPubKey, wallet);
|
Tab tab = addWalletTab(file, encryptionPubKey, wallet);
|
||||||
tabs.getSelectionModel().select(tab);
|
tabs.getSelectionModel().select(tab);
|
||||||
|
} catch (InvalidPasswordException e) {
|
||||||
|
showErrorDialog("Invalid Password", "The password was invalid.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
showErrorDialog("Error opening wallet", e.getMessage());
|
showErrorDialog("Error opening wallet", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.sparrowwallet.sparrow.control;
|
package com.sparrowwallet.sparrow.control;
|
||||||
|
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import com.sparrowwallet.drongo.crypto.ECIESKeyCrypter;
|
import com.sparrowwallet.drongo.crypto.InvalidPasswordException;
|
||||||
import com.sparrowwallet.drongo.wallet.Keystore;
|
import com.sparrowwallet.drongo.wallet.Keystore;
|
||||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||||
import com.sparrowwallet.sparrow.EventManager;
|
import com.sparrowwallet.sparrow.EventManager;
|
||||||
|
@ -83,7 +83,7 @@ public class FileKeystoreImportPane extends KeystoreImportPane {
|
||||||
if(e.getCause() != null && e.getCause().getMessage() != null && !e.getCause().getMessage().isEmpty()) {
|
if(e.getCause() != null && e.getCause().getMessage() != null && !e.getCause().getMessage().isEmpty()) {
|
||||||
errorMessage = e.getCause().getMessage();
|
errorMessage = e.getCause().getMessage();
|
||||||
}
|
}
|
||||||
if(e instanceof ECIESKeyCrypter.InvalidPasswordException || e.getCause() instanceof ECIESKeyCrypter.InvalidPasswordException) {
|
if(e instanceof InvalidPasswordException || e.getCause() instanceof InvalidPasswordException) {
|
||||||
errorMessage = "Invalid wallet password";
|
errorMessage = "Invalid wallet password";
|
||||||
}
|
}
|
||||||
if(e instanceof JsonParseException || e.getCause() instanceof JsonParseException) {
|
if(e instanceof JsonParseException || e.getCause() instanceof JsonParseException) {
|
||||||
|
|
|
@ -159,7 +159,7 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||||
|
|
||||||
apply.setOnAction(event -> {
|
apply.setOnAction(event -> {
|
||||||
try {
|
try {
|
||||||
Optional<ECKey> optionalPubKey = askForWalletPassword(walletForm.getEncryptionPubKey(), false);
|
Optional<ECKey> optionalPubKey = askForWalletPassword(walletForm.getEncryptionPubKey());
|
||||||
if(optionalPubKey.isPresent()) {
|
if(optionalPubKey.isPresent()) {
|
||||||
walletForm.setEncryptionPubKey(ECKey.fromPublicOnly(optionalPubKey.get()));
|
walletForm.setEncryptionPubKey(ECKey.fromPublicOnly(optionalPubKey.get()));
|
||||||
walletForm.save();
|
walletForm.save();
|
||||||
|
@ -261,11 +261,9 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||||
Platform.runLater(() -> apply.setDisable(!tabsValidate()));
|
Platform.runLater(() -> apply.setDisable(!tabsValidate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<ECKey> askForWalletPassword(ECKey existingPubKey, boolean required) {
|
private Optional<ECKey> askForWalletPassword(ECKey existingPubKey) {
|
||||||
WalletPasswordDialog.PasswordRequirement requirement;
|
WalletPasswordDialog.PasswordRequirement requirement;
|
||||||
if(existingPubKey == null && required) {
|
if(existingPubKey == null) {
|
||||||
requirement = WalletPasswordDialog.PasswordRequirement.LOAD;
|
|
||||||
} else if(existingPubKey == null) {
|
|
||||||
requirement = WalletPasswordDialog.PasswordRequirement.UPDATE_NEW;
|
requirement = WalletPasswordDialog.PasswordRequirement.UPDATE_NEW;
|
||||||
} else if(WalletForm.NO_PASSWORD_KEY.equals(existingPubKey)) {
|
} else if(WalletForm.NO_PASSWORD_KEY.equals(existingPubKey)) {
|
||||||
requirement = WalletPasswordDialog.PasswordRequirement.UPDATE_EMPTY;
|
requirement = WalletPasswordDialog.PasswordRequirement.UPDATE_EMPTY;
|
||||||
|
@ -276,7 +274,7 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||||
WalletPasswordDialog dlg = new WalletPasswordDialog(requirement);
|
WalletPasswordDialog dlg = new WalletPasswordDialog(requirement);
|
||||||
Optional<String> password = dlg.showAndWait();
|
Optional<String> password = dlg.showAndWait();
|
||||||
if(password.isPresent()) {
|
if(password.isPresent()) {
|
||||||
if(!required && password.get().isEmpty()) {
|
if(password.get().isEmpty()) {
|
||||||
return Optional.of(WalletForm.NO_PASSWORD_KEY);
|
return Optional.of(WalletForm.NO_PASSWORD_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue