From 37763e9557042d0fd7997abdb2901cd9f2cb2c05 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 27 Feb 2025 11:03:53 +0200 Subject: [PATCH] verify dropped release file instead of first platform specific release file found --- .../sparrowwallet/sparrow/AppController.java | 3 +- .../control/DownloadVerifierDialog.java | 32 ++++++++++++++++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 557df14c..951f1eae 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -1,9 +1,7 @@ package com.sparrowwallet.sparrow; import com.beust.jcommander.JCommander; -import com.google.common.base.Charsets; import com.google.common.eventbus.Subscribe; -import com.google.common.io.ByteSource; import com.sparrowwallet.drongo.*; import com.sparrowwallet.drongo.crypto.*; import com.sparrowwallet.drongo.policy.PolicyType; @@ -1471,6 +1469,7 @@ public class AppController implements Initializable { stage.setAlwaysOnTop(true); stage.setAlwaysOnTop(false); if(event.getSource() instanceof File file) { + downloadVerifierDialog.setInitialFile(file); downloadVerifierDialog.setSignatureFile(file); } return; diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DownloadVerifierDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/DownloadVerifierDialog.java index b4bd1845..39dc4901 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DownloadVerifierDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DownloadVerifierDialog.java @@ -62,6 +62,7 @@ public class DownloadVerifierDialog extends Dialog { private static final List ARCHIVE_EXTENSIONS = List.of("zip", "tar.gz", "tar.bz2", "tar.xz", "rar", "7z"); private static final String SPARROW_RELEASE_PREFIX = "sparrow-"; + private static final String SPARROW_RELEASE_ALT_PREFIX = "sparrow_"; private static final String SPARROW_SIGNATURE_SUFFIX = "-manifest.txt.asc"; private static final Pattern SPARROW_RELEASE_VERSION = Pattern.compile("[0-9]+(\\.[0-9]+)*"); private static final long MIN_VALID_SPARROW_RELEASE_SIZE = 10 * 1024 * 1024; @@ -70,6 +71,7 @@ public class DownloadVerifierDialog extends Dialog { private final ObjectProperty manifest = new SimpleObjectProperty<>(); private final ObjectProperty publicKey = new SimpleObjectProperty<>(); private final ObjectProperty release = new SimpleObjectProperty<>(); + private final ObjectProperty initial = new SimpleObjectProperty<>(); private final BooleanProperty manifestDisabled = new SimpleBooleanProperty(); private final BooleanProperty publicKeyDisabled = new SimpleBooleanProperty(); @@ -81,7 +83,7 @@ public class DownloadVerifierDialog extends Dialog { private static File lastFileParent; - public DownloadVerifierDialog(File initialSignatureFile) { + public DownloadVerifierDialog(File initialFile) { final DialogPane dialogPane = getDialogPane(); dialogPane.getStylesheets().add(AppServices.class.getResource("general.css").toExternalForm()); dialogPane.getStylesheets().add(AppServices.class.getResource("dialog.css").toExternalForm()); @@ -223,11 +225,17 @@ public class DownloadVerifierDialog extends Dialog { }); release.addListener((observable, oldValue, releaseFile) -> { + if(releaseFile != null) { + initial.set(null); + } verify(); }); - if(initialSignatureFile != null) { - javafx.application.Platform.runLater(() -> signature.set(initialSignatureFile)); + if(initialFile != null) { + javafx.application.Platform.runLater(() -> { + initial.set(initialFile); + signature.set(initialFile); + }); } } @@ -455,7 +463,8 @@ public class DownloadVerifierDialog extends Dialog { } } - if(providedFile.getName().toLowerCase(Locale.ROOT).startsWith(SPARROW_RELEASE_PREFIX)) { + String providedName = providedFile.getName().toLowerCase(Locale.ROOT); + if(providedName.startsWith(SPARROW_RELEASE_PREFIX) || providedName.startsWith(SPARROW_RELEASE_ALT_PREFIX)) { Matcher matcher = SPARROW_RELEASE_VERSION.matcher(providedFile.getName()); if(matcher.find()) { String version = matcher.group(); @@ -482,6 +491,15 @@ public class DownloadVerifierDialog extends Dialog { } private File findReleaseFile(File manifestFile, Map manifestMap) { + File initialFile = initial.get(); + if(initialFile != null) { + for(File file : manifestMap.keySet()) { + if(initialFile.getName().equals(file.getName())) { + return initialFile; + } + } + } + List releaseExtensions = getReleaseFileExtensions(); List> extensionLists = List.of(releaseExtensions, DISK_IMAGE_EXTENSIONS, ARCHIVE_EXTENSIONS, List.of("")); @@ -565,7 +583,7 @@ public class DownloadVerifierDialog extends Dialog { } } - if(name.startsWith(SPARROW_RELEASE_PREFIX) && file.length() >= MIN_VALID_SPARROW_RELEASE_SIZE) { + if((name.startsWith(SPARROW_RELEASE_PREFIX) || name.startsWith(SPARROW_RELEASE_ALT_PREFIX)) && file.length() >= MIN_VALID_SPARROW_RELEASE_SIZE) { Matcher matcher = SPARROW_RELEASE_VERSION.matcher(name); return matcher.find(); } @@ -578,6 +596,10 @@ public class DownloadVerifierDialog extends Dialog { signature.set(signatureFile); } + public void setInitialFile(File initialFile) { + initial.set(initialFile); + } + private static class Header extends GridPane { public Header() { setMaxWidth(Double.MAX_VALUE);