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/clear-lock] Clear lock when determining unlock expiry #1061

Merged
merged 4 commits into from
Nov 19, 2021
Merged
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
25 changes: 22 additions & 3 deletions ownCloudAppShared/AppLock/AppLockManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,32 @@ public class AppLockManager: NSObject {
}

if unlocked, !self.shouldDisplayCountdown {
if let date = self.lastApplicationBackgroundedDate {
if Int(-date.timeIntervalSinceNow) < AppLockSettings.shared.lockDelay {
return false
if let backgroundedDate = lastApplicationBackgroundedDate {
if backgroundedDate.timeIntervalSinceNow > 0 {
// Device time is earlier than lastApplicationBackgroundedDate,
// which should not be possible. Clear unlocked state immediately
// to protect against this or other attempts to gain access by
// changing the device's clock time to a moment in the past
unlocked = false
lastApplicationBackgroundedDate = nil

Log.error(tagged: ["Security"], "Current device time \(Date().description) preceeds last application backgrounded date \(backgroundedDate.description), possibly indicating device time manipulation. Unlock status cleared.")

return true
} else {
if Int(-backgroundedDate.timeIntervalSinceNow) < AppLockSettings.shared.lockDelay {
// Unlock still valid
return false
}
}
}
}

// Clear unlocked state immediately if it has expired, so subsequently
// changing the device's clock time can't lead to an unlock
unlocked = false
lastApplicationBackgroundedDate = nil

return true
}

Expand Down