• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tlsrecordlayer.TLSRecordLayer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tlslite.tlsrecordlayer.TLSRecordLayer的典型用法代码示例。如果您正苦于以下问题:Python TLSRecordLayer类的具体用法?Python TLSRecordLayer怎么用?Python TLSRecordLayer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TLSRecordLayer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test__getMsg

    def test__getMsg(self):

        mock_sock = MockSocket(
            bytearray(
                b"\x16"
                + b"\x03\x03"  # handshake
                + b"\x00\x3a"  # TLSv1.2
                + b"\x02"  # payload length
                + b"\x00\x00\x36"  # Server Hello
                + b"\x03\x03"  # hello length
                + b"\x00" * 32  # TLSv1.2
                + b"\x00"  # random
                + b"\x00\x2f"  # session ID length
                + b"\x00"  # cipher suite selected (AES128-SHA)
                + b"\x00\x0e"  # compression null
                + b"\xff\x01"  # extensions length
                + b"\x00\x01"  # renegotiation_info
                + b"\x00"  # ext length
                + b"\x00\x23"  # renegotiation info ext length - 0
                + b"\x00\x00"  # session_ticket
                + b"\x00\x0f"  # ext length
                + b"\x00\x01"  # heartbeat extension
                + b"\x01"  # ext length
            )
        )  # peer is allowed to send requests

        record_layer = TLSRecordLayer(mock_sock)

        gen = record_layer._getMsg(ContentType.handshake, HandshakeType.server_hello)

        message = next(gen)

        self.assertEqual(ServerHello, type(message))
        self.assertEqual((3, 3), message.server_version)
        self.assertEqual(0x002F, message.cipher_suite)
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:35,代码来源:test_tlslite_tlsrecordlayer.py


示例2: test_write_with_BEAST_record_splitting

    def test_write_with_BEAST_record_splitting(self):
        mock_sock = MockSocket(bytearray(0))
        record_layer = TLSRecordLayer(mock_sock)

        record_layer.version = (3, 1)
        record_layer.closed = False
        record_layer._recordLayer.calcPendingStates(
            CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA, bytearray(48), bytearray(32), bytearray(32), None
        )
        record_layer._recordLayer.changeWriteState()

        record_layer.write(bytearray(32))

        self.assertEqual(len(mock_sock.sent), 2)
        msg1 = mock_sock.sent[0]
        self.assertEqual(
            bytearray(
                b"\x17"
                + b"\x03\x01"  # application data
                + b"\x00\x20"  # TLSv1.0  # length 32 bytes = data(1) + MAC(20) + padding(11)
            ),
            msg1[:5],
        )
        self.assertEqual(len(msg1[5:]), 32)

        msg2 = mock_sock.sent[1]
        self.assertEqual(
            bytearray(
                b"\x17"
                + b"\x03\x01"  # application data
                + b"\x00\x40"  # TLSv1.0  # length 64 bytes = data(31) + MAC(20) + padding(13)
            ),
            msg2[:5],
        )
        self.assertEqual(len(msg2[5:]), 64)
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:35,代码来源:test_tlslite_tlsrecordlayer.py


示例3: test__getMsg_with_oversized_message

    def test__getMsg_with_oversized_message(self):

        mock_sock = MockSocket(
                bytearray(
                b'\x16' +           # handshake
                b'\x03\x03' +       # TLSv1.2
                b'\x40\x01' +       # payload length 2**14+1
                b'\x02' +           # Server Hello
                b'\x00\x3f\xfd' +   # hello length 2**14+1-1-3
                b'\x03\x03' +       # TLSv1.2
                b'\x00'*32 +        # random
                b'\x00' +           # session ID length
                b'\x00\x2f' +       # cipher suite selected (AES128-SHA)
                b'\x00' +           # compression null
                b'\x3f\xd5' +       # extensions length: 2**14+1-1-3-2-32-6
                b'\xff\xff' +       # extension type (padding)
                b'\x3f\xd1' +       # extension length: 2**14+1-1-3-2-32-6-4
                b'\x00'*16337       # value
                ))

        record_layer = TLSRecordLayer(mock_sock)

        gen = record_layer._getMsg(ContentType.handshake,
                HandshakeType.server_hello)

        with self.assertRaises(TLSLocalAlert):
            message = next(gen)
开发者ID:almond29,项目名称:tlslite-ng,代码行数:27,代码来源:test_tlslite_tlsrecordlayer.py


