Skip to content

Commit 3a600a9

Browse files
committed
Fix #1947 - Check expected files are still present before restoring a session.
1 parent f7aeb3e commit 3a600a9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

ElementX/Sources/Services/UserSession/SessionDirectories.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ struct SessionDirectories: Hashable, Codable {
5151
}
5252
}
5353

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

ElementX/Sources/Services/UserSession/UserSessionStore.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ class UserSessionStore: UserSessionStoreProtocol {
118118
MXLog.info("Restoring client with encrypted store.")
119119
}
120120

121+
guard credentials.restorationToken.sessionDirectories.isNonTransientUserDataValid() else {
122+
MXLog.error("Failed restoring login, missing non-transient user data")
123+
return .failure(.failedRestoringLogin)
124+
}
125+
121126
let homeserverURL = credentials.restorationToken.session.homeserverUrl
122127

123128
let builder = ClientBuilder

0 commit comments

Comments
 (0)