public void Close()
 {
     _dtlsTransport?.Close();
     _socket.Shutdown(SocketShutdown.Both);
     _socket.Close();
     entConfigIdBytes = null;
 }
Exemplo n.º 2
0
        public void TestClientServer()
        {
            SecureRandom secureRandom = new SecureRandom();

            DtlsClientProtocol clientProtocol = new DtlsClientProtocol(secureRandom);
            DtlsServerProtocol serverProtocol = new DtlsServerProtocol(secureRandom);

            MockDatagramAssociation network = new MockDatagramAssociation(1500);

            Server server = new Server(serverProtocol, network.Server);

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

            serverThread.Start();

            DatagramTransport clientTransport = network.Client;

            clientTransport = new UnreliableDatagramTransport(clientTransport, secureRandom, 0, 0);

            clientTransport = new LoggingDatagramTransport(clientTransport, Console.Out);

            MockDtlsClient client = new MockDtlsClient(null);

            DtlsTransport dtlsClient = clientProtocol.Connect(client, clientTransport);

            for (int i = 1; i <= 10; ++i)
            {
                byte[] data = new byte[i];
                Arrays.Fill(data, (byte)i);
                dtlsClient.Send(data, 0, data.Length);
            }

            byte[] buf = new byte[dtlsClient.GetReceiveLimit()];
            while (dtlsClient.Receive(buf, 0, buf.Length, 100) >= 0)
            {
            }

            dtlsClient.Close();

            server.Shutdown(serverThread);
        }
Exemplo n.º 3
0
 public void Run()
 {
     try
     {
         DtlsTransport dtlsServer = mServerProtocol.Accept(mServerImpl, mServerTransport);
         byte[]        buf        = new byte[dtlsServer.GetReceiveLimit()];
         while (!isShutdown)
         {
             int length = dtlsServer.Receive(buf, 0, buf.Length, 100);
             if (length >= 0)
             {
                 dtlsServer.Send(buf, 0, length);
             }
         }
         dtlsServer.Close();
     }
     catch (Exception e)
     {
         mCaught = e;
         mOuter.LogException(mCaught);
     }
 }
Exemplo n.º 4
0
 public void Run()
 {
     try
     {
         MockDtlsServer server     = new MockDtlsServer();
         DtlsTransport  dtlsServer = mServerProtocol.Accept(server, mServerTransport);
         byte[]         buf        = new byte[dtlsServer.GetReceiveLimit()];
         while (!isShutdown)
         {
             int length = dtlsServer.Receive(buf, 0, buf.Length, 1000);
             if (length >= 0)
             {
                 dtlsServer.Send(buf, 0, length);
             }
         }
         dtlsServer.Close();
     }
     catch (Exception e)
     {
         Console.Error.WriteLine(e.StackTrace);
     }
 }
Exemplo n.º 5
0
 public void Close()
 {
     _dtlsTransport?.Close();
     _socket.Shutdown(SocketShutdown.Both);
     _socket.Close();
 }
Exemplo n.º 6
0
 public void Close()
 {
     _dtlsTransport.Close();
 }
 public void Close()
 {
     _dtlsTransport?.Close();
     _socket.Disconnect(true);
 }
Exemplo n.º 8
0
        public void RunTest(TlsTestConfig config)
        {
            CheckDtlsVersion(config.clientMinimumVersion);
            CheckDtlsVersion(config.clientOfferVersion);
            CheckDtlsVersion(config.serverMaximumVersion);
            CheckDtlsVersion(config.serverMinimumVersion);

            SecureRandom secureRandom = new SecureRandom();

            DtlsClientProtocol clientProtocol = new DtlsClientProtocol(secureRandom);
            DtlsServerProtocol serverProtocol = new DtlsServerProtocol(secureRandom);

            MockDatagramAssociation network = new MockDatagramAssociation(1500);

            TlsTestClientImpl clientImpl = new TlsTestClientImpl(config);
            TlsTestServerImpl serverImpl = new TlsTestServerImpl(config);

            Server server = new Server(this, serverProtocol, network.Server, serverImpl);

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

            serverThread.Start();

            Exception caught = null;

            try
            {
                DatagramTransport clientTransport = network.Client;

                if (TlsTestConfig.DEBUG)
                {
                    clientTransport = new LoggingDatagramTransport(clientTransport, Console.Out);
                }

                DtlsTransport dtlsClient = clientProtocol.Connect(clientImpl, clientTransport);

                for (int i = 1; i <= 10; ++i)
                {
                    byte[] data = new byte[i];
                    Arrays.Fill(data, (byte)i);
                    dtlsClient.Send(data, 0, data.Length);
                }

                byte[] buf = new byte[dtlsClient.GetReceiveLimit()];
                while (dtlsClient.Receive(buf, 0, buf.Length, 100) >= 0)
                {
                }

                dtlsClient.Close();
            }
            catch (Exception e)
            {
                caught = e;
                LogException(caught);
            }

            server.Shutdown(serverThread);

            // TODO Add checks that the various streams were closed

            Assert.AreEqual(config.expectFatalAlertConnectionEnd, clientImpl.FirstFatalAlertConnectionEnd, "Client fatal alert connection end");
            Assert.AreEqual(config.expectFatalAlertConnectionEnd, serverImpl.FirstFatalAlertConnectionEnd, "Server fatal alert connection end");

            Assert.AreEqual(config.expectFatalAlertDescription, clientImpl.FirstFatalAlertDescription, "Client fatal alert description");
            Assert.AreEqual(config.expectFatalAlertDescription, serverImpl.FirstFatalAlertDescription, "Server fatal alert description");

            if (config.expectFatalAlertConnectionEnd == -1)
            {
                Assert.IsNull(caught, "Unexpected client exception");
                Assert.IsNull(server.mCaught, "Unexpected server exception");
            }
        }
Exemplo n.º 9
0
 public void Dispose()
 {
     _dtlsTransport?.Close();
     _udpTransport?.Dispose();
 }
Exemplo n.º 10
0
 public void Dispose()
 {
     _datagramTransport?.Close();
 }
Exemplo n.º 11
0
 public void Dispose()
 {
     _dtlsTransport?.Close();
     IsClosed = true;
 }