be absolutely sure we delete secure storage keys before writing them (#1182)
* be absolutely sure we delete secure storage keys before writing them * sync with other PR --------- Co-authored-by: fossephate <fosse@book.local> Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
Matthew Fosse committed
Nov 27, 2023 at 08:28 UTC
615d016dd5b00afb6fd2792640cf3c83947a6c41
7 files changed
+15
-3
lib/core/backup_service.dart
+4
@@ -436,6 +436,7 @@ class BackupService {
436
final backupPasswordKey = generateStoreKeyFor(key: SecretStoreKey.backupPassword);
437
final backupPassword = keychainJSON[backupPasswordKey] as String;
438
439
+ await _flutterSecureStorage.delete(key: backupPasswordKey);
440
await _flutterSecureStorage.write(key: backupPasswordKey, value: backupPassword);
441
442
keychainWalletsInfo.forEach((dynamic rawInfo) async {
@@ -443,6 +444,7 @@ class BackupService {
444
await importWalletKeychainInfo(info);
445
});
446
447
+ await _flutterSecureStorage.delete(key: pinCodeKey);
448
await _flutterSecureStorage.write(key: pinCodeKey, value: encodedPinCode(pin: decodedPin));
449
450
keychainDumpFile.deleteSync();
@@ -462,6 +464,7 @@ class BackupService {
464
final backupPasswordKey = generateStoreKeyFor(key: SecretStoreKey.backupPassword);
465
final backupPassword = keychainJSON[backupPasswordKey] as String;
466
467
+ await _flutterSecureStorage.delete(key: backupPasswordKey);
468
await _flutterSecureStorage.write(key: backupPasswordKey, value: backupPassword);
469
470
keychainWalletsInfo.forEach((dynamic rawInfo) async {
@@ -469,6 +472,7 @@ class BackupService {
472
await importWalletKeychainInfo(info);
473
});
474
475
+ await _flutterSecureStorage.delete(key: pinCodeKey);
476
await _flutterSecureStorage.write(key: pinCodeKey, value: encodedPinCode(pin: decodedPin));
477
478
keychainDumpFile.deleteSync();
lib/core/key_service.dart
+1
@@ -19,6 +19,7 @@ class KeyService {
19
key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
20
final encodedPassword = encodeWalletPassword(password: password);
21
22
+ await _secureStorage.delete(key: key);
23
await _secureStorage.write(key: key, value: encodedPassword);
24
}
25
lib/entities/default_settings_migration.dart
+1
@@ -496,6 +496,7 @@ Future<void> generateBackupPassword(FlutterSecureStorage secureStorage) async {
496
}
497
498
final password = encrypt.Key.fromSecureRandom(32).base16;
499
+ await secureStorage.delete(key: key);
500
await secureStorage.write(key: key, value: password);
501
}
502
lib/entities/fs_migration.dart
+1
@@ -147,6 +147,7 @@ Future<void> ios_migrate_pin() async {
147
148
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
149
final encodedPassword = encodedPinCode(pin: pinPassword);
150
+ await flutterSecureStorage.delete(key: key);
151
await flutterSecureStorage.write(key: key, value: encodedPassword);
152
await prefs.setBool('ios_migration_pin_completed', true);
153
}
lib/entities/get_encryption_key.dart
+3
-1
@@ -9,7 +9,9 @@ Future<List<int>> getEncryptionKey(
9
if (stringifiedKey == null) {
10
key = CakeHive.generateSecureKey();
11
final keyStringified = key.join(',');
12
- await secureStorage.write(key: 'transactionDescriptionsBoxKey', value: keyStringified);
12
+ String storageKey = 'transactionDescriptionsBoxKey';
13
+ await secureStorage.delete(key: storageKey);
14
+ await secureStorage.write(key: storageKey, value: keyStringified);
15
} else {
16
key = stringifiedKey.split(',').map((i) => int.parse(i)).toList();
17
}
lib/src/screens/support_chat/widgets/chatwoot_widget.dart
+4
-2
@@ -57,6 +57,8 @@ class ChatwootWidgetState extends State<ChatwootWidget> {
57
return true;
58
}
59
60
- Future<void> storeCookie(String value) async =>
61
- await widget.secureStorage.write(key: COOKIE_KEY, value: value);
60
+ Future<void> storeCookie(String value) async {
61
+ await widget.secureStorage.delete(key: COOKIE_KEY);
62
+ await widget.secureStorage.write(key: COOKIE_KEY, value: value);
63
+ }
64
}
lib/view_model/edit_backup_password_view_model.dart
+1
@@ -37,6 +37,7 @@ abstract class EditBackupPasswordViewModelBase with Store {
37
@action
38
Future<void> save() async {
39
final key = generateStoreKeyFor(key: SecretStoreKey.backupPassword);
40
+ await secureStorage.delete(key: key);
41
await secureStorage.write(key: key, value: backupPassword);
42
secretStore.write(key: key, value: backupPassword);
43
}