views:

547

answers:

1

Previously, I was trying to use client certificate on .NET CF 2.0 (see here) and I ultimately had to give up. I'm now on .NET CF 3.5 which has support for the ClientCertificates property on the HttpWebRequest object. However, I can't figure out how to instantiate the X509Certificate or X509Certificate2 object with a pfx file. On the full framework, I can simply do something like new X509Certificate2(filename, password). If I try to create the object with bytes read from a .pfx file, I get an exception saying ".NET CF 3.5 does not support pfx files". So how do I specify a client certificate with a private key for use with the ClientCertificates property?

A: 

According to MDSN there are only 2 contructors available/supported by the compact framework:

http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2.x509certificate2.aspx

The .NET CF supported constructors have a little device icon next to them in the first column.

These are:

X509Certificate2(array<Byte>[]()[])

http://msdn.microsoft.com/en-us/library/ms148413.aspx

X509Certificate2(IntPtr)

http://msdn.microsoft.com/en-us/library/ms148414.aspx

Martin Peck
Yes, I noticed that. What I don't understand is how do I specify a client certificate for use with SSL client authentication when compact framework's X509Certificate object does not support a private key? It is my understanding that the private key is used to authenticate the client to the server so that the server may trust the client. I can't see any way to do that on the compact framework despite Microsoft having added the ClientCertificates property in 3.5...
Jason
I think the way to do this is to use the X509Store class to access certificates in the local certificate store, then use these certificate - rather than loading one from file.
Martin Peck
Ok, interesting... How would I add a certificate to the store with the associated private key?
Jason
I've not done this personally, but I believe that provision CE devices with certificates (see http://stackoverflow.com/questions/287316/how-to-automate-importing-certificates-on-a-windows-ce-device) or you can use the CE UI to do this (see http://msdn.microsoft.com/en-us/library/ms900349.aspx for hints)
Martin Peck
Hmm, it looks like the provisioning is only available on Windows Mobile. I need to run on plain old Windows CE. The cert UI in the control panel could work, but I need to automate this programmatically. Can you add .pvk files to the store using X509Store? If not, I need to figure out how to use the appropriate Win32 API to do this...
Jason