Tuesday, May 7, 2013

Self signed Cert with Android and iPhone

Often there is a need to put a certificate on the android device (emulator | real)  for testing with SSL. This wil be the case when one needs to use a self signed cert since getting a real CA signed cert is expensive.

The high level steps are :

  1. Export the cert  from your current keystore and put it into a file
  2. Copy the cert file to android device
  3. Run settings app to add it to the trusted certificates.
The caveat it that the exported file from step 1 needs to be in p12 format.

Here are the detailed steps for Android emulator and using the source keystore as JKS.

  1. keytool -importkeystore -srckeystore -destkeystore -deststoretype PKCS12 -srcalias
  2. Start the Android emulator - emulator -avd & - Wait for this to finish
  3. adb - devices will list the android instances it know about, wait for the emulator to show up here as running.
  4. adb push /sdcard/file.p12 - Copies the exported cert file to /sdcard area of Android
  5. Go to Emulator > Settings > Security > Install Trusted Cert from SD card
  6. Type the password that you specified in step 1
  7. You should be good to go.
It is even easier for iPhone. 
  1. Just email the cert from step 1 to an email configured on iphone as an attachment
  2. Open the email from iPhone and click/tap the attachement. 



No comments: