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

Side by Side Diff: telemetry/third_party/web-page-replay/certutils.py

Issue 2811373002: [web-page-replay] Roll WPR to the latest commit (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
1 # Copyright 2014 Google Inc. All Rights Reserved. 1 # Copyright 2014 Google Inc. All Rights Reserved.
2 # 2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License. 4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at 5 # You may obtain a copy of the License at
6 # 6 #
7 # http://www.apache.org/licenses/LICENSE-2.0 7 # http://www.apache.org/licenses/LICENSE-2.0
8 # 8 #
9 # Unless required by applicable law or agreed to in writing, software 9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 10 # distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 ca_cert.set_serial_number(int(time.time()*10000)) 123 ca_cert.set_serial_number(int(time.time()*10000))
124 ca_cert.set_version(2) 124 ca_cert.set_version(2)
125 ca_cert.get_subject().CN = subject 125 ca_cert.get_subject().CN = subject
126 ca_cert.get_subject().O = subject 126 ca_cert.get_subject().O = subject
127 ca_cert.gmtime_adj_notBefore(-60 * 60 * 24 * 365 * 2) 127 ca_cert.gmtime_adj_notBefore(-60 * 60 * 24 * 365 * 2)
128 ca_cert.gmtime_adj_notAfter(60 * 60 * 24 * 365 * 2) 128 ca_cert.gmtime_adj_notAfter(60 * 60 * 24 * 365 * 2)
129 ca_cert.set_issuer(ca_cert.get_subject()) 129 ca_cert.set_issuer(ca_cert.get_subject())
130 ca_cert.set_pubkey(key) 130 ca_cert.set_pubkey(key)
131 ca_cert.add_extensions([ 131 ca_cert.add_extensions([
132 crypto.X509Extension('basicConstraints', True, 'CA:TRUE'), 132 crypto.X509Extension('basicConstraints', True, 'CA:TRUE'),
133 crypto.X509Extension('subjectAltName', False, 'DNS:' + subject),
134 crypto.X509Extension('nsCertType', True, 'sslCA'),
135 crypto.X509Extension('extendedKeyUsage', True, 133 crypto.X509Extension('extendedKeyUsage', True,
136 ('serverAuth,clientAuth,emailProtection,' 134 ('serverAuth,clientAuth,emailProtection,'
137 'timeStamping,msCodeInd,msCodeCom,msCTLSign,' 135 'timeStamping,msCodeInd,msCodeCom,msCTLSign,'
138 'msSGC,msEFS,nsSGC')), 136 'msSGC,msEFS,nsSGC')),
139 crypto.X509Extension('keyUsage', False, 'keyCertSign, cRLSign'), 137 crypto.X509Extension('keyUsage', False, 'keyCertSign, cRLSign'),
140 crypto.X509Extension('subjectKeyIdentifier', False, 'hash', 138 crypto.X509Extension('subjectKeyIdentifier', False, 'hash',
141 subject=ca_cert), 139 subject=ca_cert),
142 ]) 140 ])
143 ca_cert.sign(key, 'sha256') 141 ca_cert.sign(key, 'sha256')
144 key_str = _dump_privatekey(key) 142 key_str = _dump_privatekey(key)
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 """Generates a cert_str with the sni field in server_cert_str signed by the 221 """Generates a cert_str with the sni field in server_cert_str signed by the
224 root_ca_cert_str. 222 root_ca_cert_str.
225 223
226 Args: 224 Args:
227 root_ca_cert_str: PEM formatted string representing the root cert 225 root_ca_cert_str: PEM formatted string representing the root cert
228 server_cert_str: PEM formatted string representing cert 226 server_cert_str: PEM formatted string representing cert
229 server_host: host name to use if there is no server_cert_str 227 server_host: host name to use if there is no server_cert_str
230 Returns: 228 Returns:
231 a PEM formatted certificate string 229 a PEM formatted certificate string
232 """ 230 """
233 EXTENSION_WHITELIST = set(['subjectAltName'])
234
235 if openssl_import_error: 231 if openssl_import_error:
236 raise openssl_import_error # pylint: disable=raising-bad-type 232 raise openssl_import_error # pylint: disable=raising-bad-type
237 233
238 common_name = server_host 234 common_name = server_host
239 reused_extensions = []
240 if server_cert_str: 235 if server_cert_str:
241 original_cert = load_cert(server_cert_str) 236 original_cert = load_cert(server_cert_str)
242 common_name = original_cert.get_subject().commonName 237 common_name = original_cert.get_subject().commonName
243 for i in xrange(original_cert.get_extension_count()):
244 original_cert_extension = original_cert.get_extension(i)
245 if original_cert_extension.get_short_name() in EXTENSION_WHITELIST:
246 reused_extensions.append(original_cert_extension)
247 238
248 ca_cert = load_cert(root_ca_cert_str) 239 ca_cert = load_cert(root_ca_cert_str)
249 ca_key = load_privatekey(root_ca_cert_str) 240 ca_key = load_privatekey(root_ca_cert_str)
250 241
251 cert = crypto.X509() 242 cert = crypto.X509()
252 cert.get_subject().CN = common_name 243 cert.get_subject().CN = common_name
253 cert.gmtime_adj_notBefore(-60 * 60) 244 cert.gmtime_adj_notBefore(-60 * 60)
254 cert.gmtime_adj_notAfter(60 * 60 * 24 * 30) 245 cert.gmtime_adj_notAfter(60 * 60 * 24 * 30)
255 cert.set_issuer(ca_cert.get_subject()) 246 cert.set_issuer(ca_cert.get_subject())
256 cert.set_serial_number(int(time.time()*10000)) 247 cert.set_serial_number(int(time.time()*10000))
257 cert.set_pubkey(ca_key) 248 cert.set_pubkey(ca_key)
258 cert.add_extensions(reused_extensions) 249 cert.add_extensions([
250 crypto.X509Extension('subjectAltName', False, 'DNS:' + server_host),
251 crypto.X509Extension('extendedKeyUsage', False, 'serverAuth,clientAuth'),
252 ])
259 cert.sign(ca_key, 'sha256') 253 cert.sign(ca_key, 'sha256')
260 254
261 return _dump_cert(cert) 255 return _dump_cert(cert)
262 256
263 257
264 def install_cert_in_nssdb(home_directory_path, certificate_path): 258 def install_cert_in_nssdb(home_directory_path, certificate_path):
265 """Installs a certificate into the ~/.pki/nssdb database. 259 """Installs a certificate into the ~/.pki/nssdb database.
266 260
267 Args: 261 Args:
268 home_directory_path: Path of the home directory where to install 262 home_directory_path: Path of the home directory where to install
(...skipping 11 matching lines...) Expand all
280 cmd = ['certutil', '--empty-password', '-d', 'sql:' + cert_database_path] 274 cmd = ['certutil', '--empty-password', '-d', 'sql:' + cert_database_path]
281 cmd.extend(args) 275 cmd.extend(args)
282 logging.info(subprocess.list2cmdline(cmd)) 276 logging.info(subprocess.list2cmdline(cmd))
283 subprocess.check_call(cmd) 277 subprocess.check_call(cmd)
284 278
285 if not os.path.isdir(cert_database_path): 279 if not os.path.isdir(cert_database_path):
286 os.makedirs(cert_database_path) 280 os.makedirs(cert_database_path)
287 certutil(['-N']) 281 certutil(['-N'])
288 282
289 certutil(['-A', '-t', 'PC,,', '-n', certificate_path, '-i', certificate_path]) 283 certutil(['-A', '-t', 'PC,,', '-n', certificate_path, '-i', certificate_path])
OLDNEW
« no previous file with comments | « telemetry/third_party/web-page-replay/README.chromium ('k') | telemetry/third_party/web-page-replay/certutils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698