Manually check server's certificate using HttpWebRequest

certificate, windows-phone-8

Solution

I have read some tutorials about manually checking `SSL` certificates in `.NET` using `ServicePointManager`, and when I started implement it in Windows Phone 8 application, I realized that `.NET` Framework for WP8 (and 7) just has not got API to handle SSL certificates validating. We just can't have access to `ServicePointManager`...

Then I found this post: "Self Signed Certification SSL HTTPS" on wpdev.uservoice.com, where developers are asking Microsoft to add this API into next WP SDK updates, of course I have spent my 3 votes on that, so if you want to see `ServicePointManager` in WP .NET framework, please vote for that.

Also, I want to notice you about strange behavior of `HttpWebRequest` on WP, when you trying to work with self-signed https resource, `HttpWebRequest` will throw `404 exception`! Very strange, yes?

Problem

I am using `HttpWebRequest` to work with service's https API, now I need to check https certificate manually on client side (Windows Phone 8 application), how could I do it? I have got `certificate.cert` file, so I can put it to the `Assets` folder and then compare it to the server's certificate, but I do not know how

Original source