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,27 +197,42 @@ 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;
} }
} }
if (migrationSuccess) {
await UserService.update((u) { await UserService.update((u) {
u u
..appVersion = 113 ..appVersion = 113
@ -231,6 +246,7 @@ Future<void> runMigrations() async {
}); });
} }
} }
}
Future<void> postStartupTasks() async { Future<void> postStartupTasks() async {
Log.info('Post startup started.'); Log.info('Post startup started.');