Fix #1947 - Check expected files are still present before restoring a session.

This commit is contained in:
Stefan Ceriu
2024-11-12 14:13:28 +02:00
committed by Stefan Ceriu
parent 5ddf83b83f
commit 6a5019687b
2 changed files with 13 additions and 0 deletions

View File

@@ -51,6 +51,14 @@ struct SessionDirectories: Hashable, Codable {
}
}
/// Check that mission critical files (the crypto db) are still in the right place when restoring a session
/// iOS might decide to move the app with its user defaults and keychain but without
/// some of the files stored in the shared container e.g. after a device transfer, offloading etc.
/// If that happens we should fail the session restoration.
func isNonTransientUserDataValid() -> Bool {
FileManager.default.fileExists(atPath: dataPath.appending("/matrix-sdk-crypto.sqlite3"))
}
private func deleteFiles(at url: URL, with prefix: String) throws {
let sessionDirectoryContents = try FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil)
for url in sessionDirectoryContents where url.lastPathComponent.hasPrefix(prefix) {

View File

@@ -118,6 +118,11 @@ class UserSessionStore: UserSessionStoreProtocol {
MXLog.info("Restoring client with encrypted store.")
}
guard credentials.restorationToken.sessionDirectories.isNonTransientUserDataValid() else {
MXLog.error("Failed restoring login, missing non-transient user data")
return .failure(.failedRestoringLogin)
}
let homeserverURL = credentials.restorationToken.session.homeserverUrl
let builder = ClientBuilder