I am having a strange behavior on Window 7 (Win 10 & 11 has no issues). My code (below) works perfectly when connecting from Win7 as client to Win10/11 as server , however when roles are swapped (win7 as a server and win10/11 as client it fails). I tried both scenarios and couple of win10 and 11 machines without issues, which made me come up with the conclusion its a Win7 related.
The connection is based on mutual trust, so both client and server sends their certificates. When the server calls the custom RemoteCertificateValidationCallback it has the following fields: object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors.
When win7 is the TcpListener (i.e the host) the validation callback is called with:
- certificate = null
- sslPolicyErrors = RemoteCertificateNotAvailable.
Reminder: same code, different roles it works.
Compiled with core3.1 (tested also using 5.0). The certificates are self-signed.
Client code:
await client.ConnectAsync(remoteIP, remotePort);
SslStream sslStream = new SslStream(
client.GetStream(),
false,
new RemoteCertificateValidationCallback(ValidatePeerCertificate),
null);
sslStream.AuthenticateAsClient(remoteIP, new X509Certificate2Collection(localCertificate), false);
server:
var tcpClient = m_listener.AcceptTcpClient();
sslStream = new SslStream(
tcpClient.GetStream(),
false,
new RemoteCertificateValidationCallback(ValidatePeerCertificate),
null);
sslStream.AuthenticateAsServer(localCertificate, true, false);
I thought this might be the problem: https://learn.microsoft.com/en-US/troubleshoot/windows-server/windows-security/ssltls-communication-problems-after-install-kb931125 But the problem persists also after removing the key from the registry.
Any thoughts? Thanks ahead.