I want to see if is possible to generate a CSR (Certificate Signing Request) in iOS, and if there is a library for it. I want to generate a request, sign it with a private key from an extension, and then send the CSR request back to the server.
Is this possible, and is there a good library for it?
Thanks
Yes, it is possible but is not simple at all because iOS do not work with standard formats for keys as you could think
Generate CSR as PEM
I have used this library successfully to generate a CSR in PCKS#10 format with a key generated in KeyChain and encoded in DER format (binary).
https://github.com/ateska/ios-csr
After this, you can send the CSR to server in DER (format) or encode in PEM format (base64) depending of the capabilities of your serv
I guess you are missed the final step, returning the X509 from server to device to be stored
EDITED
Generating keys with KeyChain
I include also the code to help generating keys using iOS-KeyChain
Utilities
The following includes the utility functions used generating CSR or keys. You will see that are basically the same changing the type of result (some extra work is needed to simplify...)
EDITED
Export public key as DER
Note that this code will not provide the publickey in a readable format like DER
If you need to use the public key outside iOS (or importing a certificate and obtaining a valid key), extra actions are needed. Converting keys are supported using
CryptoExportImportManager.swift
of the following projecthttps://github.com/DigitalLeaves/CryptoExportImportManager
For example