Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading