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/bypass-lock-prevention] Bypass Passcode Prevention #1324

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions ownCloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
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 @@ -1069,6 +1070,7 @@
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 @@ -1893,6 +1895,7 @@
DC27A19B20CAB5D7008ACB6C /* FileProvider Integration */,
DC85573120513C7500189B9A /* Resources */,
DC0B37952051541C00189B9A /* ownCloud.entitlements */,
396DAD872B83F00900957C58 /* PrivacyInfo.xcprivacy */,
);
path = ownCloud;
sourceTree = "<group>";
Expand Down Expand Up @@ -4249,6 +4252,7 @@
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: 23 additions & 0 deletions ownCloud/PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypes</key>
<array/>
<key>NSPrivacyTrackingDomains</key>
<array/>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>35F9.1</string>
</array>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
</dict>
</array>
</dict>
</plist>
26 changes: 25 additions & 1 deletion ownCloudAppShared/AppLock/AppLockManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ public class AppLockManager: NSObject {
self.userDefaults.set(newValue, forKey: "applock-locked-until-date")
}
}
private var lockSetTime: TimeInterval? {
get {
return userDefaults.object(forKey: "applock-lock-set-time") as? TimeInterval
}
set(newValue) {
self.userDefaults.set(newValue, forKey: "applock-lock-set-time")
}
}
private var biometricalAuthenticationSucceeded: Bool {
get {
return userDefaults.bool(forKey: "applock-biometrical-authentication-succeeded")
Expand Down Expand Up @@ -373,6 +381,7 @@ public class AppLockManager: NSObject {
let delayUntilNextAttempt = pow(powBaseDelay, Double(failedPasscodeAttempts))

lockedUntilDate = Date().addingTimeInterval(delayUntilNextAttempt)
lockSetTime = ProcessInfo.processInfo.systemUptime
felix-schwarz marked this conversation as resolved.
Show resolved Hide resolved
startLockCountdown()
}

Expand All @@ -381,6 +390,21 @@ 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 timeRemaining = lockedUntilDate.timeIntervalSinceNow

if lockDuration < timeRemaining {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • lockDuration computes the time since the lock has been set
  • timeRemaining computes the time until the lock expires

Comparing the two will not be able to tell if there was an attempt to bypass the lock. Image a 10 second delay, where 2 seconds have passed by and 8 seconds are remaining - without any bypass attempt. These numbers would fit the condition for a lock-bypass above even though it hasn't been bypassed.

To determine a bypass, it's necessary to also keep track of the date/time the lock has been put in place - and then use that date to compute the time passed since locking, to compare it against the time passed in system uptime.
That comparison should also leave a tiny bit of wiggle-room (f.ex. ~ 0.05 seconds), because the systemUptime and the date are not taken at the exact same moment and therefore will regularly differ slightly.

// User has attempted to bypass the lock
return true
}
}
return false
}

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

private var shouldDisplayCountdown : Bool {
if let startLockBeforeDate = self.lockedUntilDate {
if let startLockBeforeDate = self.lockedUntilDate, isLockBypassed {
felix-schwarz marked this conversation as resolved.
Show resolved Hide resolved
return startLockBeforeDate > Date()
}

Expand Down
Loading