From 803e43cb45b3ca34084c7c93c2a74f481099deb3 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Fri, 1 Mar 2024 11:24:21 +0200 Subject: [PATCH] if validating derivations, disallow paths that match other networks --- drongo | 2 +- src/main/java/com/sparrowwallet/sparrow/SparrowDesktop.java | 1 + .../sparrow/preferences/GeneralPreferencesController.java | 1 + .../com/sparrowwallet/sparrow/wallet/KeystoreController.java | 5 +++-- .../com/sparrowwallet/sparrow/preferences/general.fxml | 2 +- .../resources/com/sparrowwallet/sparrow/wallet/keystore.fxml | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drongo b/drongo index c12dac9a..c8165e15 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit c12dac9a25ef410f8f1bb77dd6b1ea12c4e0b002 +Subproject commit c8165e154a4088262cdf9428f8f8a6ef95db5140 diff --git a/src/main/java/com/sparrowwallet/sparrow/SparrowDesktop.java b/src/main/java/com/sparrowwallet/sparrow/SparrowDesktop.java index 70db8fe3..e7e03e17 100644 --- a/src/main/java/com/sparrowwallet/sparrow/SparrowDesktop.java +++ b/src/main/java/com/sparrowwallet/sparrow/SparrowDesktop.java @@ -80,6 +80,7 @@ public class SparrowDesktop extends Application { } System.setProperty(Wallet.ALLOW_DERIVATIONS_MATCHING_OTHER_SCRIPT_TYPES_PROPERTY, Boolean.toString(!Config.get().isValidateDerivationPaths())); + System.setProperty(Wallet.ALLOW_DERIVATIONS_MATCHING_OTHER_NETWORKS_PROPERTY, Boolean.toString(!Config.get().isValidateDerivationPaths())); if(Config.get().getAppHeight() != null && Config.get().getAppWidth() != null) { mainStage.setWidth(Config.get().getAppWidth()); diff --git a/src/main/java/com/sparrowwallet/sparrow/preferences/GeneralPreferencesController.java b/src/main/java/com/sparrowwallet/sparrow/preferences/GeneralPreferencesController.java index df6fee28..39620c74 100644 --- a/src/main/java/com/sparrowwallet/sparrow/preferences/GeneralPreferencesController.java +++ b/src/main/java/com/sparrowwallet/sparrow/preferences/GeneralPreferencesController.java @@ -175,6 +175,7 @@ public class GeneralPreferencesController extends PreferencesDetailController { validateDerivationPaths.selectedProperty().addListener((observableValue, oldValue, newValue) -> { config.setValidateDerivationPaths(newValue); System.setProperty(Wallet.ALLOW_DERIVATIONS_MATCHING_OTHER_SCRIPT_TYPES_PROPERTY, Boolean.toString(!newValue)); + System.setProperty(Wallet.ALLOW_DERIVATIONS_MATCHING_OTHER_NETWORKS_PROPERTY, Boolean.toString(!newValue)); }); groupByAddress.setSelected(config.isGroupByAddress()); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java index 1f12ae02..8dc50a8b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java @@ -186,7 +186,7 @@ public class KeystoreController extends WalletFormController implements Initiali return null; })); derivation.textProperty().addListener((observable, oldValue, newValue) -> { - if(KeyDerivation.isValid(newValue) && !walletForm.getWallet().derivationMatchesAnotherScriptType(newValue)) { + if(KeyDerivation.isValid(newValue) && !walletForm.getWallet().derivationMatchesAnotherScriptType(newValue) && !walletForm.getWallet().derivationMatchesAnotherNetwork(newValue)) { keystore.setKeyDerivation(new KeyDerivation(keystore.getKeyDerivation().getMasterFingerprint(), newValue)); EventManager.get().post(new SettingsChangedEvent(walletForm.getWallet(), SettingsChangedEvent.Type.KEYSTORE_DERIVATION)); } @@ -287,7 +287,8 @@ public class KeystoreController extends WalletFormController implements Initiali validationSupport.registerValidator(derivation, Validator.combine( Validator.createEmptyValidator("Derivation is required"), (Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Derivation is invalid", !KeyDerivation.isValid(newValue)), - (Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Derivation matches another script type", walletForm.getWallet().derivationMatchesAnotherScriptType(newValue)) + (Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Derivation matches another script type", walletForm.getWallet().derivationMatchesAnotherScriptType(newValue)), + (Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Derivation matches another network", walletForm.getWallet().derivationMatchesAnotherNetwork(newValue)) )); validationSupport.registerValidator(fingerprint, Validator.combine( diff --git a/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml b/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml index 65788e20..79249888 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml @@ -76,7 +76,7 @@ - +
diff --git a/src/main/resources/com/sparrowwallet/sparrow/wallet/keystore.fxml b/src/main/resources/com/sparrowwallet/sparrow/wallet/keystore.fxml index 0654f9be..42f2aa57 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/wallet/keystore.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/wallet/keystore.fxml @@ -81,7 +81,7 @@ - +