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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 class HTTPSServer(tlslite.api.TLSSocketServerMixIn, | 129 class HTTPSServer(tlslite.api.TLSSocketServerMixIn, |
130 testserver_base.ClientRestrictingServerMixIn, | 130 testserver_base.ClientRestrictingServerMixIn, |
131 testserver_base.BrokenPipeHandlerMixIn, | 131 testserver_base.BrokenPipeHandlerMixIn, |
132 testserver_base.StoppableHTTPServer): | 132 testserver_base.StoppableHTTPServer): |
133 """This is a specialization of StoppableHTTPServer that add https support and | 133 """This is a specialization of StoppableHTTPServer that add https support and |
134 client verification.""" | 134 client verification.""" |
135 | 135 |
136 def __init__(self, server_address, request_hander_class, pem_cert_and_key, | 136 def __init__(self, server_address, request_hander_class, pem_cert_and_key, |
137 ssl_client_auth, ssl_client_cas, ssl_bulk_ciphers, | 137 ssl_client_auth, ssl_client_cas, ssl_bulk_ciphers, |
138 record_resume_info, tls_intolerant, signed_cert_timestamps, | 138 record_resume_info, tls_intolerant, signed_cert_timestamps, |
139 fallback_scsv_enabled, ocsp_response): | 139 fallback_scsv_enabled): |
140 self.cert_chain = tlslite.api.X509CertChain().parseChain(pem_cert_and_key) | 140 self.cert_chain = tlslite.api.X509CertChain().parseChain(pem_cert_and_key) |
141 # Force using only python implementation - otherwise behavior is different | 141 # Force using only python implementation - otherwise behavior is different |
142 # depending on whether m2crypto Python module is present (error is thrown | 142 # depending on whether m2crypto Python module is present (error is thrown |
143 # when it is). m2crypto uses a C (based on OpenSSL) implementation under | 143 # when it is). m2crypto uses a C (based on OpenSSL) implementation under |
144 # the hood. | 144 # the hood. |
145 self.private_key = tlslite.api.parsePEMKey(pem_cert_and_key, | 145 self.private_key = tlslite.api.parsePEMKey(pem_cert_and_key, |
146 private=True, | 146 private=True, |
147 implementations=['python']) | 147 implementations=['python']) |
148 self.ssl_client_auth = ssl_client_auth | 148 self.ssl_client_auth = ssl_client_auth |
149 self.ssl_client_cas = [] | 149 self.ssl_client_cas = [] |
150 self.tls_intolerant = tls_intolerant | 150 self.tls_intolerant = tls_intolerant |
151 self.signed_cert_timestamps = signed_cert_timestamps | 151 self.signed_cert_timestamps = signed_cert_timestamps |
152 self.fallback_scsv_enabled = fallback_scsv_enabled | 152 self.fallback_scsv_enabled = fallback_scsv_enabled |
153 self.ocsp_response = ocsp_response | |
154 | 153 |
155 for ca_file in ssl_client_cas: | 154 for ca_file in ssl_client_cas: |
156 s = open(ca_file).read() | 155 s = open(ca_file).read() |
157 x509 = tlslite.api.X509() | 156 x509 = tlslite.api.X509() |
158 x509.parse(s) | 157 x509.parse(s) |
159 self.ssl_client_cas.append(x509.subject) | 158 self.ssl_client_cas.append(x509.subject) |
160 self.ssl_handshake_settings = tlslite.api.HandshakeSettings() | 159 self.ssl_handshake_settings = tlslite.api.HandshakeSettings() |
161 if ssl_bulk_ciphers is not None: | 160 if ssl_bulk_ciphers is not None: |
162 self.ssl_handshake_settings.cipherNames = ssl_bulk_ciphers | 161 self.ssl_handshake_settings.cipherNames = ssl_bulk_ciphers |
163 | 162 |
(...skipping 14 matching lines...) Expand all Loading... |
178 self.tlsConnection = tlsConnection | 177 self.tlsConnection = tlsConnection |
179 tlsConnection.handshakeServer(certChain=self.cert_chain, | 178 tlsConnection.handshakeServer(certChain=self.cert_chain, |
180 privateKey=self.private_key, | 179 privateKey=self.private_key, |
181 sessionCache=self.session_cache, | 180 sessionCache=self.session_cache, |
182 reqCert=self.ssl_client_auth, | 181 reqCert=self.ssl_client_auth, |
183 settings=self.ssl_handshake_settings, | 182 settings=self.ssl_handshake_settings, |
184 reqCAs=self.ssl_client_cas, | 183 reqCAs=self.ssl_client_cas, |
185 tlsIntolerant=self.tls_intolerant, | 184 tlsIntolerant=self.tls_intolerant, |
186 signedCertTimestamps= | 185 signedCertTimestamps= |
187 self.signed_cert_timestamps, | 186 self.signed_cert_timestamps, |
188 fallbackSCSV=self.fallback_scsv_enabled, | 187 fallbackSCSV=self.fallback_scsv_enabled) |
189 ocspResponse = self.ocsp_response) | |
190 tlsConnection.ignoreAbruptClose = True | 188 tlsConnection.ignoreAbruptClose = True |
191 return True | 189 return True |
192 except tlslite.api.TLSAbruptCloseError: | 190 except tlslite.api.TLSAbruptCloseError: |
193 # Ignore abrupt close. | 191 # Ignore abrupt close. |
194 return True | 192 return True |
195 except tlslite.api.TLSError, error: | 193 except tlslite.api.TLSError, error: |
196 print "Handshake failure:", str(error) | 194 print "Handshake failure:", str(error) |
197 return False | 195 return False |
198 | 196 |
199 | 197 |
(...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 ocsp_state = ocsp_state, | 1936 ocsp_state = ocsp_state, |
1939 serial = self.options.cert_serial) | 1937 serial = self.options.cert_serial) |
1940 | 1938 |
1941 self.__ocsp_server.ocsp_response = ocsp_der | 1939 self.__ocsp_server.ocsp_response = ocsp_der |
1942 | 1940 |
1943 for ca_cert in self.options.ssl_client_ca: | 1941 for ca_cert in self.options.ssl_client_ca: |
1944 if not os.path.isfile(ca_cert): | 1942 if not os.path.isfile(ca_cert): |
1945 raise testserver_base.OptionError( | 1943 raise testserver_base.OptionError( |
1946 'specified trusted client CA file not found: ' + ca_cert + | 1944 'specified trusted client CA file not found: ' + ca_cert + |
1947 ' exiting...') | 1945 ' exiting...') |
1948 | |
1949 stapled_ocsp_response = None | |
1950 if self.__ocsp_server and self.options.staple_ocsp_response: | |
1951 stapled_ocsp_response = self.__ocsp_server.ocsp_response | |
1952 | |
1953 server = HTTPSServer((host, port), TestPageHandler, pem_cert_and_key, | 1946 server = HTTPSServer((host, port), TestPageHandler, pem_cert_and_key, |
1954 self.options.ssl_client_auth, | 1947 self.options.ssl_client_auth, |
1955 self.options.ssl_client_ca, | 1948 self.options.ssl_client_ca, |
1956 self.options.ssl_bulk_cipher, | 1949 self.options.ssl_bulk_cipher, |
1957 self.options.record_resume, | 1950 self.options.record_resume, |
1958 self.options.tls_intolerant, | 1951 self.options.tls_intolerant, |
1959 self.options.signed_cert_timestamps_tls_ext.decode( | 1952 self.options.signed_cert_timestamps.decode( |
1960 "base64"), | 1953 "base64"), |
1961 self.options.fallback_scsv, | 1954 self.options.fallback_scsv) |
1962 stapled_ocsp_response) | |
1963 print 'HTTPS server started on %s:%d...' % (host, server.server_port) | 1955 print 'HTTPS server started on %s:%d...' % (host, server.server_port) |
1964 else: | 1956 else: |
1965 server = HTTPServer((host, port), TestPageHandler) | 1957 server = HTTPServer((host, port), TestPageHandler) |
1966 print 'HTTP server started on %s:%d...' % (host, server.server_port) | 1958 print 'HTTP server started on %s:%d...' % (host, server.server_port) |
1967 | 1959 |
1968 server.data_dir = self.__make_data_dir() | 1960 server.data_dir = self.__make_data_dir() |
1969 server.file_root_url = self.options.file_root_url | 1961 server.file_root_url = self.options.file_root_url |
1970 server_data['port'] = server.server_port | 1962 server_data['port'] = server.server_port |
1971 elif self.options.server_type == SERVER_WEBSOCKET: | 1963 elif self.options.server_type == SERVER_WEBSOCKET: |
1972 # Launch pywebsocket via WebSocketServer. | 1964 # Launch pywebsocket via WebSocketServer. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2090 help='If non-zero then the generated ' | 2082 help='If non-zero then the generated ' |
2091 'certificate will have this serial number') | 2083 'certificate will have this serial number') |
2092 self.option_parser.add_option('--tls-intolerant', dest='tls_intolerant', | 2084 self.option_parser.add_option('--tls-intolerant', dest='tls_intolerant', |
2093 default='0', type='int', | 2085 default='0', type='int', |
2094 help='If nonzero, certain TLS connections ' | 2086 help='If nonzero, certain TLS connections ' |
2095 'will be aborted in order to test version ' | 2087 'will be aborted in order to test version ' |
2096 'fallback. 1 means all TLS versions will be ' | 2088 'fallback. 1 means all TLS versions will be ' |
2097 'aborted. 2 means TLS 1.1 or higher will be ' | 2089 'aborted. 2 means TLS 1.1 or higher will be ' |
2098 'aborted. 3 means TLS 1.2 or higher will be ' | 2090 'aborted. 3 means TLS 1.2 or higher will be ' |
2099 'aborted.') | 2091 'aborted.') |
2100 self.option_parser.add_option('--signed-cert-timestamps-tls-ext', | 2092 self.option_parser.add_option('--signed-cert-timestamps', |
2101 dest='signed_cert_timestamps_tls_ext', | 2093 dest='signed_cert_timestamps', |
2102 default='', | 2094 default='', |
2103 help='Base64 encoded SCT list. If set, ' | 2095 help='Base64 encoded SCT list. If set, ' |
2104 'server will respond with a ' | 2096 'server will respond with a ' |
2105 'signed_certificate_timestamp TLS extension ' | 2097 'signed_certificate_timestamp TLS extension ' |
2106 'whenever the client supports it.') | 2098 'whenever the client supports it.') |
2107 self.option_parser.add_option('--fallback-scsv', dest='fallback_scsv', | 2099 self.option_parser.add_option('--fallback-scsv', dest='fallback_scsv', |
2108 default=False, const=True, | 2100 default=False, const=True, |
2109 action='store_const', | 2101 action='store_const', |
2110 help='If given, TLS_FALLBACK_SCSV support ' | 2102 help='If given, TLS_FALLBACK_SCSV support ' |
2111 'will be enabled. This causes the server to ' | 2103 'will be enabled. This causes the server to ' |
2112 'reject fallback connections from compatible ' | 2104 'reject fallback connections from compatible ' |
2113 'clients (e.g. Chrome).') | 2105 'clients (e.g. Chrome).') |
2114 self.option_parser.add_option('--staple-ocsp-response', | |
2115 dest='staple_ocsp_response', | |
2116 default=False, action='store_true', | |
2117 help='If set, server will staple the OCSP ' | |
2118 'response whenever OCSP is on and the client ' | |
2119 'supports OCSP stapling.') | |
2120 self.option_parser.add_option('--https-record-resume', | 2106 self.option_parser.add_option('--https-record-resume', |
2121 dest='record_resume', const=True, | 2107 dest='record_resume', const=True, |
2122 default=False, action='store_const', | 2108 default=False, action='store_const', |
2123 help='Record resumption cache events rather ' | 2109 help='Record resumption cache events rather ' |
2124 'than resuming as normal. Allows the use of ' | 2110 'than resuming as normal. Allows the use of ' |
2125 'the /ssl-session-cache request') | 2111 'the /ssl-session-cache request') |
2126 self.option_parser.add_option('--ssl-client-auth', action='store_true', | 2112 self.option_parser.add_option('--ssl-client-auth', action='store_true', |
2127 help='Require SSL client auth on every ' | 2113 help='Require SSL client auth on every ' |
2128 'connection.') | 2114 'connection.') |
2129 self.option_parser.add_option('--ssl-client-ca', action='append', | 2115 self.option_parser.add_option('--ssl-client-ca', action='append', |
(...skipping 11 matching lines...) Expand all Loading... |
2141 '"aes128", "3des", "rc4". If omitted, all ' | 2127 '"aes128", "3des", "rc4". If omitted, all ' |
2142 'algorithms will be used. This option may ' | 2128 'algorithms will be used. This option may ' |
2143 'appear multiple times, indicating ' | 2129 'appear multiple times, indicating ' |
2144 'multiple algorithms should be enabled.'); | 2130 'multiple algorithms should be enabled.'); |
2145 self.option_parser.add_option('--file-root-url', default='/files/', | 2131 self.option_parser.add_option('--file-root-url', default='/files/', |
2146 help='Specify a root URL for files served.') | 2132 help='Specify a root URL for files served.') |
2147 | 2133 |
2148 | 2134 |
2149 if __name__ == '__main__': | 2135 if __name__ == '__main__': |
2150 sys.exit(ServerRunner().main()) | 2136 sys.exit(ServerRunner().main()) |
OLD | NEW |