MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_tls_unique_channel_binding

Method test_tls_unique_channel_binding

Lib/test/test_ssl.py:4002–4062  ·  view source on GitHub ↗

Test tls-unique channel binding.

(self)

Source from the content-addressed store, hash-verified

4000 @unittest.skipUnless("tls-unique" in ssl.CHANNEL_BINDING_TYPES,
4001 "'tls-unique' channel binding not available")
4002 def test_tls_unique_channel_binding(self):
4003 """Test tls-unique channel binding."""
4004 if support.verbose:
4005 sys.stdout.write("\n")
4006
4007 client_context, server_context, hostname = testing_context()
4008
4009 # tls-unique is not defined for TLSv1.3
4010 # https://datatracker.ietf.org/doc/html/rfc8446#appendix-C.5
4011 client_context.maximum_version = ssl.TLSVersion.TLSv1_2
4012
4013 server = ThreadedEchoServer(context=server_context,
4014 chatty=True,
4015 connectionchatty=False)
4016
4017 with server:
4018 with client_context.wrap_socket(
4019 socket.socket(),
4020 server_hostname=hostname) as s:
4021 s.connect((HOST, server.port))
4022 # get the data
4023 cb_data = s.get_channel_binding("tls-unique")
4024 if support.verbose:
4025 sys.stdout.write(
4026 " got channel binding data: {0!r}\n".format(cb_data))
4027
4028 # check if it is sane
4029 self.assertIsNotNone(cb_data)
4030 if s.version() == 'TLSv1.3':
4031 self.assertEqual(len(cb_data), 48)
4032 else:
4033 self.assertEqual(len(cb_data), 12) # True for TLSv1
4034
4035 # and compare with the peers version
4036 s.write(b"CB tls-unique\n")
4037 peer_data_repr = s.read().strip()
4038 self.assertEqual(peer_data_repr,
4039 repr(cb_data).encode("us-ascii"))
4040
4041 # now, again
4042 with client_context.wrap_socket(
4043 socket.socket(),
4044 server_hostname=hostname) as s:
4045 s.connect((HOST, server.port))
4046 new_cb_data = s.get_channel_binding("tls-unique")
4047 if support.verbose:
4048 sys.stdout.write(
4049 "got another channel binding data: {0!r}\n".format(
4050 new_cb_data)
4051 )
4052 # is it really unique
4053 self.assertNotEqual(cb_data, new_cb_data)
4054 self.assertIsNotNone(cb_data)
4055 if s.version() == 'TLSv1.3':
4056 self.assertEqual(len(cb_data), 48)
4057 else:
4058 self.assertEqual(len(cb_data), 12) # True for TLSv1
4059 s.write(b"CB tls-unique\n")

Callers

nothing calls this directly

Calls 15

testing_contextFunction · 0.85
ThreadedEchoServerClass · 0.85
lenFunction · 0.85
reprFunction · 0.85
wrap_socketMethod · 0.80
socketMethod · 0.80
assertIsNotNoneMethod · 0.80
assertNotEqualMethod · 0.80
writeMethod · 0.45
connectMethod · 0.45
get_channel_bindingMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected