ios - SecItemAdd returns -25299 when adding second certificate -


when trying add second certificate fails -25299 (the item exists.). have different ksecattrlabel. before trying delete fails code -25300 (the item cannot found.).

maybe knows wrong code? did miss attributes?

if let cer1 = "cert1".datausingencoding(nsutf8stringencoding),    let cer2 = "cert2".datausingencoding(nsutf8stringencoding) {        addcertificate(cer1, label: "testcertificate_1")        addcertificate(cer2, label: "testcertificate_2") }      func addcertificate(certificate: nsdata, label: string) {         let query = [             string(ksecclass) : ksecclasscertificate,             string(ksecattrlabel) : label,             string(ksecvaluedata) : certificate         ]         var status = secitemdelete(query)         if status != noerr {             print("error deleting cer keychain. error: \(status)")         }          status = secitemadd(query, nil)          if status != noerr {             print("error adding cer keychain. error: \(status)")         }     }  // output: // error deleting cer keychain. error: -25300 (the item cannot found.) // error deleting cer keychain. error: -25300 (the item cannot found.) // error adding cer keychain. error: -25299 (the item exists.) 

for keychain item of class ksecclasscertificate, primary key combination of ksecattrcertificatetype, ksecattrissuer , ksecattrserialnumber.

let query = [             string(ksecclass) : ksecclasscertificate,             string(ksecattrlabel) : label,             string(ksecvaluedata) : certificate,             string(ksecattrserialnumber) : serialnumber         ] 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -