Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: net/tools/testserver/testserver.py

Issue 280853002: Preserve transport errors for OpenSSL sockets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: USE_NSS -> USE_OPENSSL for Windows and Mac Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 class HTTPSServer(tlslite.api.TLSSocketServerMixIn, 147 class HTTPSServer(tlslite.api.TLSSocketServerMixIn,
148 testserver_base.ClientRestrictingServerMixIn, 148 testserver_base.ClientRestrictingServerMixIn,
149 testserver_base.BrokenPipeHandlerMixIn, 149 testserver_base.BrokenPipeHandlerMixIn,
150 testserver_base.StoppableHTTPServer): 150 testserver_base.StoppableHTTPServer):
151 """This is a specialization of StoppableHTTPServer that add https support and 151 """This is a specialization of StoppableHTTPServer that add https support and
152 client verification.""" 152 client verification."""
153 153
154 def __init__(self, server_address, request_hander_class, pem_cert_and_key, 154 def __init__(self, server_address, request_hander_class, pem_cert_and_key,
155 ssl_client_auth, ssl_client_cas, ssl_client_cert_types, 155 ssl_client_auth, ssl_client_cas, ssl_client_cert_types,
156 ssl_bulk_ciphers, ssl_key_exchanges, enable_npn, 156 ssl_bulk_ciphers, ssl_key_exchanges, enable_npn,
157 record_resume_info, tls_intolerant, signed_cert_timestamps, 157 record_resume_info, tls_intolerant,
158 reset_on_intolerance, signed_cert_timestamps,
158 fallback_scsv_enabled, ocsp_response): 159 fallback_scsv_enabled, ocsp_response):
159 self.cert_chain = tlslite.api.X509CertChain() 160 self.cert_chain = tlslite.api.X509CertChain()
160 self.cert_chain.parsePemList(pem_cert_and_key) 161 self.cert_chain.parsePemList(pem_cert_and_key)
161 # Force using only python implementation - otherwise behavior is different 162 # Force using only python implementation - otherwise behavior is different
162 # depending on whether m2crypto Python module is present (error is thrown 163 # depending on whether m2crypto Python module is present (error is thrown
163 # when it is). m2crypto uses a C (based on OpenSSL) implementation under 164 # when it is). m2crypto uses a C (based on OpenSSL) implementation under
164 # the hood. 165 # the hood.
165 self.private_key = tlslite.api.parsePEMKey(pem_cert_and_key, 166 self.private_key = tlslite.api.parsePEMKey(pem_cert_and_key,
166 private=True, 167 private=True,
167 implementations=['python']) 168 implementations=['python'])
168 self.ssl_client_auth = ssl_client_auth 169 self.ssl_client_auth = ssl_client_auth
169 self.ssl_client_cas = [] 170 self.ssl_client_cas = []
170 self.ssl_client_cert_types = [] 171 self.ssl_client_cert_types = []
171 if enable_npn: 172 if enable_npn:
172 self.next_protos = ['http/1.1'] 173 self.next_protos = ['http/1.1']
173 else: 174 else:
174 self.next_protos = None 175 self.next_protos = None
175 if tls_intolerant == 0:
176 self.tls_intolerant = None
177 else:
178 self.tls_intolerant = (3, tls_intolerant)
179 self.signed_cert_timestamps = signed_cert_timestamps 176 self.signed_cert_timestamps = signed_cert_timestamps
180 self.fallback_scsv_enabled = fallback_scsv_enabled 177 self.fallback_scsv_enabled = fallback_scsv_enabled
181 self.ocsp_response = ocsp_response 178 self.ocsp_response = ocsp_response
182 179
183 if ssl_client_auth: 180 if ssl_client_auth:
184 for ca_file in ssl_client_cas: 181 for ca_file in ssl_client_cas:
185 s = open(ca_file).read() 182 s = open(ca_file).read()
186 x509 = tlslite.api.X509() 183 x509 = tlslite.api.X509()
187 x509.parse(s) 184 x509.parse(s)
188 self.ssl_client_cas.append(x509.subject) 185 self.ssl_client_cas.append(x509.subject)
189 186
190 for cert_type in ssl_client_cert_types: 187 for cert_type in ssl_client_cert_types:
191 self.ssl_client_cert_types.append({ 188 self.ssl_client_cert_types.append({
192 "rsa_sign": tlslite.api.ClientCertificateType.rsa_sign, 189 "rsa_sign": tlslite.api.ClientCertificateType.rsa_sign,
193 "dss_sign": tlslite.api.ClientCertificateType.dss_sign, 190 "dss_sign": tlslite.api.ClientCertificateType.dss_sign,
194 "ecdsa_sign": tlslite.api.ClientCertificateType.ecdsa_sign, 191 "ecdsa_sign": tlslite.api.ClientCertificateType.ecdsa_sign,
195 }[cert_type]) 192 }[cert_type])
196 193
197 self.ssl_handshake_settings = tlslite.api.HandshakeSettings() 194 self.ssl_handshake_settings = tlslite.api.HandshakeSettings()
198 if ssl_bulk_ciphers is not None: 195 if ssl_bulk_ciphers is not None:
199 self.ssl_handshake_settings.cipherNames = ssl_bulk_ciphers 196 self.ssl_handshake_settings.cipherNames = ssl_bulk_ciphers
200 if ssl_key_exchanges is not None: 197 if ssl_key_exchanges is not None:
201 self.ssl_handshake_settings.keyExchangeNames = ssl_key_exchanges 198 self.ssl_handshake_settings.keyExchangeNames = ssl_key_exchanges
199 if tls_intolerant != 0:
200 self.ssl_handshake_settings.tlsIntolerant = (3, tls_intolerant)
201 self.ssl_handshake_settings.resetOnIntolerance = reset_on_intolerance
202 202
203 if record_resume_info: 203 if record_resume_info:
204 # If record_resume_info is true then we'll replace the session cache with 204 # If record_resume_info is true then we'll replace the session cache with
205 # an object that records the lookups and inserts that it sees. 205 # an object that records the lookups and inserts that it sees.
206 self.session_cache = RecordingSSLSessionCache() 206 self.session_cache = RecordingSSLSessionCache()
207 else: 207 else:
208 self.session_cache = tlslite.api.SessionCache() 208 self.session_cache = tlslite.api.SessionCache()
209 testserver_base.StoppableHTTPServer.__init__(self, 209 testserver_base.StoppableHTTPServer.__init__(self,
210 server_address, 210 server_address,
211 request_hander_class) 211 request_hander_class)
212 212
213 def handshake(self, tlsConnection): 213 def handshake(self, tlsConnection):
214 """Creates the SSL connection.""" 214 """Creates the SSL connection."""
215 215
216 try: 216 try:
217 self.tlsConnection = tlsConnection 217 self.tlsConnection = tlsConnection
218 tlsConnection.handshakeServer(certChain=self.cert_chain, 218 tlsConnection.handshakeServer(certChain=self.cert_chain,
219 privateKey=self.private_key, 219 privateKey=self.private_key,
220 sessionCache=self.session_cache, 220 sessionCache=self.session_cache,
221 reqCert=self.ssl_client_auth, 221 reqCert=self.ssl_client_auth,
222 settings=self.ssl_handshake_settings, 222 settings=self.ssl_handshake_settings,
223 reqCAs=self.ssl_client_cas, 223 reqCAs=self.ssl_client_cas,
224 reqCertTypes=self.ssl_client_cert_types, 224 reqCertTypes=self.ssl_client_cert_types,
225 nextProtos=self.next_protos, 225 nextProtos=self.next_protos,
226 tlsIntolerant=self.tls_intolerant,
227 signedCertTimestamps= 226 signedCertTimestamps=
228 self.signed_cert_timestamps, 227 self.signed_cert_timestamps,
229 fallbackSCSV=self.fallback_scsv_enabled, 228 fallbackSCSV=self.fallback_scsv_enabled,
230 ocspResponse = self.ocsp_response) 229 ocspResponse = self.ocsp_response)
231 tlsConnection.ignoreAbruptClose = True 230 tlsConnection.ignoreAbruptClose = True
232 return True 231 return True
233 except tlslite.api.TLSAbruptCloseError: 232 except tlslite.api.TLSAbruptCloseError:
234 # Ignore abrupt close. 233 # Ignore abrupt close.
235 return True 234 return True
236 except tlslite.api.TLSError, error: 235 except tlslite.api.TLSError, error:
(...skipping 1762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1999 1998
2000 server = HTTPSServer((host, port), TestPageHandler, pem_cert_and_key, 1999 server = HTTPSServer((host, port), TestPageHandler, pem_cert_and_key,
2001 self.options.ssl_client_auth, 2000 self.options.ssl_client_auth,
2002 self.options.ssl_client_ca, 2001 self.options.ssl_client_ca,
2003 self.options.ssl_client_cert_type, 2002 self.options.ssl_client_cert_type,
2004 self.options.ssl_bulk_cipher, 2003 self.options.ssl_bulk_cipher,
2005 self.options.ssl_key_exchange, 2004 self.options.ssl_key_exchange,
2006 self.options.enable_npn, 2005 self.options.enable_npn,
2007 self.options.record_resume, 2006 self.options.record_resume,
2008 self.options.tls_intolerant, 2007 self.options.tls_intolerant,
2008 self.options.reset_on_intolerance,
2009 self.options.signed_cert_timestamps_tls_ext.decode( 2009 self.options.signed_cert_timestamps_tls_ext.decode(
2010 "base64"), 2010 "base64"),
2011 self.options.fallback_scsv, 2011 self.options.fallback_scsv,
2012 stapled_ocsp_response) 2012 stapled_ocsp_response)
2013 print 'HTTPS server started on %s:%d...' % (host, server.server_port) 2013 print 'HTTPS server started on %s:%d...' % (host, server.server_port)
2014 else: 2014 else:
2015 server = HTTPServer((host, port), TestPageHandler) 2015 server = HTTPServer((host, port), TestPageHandler)
2016 print 'HTTP server started on %s:%d...' % (host, server.server_port) 2016 print 'HTTP server started on %s:%d...' % (host, server.server_port)
2017 2017
2018 server.data_dir = self.__make_data_dir() 2018 server.data_dir = self.__make_data_dir()
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2140 help='If non-zero then the generated ' 2140 help='If non-zero then the generated '
2141 'certificate will have this serial number') 2141 'certificate will have this serial number')
2142 self.option_parser.add_option('--tls-intolerant', dest='tls_intolerant', 2142 self.option_parser.add_option('--tls-intolerant', dest='tls_intolerant',
2143 default='0', type='int', 2143 default='0', type='int',
2144 help='If nonzero, certain TLS connections ' 2144 help='If nonzero, certain TLS connections '
2145 'will be aborted in order to test version ' 2145 'will be aborted in order to test version '
2146 'fallback. 1 means all TLS versions will be ' 2146 'fallback. 1 means all TLS versions will be '
2147 'aborted. 2 means TLS 1.1 or higher will be ' 2147 'aborted. 2 means TLS 1.1 or higher will be '
2148 'aborted. 3 means TLS 1.2 or higher will be ' 2148 'aborted. 3 means TLS 1.2 or higher will be '
2149 'aborted.') 2149 'aborted.')
2150 self.option_parser.add_option('--reset-on-intolerance',
2151 dest='reset_on_intolerance',
2152 default=False, const=True,
2153 action='store_const',
2154 help='Send a TCP reset on TLS version '
2155 'intolerance rather than a handshake alert')
2150 self.option_parser.add_option('--signed-cert-timestamps-tls-ext', 2156 self.option_parser.add_option('--signed-cert-timestamps-tls-ext',
2151 dest='signed_cert_timestamps_tls_ext', 2157 dest='signed_cert_timestamps_tls_ext',
2152 default='', 2158 default='',
2153 help='Base64 encoded SCT list. If set, ' 2159 help='Base64 encoded SCT list. If set, '
2154 'server will respond with a ' 2160 'server will respond with a '
2155 'signed_certificate_timestamp TLS extension ' 2161 'signed_certificate_timestamp TLS extension '
2156 'whenever the client supports it.') 2162 'whenever the client supports it.')
2157 self.option_parser.add_option('--fallback-scsv', dest='fallback_scsv', 2163 self.option_parser.add_option('--fallback-scsv', dest='fallback_scsv',
2158 default=False, const=True, 2164 default=False, const=True,
2159 action='store_const', 2165 action='store_const',
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2215 action='store_const', 2221 action='store_const',
2216 help='Enable server support for the NPN ' 2222 help='Enable server support for the NPN '
2217 'extension. The server will advertise ' 2223 'extension. The server will advertise '
2218 'support for exactly one protocol, http/1.1') 2224 'support for exactly one protocol, http/1.1')
2219 self.option_parser.add_option('--file-root-url', default='/files/', 2225 self.option_parser.add_option('--file-root-url', default='/files/',
2220 help='Specify a root URL for files served.') 2226 help='Specify a root URL for files served.')
2221 2227
2222 2228
2223 if __name__ == '__main__': 2229 if __name__ == '__main__':
2224 sys.exit(ServerRunner().main()) 2230 sys.exit(ServerRunner().main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698