From 5b203a6c61a6b00fec7a9b8c359dece80f919597 Mon Sep 17 00:00:00 2001 From: Toporin Date: Wed, 6 Sep 2023 21:07:57 +0100 Subject: [PATCH] Satochip: Add pin size check during initialization --- .../sparrow/control/DevicePane.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java b/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java index fe1d9677..0fd8b1c3 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java @@ -1075,11 +1075,17 @@ public class DevicePane extends TitledDescriptionPane { initializeButton.setOnAction(event -> { initializeButton.setDisable(true); byte[] seedBytes; - // check that pin and previous pin match - if ( !pin.get().equals(repeatedPin.getText()) ){ - seedBytes = null; // will display a proper error later in cardApi.getInitializationService() - messageProperty.set("The two entered Pin values do not correspond!"); - } else { + try{ + // check that pin and previous pin match + if ( !pin.get().equals(repeatedPin.getText()) ){ + throw new RuntimeException("The two entered PIN values do not correspond!"); + } + // check pin size + int pinSize = pin.get().getBytes(StandardCharsets.UTF_8).length; + if (pinSize < 4 || pinSize >16 ){ + throw new RuntimeException("PIN size should be between 4 and 16 characters included!"); + } + // check the seed try{ // check bip39 is correct & convert seed to masterseed bytes List mnemonicWords = Arrays.asList(mnemonic.getText().split("[\\s,]+")); // \\s*,\\s* @@ -1087,9 +1093,12 @@ public class DevicePane extends TitledDescriptionPane { DeterministicSeed seed = new DeterministicSeed(mnemonicWords, passphrase.getText(), System.currentTimeMillis(), DeterministicSeed.Type.BIP39); seedBytes = seed.getSeedBytes(); } catch (Exception e) { - seedBytes = null; // will display a proper error later in cardApi.getInitializationService() - messageProperty.set("Failed to parse the seed with error: " + e); + throw new RuntimeException("Failed to parse the seed with error: " + e); } + + } catch (Exception e) { + seedBytes = null; // will display a proper error later in cardApi.getInitializationService() + messageProperty.set(e.getMessage()); } Service cardInitializationService = cardApi.getInitializationService(seedBytes, messageProperty); cardInitializationService.setOnSucceeded(successEvent -> {