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

Side by Side Diff: net/data/verify_certificate_chain_unittest/target-serverauth-various-keyusages/generate-chains.py

Issue 2859053002: Consolidate some more verify_certificate_chain_unittest/ data. (Closed)
Patch Set: Address Matt's feedback Created 3 years, 7 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
(Empty)
1 #!/usr/bin/python
2 # Copyright (c) 2017 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Generates a variety of chains where the target certificate varies in its key
7 type and key usages."""
8
9 import sys
10 sys.path += ['..']
11
12 import common
13
14 # Self-signed root certificate (used as trust anchor).
15 root = common.create_self_signed_root_certificate('Root')
16
17 # Intermediate certificate.
18 intermediate = common.create_intermediate_certificate('Intermediate', root)
19
20 # Use either an RSA key, or an EC key for the target certificate. Generate the
21 # possible keys ahead of time so as not to duplicate the work.
22
23 KEYS = {
24 'rsa': common.get_or_generate_rsa_key(2048,
25 common.create_key_path('Target-rsa')),
26 'ec': common.get_or_generate_ec_key('secp384r1',
27 common.create_key_path('Target-ec'))
28 };
29
30 KEY_USAGES = [ 'decipherOnly',
31 'digitalSignature',
32 'keyAgreement',
33 'keyEncipherment' ]
34
35 # The proper key usage depends on the key purpose (serverAuth in this case),
36 # and the key type. Generate a variety of combinations.
37 for key_type in sorted(KEYS.keys()):
38 for key_usage in KEY_USAGES:
39 # Target certificate.
40 target = common.create_end_entity_certificate('Target', intermediate)
41 target.get_extensions().set_property('extendedKeyUsage', 'serverAuth')
42 target.get_extensions().set_property('keyUsage',
43 'critical,%s' % (key_usage))
44
45 # Set the key.
46 target.set_key(KEYS[key_type])
47
48 # Write the chain.
49 chain = [target, intermediate, root]
50 description = ('Certificate chain where the target uses a %s key and has '
51 'the single key usage %s') % (key_type.upper(), key_usage)
52 common.write_chain(description, chain, '%s-%s.pem' % (key_type, key_usage))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698