delete old keys after migration

This commit is contained in:
otsmr 2026-05-13 12:43:40 +02:00
parent f45638c58d
commit 3d1b38192e

View file

@ -197,38 +197,54 @@ Future<void> runMigrations() async {
}); });
} }
if (userService.currentUser.appVersion < 113) { if (userService.currentUser.appVersion < 113) {
var migrationSuccess = true;
final signalIdentity = await SecureStorage.instance.read( final signalIdentity = await SecureStorage.instance.read(
// ignore: deprecated_member_use_from_same_package // ignore: deprecated_member_use_from_same_package
key: SecureStorageKeys.signalIdentity, key: SecureStorageKeys.signalIdentity,
); );
if (signalIdentity != null) { if (signalIdentity != null) {
final decoded = jsonDecode(signalIdentity);
final identity = SignalIdentity.fromJson(decoded as Map<String, dynamic>);
try { try {
final decoded = jsonDecode(signalIdentity);
final identity = SignalIdentity.fromJson(
decoded as Map<String, dynamic>,
);
await RustKeyManager.importSignalIdentity( await RustKeyManager.importSignalIdentity(
identityKeyPairStructure: identity.identityKeyPairU8List, identityKeyPairStructure: identity.identityKeyPairU8List,
registrationId: identity.registrationId, registrationId: identity.registrationId,
signedPreKeyStore: await getSignalSignedPreKeyStoreOld(), signedPreKeyStore: await getSignalSignedPreKeyStoreOld(),
); );
Log.info('Importing signal identiy to the rust key manager'); Log.info('Importing signal identiy to the rust key manager');
// Clean up old keys after successful migration
await SecureStorage.instance.delete(
// ignore: deprecated_member_use_from_same_package
key: SecureStorageKeys.signalIdentity,
);
await SecureStorage.instance.delete(
// ignore: deprecated_member_use_from_same_package
key: SecureStorageKeys.signalSignedPreKey,
);
} catch (e) { } catch (e) {
Log.error(e); Log.error('Failed to migrate signal identity: $e');
migrationSuccess = false;
} }
} }
await UserService.update((u) { if (migrationSuccess) {
u await UserService.update((u) {
..appVersion = 113 u
..canUseLoginTokenForAuth = false ..appVersion = 113
// As usernames changes where not considered in the old version force users ..canUseLoginTokenForAuth = false
// to reenter there passwords. // As usernames changes where not considered in the old version force users
// ignore: deprecated_member_use_from_same_package // to reenter there passwords.
..twonlySafeBackup?.encryptionKey = [] // ignore: deprecated_member_use_from_same_package
// ignore: deprecated_member_use_from_same_package ..twonlySafeBackup?.encryptionKey = []
..twonlySafeBackup?.backupId = []; // ignore: deprecated_member_use_from_same_package
}); ..twonlySafeBackup?.backupId = [];
});
}
} }
} }