本文整理匯總了Python中tlslite.tlsrecordlayer.TLSRecordLayer.version方法的典型用法代碼示例。如果您正苦於以下問題:Python TLSRecordLayer.version方法的具體用法?Python TLSRecordLayer.version怎麽用?Python TLSRecordLayer.version使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tlslite.tlsrecordlayer.TLSRecordLayer
的用法示例。
在下文中一共展示了TLSRecordLayer.version方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_write_with_BEAST_record_splitting
# 需要導入模塊: from tlslite.tlsrecordlayer import TLSRecordLayer [as 別名]
# 或者: from tlslite.tlsrecordlayer.TLSRecordLayer import version [as 別名]
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)
示例2: test__sendMsg
# 需要導入模塊: from tlslite.tlsrecordlayer import TLSRecordLayer [as 別名]
# 或者: from tlslite.tlsrecordlayer.TLSRecordLayer import version [as 別名]
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])
示例3: test__getNextRecord
# 需要導入模塊: from tlslite.tlsrecordlayer import TLSRecordLayer [as 別名]
# 或者: from tlslite.tlsrecordlayer.TLSRecordLayer import version [as 別名]
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)
示例4: test_write_with_BEAST_record_splitting_and_empty_write
# 需要導入模塊: from tlslite.tlsrecordlayer import TLSRecordLayer [as 別名]
# 或者: from tlslite.tlsrecordlayer.TLSRecordLayer import version [as 別名]
def test_write_with_BEAST_record_splitting_and_empty_write(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(0))
self.assertEqual(len(mock_sock.sent), 1)
msg1 = mock_sock.sent[0]
self.assertEqual(bytearray(
b'\x17' + # application data
b'\x03\x01' + # TLSv1.0
b'\x00\x20' # length 32 bytes = data(0) + MAC(20) + padding(12)
), msg1[:5])
self.assertEqual(len(msg1[5:]), 32)
示例5: test_full_connection_with_external_server
# 需要導入模塊: from tlslite.tlsrecordlayer import TLSRecordLayer [as 別名]
# 或者: from tlslite.tlsrecordlayer.TLSRecordLayer import version [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 version [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/uJ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qT2KNPWVz4Fj19LiUmmjWXiwJBAIBs49O5/+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:
#.........這裏部分代碼省略.........