Always copy VaultFileCredentials when accessing it
This makes sure that mutations to the credentails can only ever be persisted intentionally.
This commit is contained in:
+3
-1
@@ -241,10 +241,12 @@ public class SecurityPreferencesFragment extends PreferencesFragment {
|
||||
if (!isBackupPasswordSet()) {
|
||||
Dialogs.showSetPasswordDialog(requireActivity(), new SetBackupPasswordListener());
|
||||
} else {
|
||||
SlotList slots = _vaultManager.getVault().getCredentials().getSlots();
|
||||
VaultFileCredentials creds = _vaultManager.getVault().getCredentials();
|
||||
SlotList slots = creds.getSlots();
|
||||
for (Slot slot : slots.findBackupPasswordSlots()) {
|
||||
slots.remove(slot);
|
||||
}
|
||||
_vaultManager.getVault().setCredentials(creds);
|
||||
|
||||
saveAndBackupVault();
|
||||
updateEncryptionPreferences();
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.beemdevelopment.aegis.vault;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.beemdevelopment.aegis.crypto.CryptParameters;
|
||||
import com.beemdevelopment.aegis.crypto.CryptResult;
|
||||
import com.beemdevelopment.aegis.crypto.MasterKey;
|
||||
import com.beemdevelopment.aegis.crypto.MasterKeyException;
|
||||
import com.beemdevelopment.aegis.util.Cloner;
|
||||
import com.beemdevelopment.aegis.vault.slots.SlotList;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -45,4 +48,10 @@ public class VaultFileCredentials implements Serializable {
|
||||
public VaultFileCredentials exportable() {
|
||||
return new VaultFileCredentials(_key, _slots.exportable());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public VaultFileCredentials clone() {
|
||||
return Cloner.clone(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,11 +220,11 @@ public class VaultRepository {
|
||||
}
|
||||
|
||||
public VaultFileCredentials getCredentials() {
|
||||
return _creds;
|
||||
return _creds == null ? null : _creds.clone();
|
||||
}
|
||||
|
||||
public void setCredentials(VaultFileCredentials creds) {
|
||||
_creds = creds;
|
||||
_creds = creds == null ? null : creds.clone();
|
||||
}
|
||||
|
||||
public boolean isEncryptionEnabled() {
|
||||
|
||||
Reference in New Issue
Block a user