Пример #1
0
        public static void RunMainTests(string[] args)
        {
            string hostname = "localhost";
            int    port     = 5556;

            long time1 = DateTime.UtcNow.Ticks;

            MockTlsClient     client   = new MockTlsClient(null);
            TlsClientProtocol protocol = OpenTlsConnection(hostname, port, client);

            protocol.Close();

            long time2 = DateTime.UtcNow.Ticks;

            Console.WriteLine("Elapsed 1: " + (time2 - time1) / TimeSpan.TicksPerMillisecond + "ms");

            client   = new MockTlsClient(client.GetSessionToResume());
            protocol = OpenTlsConnection(hostname, port, client);

            long time3 = DateTime.UtcNow.Ticks;

            Console.WriteLine("Elapsed 2: " + (time3 - time2) / TimeSpan.TicksPerMillisecond + "ms");

            byte[] req = Encoding.UTF8.GetBytes("GET / HTTP/1.1\r\n\r\n");

            Stream tlsStream = protocol.Stream;

            tlsStream.Write(req, 0, req.Length);
            tlsStream.Flush();

            StreamReader reader = new StreamReader(tlsStream);

            String line;

            while ((line = reader.ReadLine()) != null)
            {
                Console.WriteLine(">>> " + line);
            }

            protocol.Close();
        }
Пример #2
0
        public void TestClientServer()
        {
            SecureRandom secureRandom = new SecureRandom();

            PipedStream clientPipe = new PipedStream();
            PipedStream serverPipe = new PipedStream(clientPipe);

            TlsClientProtocol clientProtocol = new TlsClientProtocol(clientPipe, secureRandom);
            TlsServerProtocol serverProtocol = new TlsServerProtocol(serverPipe, secureRandom);

            Server server = new Server(serverProtocol);

            Thread serverThread = new Thread(new ThreadStart(server.Run));

            serverThread.Start();

            MockTlsClient client = new MockTlsClient(null);

            clientProtocol.Connect(client);

            // NOTE: Because we write-all before we read-any, this length can't be more than the pipe capacity
            int length = 1000;

            byte[] data = new byte[length];
            secureRandom.NextBytes(data);

            Stream output = clientProtocol.Stream;

            output.Write(data, 0, data.Length);

            byte[] echo  = new byte[data.Length];
            int    count = Streams.ReadFully(clientProtocol.Stream, echo);

            Assert.AreEqual(count, data.Length);
            Assert.IsTrue(Arrays.AreEqual(data, echo));

            output.Close();

            serverThread.Join();
        }
Пример #3
0
        public void TestClientServer()
        {
            SecureRandom secureRandom = new SecureRandom();

            PipedStream clientPipe = new PipedStream();
            PipedStream serverPipe = new PipedStream(clientPipe);

            TlsClientProtocol clientProtocol = new TlsClientProtocol(clientPipe, secureRandom);
            TlsServerProtocol serverProtocol = new TlsServerProtocol(serverPipe, secureRandom);

            Server server = new Server(serverProtocol);

            Thread serverThread = new Thread(new ThreadStart(server.Run));
            serverThread.Start();

            MockTlsClient client = new MockTlsClient(null);
            clientProtocol.Connect(client);

            // NOTE: Because we write-all before we read-any, this length can't be more than the pipe capacity
            int length = 1000;

            byte[] data = new byte[length];
            secureRandom.NextBytes(data);

            Stream output = clientProtocol.Stream;
            output.Write(data, 0, data.Length);

            byte[] echo = new byte[data.Length];
            int count = Streams.ReadFully(clientProtocol.Stream, echo);

            Assert.AreEqual(count, data.Length);
            Assert.IsTrue(Arrays.AreEqual(data, echo));

            output.Close();

            serverThread.Join();
        }
Пример #4
0
        public static void Main(string[] args)
        {
            string hostname = "localhost";
            int port = 5556;

            long time1 = DateTime.UtcNow.Ticks;

            MockTlsClient client = new MockTlsClient(null);
            TlsClientProtocol protocol = OpenTlsConnection(hostname, port, client);
            protocol.Close();

            long time2 = DateTime.UtcNow.Ticks;
            Console.WriteLine("Elapsed 1: " + (time2 - time1)/TimeSpan.TicksPerMillisecond + "ms");

            client = new MockTlsClient(client.GetSessionToResume());
            protocol = OpenTlsConnection(hostname, port, client);

            long time3 = DateTime.UtcNow.Ticks;
            Console.WriteLine("Elapsed 2: " + (time3 - time2)/TimeSpan.TicksPerMillisecond + "ms");

            byte[] req = Encoding.UTF8.GetBytes("GET / HTTP/1.1\r\n\r\n");

            Stream tlsStream = protocol.Stream;
            tlsStream.Write(req, 0, req.Length);
            tlsStream.Flush();

            StreamReader reader = new StreamReader(tlsStream);

            String line;
            while ((line = reader.ReadLine()) != null)
            {
                Console.WriteLine(">>> " + line);
            }

            protocol.Close();
        }