コード例 #1
0
        public static ClientServerHelper Create()
        {
            var listener = new TcpListener(IPAddress.Loopback, 0);
            listener.Start();
            var ar = listener.BeginAcceptSocket(null, null);

            var helper = new ClientServerHelper();
            helper.Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            helper.Client.Connect(IPAddress.Loopback, ((IPEndPoint)listener.LocalEndpoint).Port);
            helper.Server = listener.EndAcceptSocket(ar);
            listener.Stop();
            return helper;
        }
コード例 #2
0
        public void should_fail_if_client_do_not_send_handshake_within_given_time_Frame()
        {
            var certificate   = CertificateHelper.Create();
            var clientServer  = ClientServerHelper.Create();
            var buffer        = new BufferSlice(new byte[65535], 0, 65535);
            var serverChannel = new TcpChannel(buffer, new FakeEncoder(), new FakeDecoder());


            var sut = new ServerSideSslStreamBuilder(certificate);

            sut.HandshakeTimeout = TimeSpan.FromMilliseconds(100);
            Action actual = () => sut.Build(serverChannel, clientServer.Server);

            actual.ShouldThrow <InvalidOperationException>();
        }
コード例 #3
0
        public static ClientServerHelper Create()
        {
            var listener = new TcpListener(IPAddress.Loopback, 0);

            listener.Start();
            var ar = listener.BeginAcceptSocket(null, null);

            var helper = new ClientServerHelper();

            helper.Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            helper.Client.Connect(IPAddress.Loopback, ((IPEndPoint)listener.LocalEndpoint).Port);
            helper.Server = listener.EndAcceptSocket(ar);
            listener.Stop();
            return(helper);
        }
コード例 #4
0
        public void should_not_fail_before_given_time_frame()
        {
            var certificate   = CertificateHelper.Create();
            var clientServer  = ClientServerHelper.Create();
            var buffer        = new BufferSlice(new byte[65535], 0, 65535);
            var serverChannel = new TcpChannel(buffer, new FakeEncoder(), new FakeDecoder());


            var sut = new ServerSideSslStreamBuilder(certificate);

            sut.HandshakeTimeout = TimeSpan.FromMilliseconds(500);
            var    sw     = Stopwatch.StartNew();
            Action actual = () => sut.Build(serverChannel, clientServer.Server);

            actual.ShouldThrow <InvalidOperationException>();
            sw.Stop();
            sw.ElapsedMilliseconds.Should().BeGreaterOrEqualTo(500);
        }
コード例 #5
0
        public void should_Be_able_to_connect_if_protocol_and_common_name_is_matching()
        {
            var certificate   = CertificateHelper.Create();
            var clientServer  = ClientServerHelper.Create();
            var buffer        = new BufferSlice(new byte[65535], 0, 65535);
            var serverChannel = new TcpChannel(buffer, new FakeEncoder(), new FakeDecoder());
            var clientChannel = new TcpChannel(buffer, new FakeEncoder(), new FakeDecoder());


            var sut = new ServerSideSslStreamBuilder(certificate);

            sut.HandshakeTimeout = TimeSpan.FromMilliseconds(1000);
            ThreadPool.QueueUserWorkItem(x =>
            {
                var builder       = new ClientSideSslStreamBuilder("GriffinNetworking");
                builder.Protocols = SslProtocols.Tls12;
                var chan          = builder.Build(clientChannel, clientServer.Client);
            });
            var stream = sut.Build(serverChannel, clientServer.Server);
        }
コード例 #6
0
 public TcpChannelTests()
 {
     _helper = ClientServerHelper.Create();
 }
コード例 #7
0
 public SecureTcpChannelTests()
 {
     _helper      = ClientServerHelper.Create();
     _certificate = new X509Certificate2(
         AppDomain.CurrentDomain.BaseDirectory + "\\Net\\cert\\GriffinNetworkingTemp.pfx", "mamma");
 }
コード例 #8
0
 public TcpChannelTests()
 {
     _helper = ClientServerHelper.Create();
 }
コード例 #9
0
 public SecureTcpChannelTests()
 {
     _helper = ClientServerHelper.Create();
     _certificate = new X509Certificate2(
         AppDomain.CurrentDomain.BaseDirectory + "\\cert\\GriffinNetworkingTemp.pfx", "mamma");
 }