AaltoTLS.RecordLayer.RecordHandlerTest.SSLv3Test C# (CSharp) Method

SSLv3Test() private method

private SSLv3Test ( ) : void
return void
        public void SSLv3Test()
        {
            byte[] finished1eb = new byte[] {
                0x16, 0x03, 0x00, 0x00, 0x40, 0x3c, 0xcd, 0xad,
                0xec, 0xd6, 0x18, 0x75, 0x2e, 0x6e, 0x37, 0xdf,
                0x19, 0x6d, 0x4f, 0xd4, 0x9c, 0x2c, 0x42, 0x1c,
                0xe7, 0x74, 0x45, 0xf9, 0x77, 0xb1, 0xde, 0x79,
                0x0f, 0xc4, 0x8b, 0xaf, 0x85, 0x7b, 0xa3, 0x73,
                0x92, 0x4c, 0xb7, 0xf4, 0xa3, 0x45, 0x78, 0x53,
                0x88, 0x18, 0xff, 0x2f, 0x3f, 0x7d, 0x27, 0xa1,
                0x4c, 0xa4, 0x1a, 0x5d, 0x81, 0x8d, 0xf3, 0xc8,
                0x3b, 0xb3, 0x71, 0x77, 0x59
            };
            byte[] finished2eb = new byte[] {
                0x16, 0x03, 0x00, 0x00, 0x40, 0xaa, 0xd4, 0x9e,
                0x02, 0x07, 0x52, 0x0f, 0xb0, 0x82, 0x79, 0x9a,
                0xbe, 0x53, 0xce, 0xfe, 0x66, 0xb3, 0xd5, 0xb1,
                0x58, 0x84, 0x5e, 0xe4, 0x7a, 0xb7, 0x86, 0x4c,
                0xbe, 0x33, 0x75, 0xc0, 0x57, 0xab, 0x78, 0xba,
                0x18, 0x02, 0xa8, 0xcb, 0x26, 0x2b, 0x0d, 0x3e,
                0x3a, 0xdb, 0xc5, 0x7a, 0xb8, 0x33, 0x6c, 0x35,
                0xe3, 0xa6, 0x09, 0xfe, 0x54, 0x45, 0xd0, 0x66,
                0xad, 0x95, 0xff, 0xb0, 0x3c
            };
            byte[] finished1db = new byte[] {
                0x16, 0x03, 0x00, 0x00, 0x28, 0x14, 0x00, 0x00,
                0x24, 0x98, 0x29, 0xF5, 0xAB, 0x95, 0xFD, 0x76,
                0x14, 0xDA, 0xA0, 0xA7, 0x97, 0x22, 0xCF, 0xB5,
                0x27, 0x8C, 0x96, 0xC6, 0xC7, 0x37, 0xDF, 0xD6,
                0x25, 0xB9, 0x19, 0x65, 0x2B, 0xA5, 0x06, 0x7D,
                0x10, 0x73, 0x7A, 0x59, 0xEA
            };
            byte[] finished2db = new byte[] {
                0x16, 0x03, 0x00, 0x00, 0x28, 0x14, 0x00, 0x00,
                0x24, 0x34, 0xCC, 0xA5, 0xD0, 0x08, 0x84, 0x26,
                0x19, 0xD9, 0xE5, 0x20, 0x68, 0x7B, 0xE5, 0x27,
                0xC8, 0x82, 0x71, 0x4E, 0xB1, 0x0E, 0xED, 0xE9,
                0x52, 0x01, 0xF3, 0xBE, 0x10, 0x46, 0x52, 0xDE,
                0x68, 0x2B, 0x42, 0xF8, 0x5F
            };
            byte[] crandom = new byte[] {
                0x4e, 0x60, 0xc6, 0xbd, 0x66, 0xbb, 0x66, 0x74,
                0xc8, 0xa2, 0x65, 0x5a, 0x1c, 0x3d, 0xf3, 0x7d,
                0xb0, 0xbc, 0x39, 0x60, 0x82, 0x6b, 0xec, 0xe9,
                0x62, 0xc6, 0xaa, 0x92, 0x5f, 0x7c, 0x3d, 0x3a
            };
            byte[] srandom = new byte[] {
                0x4e, 0x60, 0xc6, 0xb9, 0x1f, 0xff, 0xb5, 0x62,
                0xad, 0x3b, 0xe9, 0x16, 0xd9, 0x80, 0x04, 0xc5,
                0x91, 0x92, 0xa7, 0x1b, 0xe1, 0x39, 0x9e, 0x91,
                0x16, 0x76, 0xe1, 0x71, 0x2a, 0x9e, 0x23, 0x62
            };
            byte[] master = new byte[] {
                0x7C, 0xEE, 0xFE, 0xE3, 0x6A, 0x10, 0x82, 0xDC,
                0x69, 0xB0, 0xF2, 0x7C, 0xB6, 0xC1, 0xE9, 0x93,
                0xD8, 0x53, 0x40, 0x52, 0x7F, 0xAB, 0x2A, 0x45,
                0x3B, 0x4D, 0x69, 0xEF, 0x67, 0x60, 0xC2, 0x0E,
                0x97, 0x23, 0x40, 0x2B, 0x5A, 0x99, 0x90, 0x06,
                0xA7, 0x13, 0x10, 0x47, 0x5A, 0xC7, 0x6A, 0xAA
            };

            Record finished1 = GetRecord(finished1db);
            Record finished2 = GetRecord(finished2eb);

            CipherSuitePluginManager pluginManager = GetPluginManager();
            RecordHandler recordHandler = new RecordHandler(ProtocolVersion.SSL3_0, true);

            CipherSuite cipherSuite = pluginManager.GetCipherSuite(ProtocolVersion.SSL3_0, 0x000a);
            Assert.IsNotNull(cipherSuite);

            // Set correct cipher suite
            ConnectionState connectionState = new ConnectionState(crandom, srandom, master);
            recordHandler.SetCipherSuite(cipherSuite, connectionState);

            // Test that initial state doesn't modify records
            recordHandler.ProcessOutputRecord(finished1);
            recordHandler.ProcessInputRecord(finished2);
            Assert.AreEqual(finished1db, finished1.GetBytes());
            Assert.AreEqual(finished2eb, finished2.GetBytes());

            recordHandler.ChangeLocalState();
            recordHandler.ProcessOutputRecord(finished1);
            recordHandler.ChangeRemoteState();
            recordHandler.ProcessInputRecord(finished2);

            // Ignore last block, it has some random padding
            int bsize = cipherSuite.BulkCipherAlgorithm.BlockSize;
            byte[] tmp1 = new byte[finished1eb.Length-bsize];
            byte[] tmp2 = new byte[finished1eb.Length-bsize];
            Buffer.BlockCopy(finished1eb, 0, tmp1, 0, tmp1.Length);
            Buffer.BlockCopy(finished1.GetBytes(), 0, tmp2, 0, tmp2.Length);

            Assert.AreEqual(tmp1, tmp2);
            Assert.AreEqual(finished2db, finished2.GetBytes());
        }