When I am running Server at my machine(Windows 7 OS 64 Bit) and Client at (Windows 7 OS 32 Bit) there is no error and both client server are authenticating each other. But when I reversed the Client and Server PC , At Server machine I am getting an exception saying that "Remote Certificate is invalid according to validation Procedure". Please suggest if I am missing anything.
**Server Code:**
_
securestream = new SslStream(tcpClient.GetStream(), false,new RemoteCertificateValidationCallback(ValidateClientCertificate));
string certPath = System.Reflection.Assembly.GetEntryAssembly().Location;
certPath = Path.GetDirectoryName(certPath);
certPath = Path.Combine(certPath, "MyServer.pfx");
serverCertificate = new X509Certificate2(certPath,"password");
_securestream.BeginAuthenticateAsServer(serverCertificate, true, SslProtocols.Ssl3, true, new AsyncCallback(AuthenticationCallback), _securestream);
private bool ValidateClientCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (certificate != null)
{} else {//Always Comes Here in Problem Situation}
private void AuthenticationCallback(IAsyncResult result)
{
try
{
if (result.IsCompleted)
{
_securestream.EndAuthenticateAsServer(result);......}
catch(Exception e){//Always gets exception here}
**Client Code:**
string certPath = System.Reflection.Assembly.GetEntryAssembly().Location;
certPath = Path.GetDirectoryName(certPath);
certPath = Path.Combine(certPath, ConfigurationManager.AppSettings["SSLClientCertName"]);
certCollection=new X509Certificate2Collection();
certCollection.Add(new X509Certificate2(certPath, ConfigurationManager.AppSettings["SSLClientCertPassword"], X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable));
_securestream = new SslStream(_tcpSocket.GetStream(),true,new RemoteCertificateValidationCallback( ValidateServerCertificate));
_securestream.BeginAuthenticateAsClient(_targetHost, certCollection, SslProtocols.Default, true, new AsyncCallback(AuthenticationCallback), _securestream);
...........