if validating derivations, disallow paths that match other networks

This commit is contained in:
Craig Raw 2024-03-01 11:24:21 +02:00
parent a45024ac70
commit 803e43cb45
6 changed files with 8 additions and 5 deletions

2
drongo

@ -1 +1 @@
Subproject commit c12dac9a25ef410f8f1bb77dd6b1ea12c4e0b002
Subproject commit c8165e154a4088262cdf9428f8f8a6ef95db5140

View file

@ -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());

View file

@ -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());

View file

@ -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(

View file

@ -76,7 +76,7 @@
</Field>
<Field text="Validate derivations:">
<UnlabeledToggleSwitch fx:id="validateDerivationPaths" />
<HelpLabel helpText="Disallow keystores to have derivation paths that match the defaults for other script types."/>
<HelpLabel helpText="Disallow keystores to have derivation paths that match the defaults for other script types and networks."/>
</Field>
</Fieldset>
<Fieldset inputGrow="SOMETIMES" text="Coin Selection" styleClass="wideLabelFieldSet">

View file

@ -81,7 +81,7 @@
<TextField fx:id="fingerprint" maxWidth="80" promptText="00000000"/> <Region style="-fx-max-width: 5" /> <LifeHashIcon fx:id="fingerprintIcon" /> <HelpLabel helpText="The master fingerprint uniquely identifies this keystore using the first 4 bytes of the master public key hash.\nIt is safe to use any valid value (00000000) for Watch Only Wallets." />
</Field>
<Field text="Derivation:">
<TextField fx:id="derivation" maxWidth="200"/> <HelpLabel helpText="The derivation path to the xpub from the master private key.\nFor safety, derivations that match defaults for other script types are not valid.\nThis validation can be turned off in the General Preferences." />
<TextField fx:id="derivation" maxWidth="200"/> <HelpLabel helpText="The derivation path to the xpub from the master private key.\nFor safety, derivations that match defaults for other script types and networks are not valid.\nThis validation can be turned off in the General Preferences." />
</Field>
<Field fx:id="xpubField" text="xpub:">
<TextArea fx:id="xpub" wrapText="true" prefRowCount="2" maxHeight="52" />