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 1958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1969 | 1969 |
1970 return my_data_dir | 1970 return my_data_dir |
1971 | 1971 |
1972 def create_server(self, server_data): | 1972 def create_server(self, server_data): |
1973 port = self.options.port | 1973 port = self.options.port |
1974 host = self.options.host | 1974 host = self.options.host |
1975 | 1975 |
1976 if self.options.server_type == SERVER_HTTP: | 1976 if self.options.server_type == SERVER_HTTP: |
1977 if self.options.https: | 1977 if self.options.https: |
1978 pem_cert_and_key = None | 1978 pem_cert_and_key = None |
| 1979 ocsp_der = None |
1979 if self.options.cert_and_key_file: | 1980 if self.options.cert_and_key_file: |
1980 if not os.path.isfile(self.options.cert_and_key_file): | 1981 if not os.path.isfile(self.options.cert_and_key_file): |
1981 raise testserver_base.OptionError( | 1982 raise testserver_base.OptionError( |
1982 'specified server cert file not found: ' + | 1983 'specified server cert file not found: ' + |
1983 self.options.cert_and_key_file + ' exiting...') | 1984 self.options.cert_and_key_file + ' exiting...') |
1984 pem_cert_and_key = file(self.options.cert_and_key_file, 'r').read() | 1985 pem_cert_and_key = file(self.options.cert_and_key_file, 'r').read() |
1985 else: | 1986 else: |
1986 # generate a new certificate and run an OCSP server for it. | 1987 # generate a new certificate and run an OCSP server for it. |
1987 self.__ocsp_server = OCSPServer((host, 0), OCSPHandler) | 1988 self.__ocsp_server = OCSPServer((host, 0), OCSPHandler) |
1988 print ('OCSP server started on %s:%d...' % | 1989 print ('OCSP server started on %s:%d...' % |
1989 (host, self.__ocsp_server.server_port)) | 1990 (host, self.__ocsp_server.server_port)) |
1990 | 1991 |
1991 ocsp_der = None | |
1992 ocsp_state = None | 1992 ocsp_state = None |
1993 | 1993 |
1994 if self.options.ocsp == 'ok': | 1994 if self.options.ocsp == 'ok': |
1995 ocsp_state = minica.OCSP_STATE_GOOD | 1995 ocsp_state = minica.OCSP_STATE_GOOD |
1996 elif self.options.ocsp == 'revoked': | 1996 elif self.options.ocsp == 'revoked': |
1997 ocsp_state = minica.OCSP_STATE_REVOKED | 1997 ocsp_state = minica.OCSP_STATE_REVOKED |
1998 elif self.options.ocsp == 'invalid': | 1998 elif self.options.ocsp == 'invalid': |
1999 ocsp_state = minica.OCSP_STATE_INVALID | 1999 ocsp_state = minica.OCSP_STATE_INVALID |
2000 elif self.options.ocsp == 'unauthorized': | 2000 elif self.options.ocsp == 'unauthorized': |
2001 ocsp_state = minica.OCSP_STATE_UNAUTHORIZED | 2001 ocsp_state = minica.OCSP_STATE_UNAUTHORIZED |
2002 elif self.options.ocsp == 'unknown': | 2002 elif self.options.ocsp == 'unknown': |
2003 ocsp_state = minica.OCSP_STATE_UNKNOWN | 2003 ocsp_state = minica.OCSP_STATE_UNKNOWN |
2004 else: | 2004 else: |
2005 raise testserver_base.OptionError('unknown OCSP status: ' + | 2005 raise testserver_base.OptionError('unknown OCSP status: ' + |
2006 self.options.ocsp_status) | 2006 self.options.ocsp_status) |
2007 | 2007 |
2008 (pem_cert_and_key, ocsp_der) = minica.GenerateCertKeyAndOCSP( | 2008 (pem_cert_and_key, ocsp_der) = minica.GenerateCertKeyAndOCSP( |
2009 subject = "127.0.0.1", | 2009 subject = "127.0.0.1", |
2010 ocsp_url = ("http://%s:%d/ocsp" % | 2010 ocsp_url = ("http://%s:%d/ocsp" % |
2011 (host, self.__ocsp_server.server_port)), | 2011 (host, self.__ocsp_server.server_port)), |
2012 ocsp_state = ocsp_state, | 2012 ocsp_state = ocsp_state, |
2013 serial = self.options.cert_serial) | 2013 serial = self.options.cert_serial) |
2014 | 2014 |
2015 self.__ocsp_server.ocsp_response = ocsp_der | 2015 if self.options.ocsp_server_unavailable: |
| 2016 # SEQUENCE containing ENUMERATED with value 3 (tryLater). |
| 2017 self.__ocsp_server.ocsp_response = '30030a0103'.decode('hex') |
| 2018 else: |
| 2019 self.__ocsp_server.ocsp_response = ocsp_der |
2016 | 2020 |
2017 for ca_cert in self.options.ssl_client_ca: | 2021 for ca_cert in self.options.ssl_client_ca: |
2018 if not os.path.isfile(ca_cert): | 2022 if not os.path.isfile(ca_cert): |
2019 raise testserver_base.OptionError( | 2023 raise testserver_base.OptionError( |
2020 'specified trusted client CA file not found: ' + ca_cert + | 2024 'specified trusted client CA file not found: ' + ca_cert + |
2021 ' exiting...') | 2025 ' exiting...') |
2022 | 2026 |
2023 stapled_ocsp_response = None | 2027 stapled_ocsp_response = None |
2024 if self.__ocsp_server and self.options.staple_ocsp_response: | 2028 if self.options.staple_ocsp_response: |
2025 stapled_ocsp_response = self.__ocsp_server.ocsp_response | 2029 stapled_ocsp_response = ocsp_der |
2026 | 2030 |
2027 server = HTTPSServer((host, port), TestPageHandler, pem_cert_and_key, | 2031 server = HTTPSServer((host, port), TestPageHandler, pem_cert_and_key, |
2028 self.options.ssl_client_auth, | 2032 self.options.ssl_client_auth, |
2029 self.options.ssl_client_ca, | 2033 self.options.ssl_client_ca, |
2030 self.options.ssl_client_cert_type, | 2034 self.options.ssl_client_cert_type, |
2031 self.options.ssl_bulk_cipher, | 2035 self.options.ssl_bulk_cipher, |
2032 self.options.ssl_key_exchange, | 2036 self.options.ssl_key_exchange, |
2033 self.options.enable_npn, | 2037 self.options.enable_npn, |
2034 self.options.record_resume, | 2038 self.options.record_resume, |
2035 self.options.tls_intolerant, | 2039 self.options.tls_intolerant, |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2262 action='store_const', | 2266 action='store_const', |
2263 help='Enable server support for the NPN ' | 2267 help='Enable server support for the NPN ' |
2264 'extension. The server will advertise ' | 2268 'extension. The server will advertise ' |
2265 'support for exactly one protocol, http/1.1') | 2269 'support for exactly one protocol, http/1.1') |
2266 self.option_parser.add_option('--file-root-url', default='/files/', | 2270 self.option_parser.add_option('--file-root-url', default='/files/', |
2267 help='Specify a root URL for files served.') | 2271 help='Specify a root URL for files served.') |
2268 # TODO(ricea): Generalize this to support basic auth for HTTP too. | 2272 # TODO(ricea): Generalize this to support basic auth for HTTP too. |
2269 self.option_parser.add_option('--ws-basic-auth', action='store_true', | 2273 self.option_parser.add_option('--ws-basic-auth', action='store_true', |
2270 dest='ws_basic_auth', | 2274 dest='ws_basic_auth', |
2271 help='Enable basic-auth for WebSocket') | 2275 help='Enable basic-auth for WebSocket') |
| 2276 self.option_parser.add_option('--ocsp-server-unavailable', |
| 2277 dest='ocsp_server_unavailable', |
| 2278 default=False, action='store_true', |
| 2279 help='If set, the OCSP server will return ' |
| 2280 'a tryLater status rather than the actual ' |
| 2281 'OCSP response.') |
2272 | 2282 |
2273 | 2283 |
2274 if __name__ == '__main__': | 2284 if __name__ == '__main__': |
2275 sys.exit(ServerRunner().main()) | 2285 sys.exit(ServerRunner().main()) |
OLD | NEW |