I am developing a web service that communicates with a third parties web service. the third party require that I use a SSL certificate with all communication to their system.
In my application I am loading the certificate from a file, "certificate.p12" for example, using the following code:
Cert = new X509Certificate2(certPath, certPWD);
I then add it to my web request as follows:
webRequest.ClientCertificates.Add(Cert);
On my development machine this works perfectly, however, on the test server (which is housed externally in a data centre), I simply cannot get it to work.
I've also tried putting the certificate into the certificate store in various locations, current user and local machine, and loaded it from there instead in the code. Same problem.
Using the current version the application stops as it loads the file... I have debugging information before and after that line and it doesn't get past it but also doesn't throw any error.
I'm very confused... any help is appreciated.
Thanks.
Update: though I'm not 100% certain, I'm pretty sure I am getting an "object not set to an instance of a reference" error on this line
Cert = new X509Certificate2(certPath, certPWD);
Update 2:
"Maybe the test machine is missing the certificate's root chain?" - I think this is the problem. Just asked another guy in the office and the certificate was issued BY the third party and not an existing trusted source. On my local machine this doesn't seem to be a problem but I assume there is a higher level of security stopping this on the server... now looking at several options,
- can I bypass this security check for JUST this certificate as we know it to be trusted,
- can I get the root certificates from the third party and
- can I create the root certificates for the third party.