Hi,
I'd like to allow only a specific process to read sensitive items from keychain (based on process signature using method SecItemCopyMatching), and fail any other read attempt.
Is it possible, what are the access control rules I can define for keychain access if this is not possible ?
I'm now using the default user keychain, perhaps I should create a different keychain with non-trivial access control, so that not all processes that are running with user context or even with root privileges, would be able to get the data.
Thanks
Here's my read example :
func read(service: String, account: String) -> Data? {
let query = [
kSecAttrService: service,
kSecAttrAccount: account,
kSecClass: kSecClassGenericPassword,
kSecReturnData: true
] as CFDictionary
var result: AnyObject?
SecItemCopyMatching(query, &result)
return (result as? Data)
}
except for the fact that any privileged user can directly access the keychain item
This is not about being privileged. A user can use Keychain Access to access their own keychain items in the data protection keychain. They can’t access other user’s keychain items.
FWIW, the same is true for the file-based keychain.
Preventing that takes you out of the realm of security and into the realm of DRM. You want to put something on the user’s system and prevent the user from accessing it. That’s not possible in theory so, if you want to solve this problem, you have to decide how much you want to protect this secret from the user. Options range from the simple (set kSecAttrIsInvisible
so that the user has to choose View > Show Invisible Items) to the reasonable (entangle the actual value with a fixed value built into your code) to the silly (that is, what most people think of when you say “DRM”).
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"