示例#1
0
        public void ssl_stream_with_client_certificates()
        {
            var net = new TestNetwork();

            var server = new Thread(
                () =>
                {
                    var ssl = new SslStream(net.Server, false, Validate);

                    ssl.AuthenticateAsServer(ServerCert, true, SslProtocols.Tls, false);

                     SslInfo("Server", ssl);

                    Assert.That(ssl.ReadByte() == 1);

                    ssl.WriteByte(2);
                });

            server.Start();

            var client = new Thread(
                () =>
                {
                    var ssl = new SslStream(net.Client, false, Validate, SelectCert);

                    ssl.AuthenticateAsClient("server.x", new X509CertificateCollection(new[] { ClientCert }), SslProtocols.Tls, false);

                    SslInfo("Client", ssl);

                    ssl.WriteByte(1);

                    Assert.That(ssl.ReadByte() == 2);
                });

            client.Start();

            server.Join();
            client.Join();
        }