I'm trying to add .pfx certificate to keychain which comes with password protection. So i decided to get identity from certificate and store it. I'm using system keychain to store identity.And program will run as root.
if let password = CFStringCreateCopy(kCFAllocatorDefault, "something" as CFString) {
let p12 = SecPKCS12Import(data as CFData, [kSecImportExportPassphrase as String: password] as CFDictionary, &cfarray)
print(cfarray)
if let identityArray = cfarray as? NSArray {
if let identityDict = identityArray.object(at: 0) as? NSDictionary {
let identityKey = String(kSecImportItemIdentity)
let identity = identityDict[identityKey] as! SecIdentity
let query: [String: Any] = [kSecClass as String: kSecClassIdentity,
kSecValueRef as String: identity,
kSecAttrLabel as String: "iddata",
kSecUseKeychain as String: keychain,
kSecImportExportPassphrase as String: password]
let status = SecItemAdd(query as CFDictionary, nil)
print(status)
}
}
}
When executing I'm getting -50
as output for print(status)
.
I also tried with this query
dictionary for SecItemAdd
let query: [String: Any] = [kSecClass as String: kSecClassIdentity,kSecValueRef as String: identity,kSecAttrLabel as String: "iddata",kSecUseKeychain as String: keychain,kSecImportExportPassphrase as String: password]
What is wrong with this? Please help