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

Side by Side Diff: net/data/verify_name_match_unittest/scripts/generate-names.py

Issue 1125333005: RFC 2459 name comparison. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review changes Created 5 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/env python
2 # Copyright 2015 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 import copy
7 import os
8 import subprocess
9 import tempfile
10
11
12 class RDN:
13 def __init__(self):
14 self.attrs = []
15
16 def add_attr(self, attr_type, attr_value_type, attr_value):
17 self.attrs.append((attr_type, attr_value_type, attr_value))
18 return self
19
20 def __str__(self):
21 s = ''
22 for n, attr in enumerate(self.attrs):
23 s += 'attrTypeAndValue%i=SEQUENCE:attrTypeAndValueSequence%i_%i\n' % (
24 n, id(self), n)
25
26 s += '\n'
27 for n, attr in enumerate(self.attrs):
28 s += '[attrTypeAndValueSequence%i_%i]\n' % (id(self), n)
29 # Note the quotes around the string value here, which is necessary for
30 # trailing whitespace to be included by openssl.
31 s += 'type=OID:%s\nvalue=%s:"%s"\n' % attr
32
33 return s
34
35
36 class NameGenerator:
37 def __init__(self):
38 self.rdns = []
39
40 def add_rdn(self):
41 rdn = RDN()
42 self.rdns.append(rdn)
43 return rdn
44
45 def __str__(self):
46 s = 'asn1 = SEQUENCE:rdnSequence\n\n[rdnSequence]\n'
47 for n, rdn in enumerate(self.rdns):
48 s += 'rdn%i = SET:rdnSet%i\n' % (n, n)
49
50 s += '\n'
51
52 for n, rdn in enumerate(self.rdns):
53 s += '[rdnSet%i]\n%s\n' % (n, rdn)
54
55 return s
56
57 def generate(self, outfn):
58 f = tempfile.NamedTemporaryFile()
59 f.write(str(self))
60 f.flush()
61 subprocess.check_call(['openssl', 'asn1parse', '-genconf', f.name, '-noout',
62 '-out', outfn])
63 f.close()
64
65
66 def unmangled(s):
67 return s
68
69
70 def extra_whitespace(s):
71 return ' ' + s.replace(' ', ' ') + ' '
72
73
74 def case_swap(s):
75 return s.swapcase()
76
77
78 def main():
79 output_path = '../names'
80 for valuetype in ('PRINTABLESTRING', 'T61STRING', 'UTF8', 'BMPSTRING',
81 'UNIVERSALSTRING'):
82 for string_mangler in (unmangled, extra_whitespace, case_swap):
83 n=NameGenerator()
84 n.add_rdn().add_attr('countryName', 'PRINTABLESTRING', 'US')
85 n.add_rdn().add_attr('stateOrProvinceName',
86 valuetype,
87 string_mangler('New York'))
88 n.add_rdn().add_attr('localityName',
89 valuetype,
90 string_mangler("ABCDEFGHIJKLMNOPQRSTUVWXYZ "
91 "abcdefghijklmnopqrstuvwxyz "
92 "0123456789 '()+,-./:=?"))
93
94 n_extra_attr = copy.deepcopy(n)
95 n_extra_attr.rdns[-1].add_attr('organizationName',
96 valuetype,
97 string_mangler('Name of company'))
98
99 n_extra_rdn = copy.deepcopy(n)
100 n_extra_rdn.add_rdn().add_attr('organizationName',
101 valuetype,
102 string_mangler('Name of company'))
103
104 filename_base = os.path.join(
105 output_path, 'ascii-' + valuetype + '-' + string_mangler.__name__)
106
107 n.generate(filename_base + '.der')
108 n_extra_attr.generate(filename_base + '-extra_attr.der')
109 n_extra_rdn.generate(filename_base + '-extra_rdn.der')
110
111
112 if __name__ == '__main__':
113 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698