示例4: test__getMsg

    def test__getMsg(self):

        mock_sock = MockSocket(
                bytearray(
                b'\x16' +           # handshake
                b'\x03\x03' +       # TLSv1.2
                b'\x00\x3a' +       # payload length
                b'\x02' +           # Server Hello
                b'\x00\x00\x36' +   # hello length
                b'\x03\x03' +       # TLSv1.2
                b'\x00'*32 +        # random
                b'\x00' +           # session ID length
                b'\x00\x2f' +       # cipher suite selected (AES128-SHA)
                b'\x00' +           # compression null
                b'\x00\x0e' +       # extensions length
                b'\xff\x01' +       # renegotiation_info
                b'\x00\x01' +       # ext length
                b'\x00' +           # renegotiation info ext length - 0
                b'\x00\x23' +       # session_ticket
                b'\x00\x00' +       # ext length
                b'\x00\x0f' +       # heartbeat extension
                b'\x00\x01' +       # ext length
                b'\x01'))           # peer is allowed to send requests

        record_layer = TLSRecordLayer(mock_sock)

        gen = record_layer._getMsg(ContentType.handshake,
                HandshakeType.server_hello)

        message = next(gen)

        self.assertEqual(ServerHello, type(message))
        self.assertEqual((3,3), message.server_version)
        self.assertEqual(0x002f, message.cipher_suite)
开发者ID:almond29,项目名称:tlslite-ng,代码行数:34,代码来源:test_tlslite_tlsrecordlayer.py


示例5: test__getMsg_with_oversized_message

    def test__getMsg_with_oversized_message(self):

        mock_sock = MockSocket(
            bytearray(
                b"\x16"
                + b"\x03\x03"  # handshake
                + b"\x40\x01"  # TLSv1.2
                + b"\x02"  # payload length 2**14+1
                + b"\x00\x3f\xfd"  # Server Hello
                + b"\x03\x03"  # hello length 2**14+1-1-3
                + b"\x00" * 32  # TLSv1.2
                + b"\x00"  # random
                + b"\x00\x2f"  # session ID length
                + b"\x00"  # cipher suite selected (AES128-SHA)
                + b"\x3f\xd5"  # compression null
                + b"\xff\xff"  # extensions length: 2**14+1-1-3-2-32-6
                + b"\x3f\xd1"  # extension type (padding)
                + b"\x00" * 16337  # extension length: 2**14+1-1-3-2-32-6-4  # value
            )
        )

        record_layer = TLSRecordLayer(mock_sock)

        gen = record_layer._getMsg(ContentType.handshake, HandshakeType.server_hello)

        # XXX decoder handles messages over the 2**14 limit!
        # with self.assertRaises(TLSLocalAlert):
        message = next(gen)
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:28,代码来源:test_tlslite_tlsrecordlayer.py


示例6: test__sendMsg_with_very_slow_socket

    def test__sendMsg_with_very_slow_socket(self):
        mockSock = MockSocket(bytearray(0), maxWrite=1, blockEveryOther=True)
        sock = TLSRecordLayer(mockSock)

        msg = Message(ContentType.handshake, bytearray(b"\x32" * 2))

        gotRetry = False
        # XXX using private method!
        for result in sock._sendMsg(msg, False):
            if result in (0, 1):
                gotRetry = True
            else:
                break

        self.assertTrue(gotRetry)
        self.assertEqual(
            [
                bytearray(b"\x16"),  # handshake message
                bytearray(b"\x00"),
                bytearray(b"\x00"),  # version (unset)
                bytearray(b"\x00"),
                bytearray(b"\x02"),  # payload length
                bytearray(b"\x32"),
                bytearray(b"\x32"),
            ],
            mockSock.sent,
        )
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:27,代码来源:test_tlslite_tlsrecordlayer.py


示例7: test__getNextRecord_with_multiple_messages_in_single_record

    def test__getNextRecord_with_multiple_messages_in_single_record(self):

        mock_sock = MockSocket(bytearray(
            b'\x16' +           # handshake
            b'\x03\x03' +       # TLSv1.2
            b'\x00\x35' +       # length
            # server hello
            b'\x02' +           # type - server hello
            b'\x00\x00\x26' +   # length
            b'\x03\x03' +       # TLSv1.2
            b'\x01'*32 +        # random
            b'\x00' +           # session ID length
            b'\x00\x2f' +       # cipher suite selected
            b'\x00' +           # compression method
            # certificate
            b'\x0b' +           # type - certificate
            b'\x00\x00\x03'     # length
            b'\x00\x00\x00'     # length of certificates
            # server hello done
            b'\x0e' +           # type - server hello done
            b'\x00\x00\x00'     # length
            ))

        record_layer = TLSRecordLayer(mock_sock)

        results = []
        for result in record_layer._getNextRecord():
            if result in (0,1):
                raise Exception("blocking")
            else:
                results.append(result)
                if len(results) == 3:
                    break

        header, p = results[0]

        self.assertIsInstance(header, RecordHeader3)
        self.assertEqual(ContentType.handshake, header.type)
        self.assertEqual(42, len(p.bytes))
        self.assertEqual(HandshakeType.server_hello, p.bytes[0])

        # XXX generator stops as soon as a message was read
        #self.assertEqual(1, len(results))
        #return

        header, p = results[1]

        self.assertIsInstance(header, RecordHeader3)
        self.assertEqual(ContentType.handshake, header.type)
        self.assertEqual(7, len(p.bytes))
        self.assertEqual(HandshakeType.certificate, p.bytes[0])

        header, p = results[2]

        self.assertIsInstance(header, RecordHeader3)
        self.assertEqual(ContentType.handshake, header.type)
        self.assertEqual(4, len(p.bytes))
        self.assertEqual(HandshakeType.server_hello_done, p.bytes[0])
