I'm helping develop a macOS SDK that saves generic password items in the keychain. A calling app can have multiple threads reading/writing our SDK.
Referring to the guidance on this page: https://developer.apple.com/documentation/security/certificate_key_and_trust_services/working_with_concurrency?language=objc
For macOS is says, "In general, it is safe to use this API in threads other than your main thread, but avoid calling the functions from multiple operations, work queues, or threads concurrently. Instead, serialize function calls or confine them to a single thread."
Because of where this document is located, under "certificate_key_and_trust_services", it's not 100% clear if this advice applies to all keychain usage, including generic password items. Can you confirm whether this applies? Basically, what is the scope of "this API" in the above document? All keychain-related APIs (SecItemAdd(), SecItemUpdate(), SecItemDelete(), SecItemCopyMatching())?
Assuming we need to follow this advice, are concurrent keychain read operations from a single process OK? For example, is it safe to protect keychain API calls that write to the keychain (SecItemUpdate(), SecItemAdd(), SecItemDelete()) with dispatch_barrier_sync() and calls that only read items (SecItemCopyMatching()) with dispatch_sync()? If so, this would permit concurrent reads but still safely serialize writes.
Thanks,
Dean