Bläddra i källkod

improvements bruteforce

Signed-off-by: Marino Faggiana <8616947+marinofaggiana@users.noreply.github.com>
Marino Faggiana 1 år sedan
förälder
incheckning
40cd244c74
3 ändrade filer med 18 tillägg och 6 borttagningar
  1. 1 1
      Brand/NCBrand.swift
  2. 17 4
      iOSClient/AppDelegate.swift
  3. 0 1
      iOSClient/Settings/NCKeychain.swift

+ 1 - 1
Brand/NCBrand.swift

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

+ 17 - 4
iOSClient/AppDelegate.swift

@@ -718,6 +718,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
     // MARK: - Passcode
 
+    var isPasscodeReset: Bool {
+        let passcodeCounterFailReset = NCKeychain().passcodeCounterFailReset
+        return NCKeychain().resetAppCounterFail && passcodeCounterFailReset >= NCBrandOptions.shared.resetAppPasscodeAttempts
+    }
+
+    var isPasscodeFail: Bool {
+        let passcodeCounterFail = NCKeychain().passcodeCounterFail
+        return passcodeCounterFail > 0 && passcodeCounterFail.isMultiple(of: 3)
+    }
+
     func presentPasscode(completion: @escaping () -> Void) {
 
         var error: NSError?
@@ -760,8 +770,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
               NCKeychain().touchFaceID,
               NCKeychain().passcode != nil,
               NCKeychain().requestPasscodeAtStart,
-              !(NCKeychain().passcodeCounterFail > 0 && NCKeychain().passcodeCounterFail.isMultiple(of: 3)),
-              !(NCKeychain().resetAppCounterFail && NCKeychain().passcodeCounterFailReset >= NCBrandOptions.shared.resetAppPasscodeAttempts),
+              !isPasscodeFail,
+              !isPasscodeReset,
               let passcodeViewController = privacyProtectionWindow?.rootViewController?.presentedViewController as? TOPasscodeViewController
         else { return }
 
@@ -772,6 +782,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                     DispatchQueue.main.async {
                         passcodeViewController.dismiss(animated: true) {
                             NCKeychain().passcodeCounterFail = 0
+                            NCKeychain().passcodeCounterFailReset = 0
                             self.hidePrivacyProtectionWindow()
                             self.requestAccount()
                         }
@@ -802,6 +813,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         DispatchQueue.main.async {
             passcodeViewController.dismiss(animated: true) {
                 NCKeychain().passcodeCounterFail = 0
+                NCKeychain().passcodeCounterFailReset = 0
                 self.hidePrivacyProtectionWindow()
                 self.requestAccount()
             }
@@ -830,7 +842,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
         DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
 
-            if NCKeychain().resetAppCounterFail && passcodeCounterFailReset >= NCBrandOptions.shared.resetAppPasscodeAttempts {
+            if self.isPasscodeReset {
 
                 passcodeViewController.passcodeView.resetPasscode(animated: true, playImpact: false)
                 passcodeViewController.setContentHidden(true, animated: true)
@@ -842,7 +854,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                     self.resetApplication()
                 }
 
-            } else if passcodeCounterFail > 0 && passcodeCounterFail.isMultiple(of: 3) {
+            } else if self.isPasscodeFail {
 
                 passcodeViewController.biometricButton.isHidden = true
                 passcodeViewController.passcodeView.resetPasscode(animated: true, playImpact: false)
@@ -860,6 +872,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                         alertController.dismiss(animated: true)
                         passcodeViewController.setContentHidden(false, animated: true)
                         NCKeychain().passcodeCounterFail = 0
+                        self.enableTouchFaceID()
                     }
                 }
             }

+ 0 - 1
iOSClient/Settings/NCKeychain.swift

@@ -74,7 +74,6 @@ import KeychainAccess
             return 0
         }
         set {
-            if newValue == 0 { passcodeCounterFailReset = 0 }
             keychain["passcodeCounterFail"] = String(newValue)
         }
     }