Fix ServerAsyncAuthenticateTest. (dotnet/corefx#35170)
authorMartin Baulig <mabaul@microsoft.com>
Tue, 12 Feb 2019 01:21:54 +0000 (20:21 -0500)
committerStephen Toub <stoub@microsoft.com>
Tue, 12 Feb 2019 01:21:54 +0000 (20:21 -0500)
In ServerAsyncSslHelper, pass a certificate validation callback to both
client and server.

Commit migrated from https://github.com/dotnet/corefx/commit/a46d64a21591dd36292b0f6f0946fc55babced11

src/libraries/System.Net.Security/tests/FunctionalTests/ServerAsyncAuthenticateTest.cs

index c91a0775c56f9a5378b5efa6a2b8e217a083a4e0..c0133ff52c275d32216deef1bad38450fa6ec998 100644 (file)
@@ -115,11 +115,21 @@ namespace System.Net.Security.Tests
                     TestConfiguration.PassingTestTimeoutMilliseconds);
 
                 using (TcpClient serverConnection = await serverAccept)
-                using (SslStream sslClientStream = new SslStream(clientConnection.GetStream()))
                 using (SslStream sslServerStream = new SslStream(
+                    clientConnection.GetStream(),
+                    false,
+                    AllowEmptyClientCertificate))
+                using (SslStream sslClientStream = new SslStream(
                     serverConnection.GetStream(),
                     false,
-                    AllowAnyServerCertificate))
+                    delegate {
+                        // Allow any certificate from the server.
+                        // Note that simply ignoring exceptions from AuthenticateAsClientAsync() is not enough
+                        // because in Mono, certificate validation is performed during the handshake and a failure
+                        // would result in the connection being terminated before the handshake completed, thus
+                        // making the server-side AuthenticateAsServerAsync() fail as well.
+                        return true;
+                    }))
                 {
                     string serverName = _serverCertificate.GetNameInfo(X509NameType.SimpleName, false);
 
@@ -167,7 +177,7 @@ namespace System.Net.Security.Tests
         }
 
         // The following method is invoked by the RemoteCertificateValidationDelegate.
-        private bool AllowAnyServerCertificate(
+        private bool AllowEmptyClientCertificate(
               object sender,
               X509Certificate certificate,
               X509Chain chain,