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

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!