Failure to read the Keychain on iOS 13 Simulator

Originator:serieuxchat
Number:rdar://7251207 Date Originated:11-09-2019
Status:Open Resolved:
Product:iOS Simulator Product Version:13
Classification: Reproducible:Always
 
When access control is specified (with biometrics), iOS13 Simulator fails to read data from the Keychain.

    // If run on iOS12 Simulator, status2 will be 0
    // If run on iOS13 Simulator, status2 will be -25300
    func testKeychain() {
        let tag = "com.flockoffiles.testkeychain.value"
        let savedData = "testString".data(using: .utf8)!
        var aclError: Unmanaged<CFError>?
        let accessControl =
            SecAccessControlCreateWithFlags(kCFAllocatorDefault,
                                            kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly,
                                            SecAccessControlCreateFlags.biometryCurrentSet,
                                            &aclError)!
        
        let query: [String : Any] = [kSecClass as String: kSecClassGenericPassword,
                                     kSecAttrAccount as String: tag,
                                     kSecAttrService as String: tag,
                                     kSecAttrAccessControl as String: accessControl,
                                     kSecValueData as String: savedData]
        
        var status = SecItemAdd(query as CFDictionary, nil)
        if status == errSecDuplicateItem {
            let updateQuery: [String: Any] = [kSecValueData as String: savedData]
            status = SecItemUpdate(query as CFDictionary, updateQuery as CFDictionary)
        }
        
        let query2: [String : Any] = [kSecClass as String: kSecClassGenericPassword,
                                      kSecAttrAccount as String: tag,
                                      kSecAttrService as String: tag,
                                      kSecReturnData as String: kCFBooleanFalse!,
                                      kSecUseAuthenticationUI as String: kSecUseAuthenticationUIFail]
        
        var result: CFTypeRef?
        let status2 = SecItemCopyMatching(query2 as CFDictionary, &result)
        
        // If run on iOS12 Simulator, status2 will be 0
        // If run on iOS13 Simulator, status2 will be -25300
        print("Query2 status: \(status2)")
        
    }

Comments

Re-tested on Xcode 11.4

iOS 13.5 Simulator (iPhone 11 Pro) - works. iOS 12.1 Simulator (iPhone SE 1st gen) - works.

By serieuxchat at April 13, 2021, 7:37 a.m. (reply...)

Feedback please

Hi,

Still occurring in Xcode 11.3.1 (11C504), is there any solution / workaround for this issue or expected fix?

By andre.abreu at Feb. 7, 2020, 3:29 p.m. (reply...)

Hi,

Still reproduced on Xcode 11.3 / iOS 13.3 Simulator. Any feedback from Apple?

By juan.trias at Jan. 14, 2020, 4:43 p.m. (reply...)

Any feedback?

Hi,

Have you got any feedback related to the bug? Thanks.

By marta.delarco at Nov. 1, 2019, 10:11 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!