views:

775

answers:

1

This question is all about solving a SslPolicyError.RemoteCertificateNotAvailable error.

I have developed a TCP Server with SSLStream and a TCP Client for the other end.

I authenticate the server with:

sslStream.BeginAuthenticateAsServer

I authenticate the client with:

sslStream.BeginAuthenticateAsClient

I am loading my client certificate from Trusted Publishers - Local Machine.

Both are running on the same machine.

I tried loading the client certificate from the .cer and .pfx files rather than the trusted publishers store. But the server's client (remote) certificate validator callback fails by finding that SslPolicyErrors has a RemoteCertificateNotAvailable error.

+2  A: 

The link didn't come through, but there's a problem I can spot with the statment:

"I loaded my client certificate from Trusted Publishers"

Client certificates typically live in a Personal store for a user account. Same with Server certificates (they will probably have a different Intended Purpose OID associated with them, though - "Client authentication" vs "Server Authentication"). It'd be odd for you to have a cert with a private key available in the Trusted Publishers store, I think.

If you double-click a client or server certificate in CertMgr.msc , you should see a "This certificate has a private key" message towards the bottom.

If you don't, you only have half a key pair - encryption and authentication require the private key. The server cert needs a private key at the server end, and the client cert needs a private key at the client end.

Tristank
I have also tried loading the certificate from "Personal" store.My certificate do have private key.
cdpnet
Certutil -verify -urlfetch should validate whether the certificate is able to be validated correctly. If not, no dice.The server cert needs "intended purpose: server authentication" and the client cert will probably need "client authentication", if it's meant to uniquely identify a client.
Tristank
Tristank. You have spotted the problem actually. I was having a certificate with purpose of only server auth. I needed the certificate which supports client auth. So, once I got that, it worked.
cdpnet