Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone web service calls to WCF Service with Certificate Authentication

We are a .Net shop that has standardized on WCF Services. We are in the processs of developing an iPhone application that needs to make secure web services calls to obtain data for the app. To ensure secure communiations we have enabled SSL on our web servers. But this does not ensure the service can only be consumed by authorized apps. We have configured our services to support x509 certificate authentication. Is it even possible to call a secure WCF service with certifcate authentication from an IPhone app?

I have spent many hours searching the internet for examples but to no avail. I HAVE been able to successfuly call an un-secure WCF service with no issues. I have also done a lot of research on the WS-Security and WS-Trust communications standards. I believe I understand how this should work. I am just having trouble piecing together the steps/objects within the iPhone frameworks I need to make this work.

Any thoughts and ideas on the subject would be greatly appreciated.

Also, any thoughts on any of the following:

  1. How best to deploy the P12 certifcate file with the iPhone application
  2. How best to secure the password for the P12 file within the app
  3. Is deploying the P12 file with the app a best practice
  4. Are there facilties within the iPhone frameworks to support this kind of secure communication? If not, what would be an alternative recommendation.
like image 434
Maike9 Avatar asked Feb 11 '10 13:02

Maike9


3 Answers

For starters, I'd say if you are really serious about security please dedicate the proper time and resources to it and treat it like a first class citizen in your feature list. Don't just "turn on SSL" and pretend things are secure. I'm not suggesting you are doing this or not doing this, but I just feel like I have to say it before proceeding.

That said, you probably already know that WS-* is all built on top of http requests, and any time you are doing loads of http requests, you'll probably find ASIHTTPRequest very helpful on the iPhone. However, that will not get you 100% of the way there.

From the iPhone's perspective you have:

  1. The URL loading system, which is a high level API for dealing with network resources of any kind
  2. The CFNetwork C API which is lower-level and allows you a great deal more control of encrypting streams and network traffic any way you see fit
  3. The Certificate, Key, and Trust Services that do the heavy lifting, and more specifically the X509 trust policies

On Macs you get to use Secure Transport, but as far as I know they haven't ported that to the device so I wouldn't get too distracted reading up on that unless you are planning on bringing this to the desktop or are just in the mood to learn everything :)

If you are doing any security with WCF, the first thing you probably realized is that there are many options available to you, but it all boils down to this short list:

  1. Transport layer security (https) with clear text messages (xml/json/...)
  2. Message layer security (encrypted message body) over an open transport (http)
  3. Secured messages over a secured transport

The last time I was doing WCF (about a year ago) the general recommendation from Microsoft seemed to be Message layer security over an open transport because of firewall / accessibility issues introduced when trying to secure the transport. However, this approach assumed that all parties involved were .NET / WCF capable. I believe it would be easier to consume on the device if it were an HTTPS transport level security, with clear XML or JSON message bodies. That way you can take advantage of all the stuff baked into CFNetwork and NSHTTPRequest that Apple has done.

Once you get something working, you'll want to refer to the Enterprise Deployment Guide, and specifically the documentation on Over-the-Air Enrollment so that you can install the certificates on the devices. Remember, anything is possible, and don't be afraid to use one of those Apple support tickets that come with the program :)

EDIT:

I completely forgot to mention the GenericKeychain and CryptoExcercise examples

EDIT 2:

After I got downvoted for no apparent reason I re-read my response and realized I rambled a bit too much without actually answering your question about how to open a p12 file on the device. You ought to be able to simply [[UIApplication sharedApplication] openURL:urlToP12FileEitherLocalOrRemote]] and have it kick out to the OS for the installation procedure.

like image 67
slf Avatar answered Nov 09 '22 04:11

slf


You can also use ssl + user/pass authentication at the message level.

like image 28
Yaron Naveh Avatar answered Nov 09 '22 04:11

Yaron Naveh


Generally, if you want to install certificates on the iPhone, there are two options I have found (both of them from here):

  • Email the certificate to the recipient. If it is a valid certificate and the headers in the email are in order, then it will allow the recipient of the email to install the certificate. The problem here of course is a man-in-the-middle attack.

  • Use the iPhone enterpirse configuration utlity.

That should get you part of the way there (installing the certificate locally). I should note that in general, you don't want to install one certifiate for the entire application, but have separate certificates for your users. As a general practice, authenticating the application is a very bad thing, whereas you should be authenticating the user.

However, if you are authenticating the user already, then this shouldn't be an issue, as using basic authentication over HTTPS would work just as well (and easier to code).

like image 1
casperOne Avatar answered Nov 09 '22 02:11

casperOne