Skip to content

Commit

Permalink
Converted lockUntilDate to lockDelay. This is a better prevention if …
Browse files Browse the repository at this point in the history
…user changes the system time to bypass the passcode lock. ProcessInfo.processInfo.systemUptime does not work, because system does not restart after setting the system date/time. lockUntilDate is also stored in user defaults than lockedUntilDate before.
  • Loading branch information
hosy committed Mar 15, 2024
1 parent 853e803 commit b21c0b6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 71 deletions.
4 changes: 0 additions & 4 deletions ownCloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
3968C883239C54AD00AC28AC /* ReleaseNotes.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3968C87B239C54AC00AC28AC /* ReleaseNotes.plist */; };
396C82FB2319AFDD00938262 /* CollaborateAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 396C82FA2319AFDD00938262 /* CollaborateAction.swift */; };
396D7C6523224A53002380C1 /* DiscardSceneAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 396D7C5F23224A53002380C1 /* DiscardSceneAction.swift */; };
396DAD882B83F00900957C58 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 396DAD872B83F00900957C58 /* PrivacyInfo.xcprivacy */; };
397754F82327A33500119FCB /* OpenSceneAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 397754F22327A33500119FCB /* OpenSceneAction.swift */; };
39878B7421FB1DE800DBF693 /* UINavigationController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39878B7321FB1DE800DBF693 /* UINavigationController+Extension.swift */; };
399697F5260255B100E5AEBA /* PDFGotoPageAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 399697F1260255B100E5AEBA /* PDFGotoPageAction.swift */; };
Expand Down Expand Up @@ -1070,7 +1069,6 @@
396BE4C92289500E00B254A9 /* RoundedLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundedLabel.swift; sourceTree = "<group>"; };
396C82FA2319AFDD00938262 /* CollaborateAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollaborateAction.swift; sourceTree = "<group>"; };
396D7C5F23224A53002380C1 /* DiscardSceneAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiscardSceneAction.swift; sourceTree = "<group>"; };
396DAD872B83F00900957C58 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
397754E123279EED00119FCB /* OCItem+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OCItem+Extension.swift"; sourceTree = "<group>"; };
397754F22327A33500119FCB /* OpenSceneAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenSceneAction.swift; sourceTree = "<group>"; };
397E276B23D05A5400117B07 /* ServerListToolCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServerListToolCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1895,7 +1893,6 @@
DC27A19B20CAB5D7008ACB6C /* FileProvider Integration */,
DC85573120513C7500189B9A /* Resources */,
DC0B37952051541C00189B9A /* ownCloud.entitlements */,
396DAD872B83F00900957C58 /* PrivacyInfo.xcprivacy */,
);
path = ownCloud;
sourceTree = "<group>";
Expand Down Expand Up @@ -4252,7 +4249,6 @@
39DF77D524EA854C0066E8F0 /* LaunchScreen.storyboard in Resources */,
3968C883239C54AD00AC28AC /* ReleaseNotes.plist in Resources */,
59D4895220C83F2E00369C2E /* InfoPlist.strings in Resources */,
396DAD882B83F00900957C58 /* PrivacyInfo.xcprivacy in Resources */,
593A821120C7D4C5000E2A90 /* Localizable.strings in Resources */,
DCE684F6241BD4E800799C30 /* Branding.plist in Resources */,
DC9BFBB320A19AF4007064B5 /* doc in Resources */,
Expand Down
23 changes: 0 additions & 23 deletions ownCloud/PrivacyInfo.xcprivacy

This file was deleted.

70 changes: 26 additions & 44 deletions ownCloudAppShared/AppLock/AppLockManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,16 @@ public class AppLockManager: NSObject {
self.userDefaults.set(newValue, forKey: "applock-failed-passcode-attempts")
}
}
private var lockedUntilDate: Date? {
get {
return userDefaults.object(forKey: "applock-locked-until-date") as? Date
}
set(newValue) {
self.userDefaults.set(newValue, forKey: "applock-locked-until-date")
}
}
private var lockSetTime: TimeInterval? {

private var lockDelay: Double? {
get {
return userDefaults.object(forKey: "applock-lock-set-time") as? TimeInterval
return userDefaults.object(forKey: "applock-delay") as? Double
}
set(newValue) {
self.userDefaults.set(newValue, forKey: "applock-lock-set-time")
self.userDefaults.set(newValue, forKey: "applock-delay")
}
}

private var biometricalAuthenticationSucceeded: Bool {
get {
return userDefaults.bool(forKey: "applock-biometrical-authentication-succeeded")
Expand Down Expand Up @@ -369,7 +363,8 @@ public class AppLockManager: NSObject {
if testPasscode == self.passcode {
unlocked = true
failedPasscodeAttempts = 0
lockSetTime = nil
lockDelay = nil

dismissLockscreen(animated: true)
} else {
unlocked = false
Expand All @@ -380,9 +375,7 @@ public class AppLockManager: NSObject {

if self.failedPasscodeAttempts >= self.maximumPasscodeAttempts {
let delayUntilNextAttempt = pow(powBaseDelay, Double(failedPasscodeAttempts))

lockedUntilDate = Date().addingTimeInterval(delayUntilNextAttempt)
lockSetTime = ProcessInfo.processInfo.systemUptime
lockDelay = delayUntilNextAttempt
startLockCountdown()
}

Expand All @@ -392,20 +385,6 @@ public class AppLockManager: NSObject {

// MARK: - Status

private var isLockBypassed: Bool {
if let lockedUntilDate = lockedUntilDate, let lockSetTime = lockSetTime {
let currentTime = ProcessInfo.processInfo.systemUptime
let lockDuration = currentTime - lockSetTime

let wiggleRoom: Double = 0.05

if abs(lockDuration - lockSetTime) > wiggleRoom {
return true
}
}
return false
}

private var shouldDisplayLockscreen: Bool {
if !AppLockSettings.shared.lockEnabled {
return false
Expand Down Expand Up @@ -442,9 +421,7 @@ public class AppLockManager: NSObject {
}

private var shouldDisplayCountdown : Bool {
if let startLockBeforeDate = self.lockedUntilDate {
return startLockBeforeDate > Date()
} else if isLockBypassed {
if let lockDelay = self.lockDelay, lockDelay > 0 {
return true
}

Expand All @@ -459,32 +436,37 @@ public class AppLockManager: NSObject {
passcodeViewController.view.setNeedsLayout()
}
updateLockCountdown()

lockTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.updateLockCountdown), userInfo: nil, repeats: true)

if lockTimer == nil {
lockTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.updateLockCountdown), userInfo: nil, repeats: true)
}
}
}

@objc private func updateLockCountdown() {
if let date = self.lockedUntilDate {
let interval = Int(date.timeIntervalSinceNow)
let seconds = interval % 60
let minutes = (interval / 60) % 60
let hours = (interval / 3600)

if let lockDelay = self.lockDelay {
let hours = Int(lockDelay) / 3600
let minutes = Int(lockDelay) / 60 % 60
let seconds = Int(lockDelay) % 60

if lockDelay > 0 {
self.lockDelay = (lockDelay - 1)
}

let dateFormatted:String?
if hours > 0 {
dateFormatted = String(format: "%02d:%02d:%02d", hours, minutes, seconds)
} else {
dateFormatted = String(format: "%02d:%02d", minutes, seconds)
}

let timeoutMessage:String = NSString(format: "Please try again in %@".localized as NSString, dateFormatted!) as String

performPasscodeViewControllerUpdates { (passcodeViewController) in
passcodeViewController.timeoutMessage = timeoutMessage
}

if date <= Date() {
if lockDelay <= 0 {
// Time elapsed, allow entering passcode again
self.lockTimer?.invalidate()
performPasscodeViewControllerUpdates { (passcodeViewController) in
Expand Down

0 comments on commit b21c0b6

Please sign in to comment.