Skip to content

Commit

Permalink
Fix #1947 - Check expected files are still present before restoring a…
Browse files Browse the repository at this point in the history
… session.
  • Loading branch information
stefanceriu committed Nov 12, 2024
1 parent 77ade52 commit 6683879
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions ElementX/Sources/Services/UserSession/UserSessionStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6683879

Please sign in to comment.