本文整理匯總了Python中tlslite.tlsrecordlayer.TLSRecordLayer._getMsg方法的典型用法代碼示例。如果您正苦於以下問題:Python TLSRecordLayer._getMsg方法的具體用法?Python TLSRecordLayer._getMsg怎麽用?Python TLSRecordLayer._getMsg使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tlslite.tlsrecordlayer.TLSRecordLayer
的用法示例。
在下文中一共展示了TLSRecordLayer._getMsg方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test__getMsg_with_oversized_message
# 需要導入模塊: from tlslite.tlsrecordlayer import TLSRecordLayer [as 別名]
# 或者: from tlslite.tlsrecordlayer.TLSRecordLayer import _getMsg [as 別名]
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)
示例2: test__getMsg
# 需要導入模塊: from tlslite.tlsrecordlayer import TLSRecordLayer [as 別名]
# 或者: from tlslite.tlsrecordlayer.TLSRecordLayer import _getMsg [as 別名]
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)
示例3: test__getMsg_with_oversized_message
# 需要導入模塊: from tlslite.tlsrecordlayer import TLSRecordLayer [as 別名]
# 或者: from tlslite.tlsrecordlayer.TLSRecordLayer import _getMsg [as 別名]
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)
示例4: test__getMsg
# 需要導入模塊: from tlslite.tlsrecordlayer import TLSRecordLayer [as 別名]
# 或者: from tlslite.tlsrecordlayer.TLSRecordLayer import _getMsg [as 別名]
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)
示例5: test_full_connection_with_external_server
# 需要導入模塊: from tlslite.tlsrecordlayer import TLSRecordLayer [as 別名]
# 或者: from tlslite.tlsrecordlayer.TLSRecordLayer import _getMsg [as 別名]
def test_full_connection_with_external_server(self):
# TODO test is slow (100ms) move to integration test suite
#
# start a regular TLS server locally before running this test
# e.g.: openssl s_server -key localhost.key -cert localhost.crt
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("127.0.0.1", 4433))
record_layer = TLSRecordLayer(sock)
record_layer._handshakeStart(client=True)
record_layer.version = (3, 3)
client_hello = ClientHello()
client_hello = client_hello.create(
(3, 3),
bytearray(32),
bytearray(0),
[CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA],
None,
None,
False,
False,
None,
)
for result in record_layer._sendMsg(client_hello):
if result in (0, 1):
raise Exception("blocking socket")
for result in record_layer._getMsg(ContentType.handshake, HandshakeType.server_hello):
if result in (0, 1):
raise Exception("blocking socket")
else:
break
server_hello = result
self.assertEqual(ServerHello, type(server_hello))
for result in record_layer._getMsg(ContentType.handshake, HandshakeType.certificate, CertificateType.x509):
if result in (0, 1):
raise Exception("blocking socket")
else:
break
server_certificate = result
self.assertEqual(Certificate, type(server_certificate))
for result in record_layer._getMsg(ContentType.handshake, HandshakeType.server_hello_done):
if result in (0, 1):
raise Exception("blocking socket")
else:
break
server_hello_done = result
self.assertEqual(ServerHelloDone, type(server_hello_done))
public_key = server_certificate.certChain.getEndEntityPublicKey()
premasterSecret = bytearray(48)
premasterSecret[0] = 3 # 'cause we negotiatied TLSv1.2
premasterSecret[1] = 3
encryptedPreMasterSecret = public_key.encrypt(premasterSecret)
client_key_exchange = ClientKeyExchange(CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA, (3, 3))
client_key_exchange.createRSA(encryptedPreMasterSecret)
for result in record_layer._sendMsg(client_key_exchange):
if result in (0, 1):
raise Exception("blocking socket")
else:
break
master_secret = calcMasterSecret(
(3, 3), CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA, premasterSecret, client_hello.random, server_hello.random
)
record_layer._calcPendingStates(
CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA, master_secret, client_hello.random, server_hello.random, None
)
for result in record_layer._sendMsg(ChangeCipherSpec()):
if result in (0, 1):
raise Exception("blocking socket")
else:
break
record_layer._changeWriteState()
handshake_hashes = record_layer._handshake_hash.digest("sha256")
verify_data = PRF_1_2(master_secret, b"client finished", handshake_hashes, 12)
finished = Finished((3, 3)).create(verify_data)
for result in record_layer._sendMsg(finished):
if result in (0, 1):
raise Exception("blocking socket")
else:
#.........這裏部分代碼省略.........
示例6: test_full_connection_with_RSA_kex
# 需要導入模塊: from tlslite.tlsrecordlayer import TLSRecordLayer [as 別名]
# 或者: from tlslite.tlsrecordlayer.TLSRecordLayer import _getMsg [as 別名]
def test_full_connection_with_RSA_kex(self):
clnt_sock, srv_sock = socket.socketpair()
#
# client part
#
record_layer = TLSRecordLayer(clnt_sock)
record_layer._handshakeStart(client=True)
record_layer.version = (3, 3)
client_hello = ClientHello()
client_hello = client_hello.create(
(3, 3),
bytearray(32),
bytearray(0),
[CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA],
None,
None,
False,
False,
None,
)
for result in record_layer._sendMsg(client_hello):
if result in (0, 1):
raise Exception("blocking socket")
#
# server part
#
srv_record_layer = TLSRecordLayer(srv_sock)
srv_raw_certificate = str(
"-----BEGIN CERTIFICATE-----\n"
"MIIB9jCCAV+gAwIBAgIJAMyn9DpsTG55MA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNV\n"
"BAMMCWxvY2FsaG9zdDAeFw0xNTAxMjExNDQzMDFaFw0xNTAyMjAxNDQzMDFaMBQx\n"
"EjAQBgNVBAMMCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA\n"
"0QkEeakSyV/LMtTeARdRtX5pdbzVuUuqOIdz3lg7YOyRJ/oyLTPzWXpKxr//t4FP\n"
"QvYsSJiVOlPk895FNu6sNF/uJQyQGfFWYKkE6fzFifQ6s9kssskFlL1DVI/dD/Zn\n"
"7sgzua2P1SyLJHQTTs1MtMb170/fX2EBPkDz+2kYKN0CAwEAAaNQME4wHQYDVR0O\n"
"BBYEFJtvXbRmxRFXYVMOPH/29pXCpGmLMB8GA1UdIwQYMBaAFJtvXbRmxRFXYVMO\n"
"PH/29pXCpGmLMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADgYEAkOgC7LP/\n"
"Rd6uJXY28HlD2K+/hMh1C3SRT855ggiCMiwstTHACGgNM+AZNqt6k8nSfXc6k1gw\n"
"5a7SGjzkWzMaZC3ChBeCzt/vIAGlMyXeqTRhjTCdc/ygRv3NPrhUKKsxUYyXRk5v\n"
"g/g6MwxzXfQP3IyFu3a9Jia/P89Z1rQCNRY=\n"
"-----END CERTIFICATE-----\n"
)
srv_raw_key = str(
"-----BEGIN RSA PRIVATE KEY-----\n"
"MIICXQIBAAKBgQDRCQR5qRLJX8sy1N4BF1G1fml1vNW5S6o4h3PeWDtg7JEn+jIt\n"
"M/NZekrGv/+3gU9C9ixImJU6U+Tz3kU27qw0X+4lDJAZ8VZgqQTp/MWJ9Dqz2Syy\n"
"yQWUvUNUj90P9mfuyDO5rY/VLIskdBNOzUy0xvXvT99fYQE+QPP7aRgo3QIDAQAB\n"
"AoGAVSLbE8HsyN+fHwDbuo4I1Wa7BRz33xQWLBfe9TvyUzOGm0WnkgmKn3LTacdh\n"
"GxgrdBZXSun6PVtV8I0im5DxyVaNdi33sp+PIkZU386f1VUqcnYnmgsnsUQEBJQu\n"
"fUZmgNM+bfR+Rfli4Mew8lQ0sorZ+d2/5fsM0g80Qhi5M3ECQQDvXeCyrcy0u/HZ\n"
"FNjIloyXaAIvavZ6Lc6gfznCSfHc5YwplOY7dIWp8FRRJcyXkA370l5dJ0EXj5Gx\n"
"udV9QQ43AkEA34+RxjRk4DT7Zo+tbM/Fkoi7jh1/0hFkU5NDHweJeH/mJseiHtsH\n"
"KOcPGtEGBBqT2KNPWVz4Fj19LiUmmjWXiwJBAIBs49O5/+ywMdAAqVblv0S0nweF\n"
"4fwne4cM+5ZMSiH0XsEojGY13EkTEon/N8fRmE8VzV85YmkbtFWgmPR85P0CQQCs\n"
"elWbN10EZZv3+q1wH7RsYzVgZX3yEhz3JcxJKkVzRCnKjYaUi6MweWN76vvbOq4K\n"
"G6Tiawm0Duh/K4ZmvyYVAkBppE5RRQqXiv1KF9bArcAJHvLm0vnHPpf1yIQr5bW6\n"
"njBuL4qcxlaKJVGRXT7yFtj2fj0gv3914jY2suWqp8XJ\n"
"-----END RSA PRIVATE KEY-----\n"
)
srv_private_key = parsePEMKey(srv_raw_key, private=True)
srv_cert_chain = X509CertChain([X509().parse(srv_raw_certificate)])
srv_record_layer._handshakeStart(client=False)
srv_record_layer.version = (3, 3)
for result in srv_record_layer._getMsg(ContentType.handshake, HandshakeType.client_hello):
if result in (0, 1):
raise Exception("blocking socket")
else:
break
srv_client_hello = result
self.assertEqual(ClientHello, type(srv_client_hello))
srv_cipher_suite = CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA
srv_session_id = bytearray(0)
srv_server_hello = ServerHello().create(
(3, 3), bytearray(32), srv_session_id, srv_cipher_suite, CertificateType.x509, None, None
)
srv_msgs = []
srv_msgs.append(srv_server_hello)
srv_msgs.append(Certificate(CertificateType.x509).create(srv_cert_chain))
srv_msgs.append(ServerHelloDone())
for result in srv_record_layer._sendMsgs(srv_msgs):
if result in (0, 1):
raise Exception("blocking socket")
else:
#.........這裏部分代碼省略.........