I’m attempting to import a certificates to the gadget keychain, which I get my API. I’ve used these references to save lots of acquired information in certificates format. references: (SecPKCS12Import returns totally different outcomes on iOS 11 than on iOS 10)
and Add Certificates to IOS Keychain in Swift
By doing a little modifications so as to add the certificates to the keychain I’ve accomplished under code:
` func certificateFromCertificate(certP12: Knowledge, psswd: String) {
let decodedData = certP12
let keytmp : NSString = kSecImportExportPassphrase as NSString
let choices : NSDictionary = [keytmp : psswd]
var certificateRef: SecCertificate? = nil
var gadgets : CFArray?
let securityError: OSStatus = SecPKCS12Import(decodedData as CFData, choices, &gadgets)
let theArray: CFArray = gadgets!
if securityError == noErr && CFArrayGetCount(theArray) > 0 {
let newArray = theArray as [AnyObject] as NSArray
let dictionary = newArray.object(at: 0)
let secIdentity = (dictionary as AnyObject)[kSecImportItemIdentity as String] as! SecIdentity
let securityError = SecIdentityCopyCertificate(secIdentity , &certificateRef)
if securityError != noErr {
certificateRef = nil
}
}
var keychainQueryDictionary = [String : Any]()
if let tempSecCert = certificateRef {
keychainQueryDictionary = [kSecClass as String : kSecClassCertificate, kSecValueRef as String : tempSecCert, kSecAttrLabel as String: "My Certificate"]
}
let abstract = SecCertificateCopySubjectSummary(certificateRef!)! as String
print("Cert abstract: (abstract)")
let standing = SecItemAdd(keychainQueryDictionary as CFDictionary, nil)
print(SecCopyErrorMessageString(standing, nil))
}`
I get correct certificates abstract and likewise this print(SecCopyErrorMessageString(standing, nil))
is returning no error. Non-obligatory(No error.)
The doubt I’ve is whether or not this certificates is correctly put in within the gadget keychain or not. How do I confirm that? Please notice I do not wish to belief the certificates forcefully.
I attempted
var keychainQueryDictionary = [String : Any]()
if let tempSecCert = certificateRef {
keychainQueryDictionary = [kSecClass as String : kSecClassCertificate, kSecValueRef as String : tempSecCert, kSecAttrLabel as String: "My Certificate"]
}
let abstract = SecCertificateCopySubjectSummary(certificateRef!)! as String
print("Cert abstract: (abstract)")
let standing = SecItemAdd(keychainQueryDictionary as CFDictionary, nil)
This may import the certificates to the keychain of the gadget. I wish to confirm whether it is put in efficiently.