I have imported a self-signed X509 certificate into my iPhone by simply emailing the certificate.pem to it and installing it on the device. Now I would like to verify a particular certificate in my iOS application that must be signed using the aforementioned certificate. Basically, the imported certificate acts as root certificate for a CA.
Does the imported certificate get stored in the Keychain?
How can I programmatically validate another certificate based on the imported one? (the second certificate is only valid if it is signed by the before imported CA certificate)
Does anyone have some experienced with these scenarios?
Thanks in advance!
1) yes – it sits in your keychain.
2) you verify it using the trust
SecTrustCreateWithCertificates(),SecTrustEvaluate()against either all certificates or just your own.3) If you verified it against a wide smattering of certs you can optionally lookup your own cert in the keychain; get the DER; calculate its SHA1 and compare this to a SHA1 which is hardcoded in your code.
The code is something like below.
or if you get a trust chain, say from the network stack which is already verified against the keychain (and thus against your certs) – then you can extract the certs; do a
SecCertificateCopyData()on them; and then SHA1 thatNSDatato compare to your hardcoded sha1 as to ensure it is verified against exactly that one.