osx - Install certificate in login keychain with swift 3 on MacOS -


i have cocoa project, building macos app. won't distribute on apple store.

what should use in swift 3 install certificate in login keychain, trusted, command ?

security add-trusted-cert -k ~/library/keychains/login.keychain-db ca-cert.cer 

i have ca-cert.cer , ca-cert.pem created.

i know authorization api , saw in apple documentation method https://developer.apple.com/documentation/security/1401659-secitemadd , doc https://developer.apple.com/documentation/security/certificate_key_and_trust_services/certificates/storing_a_certificate_in_the_keychain

first create der version of pem

openssl x509 -outform der -in ~/ca-cert.pem -out ~/ca-cert.der 

then following code install certificate in login keychain won't trusted.

    {         let cerdata = nsdata(contentsoffile: homedirurl.path + "/ca-cert.der")         let certificate: seccertificate? = seccertificatecreatewithdata(nil, cerdata as! cfdata)         let addquery: [string: any] = [ksecclass string: ksecclasscertificate,                                        ksecvalueref string: certificate,                                        ksecattrlabel string: "my certificate"]         let status = secitemadd(addquery cfdictionary, nil)         guard status == errsecsuccess else {             print("error \(status) : " + (seccopyerrormessagestring(status, nil) as! string))             return         }      }     catch let error nserror {         print("ooops! went wrong: \(error)")     } 

what should change trusted ?

in objective c, need following steps.

//your certificate have been installed in login.keychain using secitemadd

seccertificateref certificate; //use seccertificatecreatewithdata it.  nsdictionary *newtrustsettings = @{(id)ksectrustsettingresult:[nsnumber numberwithint:ksectrustsettingsresulttrustroot]};  sectrustsettingssettrustsettings(certificate, ksectrustsettingdomainuser, (__bridget cftyperef)newtrustsettings)); 

note type hand, check type errors yourself.

i have tested myself, need change swift code.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -