how to associate private key with a certificate in keychain - iphone

I just downloaded iphone sdk 4. when I try to install on the device I get
"Code Sign error: The identity 'iPhone
Developer' doesn't match any valid
certificate/private key pair in the
default keychain"
I have gone through the process of creating a provisioning profile and cert through iphone Development Provisioning Assistant. However, after installing the profile and cert the assistant asks to check whether public and private key are paired (surprisingly, it shows a pic of what seems to be a private key and cert being paired, i.e. the cert is 'under' private key in hierarchical terms. This is not the case in my keychain. Public key, private key and cert are there but there doesn't seem to be any associations.
Does anyone know how to pair a private key and certificate in keychain please this please?
ps. I have checked this thread but I'm hoping there's an easier way.
iPhone app signing: A valid signing identity matching this profile could not be found in your keychain

I wrote a wiki page (here) that describes how to export your certificate and private key pair. It's intended for my iOS development clients to send me their ad-hoc, but I believe it will solve your problem, too. The key is to make sure that you export the certificate and private-key PAIR all in one go -- not as two separate exports.
Hopefully, the screenshot near the bottom of that page will help out.

Related

EJBCA refuses to generate certificates with error : not allowed to use same key

We used a static value ‘usernameTest’ as username to request EJBCA to generate X.509 certifcates; after generating certificates using this satic username we changed it to a unique value identifiying uniquely each certificate (Since using a static username is considered as a renew since the username is the same for all certificates (*) ) but now EJBCA refuses to generate certificates and stil reference the old static username ‘usernameTest’; we get this error:
User '250320092916' is not allowed to use same key as the user(s) ‘usernameTest’ is/are using.
We revoked all certificates previously generated for username 'usernameTest', but we still get this error message from EJBCA. Is there any way we can remove username 'usernameTest'?
Each certificate has a unique SubjectDN and username.
The version of EJBCA is ejbca-6.2.0.
(*): All generated certificates in EJBCA Administration GUI are related to the same username.
Thanks in advance.
Tomas is correct. Go to your "Certificate Authorities" under CA Functions. Edit your CA and find the setting called "Enforce unique public keys" under the "Directives" section.
Uncheck enforce and you will be able to use the same public key for different users.
It has nothing to do with the HSM. The default policy setting for CAs is to not allow users to share the same end-user public key. I.e not to issue a certificate with the same public key to different users. This is a checkbox setting in the CA settings.
Problem solved; the problem is not that a reference to usernameTest still in EJBCA but that the same key (RSA public key) is used for the request of the other user ('250320092916').
It seems this is a known limitation when relying on the HSM PTK-C simulator from the Safenet ProtectServer series; the simulator restarts its random generator when we re-initialize it (I suspect a misuse from me), which means it will always generate the same keys in the same order (which leads to such errors).
But also the message error is not clear; talking about the "key" without specifying, this leads to a confusion with subjectDN or other attributes communicated to the EJBCA, as an error message it may be "public key" or "RSA key", ... instead of key ;)
You can configure the PTK-C simulator to not reuse the random seed (yes that is very annoying). For ejbca we have documented it here.
You have to set the environment variable ET_PTKC_SW_AUTOSEEDRNG=true. With this setting the simulator will generate real keys, a new one every time.

Is it possible to associate a certificate using two private/public keys?

I've got a weird situation here; I developed an app in 2011 using a macbook (private key: alida).. then a couple of months ago was having some problems migrating cert to another machine so just decided to revoke it and generate another certificate now using another set of private keys (francisco)
The situation is that now I have both certificates using two private keys in the keychain (and the old cert expired);
The question: is there a way to pair both priv keys (francisco & alida) with one certificate in the keychain? or I just have to left one of my apps behind? both apps I already in the Appstore;
Look hows my keychain (new machine) looks like:
Any suggestion on what should I do? is there any hope to fix this?
Thanks in advanced.
[edit]
another screenshots from the "my certificates" tab in keychain; so, basically I lost one my apps (no updates ever?) I think If thats the case, I will revoke current cert again and renew it with the keys from 2011 (first app generated) and forget the other one :/
In this context, keys come in pairs: (public, private). A certificate is just a file containing your public key plus some extra data including a "subject" which is information associating the public key to a specific person or entity (such as a DNS address) and, most importantly, a signature from a signing authority certifying (hence "certificate") that the public key is owned by the entity. These key-pairs are inextricably bound: there is no meaningful way to associate the private key from one key-pair to the public key/certificate of a different key-pair.
Normally, a signer (such as Apple in this case) will not generate two certificates with the exact same subject without revoking the earlier certificate first.
If you have an app at the iTunes store signed with a revoked certificate, it needs to be replaced with one signed by the newer, non-revoked certificate.
I think there is no way to pair both priv keys. You should now go with new priv key.

Public key and private key are not found in Keychain access

I think I accidentaly deleted public and private keys from Keychain Access-> login -> keys. Now when I generate new certificates, I am not seeing these keys. May I know how to restore or re download these?
If you deleted the private key (and don't have a backup), then you need to login to your Apple Developer account, go to provisioning portal, revoke the current developer or distribution key and follow the steps to create new ones.
Note: You will have to re-download any app provisioning profiles you may have also created to use the new private key

How to establish a SecIdentityRef in an iPhone keychain ? (Without a .p12)

How do you create a SecIdentityRef in an iPhone keychain if
1) you already have the private key in the keychain and
2) you have just received the certificate from a CA?
SecPKCS12Import does not help in this case unless there is an API to create a .p12 from a private key and a certificate.
SecIdentityCreateWithCertificate would be the answer on the Mac but it does not exist on the iPhone.
Is it possible using SecItemAdd ?
http://developer.apple.com/library/ios/#documentation/Security/Reference/keychainservices/Reference/reference.html
many thanks, Andrew
OK, to answer my own question:
On iOS the keychain will automatically bound the certificate to the private key. That means you only need to:
Generate the key pair
Get a certificate that matches the private key
Insert the certificate into the keychain.
After this you should be able to get a SecIdentityRef for the certificate / private key.
IMPORTANT:
SecItemAdd function allows you to insert the certificate data directly (NSData of the DER representation). This way you will be able to get a valid certificate reference, but not an identity ref.
The right way to insert the certificate is to first use the SecCertificateCreateWithData function over the DER bytes of the certificate. This will return a SecCertificateRef object which then should be used to persist the certificate into the keychain using the SecItemAdd function.
I hope this will make someone's life easier ;-)
Regards,
Pece

iPhone SDK 4.0: Get publicKey and privateKey from a certificate / identity profile stored in KeyChain

I am trying to get the public and private Key from a certificate which i have already installed on the iPhone. (It is shown unter Settings -> General -> Profiles)
I need this keys for encryption sensitive data. (RSA Algorithm)
Up to now i have found no way to get access to the keys.
Is it even possible ?
If not: What is the best possible way to realize my problem otherwise ?
Thank you for all helpful answers.
1.) You can't get the private key of the profile for the simple reason, that your private key is not stored in the profile, it is only signed with it.
Instead consider getting familiar with the Security.framework. This post should give you a start