开发者ID:almond29,项目名称:tlslite-ng,代码行数:58,代码来源:test_tlslite_tlsrecordlayer.py


示例8: test__getNextRecord_with_blocking_socket

    def test__getNextRecord_with_blocking_socket(self):
        mockSock = mock.MagicMock()
        mockSock.recv.side_effect = socket.error(errno.EWOULDBLOCK)

        sock = TLSRecordLayer(mockSock)

        # XXX using private method!
        gen = sock._getNextRecord()

        self.assertEqual(0, next(gen))
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:10,代码来源:test_tlslite_tlsrecordlayer.py


示例9: test__getNextRecord_with_not_complete_SSL2_record

    def test__getNextRecord_with_not_complete_SSL2_record(self):
        mockSock = MockSocket(bytearray(b"\x80" + b"\x04" + b"\x00" * 3))  # tag  # length

        sock = TLSRecordLayer(mockSock)

        # XXX using private method!
        for result in sock._getNextRecord():
            break

        self.assertEqual(0, result)
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:10,代码来源:test_tlslite_tlsrecordlayer.py


示例10: test__getNextRecord_with_SSL2_record_with_incomplete_header

    def test__getNextRecord_with_SSL2_record_with_incomplete_header(self):
        mockSock = MockSocket(bytearray(b"\x80"))  # tag

        sock = TLSRecordLayer(mockSock)

        # XXX using private method
        for result in sock._getNextRecord():
            break

        self.assertEqual(0, result)
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:10,代码来源:test_tlslite_tlsrecordlayer.py


示例11: test__getNextRecord_with_empty_socket

    def test__getNextRecord_with_empty_socket(self):
        mockSock = mock.MagicMock()
        mockSock.recv.side_effect = [bytearray(0)]

        sock = TLSRecordLayer(mockSock)

        # XXX using private method!
        gen = sock._getNextRecord()

        with self.assertRaises(TLSAbruptCloseError):
            next(gen)
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:11,代码来源:test_tlslite_tlsrecordlayer.py


示例12: test__getNextRecord_with_errored_out_socket

    def test__getNextRecord_with_errored_out_socket(self):
        mockSock = mock.MagicMock()
        mockSock.recv.side_effect = socket.error(errno.ETIMEDOUT)

        sock = TLSRecordLayer(mockSock)

        # XXX using private method!
        gen = sock._getNextRecord()

        with self.assertRaises(socket.error):
            next(gen)
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:11,代码来源:test_tlslite_tlsrecordlayer.py


示例13: test__getNextRecord_with_empty_handshake

    def test__getNextRecord_with_empty_handshake(self):

        mock_sock = MockSocket(bytearray(b"\x16" + b"\x03\x03" + b"\x00\x00"))  # handshake  # TLSv1.2  # length

        record_layer = TLSRecordLayer(mock_sock)

        with self.assertRaises(TLSLocalAlert):
            for result in record_layer._getNextRecord():
                if result in (0, 1):
                    raise Exception("blocking socket")
                else:
                    break
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:12,代码来源:test_tlslite_tlsrecordlayer.py


示例14: test__sendMsg_with_errored_out_socket

    def test__sendMsg_with_errored_out_socket(self):
        mockSock = mock.MagicMock()
        mockSock.send.side_effect = socket.error(errno.ETIMEDOUT)

        sock = TLSRecordLayer(mockSock)

        msg = Message(ContentType.handshake, bytearray(10))

        gen = sock._sendMsg(msg, False)

        with self.assertRaises(TLSAbruptCloseError):
            next(gen)
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:12,代码来源:test_tlslite_tlsrecordlayer.py


