AaltoTLS.RecordLayer.RecordHandler.SetCipherSuite C# (CSharp) Метод

SetCipherSuite() публичный Метод

public SetCipherSuite ( CipherSuite cipherSuite, ConnectionState connectionState ) : void
cipherSuite AaltoTLS.PluginInterface.CipherSuite
connectionState ConnectionState
Результат void
        public void SetCipherSuite(CipherSuite cipherSuite, ConnectionState connectionState)
        {
            // Get master secret from connectionState
            byte[] masterSecret = connectionState.MasterSecret;

            // Generate seed for changing cipher suite
            byte[] seed = new byte[64];
            Array.Copy(connectionState.ServerRandom, 0, seed, 0, 32);
            Array.Copy(connectionState.ClientRandom, 0, seed, 32, 32);

            _nextCipherSuite = cipherSuite;
            _nextKeyBlock = new KeyBlock(cipherSuite, masterSecret, seed);
        }

Usage Example

Пример #1
0
        public void PaddingTest()
        {
            CipherSuitePluginManager pluginManager = GetPluginManager();
            CipherSuite cipherSuite;

            RecordHandler clientHandler = new RecordHandler(ProtocolVersion.SSL3_0, true);
            RecordHandler serverHandler = new RecordHandler(ProtocolVersion.SSL3_0, false);

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

            ConnectionState connectionState = new ConnectionState(new byte[32], new byte[32], new byte[48]);

            clientHandler.SetCipherSuite(cipherSuite, connectionState);
            serverHandler.SetCipherSuite(cipherSuite, connectionState);
            clientHandler.ChangeLocalState();
            serverHandler.ChangeRemoteState();

            Record record = new Record(22, ProtocolVersion.SSL3_0);
            int blockSize = cipherSuite.BulkCipherAlgorithm.BlockSize;
            for (int i=0; i<blockSize*2; i++) {
                byte[] data = new byte[i];
                record.Fragment = (byte[])data.Clone();
                clientHandler.ProcessOutputRecord(record);
                Assert.AreEqual(0, record.Fragment.Length%blockSize);
                serverHandler.ProcessInputRecord(record);
                Assert.AreEqual(data, record.Fragment);
            }

            cipherSuite = pluginManager.GetCipherSuite(ProtocolVersion.TLS1_0, 0x002f);
            Assert.IsNotNull(cipherSuite);

            clientHandler.SetCipherSuite(cipherSuite, connectionState);
            serverHandler.SetCipherSuite(cipherSuite, connectionState);
            clientHandler.ChangeLocalState();
            serverHandler.ChangeRemoteState();

            record = new Record(22, ProtocolVersion.TLS1_0);
            for (int i=0; i<blockSize*2; i++) {
                byte[] data = new byte[i];
                record.Fragment = (byte[])data.Clone();
                clientHandler.ProcessOutputRecord(record);
                Assert.AreEqual(0, record.Fragment.Length%blockSize);
                serverHandler.ProcessInputRecord(record);
                Assert.AreEqual(data, record.Fragment);
            }

            cipherSuite = pluginManager.GetCipherSuite(ProtocolVersion.TLS1_2, 0x00a3);
            Assert.IsNotNull(cipherSuite);

            clientHandler.SetCipherSuite(cipherSuite, connectionState);
            serverHandler.SetCipherSuite(cipherSuite, connectionState);
            clientHandler.ChangeLocalState();
            serverHandler.ChangeRemoteState();

            record = new Record(22, ProtocolVersion.TLS1_2);
            for (int i=0; i<blockSize*2; i++) {
                byte[] data = new byte[i];
                record.Fragment = (byte[])data.Clone();
                clientHandler.ProcessOutputRecord(record);
                Assert.AreEqual(8+data.Length+16, record.Fragment.Length);
                serverHandler.ProcessInputRecord(record);
                Assert.AreEqual(data, record.Fragment);
            }
        }
All Usage Examples Of AaltoTLS.RecordLayer.RecordHandler::SetCipherSuite