def test_timeout_ssl(self): ssl_daemon = RawSSLDaemon(TimeoutTCPHandler) ssl_daemon.start() ssl_daemon.wait_for_start() port = ssl_daemon.get_port() url = URL('https://127.0.0.1:%s/' % port) self.uri_opener.settings.set_max_http_retries(0) self.uri_opener.settings.set_configured_timeout(1) self.uri_opener.clear_timeout() start = time.time() self.assertRaises(HTTPRequestException, self.uri_opener.GET, url) end = time.time() self.uri_opener.settings.set_default_values() # We set the upper limit to 4 because the uri opener needs to timeout # all the connections (one for each SSL protocol) and then, because of # some very relaxed handshake it needs to timeout a SSL protocol 3 # connection which passes handshake phase but then fails to send/get # the headers self.assertLess(end-start, 80)
def test_timeout_ssl(self): ssl_daemon = RawSSLDaemon(TimeoutTCPHandler) ssl_daemon.start() ssl_daemon.wait_for_start() port = ssl_daemon.get_port() url = URL('https://127.0.0.1:%s/' % port) self.uri_opener.settings.set_max_http_retries(0) self.uri_opener.settings.set_configured_timeout(1) self.uri_opener.clear_timeout() start = time.time() self.assertRaises(HTTPRequestException, self.uri_opener.GET, url) end = time.time() self.uri_opener.settings.set_default_values() # We set the upper limit to 4 because the uri opener needs to timeout # all the connections (one for each SSL protocol) and then, because of # some very relaxed handshake it needs to timeout a SSL protocol 3 # connection which passes handshake phase but then fails to send/get # the headers self.assertLess(end - start, 80)
def test_ssl_tls_1_0(self): ssl_daemon = RawSSLDaemon(Ok200Handler, ssl_version=ssl.PROTOCOL_TLSv1) ssl_daemon.start() ssl_daemon.wait_for_start() port = ssl_daemon.get_port() url = URL('https://127.0.0.1:%s/' % port) resp = self.uri_opener.GET(url) self.assertEqual(resp.get_body(), Ok200Handler.body)
def test_ssl_v3(self): ssl_daemon = RawSSLDaemon(Ok200Handler, ssl_version=ssl.PROTOCOL_SSLv3) ssl_daemon.start() ssl_daemon.wait_for_start() port = ssl_daemon.get_port() url = URL('https://127.0.0.1:%s/' % port) resp = self.uri_opener.GET(url) self.assertEqual(resp.get_body(), Ok200Handler.body)
def test_ssl_v3(self): # https://bugs.kali.org/view.php?id=2160 if not hasattr(ssl, 'PROTOCOL_SSLv3'): return ssl_daemon = RawSSLDaemon(Ok200Handler, ssl_version=ssl.PROTOCOL_SSLv3) ssl_daemon.start() ssl_daemon.wait_for_start() port = ssl_daemon.get_port() url = URL('https://127.0.0.1:%s/' % port) resp = self.uri_opener.GET(url) self.assertEqual(resp.get_body(), Ok200Handler.body)
class TestUpperDaemon(unittest.TestCase): """ This is a unittest for the UpperDaemon which lives in ssl_daemon.py @author: Andres Riancho <andres . riancho | gmail . com> """ def setUp(self): self.ssl_daemon = RawSSLDaemon() self.ssl_daemon.start() self.ssl_daemon.wait_for_start() def test_basic(self): sent = 'abc' sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = ssl.wrap_socket(sock) sock.connect(('127.0.0.1', self.ssl_daemon.get_port())) sock.sendall(sent) received = sock.recv(3) self.assertEqual(received, sent.upper())