本文整理汇总了Python中tlslite.extensions.SNIExtension类的典型用法代码示例。如果您正苦于以下问题:Python SNIExtension类的具体用法?Python SNIExtension怎么用?Python SNIExtension使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SNIExtension类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_alignClientHelloPadding_length_256_bytes
def test_alignClientHelloPadding_length_256_bytes(self):
clientHello = ClientHello()
clientHello.create((3,0), bytearray(32), bytearray(0), [])
clientHello.extensions = []
ext = SNIExtension()
ext.create(hostNames=[
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeee'),
])
clientHello.extensions.append(ext)
clientHelloLength = len(clientHello.write())
# clientHello length (excluding 4B header) should equal to 256
self.assertEqual(256, clientHelloLength - 4)
HandshakeHelpers.alignClientHelloPadding(clientHello)
# clientHello length (excluding 4B header) should equal to 512
data = clientHello.write()
self.assertEqual(512, len(data) - 4)
# previously created data should be extended with the padding extension
# starting with the padding extension type \x00\x15 (21)
self.assertEqual(bytearray(b'\x00\x15'), data[clientHelloLength:clientHelloLength+2])
示例2: test_alignClientHelloPadding_length_of_511_bytes
def test_alignClientHelloPadding_length_of_511_bytes(self):
clientHello = ClientHello()
clientHello.create((3,0), bytearray(32), bytearray(0), [])
clientHello.extensions = []
ext = SNIExtension()
ext.create(hostNames=[
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddd'),
])
clientHello.extensions.append(ext)
clientHelloLength = len(clientHello.write())
self.assertEqual(511, clientHelloLength - 4)
HandshakeHelpers.alignClientHelloPadding(clientHello)
# clientHello length should equal to 515, ignoring handshake
# protocol header (4B)
data = clientHello.write()
self.assertEqual(515, len(data) - 4)
# padding extension should have zero byte size
self.assertEqual(bytearray(b'\x00\x15\x00\x00'), data[clientHelloLength:])
示例3: test_alignClientHelloPadding_length_of_512_bytes
def test_alignClientHelloPadding_length_of_512_bytes(self):
clientHello = ClientHello()
clientHello.create((3,0), bytearray(32), bytearray(0), [])
clientHello.extensions = []
ext = SNIExtension()
ext.create(hostNames=[
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee'),
bytearray(b'aaaaaaaaaabbbbbbbbbbccccccccccdddddddd'),
])
clientHello.extensions.append(ext)
clientHelloLength = len(clientHello.write())
self.assertEqual(512, clientHelloLength - 4)
HandshakeHelpers.alignClientHelloPadding(clientHello)
# clientHello should not be changed due to sufficient length (>=512)
self.assertEqual(clientHelloLength, len(clientHello.write()))
示例4: test_write_with_multiple_hostnames
def test_write_with_multiple_hostnames(self):
server_name = SNIExtension()
server_name = server_name.create(host_names=[
bytearray(b'example.com'),
bytearray(b'example.org')])
self.assertEqual(bytearray(
b'\x00\x1c' + # lenght of array - 28 bytes
b'\x00' + # type of element - host_name (0)
b'\x00\x0b' + # length of element - 11 bytes
# utf-8 encoding of example.com
b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d' +
b'\x00' + # type of elemnt - host_name (0)
b'\x00\x0b' + # length of elemnet - 11 bytes
# utf-8 encoding of example.org
b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67'
), server_name.ext_data)
self.assertEqual(bytearray(
b'\x00\x00' + # type of extension - SNI (0)
b'\x00\x1e' + # length of extension - 26 bytes
b'\x00\x1c' + # lenght of array - 24 bytes
b'\x00' + # type of element - host_name (0)
b'\x00\x0b' + # length of element - 11 bytes
# utf-8 encoding of example.com
b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d' +
b'\x00' + # type of elemnt - host_name (0)
b'\x00\x0b' + # length of elemnet - 11 bytes
# utf-8 encoding of example.org
b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67'
), server_name.write())
示例5: tes_parse_with_invalid_data
def tes_parse_with_invalid_data(self):
server_name = SNIExtension()
p = Parser(bytearray(b'\x00\x01'))
with self.assertRaises(SyntaxError):
server_name.parse(p)
示例6: test_parse_with_name_length_short_by_one
def test_parse_with_name_length_short_by_one(self):
server_name = SNIExtension()
p = Parser(bytearray(
b'\x00\x1c' + # length of array - 28 bytes
b'\x0a' + # type of entry - unassigned (10)
b'\x00\x0a' + # length of name - 10 bytes (short by one)
# UTF-8 encoding of example.org
b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67' +
b'\x00' + # type of entry - host_name (0)
b'\x00\x0b' + # length of name - 11 bytes
# UTF-8 encoding of example.com
b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d'))
with self.assertRaises(SyntaxError):
server_name = server_name.parse(p)
server_name = SNIExtension()
p = Parser(bytearray(
b'\x00\x1c' + # length of array - 28 bytes
b'\x0a' + # type of entry - unassigned (10)
b'\x00\x0b' + # length of name - 11 bytes
# UTF-8 encoding of example.org
b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67' +
b'\x00' + # type of entry - host_name (0)
b'\x00\x0a' + # length of name - 10 bytes (short by one)
# UTF-8 encoding of example.com
b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d'))
with self.assertRaises(SyntaxError):
server_name = server_name.parse(p)
示例7: test_parse_with_multiple_host_names
def test_parse_with_multiple_host_names(self):
server_name = SNIExtension()
p = Parser(bytearray(
b'\x00\x1c' + # length of array - 28 bytes
b'\x0a' + # type of entry - unassigned (10)
b'\x00\x0b' + # length of name - 11 bytes
# UTF-8 encoding of example.org
b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67' +
b'\x00' + # type of entry - host_name (0)
b'\x00\x0b' + # length of name - 11 bytes
# UTF-8 encoding of example.com
b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d'))
server_name = server_name.parse(p)
self.assertEqual(bytearray(b'example.com'), server_name.host_names[0])
self.assertEqual(tuple([bytearray(b'example.com')]),
server_name.host_names)
SN = SNIExtension.ServerName
self.assertEqual([
SN(10, bytearray(b'example.org')),
SN(0, bytearray(b'example.com'))
], server_name.server_names)
示例8: test_write_of_empty_extension
def test_write_of_empty_extension(self):
server_name = SNIExtension()
self.assertEqual(bytearray(
b'\x00\x00' + # type of extension - SNI (0)
b'\x00\x00' # length of extension - 0 bytes
), server_name.write())
示例9: test_parse
def test_parse(self):
server_name = SNIExtension()
p = Parser(bytearray(0))
with self.assertRaises(SyntaxError):
server_name = server_name.parse(p)
示例10: test_parse_null_length_array
def test_parse_null_length_array(self):
server_name = SNIExtension()
p = Parser(bytearray(b'\x00\x00'))
server_name = server_name.parse(p)
self.assertEqual([], server_name.server_names)
示例11: test_parse_of_server_side_version
def test_parse_of_server_side_version(self):
server_name = SNIExtension()
p = Parser(bytearray(0))
server_name = server_name.parse(p)
self.assertIsNone(server_name.serverNames)
示例12: test_create_with_hostname
def test_create_with_hostname(self):
server_name = SNIExtension()
server_name = server_name.create(bytearray(b'example.com'))
self.assertEqual((bytearray(b'example.com'),), server_name.host_names)
self.assertEqual([SNIExtension.ServerName(
NameType.host_name,
bytearray(b'example.com')
)], server_name.server_names)
示例13: test___repr__
def test___repr__(self):
server_name = SNIExtension()
server_name = server_name.create(
server_names=[
SNIExtension.ServerName(0, bytearray(b'example.com')),
SNIExtension.ServerName(1, bytearray(b'\x04\x01'))])
self.assertEqual("SNIExtension(server_names=["\
"ServerName(name_type=0, name=bytearray(b'example.com')), "\
"ServerName(name_type=1, name=bytearray(b'\\x04\\x01'))])",
repr(server_name))
示例14: test_parse_with_array_length_short_by_one
def test_parse_with_array_length_short_by_one(self):
server_name = SNIExtension()
p = Parser(bytearray(
b'\x00\x0d' + # length of array (one too short)
b'\x00' + # type of entry - host_name (0)
b'\x00\x0b' + # length of name - 11 bytes
# UTF-8 encoding of example.com
b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d'))
with self.assertRaises(SyntaxError):
server_name = server_name.parse(p)
示例15: test_write_of_empty_list_of_names
def test_write_of_empty_list_of_names(self):
server_name = SNIExtension()
server_name = server_name.create(server_names=[])
self.assertEqual(bytearray(
b'\x00\x00' # length of array - 0 bytes
), server_name.ext_data)
self.assertEqual(bytearray(
b'\x00\x00' + # type of extension - SNI 0
b'\x00\x02' + # length of extension - 2 bytes
b'\x00\x00' # length of array of names - 0 bytes
), server_name.write())