本文整理汇总了Python中tlslite.messages.ClientHello.write方法的典型用法代码示例。如果您正苦于以下问题:Python ClientHello.write方法的具体用法?Python ClientHello.write怎么用?Python ClientHello.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tlslite.messages.ClientHello
的用法示例。
在下文中一共展示了ClientHello.write方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_alignClientHelloPadding_length_256_bytes
# 需要导入模块: from tlslite.messages import ClientHello [as 别名]
# 或者: from tlslite.messages.ClientHello import write [as 别名]
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
# 需要导入模块: from tlslite.messages import ClientHello [as 别名]
# 或者: from tlslite.messages.ClientHello import write [as 别名]
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
# 需要导入模块: from tlslite.messages import ClientHello [as 别名]
# 或者: from tlslite.messages.ClientHello import write [as 别名]
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_alignClientHelloPadding_length_less_than_256_bytes
# 需要导入模块: from tlslite.messages import ClientHello [as 别名]
# 或者: from tlslite.messages.ClientHello import write [as 别名]
def test_alignClientHelloPadding_length_less_than_256_bytes(self):
clientHello = ClientHello()
clientHello.create((3,0), bytearray(32), bytearray(0), [])
clientHelloLength = len(clientHello.write())
self.assertTrue(clientHelloLength - 4 < 256)
HandshakeHelpers.alignClientHelloPadding(clientHello)
# clientHello should not be changed due to small length
self.assertEqual(clientHelloLength, len(clientHello.write()))
示例5: test_write_with_certificate_types
# 需要导入模块: from tlslite.messages import ClientHello [as 别名]
# 或者: from tlslite.messages.ClientHello import write [as 别名]
def test_write_with_certificate_types(self):
# note that ClienHello is "clever" and doesn't send the extension
# if only x509 certificate type is present, so we pass two values
client_hello = ClientHello().create((3,1),
bytearray(b'\x00'*31 + b'\xff'), bytearray(0),
[], certificate_types=[
CertificateType.x509, CertificateType.openpgp])
self.assertEqual(list(bytearray(
b'\x01' + # type of message - client_hello
b'\x00'*2 + b'\x30' + # length - 48 bytes
b'\x03\x01' + # protocol version (TLS 1.0)
b'\x00'*31 + b'\xff' + # client random
b'\x00' + # session ID length
b'\x00\x00' + # cipher suites length
b'\x01' + # compression methods length
b'\x00' + # supported method - NULL
b'\x00\x07' + # extensions length
b'\x00\x09' + # cert_type extension value (9)
b'\x00\x03' + # size of the extension
b'\x02' + # length of supported types
b'\x00' + # type - X.509
b'\x01' # type - OpenPGP
)), list(client_hello.write()))
示例6: test_alignClientHelloPadding_extension_list_initialization
# 需要导入模块: from tlslite.messages import ClientHello [as 别名]
# 或者: from tlslite.messages.ClientHello import write [as 别名]
def test_alignClientHelloPadding_extension_list_initialization(self):
clientHello = ClientHello()
clientHello.create((3,0), bytearray(32), bytearray(0), range(0, 129))
clientHelloLength = len(clientHello.write())
self.assertTrue(512 > clientHelloLength - 4 > 255)
HandshakeHelpers.alignClientHelloPadding(clientHello)
# verify that the extension list has been added to clientHello
self.assertTrue(type(clientHello.extensions) is list)
# clientHello length should equal to 512, ignoring handshake
# protocol header (4B)
data = clientHello.write()
self.assertEqual(512, len(data) - 4)
# padding extension should have been added after 2 extra bytes
# added due to an extension list
self.assertEqual(bytearray(b'\x00\x15'), data[clientHelloLength+2:clientHelloLength+4])
示例7: test_write
# 需要导入模块: from tlslite.messages import ClientHello [as 别名]
# 或者: from tlslite.messages.ClientHello import write [as 别名]
def test_write(self):
# client_hello = ClientHello(ssl2)
client_hello = ClientHello()
self.assertEqual(list(bytearray(
b'\x01' + # type of message - client_hello
b'\x00'*2 + b'\x26' + # length - 38 bytes
b'\x00'*2 + # protocol version
b'\x00'*32 + # client random
b'\x00' + # session ID length
b'\x00'*2 + # cipher suites length
b'\x00' # compression methods length
)), list(client_hello.write()))
示例8: test_write_with_npn
# 需要导入模块: from tlslite.messages import ClientHello [as 别名]
# 或者: from tlslite.messages.ClientHello import write [as 别名]
def test_write_with_npn(self):
client_hello = ClientHello().create((3,1),
bytearray(b'\x00'*31 + b'\xff'), bytearray(0),
[], supports_npn=True)
self.assertEqual(list(bytearray(
b'\x01' + # type of message - client_hello
b'\x00'*2 + b'\x2d' + # length - 45 bytes
b'\x03\x01' + # protocol version
b'\x00'*31 + b'\xff' + # client random
b'\x00' + # session ID length
b'\x00\x00' + # cipher suites length
b'\x01' + # compression methods length
b'\x00' + # supported method - NULL
b'\x00\x04' + # extensions length
b'\x33\x74' + # NPN extension value (13172)
b'\x00\x00' # size of the extension
)), list(client_hello.write()))
示例9: test_write_with_srp_username
# 需要导入模块: from tlslite.messages import ClientHello [as 别名]
# 或者: from tlslite.messages.ClientHello import write [as 别名]
def test_write_with_srp_username(self):
client_hello = ClientHello().create((3,1),
bytearray(b'\x00'*31 + b'\xff'), bytearray(0),
[], srpUsername="example-test")
self.assertEqual(list(bytearray(
b'\x01' + # type of message - client_hello
b'\x00'*2 + b'\x3a' + # length - 58 bytes
b'\x03\x01' + # protocol version (TLS 1.0)
b'\x00'*31 + b'\xff' + # client random
b'\x00' + # session ID length
b'\x00\x00' + # cipher suites length
b'\x01' + # compression methods length
b'\x00' + # supported method - NULL
b'\x00\x11' + # extensions length
b'\x00\x0c' + # srp extension value (12)
b'\x00\x0d' + # size of the extension
b'\x0c' + # length of name
# ascii encoding of "example-test":
b'\x65\x78\x61\x6d\x70\x6c\x65\x2d\x74\x65\x73\x74'
)), list(client_hello.write()))
示例10: test_write_with_server_name
# 需要导入模块: from tlslite.messages import ClientHello [as 别名]
# 或者: from tlslite.messages.ClientHello import write [as 别名]
def test_write_with_server_name(self):
client_hello = ClientHello().create((3,1),
bytearray(b'\x00'*31 + b'\xff'), bytearray(0),
[], serverName="example.com")
self.assertEqual(list(bytearray(
b'\x01' + # type of message - client_hello
b'\x00'*2 + b'\x3d' + # length - 61 bytes
b'\x03\x01' + # protocol version
b'\x00'*31 + b'\xff' + # client random
b'\x00' + # session ID length
b'\x00\x00' + # cipher suites length
b'\x01' + # compression methods length
b'\x00' + # supported method - NULL
b'\x00\x14' + # extensions length
b'\x00\x00' + # servername extension value (0)
b'\x00\x10' + # byte size of the extension
b'\x00\x0e' + # length of the list
b'\x00' + # name type: host_name (0)
b'\x00\x0b' + # length of host name
# utf-8 encoding of "example.com"
b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d'
)), list(client_hello.write()))
示例11: test
# 需要导入模块: from tlslite.messages import ClientHello [as 别名]
# 或者: from tlslite.messages.ClientHello import write [as 别名]
def test(self):
sock = MockSocket(server_hello_ciphertext)
record_layer = RecordLayer(sock)
ext = [SNIExtension().create(bytearray(b'server')),
TLSExtension(extType=ExtensionType.renegotiation_info)
.create(bytearray(b'\x00')),
SupportedGroupsExtension().create([GroupName.x25519,
GroupName.secp256r1,
GroupName.secp384r1,
GroupName.secp521r1,
GroupName.ffdhe2048,
GroupName.ffdhe3072,
GroupName.ffdhe4096,
GroupName.ffdhe6144,
GroupName.ffdhe8192]),
ECPointFormatsExtension().create([ECPointFormat.uncompressed]),
TLSExtension(extType=35),
ClientKeyShareExtension().create([KeyShareEntry().create(GroupName.x25519,
client_key_public,
client_key_private)]),
SupportedVersionsExtension().create([TLS_1_3_DRAFT,
(3, 3), (3, 2)]),
SignatureAlgorithmsExtension().create([(HashAlgorithm.sha256,
SignatureAlgorithm.ecdsa),
(HashAlgorithm.sha384,
SignatureAlgorithm.ecdsa),
(HashAlgorithm.sha512,
SignatureAlgorithm.ecdsa),
(HashAlgorithm.sha1,
SignatureAlgorithm.ecdsa),
SignatureScheme.rsa_pss_sha256,
SignatureScheme.rsa_pss_sha384,
SignatureScheme.rsa_pss_sha512,
SignatureScheme.rsa_pkcs1_sha256,
SignatureScheme.rsa_pkcs1_sha384,
SignatureScheme.rsa_pkcs1_sha512,
SignatureScheme.rsa_pkcs1_sha1,
(HashAlgorithm.sha256,
SignatureAlgorithm.dsa),
(HashAlgorithm.sha384,
SignatureAlgorithm.dsa),
(HashAlgorithm.sha512,
SignatureAlgorithm.dsa),
(HashAlgorithm.sha1,
SignatureAlgorithm.dsa)]),
TLSExtension(extType=45).create(bytearray(b'\x01\x01')),
TLSExtension(extType=ExtensionType.client_hello_padding)
.create(bytearray(252))
]
client_hello = ClientHello()
client_hello.create((3, 3),
bytearray(b'\xaf!\x15k\x04\xdbc\x9ef\x15J\x1f\xe5'
b'\xad\xfa\xea\xdf\x9eA4\x16\x00\rW\xb8'
b'\xe1\x12mM\x11\x9a\x8b'),
bytearray(b''),
[CipherSuite.TLS_AES_128_GCM_SHA256,
CipherSuite.TLS_CHACHA20_POLY1305_SHA256,
CipherSuite.TLS_AES_256_GCM_SHA384,
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
0xCCA9,
CipherSuite.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
0x0032,
CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,
CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA,
0x0038,
CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA256,
CipherSuite.TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA,
0x0013,
CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA,
CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA256,
CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA,
CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA256,
CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA,
CipherSuite.TLS_RSA_WITH_RC4_128_SHA,
CipherSuite.TLS_RSA_WITH_RC4_128_MD5],
extensions=ext)
self.assertEqual(client_hello.write(), client_hello_ciphertext[5:])
for result in record_layer.recvRecord():
# check if non-blocking
self.assertNotIn(result, (0, 1))
header, parser = result
hs_type = parser.get(1)
self.assertEqual(hs_type, HandshakeType.server_hello)
server_hello = ServerHello().parse(parser)
#.........这里部分代码省略.........