Эх сурвалжийг харах

fix clear token

Signed-off-by: Marino Faggiana <8616947+marinofaggiana@users.noreply.github.com>
Marino Faggiana 1 жил өмнө
parent
commit
5b24e949ba

+ 1 - 1
Brand/NCBrand.swift

@@ -89,7 +89,7 @@ let userAgent: String = {
 
 
     // Number of failed attempts after reset app
     // Number of failed attempts after reset app
     @objc public let resetAppPasscodeAttempts: Int = 10
     @objc public let resetAppPasscodeAttempts: Int = 10
-    public let passcodeSecondsFail: Int = 30
+    public let passcodeSecondsFail: Int = 60
 
 
     // Info Paging
     // Info Paging
     enum NCInfoPagingTab: Int, CaseIterable {
     enum NCInfoPagingTab: Int, CaseIterable {

+ 38 - 37
iOSClient/AppDelegate.swift

@@ -62,7 +62,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     let unifiedSearchQueue = Queuer(name: "unifiedSearchQueue", maxConcurrentOperationCount: 1, qualityOfService: .default)
     let unifiedSearchQueue = Queuer(name: "unifiedSearchQueue", maxConcurrentOperationCount: 1, qualityOfService: .default)
     let saveLivePhotoQueue = Queuer(name: "saveLivePhotoQueue", maxConcurrentOperationCount: 1, qualityOfService: .default)
     let saveLivePhotoQueue = Queuer(name: "saveLivePhotoQueue", maxConcurrentOperationCount: 1, qualityOfService: .default)
 
 
-    var isTaskProcessing: Bool = false
+    var isAppRefresh: Bool = false
+    var isAppProcessing: Bool = false
 
 
     var isUiTestingEnabled: Bool {
     var isUiTestingEnabled: Bool {
         return ProcessInfo.processInfo.arguments.contains("UI_TESTING")
         return ProcessInfo.processInfo.arguments.contains("UI_TESTING")
@@ -342,19 +343,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     func handleAppRefresh(_ task: BGTask) {
     func handleAppRefresh(_ task: BGTask) {
         scheduleAppRefresh()
         scheduleAppRefresh()
 
 
-        if isTaskProcessing {
-            NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Task already in progress, abort.")
+        if isAppProcessing {
+            NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Processing task already in progress, abort.")
             task.setTaskCompleted(success: true)
             task.setTaskCompleted(success: true)
             return
             return
         }
         }
-        isTaskProcessing = true
+        isAppRefresh = true
 
 
         NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in
         NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in
             NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Refresh task auto upload with \(items) uploads")
             NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Refresh task auto upload with \(items) uploads")
             NCNetworkingProcessUpload.shared.start { items in
             NCNetworkingProcessUpload.shared.start { items in
                 NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Refresh task upload process with \(items) uploads")
                 NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Refresh task upload process with \(items) uploads")
                 task.setTaskCompleted(success: true)
                 task.setTaskCompleted(success: true)
-                self.isTaskProcessing = false
+                self.isAppRefresh = false
             }
             }
         }
         }
     }
     }
@@ -362,19 +363,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     func handleProcessingTask(_ task: BGTask) {
     func handleProcessingTask(_ task: BGTask) {
         scheduleAppProcessing()
         scheduleAppProcessing()
 
 
-        if isTaskProcessing {
-            NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Task already in progress, abort.")
+        if isAppRefresh {
+            NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Refresh task already in progress, abort.")
             task.setTaskCompleted(success: true)
             task.setTaskCompleted(success: true)
             return
             return
         }
         }
-        isTaskProcessing = true
+        isAppProcessing = true
 
 
         NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in
         NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in
             NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Processing task auto upload with \(items) uploads")
             NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Processing task auto upload with \(items) uploads")
             NCNetworkingProcessUpload.shared.start { items in
             NCNetworkingProcessUpload.shared.start { items in
                 NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Processing task upload process with \(items) uploads")
                 NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Processing task upload process with \(items) uploads")
                 task.setTaskCompleted(success: true)
                 task.setTaskCompleted(success: true)
-                self.isTaskProcessing = false
+                self.isAppProcessing = false
             }
             }
         }
         }
     }
     }
@@ -606,10 +607,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             NCManageDatabase.shared.setAccountUserProfile(account: account, userProfile: userProfile)
             NCManageDatabase.shared.setAccountUserProfile(account: account, userProfile: userProfile)
         }
         }
 
 
-        if NCGlobal.shared.capabilityServerVersionMajor > 0 {
-            NextcloudKit.shared.setup(nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor)
-        }
-
         NCPushNotification.shared().pushNotification()
         NCPushNotification.shared().pushNotification()
 
 
         NCService().startRequestServicesServer()
         NCService().startRequestServicesServer()
