I’m trying to generate a CSR in iOS. Since apparently the Apple security framework for iOS doesn’t include methods for CSR generation I had to compile the OpenSSL source code for my project.
Now I want to know how to use these methods with the keys I’ve generated in the Keychain previously. That is, I need to convert SecKeyRef type into OpenSSL types like EVP_PKEY. That will allow me to call the OpenSSL method X509_REQ_set_pubkey.
Does anyone know a way to achieve this?
Found the solution myself.
First of all you need to extract the key from the Keychain as NSData.
Now we need to cast this data as unsigned char and give it to the method d2i_RSAPublicKey
That generates a simple CSR in OpenSSL (not signed) with a public key and a common name and prints it to the standard out.