report a wallet password change that fails on the update thread, and delete backups only once the file has been written with the new password
What changed, and why it matters
This commit fixes a bug in Sparrow Wallet's password-change flow. Previously, if a password change failed while writing the wallet file on a background thread, the user was not told, and old password-protected backups could be deleted before the new password actually reached the file. The patch adds an error dialog for these failures and delays backup deletion until the wallet file is confirmed to have been written with the new password.
Treat this as a security-hardening fix and include it in the next release. Users who changed wallet passwords on prior versions should verify that their most recent backup is accessible with the expected password and that the current wallet file opens with the intended password. No immediate remote exploitation path is evident, but the prior behavior could leave users locked out or with stale backups if a write failed.
Security signals we found
Asynchronous password-change failure was silently swallowed
Backups could be deleted before the wallet file was actually rewritten with the new password
Failure reporting added via event bus to close the silent-failure window
Backup deletion now gated on confirmed write with the new encryption key
Unit tests simulate filesystem write failures and verify backup preservation
Evidence from the diff
The change addresses two related issues in asynchronous wallet persistence. First, password changes initiated in the UI are applied later on a background update thread; if that write failed, the UI had already returned success. The patch introduces WalletPasswordChangeFailedEvent, posted from DbPersistence.updateWallet when a queued password change fails, and an AppServices handler that shows an error dialog. Second, backup deletion was previously triggered immediately after setEncryptionPubKey/saveAndRefresh in SettingsController, even though the actual file rewrite with the new key happens asynchronously. The patch moves deletion tracking into Storage via an AtomicReference
Changed components
com.sparrowwallet.sparrow.io.Storagecom.sparrowwallet.sparrow.io.db.DbPersistencecom.sparrowwallet.sparrow.wallet.SettingsControllercom.sparrowwallet.sparrow.wallet.WalletFormcom.sparrowwallet.sparrow.AppServicescom.sparrowwallet.sparrow.event.WalletPasswordChangeFailedEventInspect captured patch +354 / −23
### src/main/java/com/sparrowwallet/sparrow/AppServices.java
@@ -1493,6 +1493,15 @@ public void feesUpdated(FeeRatesUpdatedEvent event) {
nextBlockMedianFeeRate = event.getNextBlockMedianFeeRate();
}
+ @Subscribe
+ public void walletPasswordChangeFailed(WalletPasswordChangeFailedEvent event) {
+ //Removing a password writes the wallet first, so its changes are saved under the password the file keeps
+ String consequence = event.isPasswordRemoved() ? "The wallet file still has its previous password, and changes to the wallet continue to be saved with it."
+ : "The wallet file keeps its previous password, and changes to the wallet cannot be saved until the password has been changed.";
+ String content = event.getException().getMessage() + "\n\n" + consequence;
+ Platform.runLater(() -> showErrorDialog("Error saving " + event.getWallet().getMasterName(), content));
+ }
+
@Subscribe
public void mempoolRateSizes(MempoolRateSizesUpdatedEvent event) {
if(event.getMempoolRateSizes() != null) {
### src/main/java/com/sparrowwallet/sparrow/event/WalletPasswordChangeFailedEvent.java
@@ -0,0 +1,31 @@
+package com.sparrowwallet.sparrow.event;
+
+import com.sparrowwallet.drongo.wallet.Wallet;
+
+/**
+ * Posted from the wallet update thread when the wallet file could not be written with a new password, which the code that changed the password
+ * has already returned from and so cannot report.
+ */
+public class WalletPasswordChangeFailedEvent {
+ private final Wallet wallet;
+ private final boolean passwordRemoved;
+ private final Throwable exception;
+
+ public WalletPasswordChangeFailedEvent(Wallet wallet, boolean passwordRemoved, Throwable exception) {
+ this.wallet = wallet;
+ this.passwordRemoved = passwordRemoved;
+ this.exception = exception;
+ }
+
+ public Wallet getWallet() {
+ return wallet;
+ }
+
+ public boolean isPasswordRemoved() {
+ return passwordRemoved;
+ }
+
+ public Throwable getException() {
+ return exception;
+ }
+}
### src/main/java/com/sparrowwallet/sparrow/io/Storage.java
@@ -31,6 +31,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -50,6 +51,7 @@ public class Storage {
private Persistence persistence;
private File walletFile;
private volatile ECKey encryptionPubKey; //set where the wallet is saved, and read by the queued updates that follow on another thread
+ private final AtomicReference<ECKey> deleteBackupsKey = new AtomicReference<>(); //the key backups are to be deleted once the file is written with
public Storage(File walletFile) {
this(!walletFile.exists() || walletFile.getName().endsWith("." + PersistenceType.DB.getExtension()) ? PersistenceType.DB : PersistenceType.JSON, walletFile);
@@ -111,12 +113,14 @@ public void saveWallet(Wallet wallet) throws IOException, StorageException {
throw new IOException("Could not create folder " + parent);
}
- if(encryptionPubKey != null && !NO_PASSWORD_KEY.equals(encryptionPubKey)) {
- walletFile = persistence.storeWallet(this, wallet, encryptionPubKey);
- return;
+ ECKey savedKey = encryptionPubKey;
+ if(savedKey != null && !NO_PASSWORD_KEY.equals(savedKey)) {
+ walletFile = persistence.storeWallet(this, wallet, savedKey);
+ } else {
+ walletFile = persistence.storeWallet(this, wallet);
}
- walletFile = persistence.storeWallet(this, wallet);
+ encryptionKeySaved(savedKey);
}
public void updateWallet(Wallet wallet) throws IOException, StorageException {
@@ -395,7 +399,27 @@ public ECKey getEncryptionPubKey() {
}
public void setEncryptionPubKey(ECKey encryptionPubKey) {
+ setEncryptionPubKey(encryptionPubKey, false);
+ }
+
+ /**
+ * Sets the key the wallet file is to be saved with. Backups made under the previous password are deleted only once the file has been written
+ * with this key, which for a password change made without a full save happens later on the update thread, and may not happen at all. Setting
+ * the same key again without deleting backups, as a save confirming the password does, leaves a deletion still waiting for that key in place.
+ */
+ public void setEncryptionPubKey(ECKey encryptionPubKey, boolean deleteBackups) {
this.encryptionPubKey = encryptionPubKey;
+ deleteBackupsKey.getAndUpdate(requestedKey -> deleteBackups ? encryptionPubKey : (Objects.equals(requestedKey, encryptionPubKey) ? requestedKey : null));
+ }
+
+ /**
+ * Called once the wallet file has been written with the given encryption key, which a write that started before the key was last set may not be.
+ */
+ public void encryptionKeySaved(ECKey savedKey) {
+ ECKey requestedKey = deleteBackupsKey.get();
+ if(savedKey != null && savedKey.equals(requestedKey) && deleteBackupsKey.compareAndSet(requestedKey, null)) {
+ deleteBackups();
+ }
}
public ECKey getEncryptionKey(CharSequence password) throws IOException, StorageException {
### src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java
@@ -127,6 +127,7 @@ public class DbPersistence implements Persistence {
private Wallet masterWallet;
private final Map<Wallet, DirtyPersistables> dirtyPersistablesMap = new HashMap<>();
private ExecutorService updateExecutor;
+ private volatile ECKey passwordFailureKey; //the storage key a failed password change was last reported for, by a full save or the update thread
public DbPersistence() {
EventManager.get().register(this);
@@ -205,7 +206,7 @@ public File storeWallet(Storage storage, Wallet wallet) throws IOException, Stor
File walletFile = storage.getWalletFile();
walletFile = renameToDbFile(walletFile);
- updatePassword(storage, null);
+ updatePasswordForSave(storage, null);
cleanAndAddWallet(storage, wallet, null);
return walletFile;
@@ -217,7 +218,7 @@ public File storeWallet(Storage storage, Wallet wallet, ECKey encryptionPubKey)
walletFile = renameToDbFile(walletFile);
boolean existing = walletFile.exists();
- updatePassword(storage, encryptionPubKey);
+ updatePasswordForSave(storage, encryptionPubKey);
cleanAndAddWallet(storage, wallet, getFilePassword(encryptionPubKey));
if(!existing) {
writeBinaryHeader(walletFile);
@@ -226,6 +227,17 @@ public File storeWallet(Storage storage, Wallet wallet, ECKey encryptionPubKey)
return walletFile;
}
+ private void updatePasswordForSave(Storage storage, ECKey encryptionPubKey) throws StorageException {
+ try {
+ updatePassword(storage, encryptionPubKey);
+ passwordFailureKey = null;
+ } catch(StorageException e) {
+ //The caller of a save reports this failure, so the update thread retrying the change does not report it again
+ passwordFailureKey = storage.getEncryptionPubKey();
+ throw e;
+ }
+ }
+
@Override
public void updateWallet(Storage storage, Wallet wallet) throws StorageException {
updateWallet(storage, wallet, null);
@@ -234,27 +246,43 @@ public void updateWallet(Storage storage, Wallet wallet) throws StorageException
@Override
public void updateWallet(Storage storage, Wallet wallet, ECKey encryptionPubKey) throws StorageException {
updateExecutor.execute(() -> {
+ //An update can wait behind others while the wallet is saved with a password added or removed. The key it was queued with is then
+ //no longer the key of the storage, and it leaves the encryption of the file as it finds it
+ ECKey storagePubKey = storage.getEncryptionPubKey();
+ boolean queuedWithStorageKey = Objects.equals(encryptionPubKey, Storage.NO_PASSWORD_KEY.equals(storagePubKey) ? null : storagePubKey);
+ String newPassword = getFilePassword(encryptionPubKey);
+ boolean passwordUpdated = false;
+
try {
- //An update can wait behind others while the wallet is saved with a password added or removed. The key it was queued with is then
- //no longer the key of the storage, and it leaves the encryption of the file as it finds it
- ECKey storagePubKey = storage.getEncryptionPubKey();
- boolean queuedWithStorageKey = Objects.equals(encryptionPubKey, Storage.NO_PASSWORD_KEY.equals(storagePubKey) ? null : storagePubKey);
- String newPassword = getFilePassword(encryptionPubKey);
String currentPassword = getDatasourcePassword();
if(!queuedWithStorageKey) {
update(storage, wallet, currentPassword);
} else if(dataSource != null && currentPassword != null && newPassword == null) {
//Removing encryption: write data first
update(storage, wallet, currentPassword);
+ passwordUpdated = true;
updatePassword(storage, encryptionPubKey);
} else {
//Adding encryption or no change: change file first
+ passwordUpdated = true;
updatePassword(storage, encryptionPubKey);
update(storage, wallet, newPassword);
}
+
+ if(queuedWithStorageKey) {
+ passwordFailureKey = null;
+ storage.encryptionKeySaved(storagePubKey);
+ }
} catch(Exception e) {
log.error("Error updating wallet db", e);
+
+ //A password changed without a full save of the wallet reaches the file only here, after the change has been reported as made.
+ //Each later update tries the change again, so it is reported once for each password rather than on every attempt
+ if(passwordUpdated && !Objects.equals(getDatasourcePassword(), newPassword) && !Objects.equals(storagePubKey, passwordFailureKey)) {
+ passwordFailureKey = storagePubKey;
+ EventManager.get().post(new WalletPasswordChangeFailedEvent(wallet, newPassword == null, e));
+ }
}
});
}
### src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java
@@ -1071,11 +1071,8 @@ private boolean saveWallet(boolean changePassword, boolean suggestChangePassword
if(password.get().length() == 0 && requirement != WalletPasswordDialog.PasswordRequirement.UPDATE_SET) {
try {
- walletForm.getStorage().setEncryptionPubKey(Storage.NO_PASSWORD_KEY);
+ walletForm.getStorage().setEncryptionPubKey(Storage.NO_PASSWORD_KEY, deleteBackups);
walletForm.saveAndRefresh();
- if(deleteBackups) {
- walletForm.deleteBackups();
- }
EventManager.get().post(new RequestOpenWalletsEvent());
} catch (IOException | StorageException e) {
log.error("Error saving wallet", e);
@@ -1130,11 +1127,8 @@ private boolean saveWallet(boolean changePassword, boolean suggestChangePassword
childWallet.encrypt(key);
}
}
- walletForm.getStorage().setEncryptionPubKey(encryptionPubKey);
+ walletForm.getStorage().setEncryptionPubKey(encryptionPubKey, deleteBackups || dlg.isDeleteBackups());
walletForm.saveAndRefresh();
- if(deleteBackups || dlg.isDeleteBackups()) {
- walletForm.deleteBackups();
- }
EventManager.get().post(new RequestOpenWalletsEvent());
} catch (Exception e) {
log.error("Error saving wallet", e);
### src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java
@@ -148,10 +148,6 @@ protected void backgroundUpdate() {
}
}
- public void deleteBackups() {
- storage.deleteBackups();
- }
-
public void refreshHistory(Integer blockHeight) {
refreshHistory(blockHeight, null, null);
}
### src/test/java/com/sparrowwallet/sparrow/io/DbPersistenceTest.java
@@ -1,5 +1,6 @@
package com.sparrowwallet.sparrow.io;
+import com.google.common.eventbus.Subscribe;
import com.sparrowwallet.drongo.ExtendedKey;
import com.sparrowwallet.drongo.KeyDerivation;
import com.sparrowwallet.drongo.crypto.Argon2KeyDeriver;
@@ -13,21 +14,30 @@
import com.sparrowwallet.drongo.wallet.StandardAccount;
import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.drongo.wallet.WalletModel;
+import com.sparrowwallet.sparrow.EventManager;
+import com.sparrowwallet.sparrow.event.WalletBlockHeightChangedEvent;
+import com.sparrowwallet.sparrow.event.WalletPasswordChangeFailedEvent;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.function.Executable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.attribute.PosixFilePermission;
+import java.nio.file.attribute.PosixFilePermissions;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Comparator;
import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
public class DbPersistenceTest {
@@ -314,6 +324,245 @@ public void updateQueuedWithANewPasswordEncryptsTheFile() throws Exception {
Assertions.assertTrue(isWalletValid(storage.getWalletFile(), "pass"));
}
+ /**
+ * Backups requested deleted with a password change go once the update queued with the new key has written the file.
+ */
+ @Test
+ public void updateQueuedWithANewPasswordDeletesBackupsOnceWritten() throws Exception {
+ AtomicInteger backupDeletions = new AtomicInteger();
+ Storage storage = createBackupCountingStorage("Savings", backupDeletions);
+ Wallet wallet = createWallet("Savings");
+ storage.saveWallet(wallet);
+
+ storage.setEncryptionPubKey(ECKey.fromPublicOnly(storage.getKeyDeriver().deriveECKey("pass")), true);
+ Assertions.assertEquals(0, backupDeletions.get());
+ storage.updateWallet(wallet);
+ storage.updateWallet(wallet);
+ storage.closeAndWait();
+
+ Assertions.assertEquals(1, backupDeletions.get());
+ Assertions.assertTrue(isWalletValid(storage.getWalletFile(), "pass"));
+ }
+
+ /**
+ * A write that started before the password was last changed has not written the file with the new key, so it leaves the backups requested deleted.
+ */
+ @Test
+ public void backupsAreDeletedOnlyForTheKeyTheyWereRequestedWith() throws Exception {
+ AtomicInteger backupDeletions = new AtomicInteger();
+ Storage storage = createBackupCountingStorage("Savings", backupDeletions);
+ ECKey previousKey = ECKey.fromPublicOnly(storage.getKeyDeriver().deriveECKey("previous"));
+ ECKey requestedKey = ECKey.fromPublicOnly(storage.getKeyDeriver().deriveECKey("pass"));
+
+ storage.setEncryptionPubKey(requestedKey, true);
+ storage.encryptionKeySaved(previousKey);
+ storage.encryptionKeySaved(Storage.NO_PASSWORD_KEY);
+ Assertions.assertEquals(0, backupDeletions.get());
+
+ storage.encryptionKeySaved(ECKey.fromPublicOnly(storage.getKeyDeriver().deriveECKey("pass")));
+ storage.encryptionKeySaved(requestedKey);
+ Assertions.assertEquals(1, backupDeletions.get());
+ }
+
+ /**
+ * A save confirming the password while a change to it is still to reach the file keeps the deletion requested with the change, and a change to
+ * another password without deleting backups withdraws it.
+ */
+ @Test
+ public void backupDeletionSurvivesASaveKeepingThePassword() throws Exception {
+ AtomicInteger backupDeletions = new AtomicInteger();
+ Storage storage = createBackupCountingStorage("Savings", backupDeletions);
+ ECKey requestedKey = ECKey.fromPublicOnly(storage.getKeyDeriver().deriveECKey("pass"));
+
+ storage.setEncryptionPubKey(requestedKey, true);
+ storage.setEncryptionPubKey(ECKey.fromPublicOnly(storage.getKeyDeriver().deriveECKey("pass")), false);
+ storage.encryptionKeySaved(requestedKey);
+ Assertions.assertEquals(1, backupDeletions.get());
+
+ ECKey otherKey = ECKey.fromPublicOnly(storage.getKeyDeriver().deriveECKey("other"));
+ storage.setEncryptionPubKey(requestedKey, true);
+ storage.setEncryptionPubKey(otherKey, false);
+ storage.encryptionKeySaved(requestedKey);
+ storage.encryptionKeySaved(otherKey);
+ Assertions.assertEquals(1, backupDeletions.get());
+ }
+
+ /**
+ * A password change that fails on the update thread is reported once, however many updates go on to try it, and leaves the file and its backups as
+ * they were.
+ */
+ @Test
+ public void updateFailingToChangeThePasswordIsReportedAndKeepsBackups() throws Throwable {
+ AtomicInteger backupDeletions = new AtomicInteger();
+ Storage storage = createBackupCountingStorage("Savings", backupDeletions);
+ Wallet wallet = createWallet("Savings");
+ storage.saveWallet(wallet);
+
+ List<WalletPasswordChangeFailedEvent> events = failPasswordChange(() -> {
+ storage.setEncryptionPubKey(ECKey.fromPublicOnly(storage.getKeyDeriver().deriveECKey("pass")), true);
+ storage.updateWallet(wallet);
+ storage.updateWallet(wallet);
+ storage.closeAndWait();
+ });
+
+ Assertions.assertEquals(1, events.size());
+ Assertions.assertSame(wallet, events.getFirst().getWallet());
+ Assertions.assertEquals(0, backupDeletions.get());
+ Assertions.assertFalse(Storage.isEncrypted(storage.getWalletFile()));
+ Assertions.assertTrue(isWalletValid(storage.getWalletFile(), null));
+ }
+
+ /**
+ * A full save that fails to change the password throws to its caller, which reports it, so the updates that go on to retry the change do not.
+ */
+ @Test
+ public void fullSaveFailingToChangeThePasswordIsNotReportedAgain() throws Throwable {
+ AtomicInteger backupDeletions = new AtomicInteger();
+ Storage storage = createBackupCountingStorage("Savings", backupDeletions);
+ Wallet wallet = createWallet("Savings");
+ storage.saveWallet(wallet);
+
+ List<WalletPasswordChangeFailedEvent> events = failPasswordChange(() -> {
+ storage.setEncryptionPubKey(ECKey.fromPublicOnly(storage.getKeyDeriver().deriveECKey("pass")), true);
+ Assertions.assertThrows(StorageException.class, () -> storage.saveWallet(wallet));
+ storage.updateWallet(wallet);
+ storage.closeAndWait();
+ });
+
+ Assertions.assertEquals(0, events.size());
+ Assertions.assertEquals(0, backupDeletions.get());
+ Assertions.assertTrue(isWalletValid(storage.getWalletFile(), null));
+ }
+
+ /**
+ * The same for a full save removing the password.
+ */
+ @Test
+ public void fullSaveFailingToRemoveThePasswordIsNotReportedAgain() throws Throwable {
+ AtomicInteger backupDeletions = new AtomicInteger();
+ Storage storage = createBackupCountingStorage("Savings", backupDeletions);
+ Wallet wallet = createWallet("Savings");
+ storage.setEncryptionPubKey(ECKey.fromPublicOnly(storage.getKeyDeriver().deriveECKey("pass")));
+ storage.saveWallet(wallet);
+
+ List<WalletPasswordChangeFailedEvent> events = failPasswordChange(() -> {
+ storage.setEncryptionPubKey(Storage.NO_PASSWORD_KEY, true);
+ Assertions.assertThrows(StorageException.class, () -> storage.saveWallet(wallet));
+ storage.updateWallet(wallet);
+ storage.closeAndWait();
+ });
+
+ Assertions.assertEquals(0, events.size());
+ Assertions.assertEquals(0, backupDeletions.get());
+ Assertions.assertTrue(isWalletValid(storage.getWalletFile(), "pass"));
+ }
+
+ /**
+ * Removing a password writes the wallet before the file, so a removal failing on the update thread is reported as one, and the data still saved.
+ */
+ @Test
+ public void updateFailingToRemoveThePasswordIsReportedAsARemoval() throws Throwable {
+ AtomicInteger backupDeletions = new AtomicInteger();
+ Storage storage = createBackupCountingStorage("Savings", backupDeletions);
+ Wallet wallet = createWallet("Savings");
+ storage.setEncryptionPubKey(ECKey.fromPublicOnly(storage.getKeyDeriver().deriveECKey("pass")));
+ storage.saveWallet(wallet);
+
+ List<WalletPasswordChangeFailedEvent> events = failPasswordChange(() -> {
+ storage.setEncryptionPubKey(Storage.NO_PASSWORD_KEY, true);
+ EventManager.get().post(new WalletBlockHeightChangedEvent(wallet, 850000));
+ storage.updateWallet(wallet);
+ storage.closeAndWait();
+ });
+
+ Assertions.assertEquals(1, events.size());
+ Assertions.assertTrue(events.getFirst().isPasswordRemoved());
+ Assertions.assertEquals(0, backupDeletions.get());
+
+ Storage savedStorage = new Storage(PersistenceType.DB, storage.getWalletFile());
+ try {
+ Assertions.assertEquals(850000, savedStorage.loadEncryptedWallet("pass").getWallet().getStoredBlockHeight());
+ } finally {
+ savedStorage.closeAndWait();
+ }
+ }
+
+ /**
+ * A full save that succeeds with another password clears a failure recorded by an earlier one, so the same password failing again is reported.
+ */
+ @Test
+ public void passwordFailingAgainAfterASuccessfulSaveIsReported() throws Throwable {
+ Storage storage = createBackupCountingStorage("Savings", new AtomicInteger());
+ Wallet wallet = createWallet("Savings");
+ storage.saveWallet(wallet);
+ ECKey failingKey = ECKey.fromPublicOnly(storage.getKeyDeriver().deriveECKey("pass"));
+
+ List<WalletPasswordChangeFailedEvent> events = failPasswordChange(() -> {
+ storage.setEncryptionPubKey(failingKey);
+ Assertions.assertThrows(StorageException.class, () -> storage.saveWallet(wallet));
+ });
+ Assertions.assertEquals(0, events.size());
+
+ storage.setEncryptionPubKey(ECKey.fromPublicOnly(storage.getKeyDeriver().deriveECKey("other")));
+ storage.saveWallet(wallet);
+
+ events = failPasswordChange(() -> {
+ storage.setEncryptionPubKey(failingKey);
+ storage.updateWallet(wallet);
+ storage.closeAndWait();
+ });
+
+ Assertions.assertEquals(1, events.size());
+ Assertions.assertFalse(events.getFirst().isPasswordRemoved());
+ Assertions.assertTrue(isWalletValid(storage.getWalletFile(), "other"));
+ }
+
+ /**
+ * Runs the password change with the wallet folder unable to take new entries, which the new file is written as. Updates queued by the change
+ * run when the storage is closed, which must be done within it.
+ */
+ private List<WalletPasswordChangeFailedEvent> failPasswordChange(Executable passwordChange) throws Throwable {
+ List<WalletPasswordChangeFailedEvent> events = new CopyOnWriteArrayList<>();
+ Object subscriber = new Object() {
+ @Subscribe
+ public void walletPasswordChangeFailed(WalletPasswordChangeFailedEvent event) {
+ events.add(event);
+ }
+ };
+
+ Set<PosixFilePermission> permissions;
+ try {
+ permissions = Files.getPosixFilePermissions(tempDir);
+ } catch(UnsupportedOperationException e) {
+ throw Assumptions.<RuntimeException>abort("POSIX permissions are not supported: " + e.getMessage());
+ }
+
+ EventManager.get().register(subscriber);
+ Files.setPosixFilePermissions(tempDir, PosixFilePermissions.fromString("r-x------"));
+ try {
+ Assumptions.assumeFalse(Files.isWritable(tempDir), "folder permissions are not enforced for this user");
+ passwordChange.execute();
+ } finally {
+ Files.setPosixFilePermissions(tempDir, permissions);
+ EventManager.get().unregister(subscriber);
+ }
+
+ return events;
+ }
+
+ private Storage createBackupCountingStorage(String walletName, AtomicInteger backupDeletions) {
+ Storage storage = new Storage(PersistenceType.DB, tempDir.resolve(walletName + "." + PersistenceType.DB.getExtension()).toFile()) {
+ @Override
+ public void deleteBackups() {
+ backupDeletions.incrementAndGet();
+ }
+ };
+ storage.setKeyDeriver(new Argon2KeyDeriver());
+ storage.setEncryptionPubKey(Storage.NO_PASSWORD_KEY);
+
+ return storage;
+ }
+
@Test
public void passwordChangeKeepsSymlinkedWalletInPlace() throws Exception {
Storage targetStorage = createUnencryptedWallet("Volume");Why this scored 60/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.