AaltoTLS.RecordLayer.RecordHandler.ProcessOutputRecord C# (CSharp) Method

ProcessOutputRecord() public method

public ProcessOutputRecord ( Record output ) : void
output Record
return void
        public void ProcessOutputRecord(Record output)
        {
            // Construct the sequence number correctly
            UInt64 seqNum = _outputSequenceNumber;
            if (output.Version.IsUsingDatagrams) {
                if ((_outputSequenceNumber >> 48) != 0) {
                    // TODO: need renegotiation, throw Exception?
                }
                seqNum = (((UInt64)_outputEpoch) << 48) | _outputSequenceNumber;
            }

            // In case of AEAD we need to create a new encryptor for each record
            byte[] nonceExplicit = new byte[0];
            if (_outputCipherSuite.BulkCipherAlgorithm.Type == BulkCipherAlgorithmType.AEAD) {
                _encryptor = CreateAEADEncryptor(_outputCipherSuite, output, _outputKey, _outputFixedIV, _outputRecordIV, seqNum, out nonceExplicit);
            }

            CompressRecord(output);
            GenerateMAC(_outputCipherSuite, output, seqNum, _outputHasher);
            GeneratePadding(_outputCipherSuite, output);
            EncryptRecord(_outputCipherSuite, output, _encryptor, nonceExplicit);

            // If we're running DTLS, set epoch and seqnum
            if (output.Version.IsUsingDatagrams) {
                output.Epoch = _outputEpoch;
                output.SequenceNumber = _outputSequenceNumber;
            }

            // Update the output sequence number
            _outputSequenceNumber++;
        }

Usage Example

Beispiel #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::ProcessOutputRecord