Hi,
I'm certainly not an expert in RSA, Certificate, etc and I miss a lot of things. But I have made it working in Android and Windows.
There is my goal : I want to generate a KeyPair with RSA and be able on the iPhone to communicate securely with my server. So on my server I create a self-signed certificate for the iPhone and I want iPhone to create a self-signed certificate for the server. At this point I can both encrypt and sign exchange information between iPhone and the server.
Actually I can easily create a KeyPair with SecKey.GenerateKeyPair, but after that I'm struggling to create the self-signed certificate.
Is it possible with iOS ? If so, how can I do it ?
Thank you
So, the thing about self-signed certificates is that they don’t make a lot of sense (-: Lemme explain a bit…
The whole point of a certificate is that the issuer (the entity that signed the certificate) certifies that the subject (the entity that requested the certificate) holds the private key associated with the public key that’s wrapped up in the certificate. For example, when you upload a CSR to the developer web site and have it issue you a certificate, that CSR contains your public key and the developer web site acts as the issuer. It creates and signs a certificate that says that “I, the Apple developer web site, certify that developer XXX holds the private key associated with the public key in this certificate”. So, the certificate contains both a public key /and/ identifying information.
Once you understand this you can see the problem with self-signed certificates. Like all certificates they contain a public key, info about the subject, and info about the issuer. However, because they’re self signed then the last two items are meaningless. There’s no way to check that the info is good because there’s no issuer to consult.
In some cases creating a self-signed certificate is necessary. For example, the TLS protocol requires [1] that you start with a digital identity (the combination of a private key and a certificate whose public key matches that private key) and so you may end up needing to generate a self-signed certificate just to meet that requirement.
However, in your situation that doesn’t seem to be case. AFAICT you’re planning to do this:
-
Generate a key pair.
-
Hold on to the private key.
-
Wrap the public key in a certificate.
-
Send that certificate to your server.
-
Have your server extract the public key from the certificate.
-
Then do crypto stuff with that public key.
So, you don’t actually need a certificate. Rather, in step 3 you could export the public key and send that to the server, cutting out the certificate completely. And that’s important because iOS has good APIs to export public keys but it has no APIs for generating self-signed certificates.
So, does my analysis sound right? If so, I’d be happy to help you with the whole ‘exporting a public key’ malarkey.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Not quite. TLS also supports a pre-shared key mode but that mode is not widely supported.