Monday, November 28, 2011

Installing SSL certificates to Windows Phone 7 emulator

The days are again getting tight due to new technologies like Windows Azure, Windows Phone 7 & iPhone development. It is always interesting to work in new technologies where we learn so many new things ,hacks etc…My recent project uses Windows Azure as server side technology and mobile as client side. For the time being we are using iPhone as client.

When we start with Azure we could see that we can simulate the https scenario even in the emulator which is more like the production environment. Really like it. But after some time, it became trouble. There were not enough MAC machines where we can test the iPhone application. So I moved to WP 7 as client for testing purpose. I integrated the Azure tool kit for WP 7 and when tried to access the Azure ACS, it started throwing errors .Our REST based services hosted using HTTPS in emulator are not working. ie simply says network error.

After a google we could see that it is due to lack of certificates. If it was some other .Net client I can live with ServicePointManager and its validation callback. But unfortunately there is no such ServicePointManager in Silverlight. So it is proved that WP7 never allows you to access the https url without proper certificate. But how to install certs in WP7 .When I asked my fellow developer who has Windows Phone, he told that he normally send the certificate file (.cer)through mail and the opening of attachment in phone will prompt for installation.

But where is the mail client in simulator. Tried to send to my gmail id. But no luck.Then I tried the next way. Export the certificate into .cer format, host the .cer file in IIS and access it from Phone’s browser.Yes it worked. I was able to install the certificate. But again I got error in getting data through REST service. That was due to certificate URL issue .I should have used the exact certificate which is created for the IIS. ie for the localhost/127.0.0.1.

Below are the steps to install the certificate in WP7 and get the Azure REST services working which is hosted in Azure emulator.
  • Export the certificate as .cer
    • The certificate should be for the exact web address. ie export the certificate for 127.0.0.1 from IIS.
  • Host this certificate .Even in your http://localhost/<cert Name>.cer
  • Make sure your IIS has the proper MIME type for the .cer
    • MIME type for .cer certificate file is application/x-x509-ca-cert
  • Browse to this certificate path from Windows Phone 7 emulator.
  • Install the certificate.
Now you are all set to access https service hosted Windows Azure emulator from Windows Phone 7 with debugging support.
Enjoy… production environment in development.

No comments: