Przeglądaj źródła

Merge pull request #1638 from deltachat/ensure_open_encrypted_accounts

ensure encrypted accounts are always opened when resuming from background
cyBerta 3 lat temu
rodzic
commit
0aa9f19b24

+ 1 - 0
DcCore/DcCore/Extensions/UserDefaults+Extensions.swift

@@ -2,6 +2,7 @@ import Foundation
 public extension UserDefaults {
     static var hasExtensionAttemptedToSend = "hasExtensionAttemptedToSend"
     static var hasSavedKeyToKeychain = "hasSavedKeyToKeychain"
+    static var upgradedKeychainEntry = "upgradedKeychainEntry_"
     static var shared: UserDefaults? {
         return UserDefaults(suiteName: "group.chat.delta.ios")
     }

+ 8 - 3
DcCore/DcCore/Helper/KeychainManager.swift

@@ -46,6 +46,7 @@ public class KeychainManager {
           kSecAttrAccount as String: "\(id)",
           kSecClass: kSecClassGenericPassword,
           kSecAttrAccessGroup as String: KcM.sharedKeychainGroup as AnyObject,
+          kSecAttrAccessible: kSecAttrAccessibleAfterFirstUnlock,
         ] as CFDictionary
 
         let status = SecItemAdd(keychainItemQuery, nil)
@@ -66,10 +67,14 @@ public class KeychainManager {
                                     kSecReturnData as String: true]
         var item: CFTypeRef?
         let status = SecItemCopyMatching(query as CFDictionary, &item)
-        guard status != errSecItemNotFound else {
+        switch status {
+        case errSecSuccess:
+            break
+        case errSecItemNotFound:
             throw KeychainError.noPassword
-        }
-        guard status == errSecSuccess else {
+        case errSecInteractionNotAllowed:
+            throw KeychainError.unhandledError(message: "Keychain not yet available.", status: status)
+        default:
             throw KeychainError.unhandledError(message: "Unknown error while querying secret for account \(id):",
                                                status: status)
         }

+ 8 - 0
deltachat-ios/AppDelegate.swift

@@ -207,6 +207,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         }
     }
 
+    func applicationProtectedDataDidBecomeAvailable(_ application: UIApplication) {
+        logger.info("➡️ applicationProtectedDataDidBecomeAvailable")
+    }
+
+    func applicationProtectedDataWillBecomeUnavailable(_ application: UIApplication) {
+        logger.info("⬅️ applicationProtectedDataWillBecomeUnavailable")
+    }
+
     static func emitMsgsChangedIfShareExtensionWasUsed() {
         if let userDefaults = UserDefaults.shared, userDefaults.bool(forKey: UserDefaults.hasExtensionAttemptedToSend) {
             userDefaults.removeObject(forKey: UserDefaults.hasExtensionAttemptedToSend)

+ 2 - 2
deltachat-ios/Controller/WelcomeViewController.swift

@@ -233,10 +233,10 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
     @objc private func cancelButtonPressed() {
         guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
         // take a bit care on account removal:
-        // remove only unconfigured and make sure, there is another account
+        // remove only openend and unconfigured and make sure, there is another account
         // (normally, both checks are not needed, however, some resilience wrt future program-flow-changes seems to be reasonable here)
         let selectedAccount = dcAccounts.getSelected()
-        if !selectedAccount.isConfigured() {
+        if selectedAccount.isOpen() && !selectedAccount.isConfigured() {
             _ = dcAccounts.remove(id: selectedAccount.id)
             if self.dcAccounts.getAll().isEmpty {
                 _ = self.dcAccounts.add()