Example #1
0
 def test_ssl_no_handshake_on_connect(self):
     # Ensure that when create_connection(ssl=True) returns, that the SSL
     # handshake has completed.
     context = self.get_ssl_context()
     server = create_server(StreamProtocol, ('localhost', 0), ssl=context)
     addr = server.addresses[0]
     ssl_args = {'do_handshake_on_connect': False}
     ctrans, cproto = create_connection(StreamProtocol,
                                        addr,
                                        ssl=context,
                                        ssl_args=ssl_args)
     # The SSL handshake has not been established at this point.
     sslobj = ctrans.get_extra_info('ssl')
     self.assertIsNone(sslobj)
     # Now initiate the SSL handshake and allow it some time to complete
     ctrans.do_handshake()
     gruvi.sleep(0.1)
     # There should be a channel binding now.
     sslobj = ctrans.get_extra_info('ssl')
     self.assertIsNotNone(sslobj)
     sslcb = sslobj.get_channel_binding('tls-unique')
     self.assertGreater(len(sslcb), 0)
     strans, sproto = list(server.connections)[0]
     cproto.stream.write(b'foo\n')
     self.assertEqual(sproto.stream.readline(), b'foo\n')
     server.close()
     self.assertEqual(len(list(server.connections)), 0)
     self.assertEqual(cproto.stream.readline(), b'')
     ctrans.close()
Example #2
0
 def test_ssl_no_handshake_on_connect(self):
     # Ensure that when create_connection(ssl=True) returns, that the SSL
     # handshake has completed.
     context = self.get_ssl_context()
     server = create_server(StreamProtocol, ('localhost', 0), ssl=context)
     addr = server.addresses[0]
     ssl_args = {'do_handshake_on_connect': False}
     ctrans, cproto = create_connection(StreamProtocol, addr, ssl=context, ssl_args=ssl_args)
     # The SSL handshake has not been established at this point.
     sslobj = ctrans.get_extra_info('ssl')
     self.assertIsNone(sslobj)
     # Now initiate the SSL handshake and allow it some time to complete
     ctrans.do_handshake()
     gruvi.sleep(0.1)
     # There should be a channel binding now.
     sslobj = ctrans.get_extra_info('ssl')
     self.assertIsNotNone(sslobj)
     sslcb = sslobj.get_channel_binding('tls-unique')
     self.assertGreater(len(sslcb), 0)
     strans, sproto = list(server.connections)[0]
     cproto.stream.write(b'foo\n')
     self.assertEqual(sproto.stream.readline(), b'foo\n')
     server.close()
     self.assertEqual(len(list(server.connections)), 0)
     self.assertEqual(cproto.stream.readline(), b'')
     ctrans.close()
Example #3
0
 def test_pipe(self):
     # Ensure that create_connection() and create_server() can be used to
     # connect to each other over a pipe.
     addr = self.pipename()
     server = create_server(StreamProtocol, addr)
     ctrans, cproto = create_connection(StreamProtocol, addr)
     gruvi.sleep(0.1)  # allow Server to accept()
     strans, sproto = list(server.connections)[0]
     cproto.stream.write(b'foo\n')
     self.assertEqual(sproto.stream.readline(), b'foo\n')
     server.close()
     self.assertEqual(len(list(server.connections)), 0)
     self.assertEqual(cproto.stream.readline(), b'')
     ctrans.close()
Example #4
0
 def test_pipe(self):
     # Ensure that create_connection() and create_server() can be used to
     # connect to each other over a pipe.
     addr = self.pipename()
     server = create_server(StreamProtocol, addr)
     ctrans, cproto = create_connection(StreamProtocol, addr)
     gruvi.sleep(0.1)  # allow Server to accept()
     strans, sproto = list(server.connections)[0]
     cproto.stream.write(b'foo\n')
     self.assertEqual(sproto.stream.readline(), b'foo\n')
     server.close()
     self.assertEqual(len(list(server.connections)), 0)
     self.assertEqual(cproto.stream.readline(), b'')
     ctrans.close()