@@ -752,7 +749,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             let passcodeCounterFail = NCKeychain().passcodeCounterFail
             let passcodeCounterFail = NCKeychain().passcodeCounterFail
             if NCKeychain().resetAppCounterFail && (passcodeCounterFail >= NCBrandOptions.shared.resetAppPasscodeAttempts) {
             if NCKeychain().resetAppCounterFail && (passcodeCounterFail >= NCBrandOptions.shared.resetAppPasscodeAttempts) {
                 self.passcodeResetApp(passcodeViewController)
                 self.passcodeResetApp(passcodeViewController)
-            } else if passcodeCounterFail >= 3 {
+            } else if passcodeCounterFail == 3 || passcodeCounterFail == 5 {
                 self.passcodeAlert(passcodeViewController)
                 self.passcodeAlert(passcodeViewController)
             }
             }
             completion()
             completion()
@@ -782,14 +779,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                         }
                         }
                     }
                     }
                 } else {
                 } else {
+                    let counterFail = NCKeychain().passcodeCounterFail
                     if let error = evaluateError {
                     if let error = evaluateError {
                         if error._code == LAError.authenticationFailed.rawValue {
                         if error._code == LAError.authenticationFailed.rawValue {
-                            // var error: NSError?
-                            // LAContext().canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error)
+                            DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
+                                if counterFail < 3 { NCKeychain().passcodeCounterFail = 3 }
+                                self.passcodeAlert(passcodeViewController)
+                            }
                         } else if error._code == LAError.biometryLockout.rawValue {
                         } else if error._code == LAError.biometryLockout.rawValue {
-                            let reason = "TouchID has been locked out due to few fail attemp. Enter iPhone passcode to enable TouchID."
-                            LAContext().evaluatePolicy(LAPolicy.deviceOwnerAuthentication, localizedReason: reason, reply: { success, _ in
-                                if success { DispatchQueue.main.async { self.enableTouchFaceID() } }
+                            if counterFail < 5 { NCKeychain().passcodeCounterFail = 5 }
+                            LAContext().evaluatePolicy(LAPolicy.deviceOwnerAuthentication, localizedReason: NSLocalizedString("_deviceOwnerAuthentication_", comment: ""), reply: { success, _ in
+                                if success {
+                                    DispatchQueue.main.async {
+                                        self.enableTouchFaceID()
+                                    }
+                                }
                             })
                             })
                         }
                         }
                     }
                     }
@@ -816,7 +820,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             let passcodeCounterFail = NCKeychain().passcodeCounterFail
             let passcodeCounterFail = NCKeychain().passcodeCounterFail
             if NCKeychain().resetAppCounterFail && (passcodeCounterFail >= NCBrandOptions.shared.resetAppPasscodeAttempts) {
             if NCKeychain().resetAppCounterFail && (passcodeCounterFail >= NCBrandOptions.shared.resetAppPasscodeAttempts) {
                 DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { self.passcodeResetApp(passcodeViewController) }
                 DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { self.passcodeResetApp(passcodeViewController) }
-            } else if passcodeCounterFail >= 3 {
+            } else if passcodeCounterFail == 3 || passcodeCounterFail == 5 {
                 DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { self.passcodeAlert(passcodeViewController) }
                 DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { self.passcodeAlert(passcodeViewController) }
             }
             }
             return false
             return false
@@ -836,15 +840,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         let alertController = UIAlertController(title: NSLocalizedString("_passcode_counter_fail_", comment: ""), message: nil, preferredStyle: .alert)
         let alertController = UIAlertController(title: NSLocalizedString("_passcode_counter_fail_", comment: ""), message: nil, preferredStyle: .alert)
         passcodeViewController.present(alertController, animated: true, completion: { })
         passcodeViewController.present(alertController, animated: true, completion: { })
 
 
-        var seconds = NCKeychain().passcodeSecondsFail * NCBrandOptions.shared.passcodeSecondsFail
+        var seconds = NCBrandOptions.shared.passcodeSecondsFail
         _ = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { timer in
         _ = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { timer in
             alertController.message = "\(seconds) " + NSLocalizedString("_seconds_", comment: "")
             alertController.message = "\(seconds) " + NSLocalizedString("_seconds_", comment: "")
             seconds -= 1
             seconds -= 1
             if seconds < 0 {
             if seconds < 0 {
-                NCKeychain().passcodeSecondsFail += 1
                 timer.invalidate()
                 timer.invalidate()
                 alertController.dismiss(animated: true)
                 alertController.dismiss(animated: true)
                 passcodeViewController.setContentHidden(false, animated: true)
                 passcodeViewController.setContentHidden(false, animated: true)
+                let counterFail = NCKeychain().passcodeCounterFail
             }
             }
         }
         }
     }
     }
@@ -873,24 +877,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         NCNetworking.shared.cancelUploadTasks()
         NCNetworking.shared.cancelUploadTasks()
         NCNetworking.shared.cancelUploadBackgroundTask()
         NCNetworking.shared.cancelUploadBackgroundTask()
 
 
-        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
-
-            URLCache.shared.memoryCapacity = 0
-            URLCache.shared.diskCapacity = 0
+        URLCache.shared.memoryCapacity = 0
+        URLCache.shared.diskCapacity = 0
 
 
-            utilityFileSystem.removeGroupDirectoryProviderStorage()
-            utilityFileSystem.removeGroupApplicationSupport()
-            utilityFileSystem.removeDocumentsDirectory()
-            utilityFileSystem.removeTemporaryDirectory()
+        utilityFileSystem.removeGroupDirectoryProviderStorage()
+        utilityFileSystem.removeGroupApplicationSupport()
+        utilityFileSystem.removeDocumentsDirectory()
+        utilityFileSystem.removeTemporaryDirectory()
 
 
-            NCKeychain().removeAll()
+        NCKeychain().removeAll()
 
 
-            if killEmAll {
-                NCManageDatabase.shared.removeDB()
-                exit(0)
-            } else {
-                NCManageDatabase.shared.clearDatabase(account: nil, removeAccount: true)
-            }
+        if killEmAll {
+            NCManageDatabase.shared.removeDB()
+            exit(0)
+        } else {
+            NCManageDatabase.shared.clearDatabase(account: nil, removeAccount: true)
         }
         }
     }
     }
 
 

+ 0 - 5
iOSClient/Networking/NCService.swift

@@ -184,11 +184,6 @@ class NCService: NSObject {
             NCManageDatabase.shared.addCapabilitiesJSon(data, account: account)
             NCManageDatabase.shared.addCapabilitiesJSon(data, account: account)
             NCManageDatabase.shared.setCapabilities(account: account, data: data)
             NCManageDatabase.shared.setCapabilities(account: account, data: data)
 
 
-            // Setup communication
-            if NCGlobal.shared.capabilityServerVersionMajor > 0 {
-                NextcloudKit.shared.setup(nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor)
-            }
-
             // Theming
             // Theming
             if NCGlobal.shared.capabilityThemingColor != NCBrandColor.shared.themingColor || NCGlobal.shared.capabilityThemingColorElement != NCBrandColor.shared.themingColorElement || NCGlobal.shared.capabilityThemingColorText != NCBrandColor.shared.themingColorText {
             if NCGlobal.shared.capabilityThemingColor != NCBrandColor.shared.themingColor || NCGlobal.shared.capabilityThemingColorElement != NCBrandColor.shared.themingColorElement || NCGlobal.shared.capabilityThemingColorText != NCBrandColor.shared.themingColorText {
                 NCBrandColor.shared.settingThemingColor(account: account)
                 NCBrandColor.shared.settingThemingColor(account: account)

+ 0 - 13
iOSClient/Settings/NCKeychain.swift

@@ -74,23 +74,10 @@ import KeychainAccess
             return 0
             return 0
         }
         }
         set {
         set {
-            if newValue == 0 { passcodeSecondsFail = 1 }
             keychain["passcodeCounterFail"] = String(newValue)
             keychain["passcodeCounterFail"] = String(newValue)
         }
         }
     }
     }
 
 
-    var passcodeSecondsFail: Int {
-        get {
-            if let value = try? keychain.get("passcodeSecondsFail"), let result = Int(value) {
-                return result
-            }
-            return 1
-        }
-        set {
-            keychain["passcodeSecondsFail"] = String(newValue)
-        }
-    }
-
     @objc var requestPasscodeAtStart: Bool {
     @objc var requestPasscodeAtStart: Bool {
         get {
         get {
             let keychainOLD = Keychain(service: "Crypto Cloud")
             let keychainOLD = Keychain(service: "Crypto Cloud")

+ 1 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -949,6 +949,7 @@
 "_download_video_"          = "Download video";
 "_download_video_"          = "Download video";
 "_reset_wrong_passcode_"    = "Reset application";
 "_reset_wrong_passcode_"    = "Reset application";
 "_reset_wrong_passcode_desc_" = "Use \"Reset application\" for remove all accounts and local data after %d failed code entry attempts.";
 "_reset_wrong_passcode_desc_" = "Use \"Reset application\" for remove all accounts and local data after %d failed code entry attempts.";
+"_deviceOwnerAuthentication_" = "Biometric sensor has been locked out due to few fail attemps. Enter device passcode to enable sensor.";
 
 
 // Video
 // Video
 "_select_trace_"            = "Select the trace";
 "_select_trace_"            = "Select the trace";