public void TestSslServerAuthentication()
        {
            var location = new IPEndPoint(IPAddress.Loopback, 5055);

            Console.WriteLine(Directory.GetCurrentDirectory());
            server = new SslServer(location)
            {
                ServerCertificate =
                    SslServer.LoadCertificate(serverCert)
            };
            server.Start();

            SslClient client =
                new SslClient(location)
            {
                ServerName = "MyServerName",
                Protocol   = SslProtocols.Default
            };

            try
            {
                client.Connect();

                string echo = client.Echo("Hello World");
                Assert.AreEqual(echo, "Hello World");
            }
            finally
            {
                client.Close();
                server.Stop();
                client = null;
            }
        }
        public void TestSslClientAuthenticationException()
        {
            var location = new IPEndPoint(IPAddress.Loopback, 5055);

            server = new SslServer(location)
            {
                ServerCertificate  = SslServer.LoadCertificate(serverCert),
                AuthenticateClient = true
            };
            server.Start();

            SslClient client =
                new SslClient(location)
            {
                ServerName   = "MyServerName",
                Protocol     = SslProtocols.Default,
                Certificates = null
            };

            try
            {
                client.Connect();

                string echo = client.Echo("Hello World");
                Assert.AreEqual(echo, "Hello World");
            }
            finally
            {
                client.Close();
                server.Stop();
                client = null;
            }
        }
Beispiel #3
0
        public void TestSslClientAuthentication()
        {
            var location = new IPEndPoint(IPAddress.Loopback, 5055);

            server = new SslServer(location)
            {
                ServerCertificate =
                    SslServer.LoadCertificate(
                        serverCert),
                AuthenticateClient = true
            };
            server.Start();

            try
            {
                SslClient client =
                    new SslClient(location)
                {
                    ServerName = "MyServerName",
                    Protocol   = SslProtocols.Default
                };
                client.AppendCertificate(new X509Certificate(clientCert, clientCertPassword));
                client.Connect();

                string echo = client.Echo("Hello World");
                Assert.AreEqual(echo, "Hello World");
            }
            finally
            {
                server.Stop();
            }
        }