Example #5
0
 def test_pipe_ssl(self):
     # Ensure that create_connection() and create_server() can be used to
     # connect to each other over a pipe using SSL.
     addr = self.pipename()
     server = create_server(StreamProtocol, addr, **self.ssl_s_args)
     ctrans, cproto = create_connection(StreamProtocol, addr, **self.ssl_cp_args)
     # No need to sleep here because create_connection waits for the SSL
     # handshake to complete
     strans, sproto = list(server.connections)[0]
     cproto.stream.write(b'foo\n')
     self.assertEqual(sproto.stream.readline(), b'foo\n')
     server.close()
     self.assertEqual(len(list(server.connections)), 0)
     self.assertEqual(cproto.stream.readline(), b'')
     ctrans.close()
Example #6
0
 def test_tcp_ssl(self):
     # Ensure that create_connection() and create_server() can be used to
     # connect to each other over TCP using SSL.
     context = self.get_ssl_context()
     server = create_server(StreamProtocol, ('localhost', 0), ssl=context)
     addr = server.addresses[0]
     ctrans, cproto = create_connection(StreamProtocol, addr, ssl=context)
     # No need to sleep here because create_connection waits for the SSL
     # handshake to complete
     strans, sproto = list(server.connections)[0]
     cproto.stream.write(b'foo\n')
     self.assertEqual(sproto.stream.readline(), b'foo\n')
     server.close()
     self.assertEqual(len(list(server.connections)), 0)
     self.assertEqual(cproto.stream.readline(), b'')
     ctrans.close()
Example #7
0
 def test_pipe_ssl(self):
     # Ensure that create_connection() and create_server() can be used to
     # connect to each other over a pipe using SSL.
     context = self.get_ssl_context()
     addr = self.pipename()
     server = create_server(StreamProtocol, addr, ssl=context)
     ctrans, cproto = create_connection(StreamProtocol, addr, ssl=context)
     # No need to sleep here because create_connection waits for the SSL
     # handshake to complete
     strans, sproto = list(server.connections)[0]
     cproto.stream.write(b'foo\n')
     self.assertEqual(sproto.stream.readline(), b'foo\n')
     server.close()
     self.assertEqual(len(list(server.connections)), 0)
     self.assertEqual(cproto.stream.readline(), b'')
     ctrans.close()
Example #8
0
 def test_ssl_handshake_on_connect(self):
     # Ensure that when create_connection(ssl=True) returns, that the SSL
     # handshake has completed.
     server = create_server(StreamProtocol, ('localhost', 0), **self.ssl_s_args)
     addr = server.addresses[0]
     ctrans, cproto = create_connection(StreamProtocol, addr, **self.ssl_c_args)
     # The SSL handshake should be completed at this point. This means that
     # there should be a channel binding.
     sslobj = ctrans.get_extra_info('ssl')
     self.assertIsNotNone(sslobj)
     sslcb = sslobj.get_channel_binding('tls-unique')
     self.assertGreater(len(sslcb), 0)
     strans, sproto = list(server.connections)[0]
     cproto.stream.write(b'foo\n')
     self.assertEqual(sproto.stream.readline(), b'foo\n')
     server.close()
     self.assertEqual(len(list(server.connections)), 0)
     self.assertEqual(cproto.stream.readline(), b'')
     ctrans.close()
Example #9
0
 def test_ssl_handshake_on_connect(self):
     # Ensure that when create_connection(ssl=True) returns, that the SSL
     # handshake has completed.
     context = self.get_ssl_context()
     server = create_server(StreamProtocol, ('localhost', 0), ssl=context)
     addr = server.addresses[0]
     ctrans, cproto = create_connection(StreamProtocol, addr, ssl=context)
     # The SSL handshake should be completed at this point. This means that
     # there should be a channel binding.
     sslobj = ctrans.get_extra_info('ssl')
     self.assertIsNotNone(sslobj)
     sslcb = sslobj.get_channel_binding('tls-unique')
     self.assertGreater(len(sslcb), 0)
     strans, sproto = list(server.connections)[0]
     cproto.stream.write(b'foo\n')
     self.assertEqual(sproto.stream.readline(), b'foo\n')
     server.close()
     self.assertEqual(len(list(server.connections)), 0)
     self.assertEqual(cproto.stream.readline(), b'')
     ctrans.close()