AaltoTLS.RecordLayer.RecordHandler.ProcessInputRecord C# (CSharp) 메소드

ProcessInputRecord() 공개 메소드

public ProcessInputRecord ( Record input ) : bool
input Record
리턴 bool
        public bool ProcessInputRecord(Record input)
        {
            // If we're running DTLS, ignore packets with incorrect epoch
            if (input.Version.IsUsingDatagrams && input.Epoch != _inputEpoch) {
                return false;
            }

            // If we're running DTLS, get epoch and seqnum
            UInt64 seqNum = _inputSequenceNumber;
            if (input.Version.IsUsingDatagrams) {
                seqNum = (((UInt64)input.Epoch) << 48) | input.SequenceNumber;
            }

            // In case of AEAD we need to create a new decryptor for each record
            if (_inputCipherSuite.BulkCipherAlgorithm.Type == BulkCipherAlgorithmType.AEAD) {
                _decryptor = CreateAEADDecryptor(_inputCipherSuite, input, _inputKey, _inputFixedIV, seqNum);
            }

            bool decryptValid = DecryptRecord(_inputCipherSuite, input, _decryptor);
            bool paddingValid = RemovePadding(_inputCipherSuite, input);
            bool MACValid = RemoveMAC(_inputCipherSuite, input, seqNum, _inputHasher);
            DecompressRecord(input);

            if (!decryptValid || !paddingValid || !MACValid) {
                string message = "Invalid MAC: decrypt " + decryptValid + " padding " + paddingValid + " MAC " + MACValid;
                throw new AlertException(AlertDescription.BadRecordMAC, message);
            }

            _inputSequenceNumber++;
            return true;
        }

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::ProcessInputRecord