Andrew Grieve | 9c2b31d | 2019-03-26 15:08:10 +0000 | [diff] [blame] | 1 | #!/usr/bin/env vpython |
rsimha@chromium.org | 99a6f17 | 2013-01-20 01:10:24 +0000 | [diff] [blame] | 2 | # Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | f3378c2 | 2008-08-24 00:55:55 +0000 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 5 | |
Matt Menke | 3a293bd | 2021-08-13 20:34:43 +0000 | [diff] [blame] | 6 | """This is a simple HTTP/TCP/PROXY/BASIC_AUTH_PROXY/WEBSOCKET server used for |
| 7 | testing Chrome. |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 8 | |
| 9 | It supports several test URLs, as specified by the handlers in TestPageHandler. |
cbentzel@chromium.org | 0787bc7 | 2010-11-11 20:31:31 +0000 | [diff] [blame] | 10 | By default, it listens on an ephemeral port and sends the port number back to |
| 11 | the originating process over a pipe. The originating process can specify an |
| 12 | explicit port if necessary. |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 13 | It can use https if you specify the flag --https=CERT where CERT is the path |
| 14 | to a pem file containing the certificate and private key that should be used. |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 15 | """ |
| 16 | |
| 17 | import base64 |
| 18 | import BaseHTTPServer |
toyoshim@chromium.org | aa1b6e7 | 2012-10-09 03:43:19 +0000 | [diff] [blame] | 19 | import logging |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 20 | import os |
akalin@chromium.org | 4e4f3c9 | 2010-11-27 04:04:52 +0000 | [diff] [blame] | 21 | import select |
agl@chromium.org | b3ec346 | 2012-03-19 20:32:47 +0000 | [diff] [blame] | 22 | import socket |
agl@chromium.org | 77a9ad9 | 2012-03-20 15:14:27 +0000 | [diff] [blame] | 23 | import SocketServer |
yhirano@chromium.org | 51f90d9 | 2014-03-24 04:49:23 +0000 | [diff] [blame] | 24 | import ssl |
agl@chromium.org | 77a9ad9 | 2012-03-20 15:14:27 +0000 | [diff] [blame] | 25 | import sys |
cbentzel@chromium.org | e30b32d | 2010-11-06 17:33:56 +0000 | [diff] [blame] | 26 | import urlparse |
phajdan.jr@chromium.org | bf74e2b | 2010-08-17 20:07:11 +0000 | [diff] [blame] | 27 | |
maruel@chromium.org | 5ddc64e | 2013-12-05 17:50:12 +0000 | [diff] [blame] | 28 | BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 29 | ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(BASE_DIR))) |
| 30 | |
davidben@chromium.org | 7d53b54 | 2014-04-10 17:56:44 +0000 | [diff] [blame] | 31 | # Insert at the beginning of the path, we want to use our copies of the library |
Robert Iannucci | 0e7ec95 | 2018-01-18 22:44:16 +0000 | [diff] [blame] | 32 | # unconditionally (since they contain modifications from anything that might be |
| 33 | # obtained from e.g. PyPi). |
Keita Suzuki | 83e26f9 | 2020-03-06 09:42:48 +0000 | [diff] [blame] | 34 | sys.path.insert(0, os.path.join(ROOT_DIR, 'third_party', 'pywebsocket3', 'src')) |
davidben@chromium.org | 7d53b54 | 2014-04-10 17:56:44 +0000 | [diff] [blame] | 35 | sys.path.insert(0, os.path.join(ROOT_DIR, 'third_party', 'tlslite')) |
| 36 | |
yhirano@chromium.org | 51f90d9 | 2014-03-24 04:49:23 +0000 | [diff] [blame] | 37 | import mod_pywebsocket.standalone |
pliard@chromium.org | 3f8873f | 2012-11-14 11:38:55 +0000 | [diff] [blame] | 38 | from mod_pywebsocket.standalone import WebSocketServer |
yhirano@chromium.org | 51f90d9 | 2014-03-24 04:49:23 +0000 | [diff] [blame] | 39 | # import manually |
| 40 | mod_pywebsocket.standalone.ssl = ssl |
davidben@chromium.org | 06fcf20 | 2010-09-22 18:15:23 +0000 | [diff] [blame] | 41 | |
davidben@chromium.org | 7d53b54 | 2014-04-10 17:56:44 +0000 | [diff] [blame] | 42 | import tlslite |
| 43 | import tlslite.api |
| 44 | |
davidben@chromium.org | 7d53b54 | 2014-04-10 17:56:44 +0000 | [diff] [blame] | 45 | import testserver_base |
| 46 | |
maruel@chromium.org | 756cf98 | 2009-03-05 12:46:38 +0000 | [diff] [blame] | 47 | SERVER_HTTP = 0 |
Matt Menke | 3a293bd | 2021-08-13 20:34:43 +0000 | [diff] [blame] | 48 | SERVER_BASIC_AUTH_PROXY = 1 |
| 49 | SERVER_WEBSOCKET = 2 |
| 50 | SERVER_PROXY = 3 |
toyoshim@chromium.org | aa1b6e7 | 2012-10-09 03:43:19 +0000 | [diff] [blame] | 51 | |
| 52 | # Default request queue size for WebSocketServer. |
| 53 | _DEFAULT_REQUEST_QUEUE_SIZE = 128 |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 54 | |
toyoshim@chromium.org | aa1b6e7 | 2012-10-09 03:43:19 +0000 | [diff] [blame] | 55 | class WebSocketOptions: |
| 56 | """Holds options for WebSocketServer.""" |
| 57 | |
| 58 | def __init__(self, host, port, data_dir): |
| 59 | self.request_queue_size = _DEFAULT_REQUEST_QUEUE_SIZE |
| 60 | self.server_host = host |
| 61 | self.port = port |
| 62 | self.websock_handlers = data_dir |
| 63 | self.scan_dir = None |
| 64 | self.allow_handlers_outside_root_dir = False |
| 65 | self.websock_handlers_map_file = None |
| 66 | self.cgi_directories = [] |
| 67 | self.is_executable_method = None |
toyoshim@chromium.org | aa1b6e7 | 2012-10-09 03:43:19 +0000 | [diff] [blame] | 68 | |
toyoshim@chromium.org | aa1b6e7 | 2012-10-09 03:43:19 +0000 | [diff] [blame] | 69 | self.use_tls = False |
| 70 | self.private_key = None |
| 71 | self.certificate = None |
toyoshim@chromium.org | d532cf3 | 2012-10-18 05:05:51 +0000 | [diff] [blame] | 72 | self.tls_client_auth = False |
toyoshim@chromium.org | aa1b6e7 | 2012-10-09 03:43:19 +0000 | [diff] [blame] | 73 | self.tls_client_ca = None |
| 74 | self.use_basic_auth = False |
Keita Suzuki | 83e26f9 | 2020-03-06 09:42:48 +0000 | [diff] [blame] | 75 | self.basic_auth_credential = 'Basic ' + base64.b64encode( |
| 76 | 'test:test').decode() |
toyoshim@chromium.org | aa1b6e7 | 2012-10-09 03:43:19 +0000 | [diff] [blame] | 77 | |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 78 | |
rsimha@chromium.org | 99a6f17 | 2013-01-20 01:10:24 +0000 | [diff] [blame] | 79 | class HTTPServer(testserver_base.ClientRestrictingServerMixIn, |
| 80 | testserver_base.BrokenPipeHandlerMixIn, |
| 81 | testserver_base.StoppableHTTPServer): |
agl@chromium.org | 77a9ad9 | 2012-03-20 15:14:27 +0000 | [diff] [blame] | 82 | """This is a specialization of StoppableHTTPServer that adds client |
erikwright@chromium.org | 847ef28 | 2012-02-22 16:41:10 +0000 | [diff] [blame] | 83 | verification.""" |
| 84 | |
| 85 | pass |
| 86 | |
Adam Rice | 34b2e31 | 2018-04-06 16:48:30 +0000 | [diff] [blame] | 87 | class ThreadingHTTPServer(SocketServer.ThreadingMixIn, |
| 88 | HTTPServer): |
| 89 | """This variant of HTTPServer creates a new thread for every connection. It |
| 90 | should only be used with handlers that are known to be threadsafe.""" |
| 91 | |
| 92 | pass |
| 93 | |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 94 | |
erikwright@chromium.org | 847ef28 | 2012-02-22 16:41:10 +0000 | [diff] [blame] | 95 | class HTTPSServer(tlslite.api.TLSSocketServerMixIn, |
rsimha@chromium.org | 99a6f17 | 2013-01-20 01:10:24 +0000 | [diff] [blame] | 96 | testserver_base.ClientRestrictingServerMixIn, |
| 97 | testserver_base.BrokenPipeHandlerMixIn, |
| 98 | testserver_base.StoppableHTTPServer): |
agl@chromium.org | 77a9ad9 | 2012-03-20 15:14:27 +0000 | [diff] [blame] | 99 | """This is a specialization of StoppableHTTPServer that add https support and |
erikwright@chromium.org | 847ef28 | 2012-02-22 16:41:10 +0000 | [diff] [blame] | 100 | client verification.""" |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 101 | |
agl@chromium.org | 77a9ad9 | 2012-03-20 15:14:27 +0000 | [diff] [blame] | 102 | def __init__(self, server_address, request_hander_class, pem_cert_and_key, |
davidben@chromium.org | c52e2e6 | 2014-05-20 21:51:44 +0000 | [diff] [blame] | 103 | ssl_client_auth, ssl_client_cas, ssl_client_cert_types, |
bnc | 5fb33bd | 2016-08-05 12:09:21 -0700 | [diff] [blame] | 104 | ssl_bulk_ciphers, ssl_key_exchanges, alpn_protocols, |
David Benjamin | 9aadbed | 2021-09-15 03:29:09 +0000 | [diff] [blame] | 105 | npn_protocols, tls_intolerant, tls_intolerance_type, |
| 106 | signed_cert_timestamps, fallback_scsv_enabled, ocsp_response, |
David Benjamin | f839f1c | 2018-10-16 06:01:29 +0000 | [diff] [blame] | 107 | alert_after_handshake, disable_channel_id, disable_ems, |
| 108 | simulate_tls13_downgrade, simulate_tls12_downgrade, |
| 109 | tls_max_version): |
davidben@chromium.org | 7d53b54 | 2014-04-10 17:56:44 +0000 | [diff] [blame] | 110 | self.cert_chain = tlslite.api.X509CertChain() |
| 111 | self.cert_chain.parsePemList(pem_cert_and_key) |
phajdan.jr@chromium.org | 9e6098d | 2013-06-24 19:00:38 +0000 | [diff] [blame] | 112 | # Force using only python implementation - otherwise behavior is different |
| 113 | # depending on whether m2crypto Python module is present (error is thrown |
| 114 | # when it is). m2crypto uses a C (based on OpenSSL) implementation under |
| 115 | # the hood. |
| 116 | self.private_key = tlslite.api.parsePEMKey(pem_cert_and_key, |
| 117 | private=True, |
| 118 | implementations=['python']) |
davidben@chromium.org | 31282a1 | 2010-08-07 01:10:02 +0000 | [diff] [blame] | 119 | self.ssl_client_auth = ssl_client_auth |
rsleevi@chromium.org | b2ecdab | 2010-08-21 04:02:44 +0000 | [diff] [blame] | 120 | self.ssl_client_cas = [] |
davidben@chromium.org | c52e2e6 | 2014-05-20 21:51:44 +0000 | [diff] [blame] | 121 | self.ssl_client_cert_types = [] |
bnc | 609ad4c | 2015-10-02 05:11:24 -0700 | [diff] [blame] | 122 | self.npn_protocols = npn_protocols |
ekasper@google.com | 24aa822 | 2013-11-28 13:43:26 +0000 | [diff] [blame] | 123 | self.signed_cert_timestamps = signed_cert_timestamps |
agl@chromium.org | d0e11ca | 2013-12-11 20:16:13 +0000 | [diff] [blame] | 124 | self.fallback_scsv_enabled = fallback_scsv_enabled |
ekasper@google.com | 3bce2cf | 2013-12-17 00:25:51 +0000 | [diff] [blame] | 125 | self.ocsp_response = ocsp_response |
agl@chromium.org | 143daa4 | 2012-04-26 18:45:34 +0000 | [diff] [blame] | 126 | |
davidben@chromium.org | c52e2e6 | 2014-05-20 21:51:44 +0000 | [diff] [blame] | 127 | if ssl_client_auth: |
| 128 | for ca_file in ssl_client_cas: |
| 129 | s = open(ca_file).read() |
| 130 | x509 = tlslite.api.X509() |
| 131 | x509.parse(s) |
| 132 | self.ssl_client_cas.append(x509.subject) |
| 133 | |
| 134 | for cert_type in ssl_client_cert_types: |
| 135 | self.ssl_client_cert_types.append({ |
| 136 | "rsa_sign": tlslite.api.ClientCertificateType.rsa_sign, |
davidben@chromium.org | c52e2e6 | 2014-05-20 21:51:44 +0000 | [diff] [blame] | 137 | "ecdsa_sign": tlslite.api.ClientCertificateType.ecdsa_sign, |
| 138 | }[cert_type]) |
| 139 | |
rsleevi@chromium.org | 2124c81 | 2010-10-28 11:57:36 +0000 | [diff] [blame] | 140 | self.ssl_handshake_settings = tlslite.api.HandshakeSettings() |
davidben | c16cde3 | 2015-01-21 18:21:30 -0800 | [diff] [blame] | 141 | # Enable SSLv3 for testing purposes. |
| 142 | self.ssl_handshake_settings.minVersion = (3, 0) |
rsleevi@chromium.org | 2124c81 | 2010-10-28 11:57:36 +0000 | [diff] [blame] | 143 | if ssl_bulk_ciphers is not None: |
| 144 | self.ssl_handshake_settings.cipherNames = ssl_bulk_ciphers |
davidben@chromium.org | 74aa8dd | 2014-04-11 07:20:26 +0000 | [diff] [blame] | 145 | if ssl_key_exchanges is not None: |
| 146 | self.ssl_handshake_settings.keyExchangeNames = ssl_key_exchanges |
davidben@chromium.org | bbf4f40 | 2014-06-27 01:16:55 +0000 | [diff] [blame] | 147 | if tls_intolerant != 0: |
| 148 | self.ssl_handshake_settings.tlsIntolerant = (3, tls_intolerant) |
| 149 | self.ssl_handshake_settings.tlsIntoleranceType = tls_intolerance_type |
davidben | 21cda34 | 2015-03-17 18:04:28 -0700 | [diff] [blame] | 150 | if alert_after_handshake: |
| 151 | self.ssl_handshake_settings.alertAfterHandshake = True |
nharper | 1e8bf4b | 2015-09-18 12:23:02 -0700 | [diff] [blame] | 152 | if disable_channel_id: |
| 153 | self.ssl_handshake_settings.enableChannelID = False |
| 154 | if disable_ems: |
| 155 | self.ssl_handshake_settings.enableExtendedMasterSecret = False |
David Benjamin | f839f1c | 2018-10-16 06:01:29 +0000 | [diff] [blame] | 156 | if simulate_tls13_downgrade: |
| 157 | self.ssl_handshake_settings.simulateTLS13Downgrade = True |
| 158 | if simulate_tls12_downgrade: |
| 159 | self.ssl_handshake_settings.simulateTLS12Downgrade = True |
| 160 | if tls_max_version != 0: |
| 161 | self.ssl_handshake_settings.maxVersion = (3, tls_max_version) |
bnc | 5fb33bd | 2016-08-05 12:09:21 -0700 | [diff] [blame] | 162 | self.ssl_handshake_settings.alpnProtos=alpn_protocols; |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 163 | |
David Benjamin | 9aadbed | 2021-09-15 03:29:09 +0000 | [diff] [blame] | 164 | self.session_cache = tlslite.api.SessionCache() |
rsimha@chromium.org | 99a6f17 | 2013-01-20 01:10:24 +0000 | [diff] [blame] | 165 | testserver_base.StoppableHTTPServer.__init__(self, |
| 166 | server_address, |
| 167 | request_hander_class) |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 168 | |
| 169 | def handshake(self, tlsConnection): |
| 170 | """Creates the SSL connection.""" |
toyoshim@chromium.org | 9d7219e | 2012-10-25 03:30:10 +0000 | [diff] [blame] | 171 | |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 172 | try: |
agl@chromium.org | 04700be | 2013-03-02 18:40:41 +0000 | [diff] [blame] | 173 | self.tlsConnection = tlsConnection |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 174 | tlsConnection.handshakeServer(certChain=self.cert_chain, |
| 175 | privateKey=self.private_key, |
davidben@chromium.org | 31282a1 | 2010-08-07 01:10:02 +0000 | [diff] [blame] | 176 | sessionCache=self.session_cache, |
rsleevi@chromium.org | b2ecdab | 2010-08-21 04:02:44 +0000 | [diff] [blame] | 177 | reqCert=self.ssl_client_auth, |
rsleevi@chromium.org | 2124c81 | 2010-10-28 11:57:36 +0000 | [diff] [blame] | 178 | settings=self.ssl_handshake_settings, |
agl@chromium.org | 143daa4 | 2012-04-26 18:45:34 +0000 | [diff] [blame] | 179 | reqCAs=self.ssl_client_cas, |
davidben@chromium.org | c52e2e6 | 2014-05-20 21:51:44 +0000 | [diff] [blame] | 180 | reqCertTypes=self.ssl_client_cert_types, |
bnc | 609ad4c | 2015-10-02 05:11:24 -0700 | [diff] [blame] | 181 | nextProtos=self.npn_protocols, |
ekasper@google.com | 24aa822 | 2013-11-28 13:43:26 +0000 | [diff] [blame] | 182 | signedCertTimestamps= |
agl@chromium.org | d0e11ca | 2013-12-11 20:16:13 +0000 | [diff] [blame] | 183 | self.signed_cert_timestamps, |
ekasper@google.com | 3bce2cf | 2013-12-17 00:25:51 +0000 | [diff] [blame] | 184 | fallbackSCSV=self.fallback_scsv_enabled, |
| 185 | ocspResponse = self.ocsp_response) |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 186 | tlsConnection.ignoreAbruptClose = True |
| 187 | return True |
phajdan.jr@chromium.org | bf74e2b | 2010-08-17 20:07:11 +0000 | [diff] [blame] | 188 | except tlslite.api.TLSAbruptCloseError: |
| 189 | # Ignore abrupt close. |
| 190 | return True |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 191 | except tlslite.api.TLSError, error: |
wjia@chromium.org | ff532f3 | 2013-03-18 19:23:44 +0000 | [diff] [blame] | 192 | print "Handshake failure:", str(error) |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 193 | return False |
| 194 | |
akalin@chromium.org | 154bb13 | 2010-11-12 02:20:27 +0000 | [diff] [blame] | 195 | |
rsimha@chromium.org | 99a6f17 | 2013-01-20 01:10:24 +0000 | [diff] [blame] | 196 | class TestPageHandler(testserver_base.BasePageHandler): |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 197 | def __init__(self, request, client_address, socket_server): |
David Benjamin | 1f5bdcf | 2021-09-15 14:46:41 +0000 | [diff] [blame] | 198 | connect_handlers = [self.DefaultConnectResponseHandler] |
| 199 | get_handlers = [self.DefaultResponseHandler] |
| 200 | post_handlers = get_handlers |
| 201 | put_handlers = get_handlers |
| 202 | head_handlers = [self.DefaultResponseHandler] |
rsimha@chromium.org | 99a6f17 | 2013-01-20 01:10:24 +0000 | [diff] [blame] | 203 | testserver_base.BasePageHandler.__init__(self, request, client_address, |
| 204 | socket_server, connect_handlers, |
| 205 | get_handlers, head_handlers, |
| 206 | post_handlers, put_handlers) |
nsylvain@chromium.org | 8d5763b | 2008-12-30 23:44:27 +0000 | [diff] [blame] | 207 | |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 208 | def DefaultResponseHandler(self): |
| 209 | """This is the catch-all response handler for requests that aren't handled |
| 210 | by one of the special handlers above. |
| 211 | Note that we specify the content-length as without it the https connection |
| 212 | is not closed properly (and the browser keeps expecting data).""" |
| 213 | |
| 214 | contents = "Default response given for path: " + self.path |
| 215 | self.send_response(200) |
mmenke@chromium.org | bfff75b | 2011-11-01 02:32:05 +0000 | [diff] [blame] | 216 | self.send_header('Content-Type', 'text/html') |
| 217 | self.send_header('Content-Length', len(contents)) |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 218 | self.end_headers() |
mmenke@chromium.org | bfff75b | 2011-11-01 02:32:05 +0000 | [diff] [blame] | 219 | if (self.command != 'HEAD'): |
| 220 | self.wfile.write(contents) |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 221 | return True |
| 222 | |
wtc@chromium.org | 743d77b | 2009-02-11 02:48:15 +0000 | [diff] [blame] | 223 | def DefaultConnectResponseHandler(self): |
| 224 | """This is the catch-all response handler for CONNECT requests that aren't |
| 225 | handled by one of the special handlers above. Real Web servers respond |
| 226 | with 400 to CONNECT requests.""" |
| 227 | |
| 228 | contents = "Your client has issued a malformed or illegal request." |
| 229 | self.send_response(400) # bad request |
mmenke@chromium.org | bfff75b | 2011-11-01 02:32:05 +0000 | [diff] [blame] | 230 | self.send_header('Content-Type', 'text/html') |
| 231 | self.send_header('Content-Length', len(contents)) |
wtc@chromium.org | 743d77b | 2009-02-11 02:48:15 +0000 | [diff] [blame] | 232 | self.end_headers() |
| 233 | self.wfile.write(contents) |
| 234 | return True |
| 235 | |
akalin@chromium.org | 154bb13 | 2010-11-12 02:20:27 +0000 | [diff] [blame] | 236 | |
Adam Rice | 9476b8c | 2018-08-02 15:28:43 +0000 | [diff] [blame] | 237 | class ProxyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
| 238 | """A request handler that behaves as a proxy server. Only CONNECT, GET and |
| 239 | HEAD methods are supported. |
bashi@chromium.org | 3323353 | 2012-09-08 17:37:24 +0000 | [diff] [blame] | 240 | """ |
| 241 | |
Pavol Marko | 8ccaaed | 2018-01-04 18:40:04 +0100 | [diff] [blame] | 242 | redirect_connect_to_localhost = False; |
bashi@chromium.org | 3323353 | 2012-09-08 17:37:24 +0000 | [diff] [blame] | 243 | |
bashi@chromium.org | 3323353 | 2012-09-08 17:37:24 +0000 | [diff] [blame] | 244 | def _start_read_write(self, sock): |
| 245 | sock.setblocking(0) |
| 246 | self.request.setblocking(0) |
| 247 | rlist = [self.request, sock] |
| 248 | while True: |
toyoshim@chromium.org | 9d7219e | 2012-10-25 03:30:10 +0000 | [diff] [blame] | 249 | ready_sockets, _unused, errors = select.select(rlist, [], []) |
bashi@chromium.org | 3323353 | 2012-09-08 17:37:24 +0000 | [diff] [blame] | 250 | if errors: |
| 251 | self.send_response(500) |
| 252 | self.end_headers() |
| 253 | return |
| 254 | for s in ready_sockets: |
| 255 | received = s.recv(1024) |
| 256 | if len(received) == 0: |
| 257 | return |
| 258 | if s == self.request: |
| 259 | other = sock |
| 260 | else: |
| 261 | other = self.request |
Adam Rice | 54443aa | 2018-06-06 00:11:54 +0000 | [diff] [blame] | 262 | # This will lose data if the kernel write buffer fills up. |
| 263 | # TODO(ricea): Correctly use the return value to track how much was |
| 264 | # written and buffer the rest. Use select to determine when the socket |
| 265 | # becomes writable again. |
bashi@chromium.org | 3323353 | 2012-09-08 17:37:24 +0000 | [diff] [blame] | 266 | other.send(received) |
| 267 | |
| 268 | def _do_common_method(self): |
| 269 | url = urlparse.urlparse(self.path) |
| 270 | port = url.port |
| 271 | if not port: |
| 272 | if url.scheme == 'http': |
| 273 | port = 80 |
| 274 | elif url.scheme == 'https': |
| 275 | port = 443 |
| 276 | if not url.hostname or not port: |
| 277 | self.send_response(400) |
| 278 | self.end_headers() |
| 279 | return |
| 280 | |
| 281 | if len(url.path) == 0: |
| 282 | path = '/' |
| 283 | else: |
| 284 | path = url.path |
| 285 | if len(url.query) > 0: |
| 286 | path = '%s?%s' % (url.path, url.query) |
| 287 | |
| 288 | sock = None |
| 289 | try: |
| 290 | sock = socket.create_connection((url.hostname, port)) |
| 291 | sock.send('%s %s %s\r\n' % ( |
| 292 | self.command, path, self.protocol_version)) |
| 293 | for header in self.headers.headers: |
| 294 | header = header.strip() |
| 295 | if (header.lower().startswith('connection') or |
| 296 | header.lower().startswith('proxy')): |
| 297 | continue |
| 298 | sock.send('%s\r\n' % header) |
| 299 | sock.send('\r\n') |
Adam Rice | 54443aa | 2018-06-06 00:11:54 +0000 | [diff] [blame] | 300 | # This is wrong: it will pass through connection-level headers and |
| 301 | # misbehave on connection reuse. The only reason it works at all is that |
| 302 | # our test servers have never supported connection reuse. |
| 303 | # TODO(ricea): Use a proper HTTP client library instead. |
bashi@chromium.org | 3323353 | 2012-09-08 17:37:24 +0000 | [diff] [blame] | 304 | self._start_read_write(sock) |
toyoshim@chromium.org | 9d7219e | 2012-10-25 03:30:10 +0000 | [diff] [blame] | 305 | except Exception: |
Adam Rice | 54443aa | 2018-06-06 00:11:54 +0000 | [diff] [blame] | 306 | logging.exception('failure in common method: %s %s', self.command, path) |
bashi@chromium.org | 3323353 | 2012-09-08 17:37:24 +0000 | [diff] [blame] | 307 | self.send_response(500) |
| 308 | self.end_headers() |
| 309 | finally: |
| 310 | if sock is not None: |
| 311 | sock.close() |
| 312 | |
| 313 | def do_CONNECT(self): |
| 314 | try: |
| 315 | pos = self.path.rfind(':') |
| 316 | host = self.path[:pos] |
| 317 | port = int(self.path[pos+1:]) |
toyoshim@chromium.org | 9d7219e | 2012-10-25 03:30:10 +0000 | [diff] [blame] | 318 | except Exception: |
bashi@chromium.org | 3323353 | 2012-09-08 17:37:24 +0000 | [diff] [blame] | 319 | self.send_response(400) |
| 320 | self.end_headers() |
| 321 | |
Adam Rice | 9476b8c | 2018-08-02 15:28:43 +0000 | [diff] [blame] | 322 | if ProxyRequestHandler.redirect_connect_to_localhost: |
Pavol Marko | 8ccaaed | 2018-01-04 18:40:04 +0100 | [diff] [blame] | 323 | host = "127.0.0.1" |
| 324 | |
Adam Rice | 54443aa | 2018-06-06 00:11:54 +0000 | [diff] [blame] | 325 | sock = None |
bashi@chromium.org | 3323353 | 2012-09-08 17:37:24 +0000 | [diff] [blame] | 326 | try: |
| 327 | sock = socket.create_connection((host, port)) |
| 328 | self.send_response(200, 'Connection established') |
| 329 | self.end_headers() |
| 330 | self._start_read_write(sock) |
toyoshim@chromium.org | 9d7219e | 2012-10-25 03:30:10 +0000 | [diff] [blame] | 331 | except Exception: |
Adam Rice | 54443aa | 2018-06-06 00:11:54 +0000 | [diff] [blame] | 332 | logging.exception('failure in CONNECT: %s', path) |
bashi@chromium.org | 3323353 | 2012-09-08 17:37:24 +0000 | [diff] [blame] | 333 | self.send_response(500) |
| 334 | self.end_headers() |
| 335 | finally: |
Adam Rice | 54443aa | 2018-06-06 00:11:54 +0000 | [diff] [blame] | 336 | if sock is not None: |
| 337 | sock.close() |
bashi@chromium.org | 3323353 | 2012-09-08 17:37:24 +0000 | [diff] [blame] | 338 | |
| 339 | def do_GET(self): |
| 340 | self._do_common_method() |
| 341 | |
| 342 | def do_HEAD(self): |
| 343 | self._do_common_method() |
| 344 | |
Adam Rice | 9476b8c | 2018-08-02 15:28:43 +0000 | [diff] [blame] | 345 | class BasicAuthProxyRequestHandler(ProxyRequestHandler): |
| 346 | """A request handler that behaves as a proxy server which requires |
| 347 | basic authentication. |
| 348 | """ |
| 349 | |
| 350 | _AUTH_CREDENTIAL = 'Basic Zm9vOmJhcg==' # foo:bar |
| 351 | |
| 352 | def parse_request(self): |
| 353 | """Overrides parse_request to check credential.""" |
| 354 | |
| 355 | if not ProxyRequestHandler.parse_request(self): |
| 356 | return False |
| 357 | |
| 358 | auth = self.headers.getheader('Proxy-Authorization') |
| 359 | if auth != self._AUTH_CREDENTIAL: |
| 360 | self.send_response(407) |
| 361 | self.send_header('Proxy-Authenticate', 'Basic realm="MyRealm1"') |
| 362 | self.end_headers() |
| 363 | return False |
| 364 | |
| 365 | return True |
| 366 | |
bashi@chromium.org | 3323353 | 2012-09-08 17:37:24 +0000 | [diff] [blame] | 367 | |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 368 | class ServerRunner(testserver_base.TestServerRunner): |
| 369 | """TestServerRunner for the net test servers.""" |
phajdan.jr@chromium.org | bf74e2b | 2010-08-17 20:07:11 +0000 | [diff] [blame] | 370 | |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 371 | def __init__(self): |
| 372 | super(ServerRunner, self).__init__() |
phajdan.jr@chromium.org | bf74e2b | 2010-08-17 20:07:11 +0000 | [diff] [blame] | 373 | |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 374 | def __make_data_dir(self): |
| 375 | if self.options.data_dir: |
| 376 | if not os.path.isdir(self.options.data_dir): |
| 377 | raise testserver_base.OptionError('specified data dir not found: ' + |
| 378 | self.options.data_dir + ' exiting...') |
| 379 | my_data_dir = self.options.data_dir |
| 380 | else: |
| 381 | # Create the default path to our data dir, relative to the exe dir. |
Asanka Herath | 0ec3715 | 2019-08-02 15:23:57 +0000 | [diff] [blame] | 382 | my_data_dir = os.path.join(BASE_DIR, "..", "..", "data") |
phajdan.jr@chromium.org | bf74e2b | 2010-08-17 20:07:11 +0000 | [diff] [blame] | 383 | |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 384 | return my_data_dir |
newt@chromium.org | 1fc3274 | 2012-10-20 00:28:35 +0000 | [diff] [blame] | 385 | |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 386 | def create_server(self, server_data): |
| 387 | port = self.options.port |
| 388 | host = self.options.host |
newt@chromium.org | 1fc3274 | 2012-10-20 00:28:35 +0000 | [diff] [blame] | 389 | |
Adam Rice | 54443aa | 2018-06-06 00:11:54 +0000 | [diff] [blame] | 390 | logging.basicConfig() |
| 391 | |
estark | 21667d6 | 2015-04-08 21:00:16 -0700 | [diff] [blame] | 392 | # Work around a bug in Mac OS 10.6. Spawning a WebSockets server |
| 393 | # will result in a call to |getaddrinfo|, which fails with "nodename |
| 394 | # nor servname provided" for localhost:0 on 10.6. |
Adam Rice | 54443aa | 2018-06-06 00:11:54 +0000 | [diff] [blame] | 395 | # TODO(ricea): Remove this if no longer needed. |
estark | 21667d6 | 2015-04-08 21:00:16 -0700 | [diff] [blame] | 396 | if self.options.server_type == SERVER_WEBSOCKET and \ |
| 397 | host == "localhost" and \ |
| 398 | port == 0: |
| 399 | host = "127.0.0.1" |
| 400 | |
Ryan Sleevi | 3bfd15d | 2018-01-23 21:12:24 +0000 | [diff] [blame] | 401 | # Construct the subjectAltNames for any ad-hoc generated certificates. |
| 402 | # As host can be either a DNS name or IP address, attempt to determine |
| 403 | # which it is, so it can be placed in the appropriate SAN. |
| 404 | dns_sans = None |
| 405 | ip_sans = None |
| 406 | ip = None |
| 407 | try: |
| 408 | ip = socket.inet_aton(host) |
| 409 | ip_sans = [ip] |
| 410 | except socket.error: |
| 411 | pass |
| 412 | if ip is None: |
| 413 | dns_sans = [host] |
| 414 | |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 415 | if self.options.server_type == SERVER_HTTP: |
| 416 | if self.options.https: |
David Benjamin | 8ed48d1 | 2021-09-14 21:28:30 +0000 | [diff] [blame] | 417 | if not self.options.cert_and_key_file: |
| 418 | raise testserver_base.OptionError('server cert file not specified') |
| 419 | if not os.path.isfile(self.options.cert_and_key_file): |
| 420 | raise testserver_base.OptionError( |
| 421 | 'specified server cert file not found: ' + |
| 422 | self.options.cert_and_key_file + ' exiting...') |
| 423 | pem_cert_and_key = file(self.options.cert_and_key_file, 'r').read() |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 424 | |
| 425 | for ca_cert in self.options.ssl_client_ca: |
| 426 | if not os.path.isfile(ca_cert): |
| 427 | raise testserver_base.OptionError( |
| 428 | 'specified trusted client CA file not found: ' + ca_cert + |
| 429 | ' exiting...') |
ekasper@google.com | 3bce2cf | 2013-12-17 00:25:51 +0000 | [diff] [blame] | 430 | |
| 431 | stapled_ocsp_response = None |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 432 | server = HTTPSServer((host, port), TestPageHandler, pem_cert_and_key, |
| 433 | self.options.ssl_client_auth, |
| 434 | self.options.ssl_client_ca, |
davidben@chromium.org | c52e2e6 | 2014-05-20 21:51:44 +0000 | [diff] [blame] | 435 | self.options.ssl_client_cert_type, |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 436 | self.options.ssl_bulk_cipher, |
davidben@chromium.org | 74aa8dd | 2014-04-11 07:20:26 +0000 | [diff] [blame] | 437 | self.options.ssl_key_exchange, |
bnc | 5fb33bd | 2016-08-05 12:09:21 -0700 | [diff] [blame] | 438 | self.options.alpn_protocols, |
bnc | 609ad4c | 2015-10-02 05:11:24 -0700 | [diff] [blame] | 439 | self.options.npn_protocols, |
ekasper@google.com | 24aa822 | 2013-11-28 13:43:26 +0000 | [diff] [blame] | 440 | self.options.tls_intolerant, |
davidben@chromium.org | bbf4f40 | 2014-06-27 01:16:55 +0000 | [diff] [blame] | 441 | self.options.tls_intolerance_type, |
ekasper@google.com | 3bce2cf | 2013-12-17 00:25:51 +0000 | [diff] [blame] | 442 | self.options.signed_cert_timestamps_tls_ext.decode( |
agl@chromium.org | d0e11ca | 2013-12-11 20:16:13 +0000 | [diff] [blame] | 443 | "base64"), |
ekasper@google.com | 3bce2cf | 2013-12-17 00:25:51 +0000 | [diff] [blame] | 444 | self.options.fallback_scsv, |
davidben | 21cda34 | 2015-03-17 18:04:28 -0700 | [diff] [blame] | 445 | stapled_ocsp_response, |
nharper | 1e8bf4b | 2015-09-18 12:23:02 -0700 | [diff] [blame] | 446 | self.options.alert_after_handshake, |
| 447 | self.options.disable_channel_id, |
David Benjamin | f839f1c | 2018-10-16 06:01:29 +0000 | [diff] [blame] | 448 | self.options.disable_extended_master_secret, |
| 449 | self.options.simulate_tls13_downgrade, |
| 450 | self.options.simulate_tls12_downgrade, |
| 451 | self.options.tls_max_version) |
davidben@chromium.org | 009843a | 2014-06-03 00:13:08 +0000 | [diff] [blame] | 452 | print 'HTTPS server started on https://%s:%d...' % \ |
| 453 | (host, server.server_port) |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 454 | else: |
| 455 | server = HTTPServer((host, port), TestPageHandler) |
davidben@chromium.org | 009843a | 2014-06-03 00:13:08 +0000 | [diff] [blame] | 456 | print 'HTTP server started on http://%s:%d...' % \ |
| 457 | (host, server.server_port) |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 458 | |
| 459 | server.data_dir = self.__make_data_dir() |
| 460 | server.file_root_url = self.options.file_root_url |
| 461 | server_data['port'] = server.server_port |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 462 | elif self.options.server_type == SERVER_WEBSOCKET: |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 463 | # TODO(toyoshim): Remove following os.chdir. Currently this operation |
| 464 | # is required to work correctly. It should be fixed from pywebsocket side. |
| 465 | os.chdir(self.__make_data_dir()) |
| 466 | websocket_options = WebSocketOptions(host, port, '.') |
davidben@chromium.org | 009843a | 2014-06-03 00:13:08 +0000 | [diff] [blame] | 467 | scheme = "ws" |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 468 | if self.options.cert_and_key_file: |
davidben@chromium.org | 009843a | 2014-06-03 00:13:08 +0000 | [diff] [blame] | 469 | scheme = "wss" |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 470 | websocket_options.use_tls = True |
Sergey Ulanov | dd8b8ea | 2017-09-08 22:53:25 +0000 | [diff] [blame] | 471 | key_path = os.path.join(ROOT_DIR, self.options.cert_and_key_file) |
| 472 | if not os.path.isfile(key_path): |
| 473 | raise testserver_base.OptionError( |
| 474 | 'specified server cert file not found: ' + |
| 475 | self.options.cert_and_key_file + ' exiting...') |
| 476 | websocket_options.private_key = key_path |
| 477 | websocket_options.certificate = key_path |
| 478 | |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 479 | if self.options.ssl_client_auth: |
pneubeck@chromium.org | f500711 | 2014-07-21 15:22:41 +0000 | [diff] [blame] | 480 | websocket_options.tls_client_cert_optional = False |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 481 | websocket_options.tls_client_auth = True |
| 482 | if len(self.options.ssl_client_ca) != 1: |
| 483 | raise testserver_base.OptionError( |
| 484 | 'one trusted client CA file should be specified') |
| 485 | if not os.path.isfile(self.options.ssl_client_ca[0]): |
| 486 | raise testserver_base.OptionError( |
| 487 | 'specified trusted client CA file not found: ' + |
| 488 | self.options.ssl_client_ca[0] + ' exiting...') |
| 489 | websocket_options.tls_client_ca = self.options.ssl_client_ca[0] |
estark | 21667d6 | 2015-04-08 21:00:16 -0700 | [diff] [blame] | 490 | print 'Trying to start websocket server on %s://%s:%d...' % \ |
| 491 | (scheme, websocket_options.server_host, websocket_options.port) |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 492 | server = WebSocketServer(websocket_options) |
davidben@chromium.org | 009843a | 2014-06-03 00:13:08 +0000 | [diff] [blame] | 493 | print 'WebSocket server started on %s://%s:%d...' % \ |
| 494 | (scheme, host, server.server_port) |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 495 | server_data['port'] = server.server_port |
ricea@chromium.org | a52ebdc | 2014-07-29 07:42:29 +0000 | [diff] [blame] | 496 | websocket_options.use_basic_auth = self.options.ws_basic_auth |
Adam Rice | 9476b8c | 2018-08-02 15:28:43 +0000 | [diff] [blame] | 497 | elif self.options.server_type == SERVER_PROXY: |
| 498 | ProxyRequestHandler.redirect_connect_to_localhost = \ |
| 499 | self.options.redirect_connect_to_localhost |
| 500 | server = ThreadingHTTPServer((host, port), ProxyRequestHandler) |
| 501 | print 'Proxy server started on port %d...' % server.server_port |
| 502 | server_data['port'] = server.server_port |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 503 | elif self.options.server_type == SERVER_BASIC_AUTH_PROXY: |
Adam Rice | 9476b8c | 2018-08-02 15:28:43 +0000 | [diff] [blame] | 504 | ProxyRequestHandler.redirect_connect_to_localhost = \ |
Pavol Marko | 8ccaaed | 2018-01-04 18:40:04 +0100 | [diff] [blame] | 505 | self.options.redirect_connect_to_localhost |
Adam Rice | 34b2e31 | 2018-04-06 16:48:30 +0000 | [diff] [blame] | 506 | server = ThreadingHTTPServer((host, port), BasicAuthProxyRequestHandler) |
wjia@chromium.org | ff532f3 | 2013-03-18 19:23:44 +0000 | [diff] [blame] | 507 | print 'BasicAuthProxy server started on port %d...' % server.server_port |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 508 | server_data['port'] = server.server_port |
erikkay@google.com | d5182ff | 2009-01-08 20:45:27 +0000 | [diff] [blame] | 509 | else: |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 510 | raise testserver_base.OptionError('unknown server type' + |
| 511 | self.options.server_type) |
erikkay@google.com | 70397b6 | 2008-12-30 21:49:21 +0000 | [diff] [blame] | 512 | |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 513 | return server |
erikkay@google.com | d5182ff | 2009-01-08 20:45:27 +0000 | [diff] [blame] | 514 | |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 515 | def add_options(self): |
| 516 | testserver_base.TestServerRunner.add_options(self) |
Adam Rice | 9476b8c | 2018-08-02 15:28:43 +0000 | [diff] [blame] | 517 | self.option_parser.add_option('--proxy', action='store_const', |
| 518 | const=SERVER_PROXY, |
| 519 | default=SERVER_HTTP, dest='server_type', |
| 520 | help='start up a proxy server.') |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 521 | self.option_parser.add_option('--basic-auth-proxy', action='store_const', |
| 522 | const=SERVER_BASIC_AUTH_PROXY, |
| 523 | default=SERVER_HTTP, dest='server_type', |
| 524 | help='start up a proxy server which requires ' |
| 525 | 'basic authentication.') |
| 526 | self.option_parser.add_option('--websocket', action='store_const', |
| 527 | const=SERVER_WEBSOCKET, default=SERVER_HTTP, |
| 528 | dest='server_type', |
| 529 | help='start up a WebSocket server.') |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 530 | self.option_parser.add_option('--https', action='store_true', |
| 531 | dest='https', help='Specify that https ' |
| 532 | 'should be used.') |
| 533 | self.option_parser.add_option('--cert-and-key-file', |
| 534 | dest='cert_and_key_file', help='specify the ' |
| 535 | 'path to the file containing the certificate ' |
| 536 | 'and private key for the server in PEM ' |
| 537 | 'format') |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 538 | self.option_parser.add_option('--tls-intolerant', dest='tls_intolerant', |
| 539 | default='0', type='int', |
| 540 | help='If nonzero, certain TLS connections ' |
| 541 | 'will be aborted in order to test version ' |
| 542 | 'fallback. 1 means all TLS versions will be ' |
| 543 | 'aborted. 2 means TLS 1.1 or higher will be ' |
| 544 | 'aborted. 3 means TLS 1.2 or higher will be ' |
davidben | df2e386 | 2017-04-12 15:23:34 -0700 | [diff] [blame] | 545 | 'aborted. 4 means TLS 1.3 or higher will be ' |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 546 | 'aborted.') |
davidben@chromium.org | bbf4f40 | 2014-06-27 01:16:55 +0000 | [diff] [blame] | 547 | self.option_parser.add_option('--tls-intolerance-type', |
| 548 | dest='tls_intolerance_type', |
| 549 | default="alert", |
| 550 | help='Controls how the server reacts to a ' |
| 551 | 'TLS version it is intolerant to. Valid ' |
| 552 | 'values are "alert", "close", and "reset".') |
ekasper@google.com | 3bce2cf | 2013-12-17 00:25:51 +0000 | [diff] [blame] | 553 | self.option_parser.add_option('--signed-cert-timestamps-tls-ext', |
| 554 | dest='signed_cert_timestamps_tls_ext', |
ekasper@google.com | 24aa822 | 2013-11-28 13:43:26 +0000 | [diff] [blame] | 555 | default='', |
| 556 | help='Base64 encoded SCT list. If set, ' |
| 557 | 'server will respond with a ' |
| 558 | 'signed_certificate_timestamp TLS extension ' |
| 559 | 'whenever the client supports it.') |
agl@chromium.org | d0e11ca | 2013-12-11 20:16:13 +0000 | [diff] [blame] | 560 | self.option_parser.add_option('--fallback-scsv', dest='fallback_scsv', |
| 561 | default=False, const=True, |
| 562 | action='store_const', |
| 563 | help='If given, TLS_FALLBACK_SCSV support ' |
| 564 | 'will be enabled. This causes the server to ' |
| 565 | 'reject fallback connections from compatible ' |
| 566 | 'clients (e.g. Chrome).') |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 567 | self.option_parser.add_option('--ssl-client-auth', action='store_true', |
| 568 | help='Require SSL client auth on every ' |
| 569 | 'connection.') |
| 570 | self.option_parser.add_option('--ssl-client-ca', action='append', |
| 571 | default=[], help='Specify that the client ' |
| 572 | 'certificate request should include the CA ' |
| 573 | 'named in the subject of the DER-encoded ' |
| 574 | 'certificate contained in the specified ' |
| 575 | 'file. This option may appear multiple ' |
| 576 | 'times, indicating multiple CA names should ' |
| 577 | 'be sent in the request.') |
davidben@chromium.org | c52e2e6 | 2014-05-20 21:51:44 +0000 | [diff] [blame] | 578 | self.option_parser.add_option('--ssl-client-cert-type', action='append', |
| 579 | default=[], help='Specify that the client ' |
| 580 | 'certificate request should include the ' |
| 581 | 'specified certificate_type value. This ' |
| 582 | 'option may appear multiple times, ' |
| 583 | 'indicating multiple values should be send ' |
| 584 | 'in the request. Valid values are ' |
| 585 | '"rsa_sign", "dss_sign", and "ecdsa_sign". ' |
| 586 | 'If omitted, "rsa_sign" will be used.') |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 587 | self.option_parser.add_option('--ssl-bulk-cipher', action='append', |
| 588 | help='Specify the bulk encryption ' |
| 589 | 'algorithm(s) that will be accepted by the ' |
davidben | 2625476 | 2015-01-29 14:32:53 -0800 | [diff] [blame] | 590 | 'SSL server. Valid values are "aes128gcm", ' |
| 591 | '"aes256", "aes128", "3des", "rc4". If ' |
| 592 | 'omitted, all algorithms will be used. This ' |
| 593 | 'option may appear multiple times, ' |
| 594 | 'indicating multiple algorithms should be ' |
| 595 | 'enabled.'); |
davidben@chromium.org | 74aa8dd | 2014-04-11 07:20:26 +0000 | [diff] [blame] | 596 | self.option_parser.add_option('--ssl-key-exchange', action='append', |
| 597 | help='Specify the key exchange algorithm(s)' |
| 598 | 'that will be accepted by the SSL server. ' |
davidben | 405745f | 2015-04-03 11:35:35 -0700 | [diff] [blame] | 599 | 'Valid values are "rsa", "dhe_rsa", ' |
| 600 | '"ecdhe_rsa". If omitted, all algorithms ' |
| 601 | 'will be used. This option may appear ' |
| 602 | 'multiple times, indicating multiple ' |
| 603 | 'algorithms should be enabled.'); |
bnc | 5fb33bd | 2016-08-05 12:09:21 -0700 | [diff] [blame] | 604 | self.option_parser.add_option('--alpn-protocols', action='append', |
| 605 | help='Specify the list of ALPN protocols. ' |
| 606 | 'The server will not send an ALPN response ' |
| 607 | 'if this list does not overlap with the ' |
| 608 | 'list of protocols the client advertises.') |
bnc | 609ad4c | 2015-10-02 05:11:24 -0700 | [diff] [blame] | 609 | self.option_parser.add_option('--npn-protocols', action='append', |
bnc | 5fb33bd | 2016-08-05 12:09:21 -0700 | [diff] [blame] | 610 | help='Specify the list of protocols sent in ' |
bnc | 609ad4c | 2015-10-02 05:11:24 -0700 | [diff] [blame] | 611 | 'an NPN response. The server will not' |
| 612 | 'support NPN if the list is empty.') |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 613 | self.option_parser.add_option('--file-root-url', default='/files/', |
| 614 | help='Specify a root URL for files served.') |
ricea@chromium.org | a52ebdc | 2014-07-29 07:42:29 +0000 | [diff] [blame] | 615 | # TODO(ricea): Generalize this to support basic auth for HTTP too. |
| 616 | self.option_parser.add_option('--ws-basic-auth', action='store_true', |
| 617 | dest='ws_basic_auth', |
| 618 | help='Enable basic-auth for WebSocket') |
davidben | 21cda34 | 2015-03-17 18:04:28 -0700 | [diff] [blame] | 619 | self.option_parser.add_option('--alert-after-handshake', |
| 620 | dest='alert_after_handshake', |
| 621 | default=False, action='store_true', |
| 622 | help='If set, the server will send a fatal ' |
| 623 | 'alert immediately after the handshake.') |
nharper | 1e8bf4b | 2015-09-18 12:23:02 -0700 | [diff] [blame] | 624 | self.option_parser.add_option('--disable-channel-id', action='store_true') |
| 625 | self.option_parser.add_option('--disable-extended-master-secret', |
| 626 | action='store_true') |
David Benjamin | f839f1c | 2018-10-16 06:01:29 +0000 | [diff] [blame] | 627 | self.option_parser.add_option('--simulate-tls13-downgrade', |
| 628 | action='store_true') |
| 629 | self.option_parser.add_option('--simulate-tls12-downgrade', |
| 630 | action='store_true') |
| 631 | self.option_parser.add_option('--tls-max-version', default='0', type='int', |
| 632 | help='If non-zero, the maximum TLS version ' |
| 633 | 'to support. 1 means TLS 1.0, 2 means ' |
| 634 | 'TLS 1.1, and 3 means TLS 1.2.') |
Pavol Marko | 8ccaaed | 2018-01-04 18:40:04 +0100 | [diff] [blame] | 635 | self.option_parser.add_option('--redirect-connect-to-localhost', |
| 636 | dest='redirect_connect_to_localhost', |
| 637 | default=False, action='store_true', |
| 638 | help='If set, the Proxy server will connect ' |
| 639 | 'to localhost instead of the requested URL ' |
| 640 | 'on CONNECT requests') |
erikkay@google.com | d5182ff | 2009-01-08 20:45:27 +0000 | [diff] [blame] | 641 | |
toyoshim@chromium.org | 16f5752 | 2012-10-24 06:14:38 +0000 | [diff] [blame] | 642 | |
initial.commit | 94958cf | 2008-07-26 22:42:52 +0000 | [diff] [blame] | 643 | if __name__ == '__main__': |
mattm@chromium.org | 830a371 | 2012-11-07 23:00:07 +0000 | [diff] [blame] | 644 | sys.exit(ServerRunner().main()) |