public void ClientCertNotRequiredCheckTest()
        {
            var serverName = "TestServer";

            using (X509Certificate serverCert = MakeCert(serverName))
            {
                var server = new EncryptionTestTcpServer();
                server.ErrorEvent += Server_ErrorEvent;

                var epList = new List <TcpServerLocalEndpoint>();
                var ipEp1  = (new TcpServerLocalEndpoint(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1234), 1));

                epList.Add(ipEp1);
                server.Start(epList, serverCert, false, SslProtocols.None, false, EncryptionPolicy.RequireEncryption);
                X509Certificate clientCert = MakeCert(serverName);
                var             client     = new TcpClient();

                server.ClientCertificate = null;
                client.Start(ipEp1.EndPoint, serverName, clientCert, SslProtocols.None, false, EncryptionPolicy.RequireEncryption);
                Thread.Sleep(5000);
                Assert.IsNull(server.ClientCertificate);

                client.Stop();
                server.Stop();

                server.Dispose();
                client.Dispose();
                clientCert.Dispose();
            }
        }
        public void ClientCertRequiredCheckTest()
        {
            var serverName = "TestServer";

            using (X509Certificate serverCert = MakeCert(serverName))
            {
                var server = new EncryptionTestTcpServer();
                server.ErrorEvent += Server_ErrorEvent;

                var epList = new List <TcpServerLocalEndpoint>();
                var ipEp1  = (new TcpServerLocalEndpoint(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1234), 1));

                epList.Add(ipEp1);
                server.Start(epList, serverCert, true, SslProtocols.None, false, EncryptionPolicy.RequireEncryption);
                X509Certificate clientCert = MakeCert(serverName);
                var             client     = new TcpClient();

                server.ClientCertificate = null;
                client.Start(ipEp1.EndPoint, serverName, clientCert, SslProtocols.None, false, EncryptionPolicy.RequireEncryption);
                var waitStart = DateTime.Now;
                while (server.ClientCertificate == null)
                {
                    var delta = DateTime.Now - waitStart;
                    if (delta.TotalSeconds > 5)
                    {
                        Assert.Fail("Wait Timeout");
                    }
                }
                Assert.IsNotNull(server.ClientCertificate);
                Assert.AreEqual(clientCert, server.ClientCertificate);

                client.Stop();
                server.Stop();

                server.Dispose();
                client.Dispose();
                clientCert.Dispose();
            }
        }