示例15: test__getNextRecord_with_malformed_record

    def test__getNextRecord_with_malformed_record(self):
        mockSock = MockSocket(
            bytearray(b"\x01" + b"\x03\x03" + b"\x00\x01" + b"\x00")  # wrong type  # TLSv1.2  # length
        )

        sock = TLSRecordLayer(mockSock)

        # XXX using private method!
        gen = sock._getNextRecord()

        with self.assertRaises(TLSLocalAlert) as context:
            next(gen)

        self.assertEqual(str(context.exception), "illegal_parameter")
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:14,代码来源:test_tlslite_tlsrecordlayer.py


示例16: test__getNextRecord_with_too_big_record

    def test__getNextRecord_with_too_big_record(self):
        mockSock = MockSocket(
            bytearray(b"\x16" + b"\x03\x03" + b"\xff\xff" + b"\x00" * 65536)  # type - handshake  # TLSv1.2  # length
        )

        sock = TLSRecordLayer(mockSock)

        # XXX using private method!
        gen = sock._getNextRecord()

        with self.assertRaises(TLSLocalAlert) as context:
            next(gen)

        self.assertEqual(str(context.exception), "record_overflow")
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:14,代码来源:test_tlslite_tlsrecordlayer.py


示例17: test__getNextRecord_with_trickling_socket

    def test__getNextRecord_with_trickling_socket(self):
        mockSock = MockSocket(
            bytearray(b"\x16" + b"\x03\x03" + b"\x00\x04" + b"\x00" * 4),  # type - handshake  # TLSv1.2  # length
            maxRet=1,
        )

        sock = TLSRecordLayer(mockSock)

        # XXX using private method!
        for result in sock._getNextRecord():
            if result in (0, 1):
                self.assertTrue(False, "blocking socket")
            else:
                break

        header, data = result
        data = data.bytes

        self.assertEqual(bytearray(4), data)
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:19,代码来源:test_tlslite_tlsrecordlayer.py


示例18: test__sendMsg

    def test__sendMsg(self):
        mockSock = MockSocket(bytearray(0))
        sock = TLSRecordLayer(mockSock)
        sock.version = (3, 3)

        msg = Message(ContentType.handshake, bytearray(10))

        # XXX using private method
        for result in sock._sendMsg(msg, False):
            if result in (0, 1):
                self.assertTrue(False, "Blocking socket")
            else: break

        self.assertEqual(len(mockSock.sent), 1)
        self.assertEqual(bytearray(
            b'\x16' +           # handshake message
            b'\x03\x03' +       # version
            b'\x00\x0a' +       # payload length
            b'\x00'*10          # payload
            ), mockSock.sent[0])
开发者ID:almond29,项目名称:tlslite-ng,代码行数:20,代码来源:test_tlslite_tlsrecordlayer.py


示例19: test__sendMsg_with_large_message

    def test__sendMsg_with_large_message(self):

        mock_sock = MockSocket(bytearray(0))

        record_layer = TLSRecordLayer(mock_sock)

        client_hello = ClientHello().create((3, 3), bytearray(32), bytearray(0), [x for x in range(2 ** 15 - 1)])

        gen = record_layer._sendMsg(client_hello)

        for result in gen:
            if result in (0, 1):
                self.assertTrue(False, "blocking")
            else:
                break

        # The maximum length that can be sent in single record is 2**14
        # record layer adds 5 byte on top of that
        self.assertEqual(len(mock_sock.sent), 5)
        for msg in mock_sock.sent:
            self.assertTrue(len(msg) <= 2 ** 14 + 5)
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:21,代码来源:test_tlslite_tlsrecordlayer.py


示例20: test__getNextRecord

    def test__getNextRecord(self):
        mockSock = MockSocket(
            bytearray(b"\x16" + b"\x03\x03" + b"\x00\x04" + b"\x00" * 4)  # type - handshake  # TLSv1.2  # length
        )
        sock = TLSRecordLayer(mockSock)
        sock.version = (3, 3)

        # XXX using private method!
        for result in sock._getNextRecord():
            if result in (0, 1):
                self.assertTrue(False, "blocking socket")
            else:
                break

        header, data = result
        data = data.bytes

        self.assertEqual(data, bytearray(4))
        self.assertEqual(header.type, ContentType.handshake)
        self.assertEqual(header.version, (3, 3))
        self.assertEqual(header.length, 0)
开发者ID:RedHatLab,项目名称:tlslite-ng,代码行数:21,代码来源:test_tlslite_tlsrecordlayer.py



注:本文中的tlslite.tlsrecordlayer.TLSRecordLayer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python codec.Parser类代码示例发布时间:2022-05-27
下一篇:
Python messages.ClientHello类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap