Пример #1
0
        public void TestLongTest()
        {
            var docs      = new DtlsOverlordClientServer(false, true, true, 0);
            var to_server = docs.Client.CreateSecurityAssociation(docs.ToServer) as DtlsAssociation;

            Assert.AreEqual(to_server.State, SecurityAssociation.States.Active, "Client.State == SslState.OK");

            byte[]        msg  = new byte[1024];
            System.Random rand = new System.Random();
            rand.NextBytes(msg);
            MemBlock mmsg0 = MemBlock.Reference(msg);

            msg = new byte[1024];
            rand.NextBytes(msg);
            MemBlock mmsg1 = MemBlock.Reference(msg);

            Assert.AreEqual(to_server.SslState, SslState.OK, "Client.State == SslState.OK");

            for (int i = 0; i < Int16.MaxValue; i++)
            {
                if (i % 2 == 0)
                {
                    to_server.Send(mmsg0);
                    Assert.AreEqual(docs.ServerIn.LastReceived, mmsg0, "Client -> Server");
                }
                else
                {
                    to_server.Send(mmsg1);
                    Assert.AreEqual(docs.ServerIn.LastReceived, mmsg1, "Client -> Server");
                }
            }
        }
Пример #2
0
//    This test frequently causes Assertion errors in openssl... they shouldn't exist, but oh well... it works sometimes...
//    [Test]
        public void TestLossyNetwork()
        {
            var docs      = new DtlsOverlordClientServer(false, true, true, .5);
            var to_server = docs.Client.CreateSecurityAssociation(docs.ToServer) as DtlsAssociation;

            DateTime end = DateTime.UtcNow.AddSeconds(120);

            while (end > DateTime.UtcNow && !(to_server.SslState == SslState.OK))
            {
                Thread.Sleep(1000);
            }

            Assert.AreEqual(to_server.State, SecurityAssociation.States.Active, "Client.State == SslState.OK");
        }
Пример #3
0
        public void SendBadPacket()
        {
            var docs      = new DtlsOverlordClientServer(false, true, true, 0);
            var to_server = docs.Client.CreateSecurityAssociation(docs.ToServer) as DtlsAssociation;

            Assert.AreEqual(to_server.SslState, SslState.OK, "Client.State == SslState.OK");

            byte[]   msg  = System.Text.Encoding.UTF8.GetBytes("HelloWorld!");
            MemBlock mmsg = MemBlock.Reference(msg);

            to_server.Send(mmsg);
            Assert.AreEqual(docs.ServerIn.LastReceived, mmsg, "Client -> Server");
            to_server.Sender.Send(new CopyList(to_server.PType, to_server.Header, mmsg));
            Assert.AreEqual(docs.ServerIn.LastReceived, mmsg, "Client -> Server 2");
        }
Пример #4
0
//    This test needs for us to create a second CA cert incompatible with the first...
//    [Test]
        public void TestBadServer()
        {
            var docs      = new DtlsOverlordClientServer(true, true, false, 0);
            var to_server = docs.Client.CreateSecurityAssociation(docs.ToServer) as DtlsAssociation;

            DateTime end = DateTime.UtcNow.AddMinutes(4);

            while (end > DateTime.UtcNow && to_server.State != SecurityAssociation.States.Closed)
            {
                Thread.Sleep(1000);
            }

            Assert.AreEqual(to_server.State, SecurityAssociation.States.Closed, "Client closed");
            Assert.AreNotEqual(to_server.SslState, SslState.OK, "Client.State != SslState.OK");
        }
Пример #5
0
        public void SimpleTest()
        {
            var docs      = new DtlsOverlordClientServer(true, true, true, 0);
            var to_server = docs.Client.CreateSecurityAssociation(docs.ToServer) as DtlsAssociation;

            Thread.Sleep(1000);

            Assert.AreEqual(to_server.SslState, SslState.OK, "Client.State == SslState.OK");

            byte[] msg = System.Text.Encoding.UTF8.GetBytes("HelloWorld!");

            MemBlock lastin = docs.ServerIn.LastReceived;
            MemBlock mmsg   = MemBlock.Reference(msg);

            to_server.Send(mmsg);
            NextReceived(docs.ServerIn, lastin);
            Assert.AreEqual(docs.ServerIn.LastReceived, mmsg, "Client -> Server");
        }
Пример #6
0
        public void TestClientRenegotiate()
        {
            var docs      = new DtlsOverlordClientServer(false, true, true, 0);
            var to_server = docs.Client.CreateSecurityAssociation(docs.ToServer) as DtlsAssociation;

            Assert.AreEqual(to_server.State, SecurityAssociation.States.Active, "Client.State == SslState.OK");

            byte[]   msg  = System.Text.Encoding.UTF8.GetBytes("HelloWorld!");
            MemBlock mmsg = MemBlock.Reference(msg);

            to_server.Send(mmsg);
            Assert.AreEqual(docs.ServerIn.LastReceived, mmsg, "Client -> Server");

            to_server.Renegotiate();
            to_server.Send(mmsg);
            Assert.AreEqual(to_server.State, SecurityAssociation.States.Active, "Client.State == SslState.OK 2");

            msg  = System.Text.Encoding.UTF8.GetBytes("HelloWorld!!!");
            mmsg = MemBlock.Reference(msg);
            to_server.Send(mmsg);
            Assert.AreEqual(docs.ServerIn.LastReceived, mmsg, "Client -> Server 2");
        }