Hi,
I am facing issues extracting system certificates/identity on an iOS device.
I am using the following code to get all identities from my system keychain ( not the app level keychain)
let getquery = [kSecMatchLimit: kSecMatchLimitAll,
kSecReturnRef: true,
kSecClass: kSecClassIdentity]
as CFDictionary
var item: CFTypeRef?
let status = SecItemCopyMatching(getquery, &item)
guard status != errSecSuccess else {
let key = item as! SecKey
print(key)
return;
}
This works if I run this for MacOS as target platform but returns -25300 for my iOS app. I have the same identities/certificates installed. For iOS it is at “general->VPN and device management->Configuration profiles->{profile name} (which shows “contains: Certificate”} and for MacOS it is at “Keychain Access”.
How I downloaded the certificates: visited the site on my browser and downloaded it through safari, in settings verified it using passwords. So I didn’t download it from code.
Do I have to add some permission in info.plist or something. I didn’t add it for the MacOS app. Or is this even possible, with all the sandbox features and how iOS app were not able to access keychain items before. But I couldn’t find anything as such about this issue and it looks like it is possible.
I also tried another query which again worked on my MacOS target platform and gave me all certificates from system keychain
let dic : NSDictionary = [kSecMatchLimit: kSecMatchLimitAll,
kSecReturnAttributes: kCFBooleanTrue!,
kSecReturnRef: kCFBooleanTrue!,
kSecClass: kSecClassCertificate]
var result : CFTypeRef?
let resultCode : OSStatus = SecItemCopyMatching(dic, &result)
if resultCode == errSecSuccess { print(result) }
I also looked at https://developer.apple.com/library/archive/qa/qa1745/_index.html for some reference. I didn’t get the part of "reading in a PKCS#12-formatted blob and then importing the contents of the blob into the app's keychain using the function SecPKCS12Import”. If I can get any example of reading in a PKCS#12 blob that’d be very helpful as well.
Thanks.