OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """This is a simple HTTP/FTP/TCP/UDP/BASIC_AUTH_PROXY/WEBSOCKET server used for | 6 """This is a simple HTTP/FTP/TCP/UDP/BASIC_AUTH_PROXY/WEBSOCKET server used for |
7 testing Chrome. | 7 testing Chrome. |
8 | 8 |
9 It supports several test URLs, as specified by the handlers in TestPageHandler. | 9 It supports several test URLs, as specified by the handlers in TestPageHandler. |
10 By default, it listens on an ephemeral port and sends the port number back to | 10 By default, it listens on an ephemeral port and sends the port number back to |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 testserver_base.BrokenPipeHandlerMixIn, | 150 testserver_base.BrokenPipeHandlerMixIn, |
151 testserver_base.StoppableHTTPServer): | 151 testserver_base.StoppableHTTPServer): |
152 """This is a specialization of StoppableHTTPServer that add https support and | 152 """This is a specialization of StoppableHTTPServer that add https support and |
153 client verification.""" | 153 client verification.""" |
154 | 154 |
155 def __init__(self, server_address, request_hander_class, pem_cert_and_key, | 155 def __init__(self, server_address, request_hander_class, pem_cert_and_key, |
156 ssl_client_auth, ssl_client_cas, ssl_client_cert_types, | 156 ssl_client_auth, ssl_client_cas, ssl_client_cert_types, |
157 ssl_bulk_ciphers, ssl_key_exchanges, enable_npn, | 157 ssl_bulk_ciphers, ssl_key_exchanges, enable_npn, |
158 record_resume_info, tls_intolerant, | 158 record_resume_info, tls_intolerant, |
159 tls_intolerance_type, signed_cert_timestamps, | 159 tls_intolerance_type, signed_cert_timestamps, |
160 fallback_scsv_enabled, ocsp_response): | 160 fallback_scsv_enabled, ocsp_response, none_session_cache): |
161 self.cert_chain = tlslite.api.X509CertChain() | 161 self.cert_chain = tlslite.api.X509CertChain() |
162 self.cert_chain.parsePemList(pem_cert_and_key) | 162 self.cert_chain.parsePemList(pem_cert_and_key) |
163 # Force using only python implementation - otherwise behavior is different | 163 # Force using only python implementation - otherwise behavior is different |
164 # depending on whether m2crypto Python module is present (error is thrown | 164 # depending on whether m2crypto Python module is present (error is thrown |
165 # when it is). m2crypto uses a C (based on OpenSSL) implementation under | 165 # when it is). m2crypto uses a C (based on OpenSSL) implementation under |
166 # the hood. | 166 # the hood. |
167 self.private_key = tlslite.api.parsePEMKey(pem_cert_and_key, | 167 self.private_key = tlslite.api.parsePEMKey(pem_cert_and_key, |
168 private=True, | 168 private=True, |
169 implementations=['python']) | 169 implementations=['python']) |
170 self.ssl_client_auth = ssl_client_auth | 170 self.ssl_client_auth = ssl_client_auth |
(...skipping 27 matching lines...) Expand all Loading... |
198 if ssl_key_exchanges is not None: | 198 if ssl_key_exchanges is not None: |
199 self.ssl_handshake_settings.keyExchangeNames = ssl_key_exchanges | 199 self.ssl_handshake_settings.keyExchangeNames = ssl_key_exchanges |
200 if tls_intolerant != 0: | 200 if tls_intolerant != 0: |
201 self.ssl_handshake_settings.tlsIntolerant = (3, tls_intolerant) | 201 self.ssl_handshake_settings.tlsIntolerant = (3, tls_intolerant) |
202 self.ssl_handshake_settings.tlsIntoleranceType = tls_intolerance_type | 202 self.ssl_handshake_settings.tlsIntoleranceType = tls_intolerance_type |
203 | 203 |
204 if record_resume_info: | 204 if record_resume_info: |
205 # If record_resume_info is true then we'll replace the session cache with | 205 # If record_resume_info is true then we'll replace the session cache with |
206 # an object that records the lookups and inserts that it sees. | 206 # an object that records the lookups and inserts that it sees. |
207 self.session_cache = RecordingSSLSessionCache() | 207 self.session_cache = RecordingSSLSessionCache() |
| 208 elif none_session_cache: |
| 209 self.session_cache = None |
208 else: | 210 else: |
209 self.session_cache = tlslite.api.SessionCache() | 211 self.session_cache = tlslite.api.SessionCache() |
210 testserver_base.StoppableHTTPServer.__init__(self, | 212 testserver_base.StoppableHTTPServer.__init__(self, |
211 server_address, | 213 server_address, |
212 request_hander_class) | 214 request_hander_class) |
213 | 215 |
214 def handshake(self, tlsConnection): | 216 def handshake(self, tlsConnection): |
215 """Creates the SSL connection.""" | 217 """Creates the SSL connection.""" |
216 | 218 |
217 try: | 219 try: |
(...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 self.options.ssl_client_cert_type, | 1981 self.options.ssl_client_cert_type, |
1980 self.options.ssl_bulk_cipher, | 1982 self.options.ssl_bulk_cipher, |
1981 self.options.ssl_key_exchange, | 1983 self.options.ssl_key_exchange, |
1982 self.options.enable_npn, | 1984 self.options.enable_npn, |
1983 self.options.record_resume, | 1985 self.options.record_resume, |
1984 self.options.tls_intolerant, | 1986 self.options.tls_intolerant, |
1985 self.options.tls_intolerance_type, | 1987 self.options.tls_intolerance_type, |
1986 self.options.signed_cert_timestamps_tls_ext.decode( | 1988 self.options.signed_cert_timestamps_tls_ext.decode( |
1987 "base64"), | 1989 "base64"), |
1988 self.options.fallback_scsv, | 1990 self.options.fallback_scsv, |
1989 stapled_ocsp_response) | 1991 stapled_ocsp_response, |
| 1992 self.options.none_session_cache) |
1990 print 'HTTPS server started on https://%s:%d...' % \ | 1993 print 'HTTPS server started on https://%s:%d...' % \ |
1991 (host, server.server_port) | 1994 (host, server.server_port) |
1992 else: | 1995 else: |
1993 server = HTTPServer((host, port), TestPageHandler) | 1996 server = HTTPServer((host, port), TestPageHandler) |
1994 print 'HTTP server started on http://%s:%d...' % \ | 1997 print 'HTTP server started on http://%s:%d...' % \ |
1995 (host, server.server_port) | 1998 (host, server.server_port) |
1996 | 1999 |
1997 server.data_dir = self.__make_data_dir() | 2000 server.data_dir = self.__make_data_dir() |
1998 server.file_root_url = self.options.file_root_url | 2001 server.file_root_url = self.options.file_root_url |
1999 server_data['port'] = server.server_port | 2002 server_data['port'] = server.server_port |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2079 if self.__ocsp_server: | 2082 if self.__ocsp_server: |
2080 self.__ocsp_server.serve_forever_on_thread() | 2083 self.__ocsp_server.serve_forever_on_thread() |
2081 | 2084 |
2082 testserver_base.TestServerRunner.run_server(self) | 2085 testserver_base.TestServerRunner.run_server(self) |
2083 | 2086 |
2084 if self.__ocsp_server: | 2087 if self.__ocsp_server: |
2085 self.__ocsp_server.stop_serving() | 2088 self.__ocsp_server.stop_serving() |
2086 | 2089 |
2087 def add_options(self): | 2090 def add_options(self): |
2088 testserver_base.TestServerRunner.add_options(self) | 2091 testserver_base.TestServerRunner.add_options(self) |
| 2092 self.option_parser.add_option('--none-session-cache', action='store_true', |
| 2093 dest='none_session_cache', |
| 2094 help='tells the server to use a None' |
| 2095 'session cache.') |
2089 self.option_parser.add_option('-f', '--ftp', action='store_const', | 2096 self.option_parser.add_option('-f', '--ftp', action='store_const', |
2090 const=SERVER_FTP, default=SERVER_HTTP, | 2097 const=SERVER_FTP, default=SERVER_HTTP, |
2091 dest='server_type', | 2098 dest='server_type', |
2092 help='start up an FTP server.') | 2099 help='start up an FTP server.') |
2093 self.option_parser.add_option('--tcp-echo', action='store_const', | 2100 self.option_parser.add_option('--tcp-echo', action='store_const', |
2094 const=SERVER_TCP_ECHO, default=SERVER_HTTP, | 2101 const=SERVER_TCP_ECHO, default=SERVER_HTTP, |
2095 dest='server_type', | 2102 dest='server_type', |
2096 help='start up a tcp echo server.') | 2103 help='start up a tcp echo server.') |
2097 self.option_parser.add_option('--udp-echo', action='store_const', | 2104 self.option_parser.add_option('--udp-echo', action='store_const', |
2098 const=SERVER_UDP_ECHO, default=SERVER_HTTP, | 2105 const=SERVER_UDP_ECHO, default=SERVER_HTTP, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2209 self.option_parser.add_option('--file-root-url', default='/files/', | 2216 self.option_parser.add_option('--file-root-url', default='/files/', |
2210 help='Specify a root URL for files served.') | 2217 help='Specify a root URL for files served.') |
2211 # TODO(ricea): Generalize this to support basic auth for HTTP too. | 2218 # TODO(ricea): Generalize this to support basic auth for HTTP too. |
2212 self.option_parser.add_option('--ws-basic-auth', action='store_true', | 2219 self.option_parser.add_option('--ws-basic-auth', action='store_true', |
2213 dest='ws_basic_auth', | 2220 dest='ws_basic_auth', |
2214 help='Enable basic-auth for WebSocket') | 2221 help='Enable basic-auth for WebSocket') |
2215 | 2222 |
2216 | 2223 |
2217 if __name__ == '__main__': | 2224 if __name__ == '__main__': |
2218 sys.exit(ServerRunner().main()) | 2225 sys.exit(ServerRunner().main()) |
OLD | NEW |