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

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, implement unicode transcoding Created 5 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
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 attr_modifier=None):
18 self.attrs.append((attr_type, attr_value_type, attr_value, attr_modifier))
19 return self
20
21 def __str__(self):
22 s = ''
23 for n, attr in enumerate(self.attrs):
24 s += 'attrTypeAndValue%i=SEQUENCE:attrTypeAndValueSequence%i_%i\n' % (
25 n, id(self), n)
26
27 s += '\n'
28 for n, attr in enumerate(self.attrs):
29 attr_type, attr_value_type, attr_value, attr_modifier = attr
30 s += '[attrTypeAndValueSequence%i_%i]\n' % (id(self), n)
31 # Note the quotes around the string value here, which is necessary for
32 # trailing whitespace to be included by openssl.
33 s += 'type=OID:%s\n' % attr_type
34 s += 'value='
35 if attr_modifier:
36 s += attr_modifier + ','
37 s += '%s:"%s"\n' % (attr_value_type, attr_value)
38
39 return s
40
41
42 class NameGenerator:
43 def __init__(self):
44 self.rdns = []
45
46 def add_rdn(self):
47 rdn = RDN()
48 self.rdns.append(rdn)
49 return rdn
50
51 def __str__(self):
52 s = 'asn1 = SEQUENCE:rdnSequence\n\n[rdnSequence]\n'
53 for n, rdn in enumerate(self.rdns):
54 s += 'rdn%i = SET:rdnSet%i\n' % (n, n)
55
56 s += '\n'
57
58 for n, rdn in enumerate(self.rdns):
59 s += '[rdnSet%i]\n%s\n' % (n, rdn)
60
61 return s
62
63
64 def generate(s, fn):
65 outfn = os.path.join('..', 'names', fn)
66 f = tempfile.NamedTemporaryFile()
67 f.write(str(s))
68 f.flush()
69 subprocess.check_call(['openssl', 'asn1parse', '-genconf', f.name, '-noout',
70 '-out', outfn])
71 f.close()
72
73
74 def unmangled(s):
75 return s
76
77
78 def extra_whitespace(s):
79 return ' ' + s.replace(' ', ' ') + ' '
80
81
82 def case_swap(s):
83 return s.swapcase()
84
85
86 def main():
87 for valuetype in ('PRINTABLESTRING', 'T61STRING', 'UTF8', 'BMPSTRING',
88 'UNIVERSALSTRING'):
89 for string_mangler in (unmangled, extra_whitespace, case_swap):
90 n=NameGenerator()
91 n.add_rdn().add_attr('countryName', 'PRINTABLESTRING', 'US')
92 n.add_rdn().add_attr('stateOrProvinceName',
93 valuetype,
94 string_mangler('New York'))
95 n.add_rdn().add_attr('localityName',
96 valuetype,
97 string_mangler("ABCDEFGHIJKLMNOPQRSTUVWXYZ "
98 "abcdefghijklmnopqrstuvwxyz "
99 "0123456789 '()+,-./:=?"))
100
101 n_extra_attr = copy.deepcopy(n)
102 n_extra_attr.rdns[-1].add_attr('organizationName',
103 valuetype,
104 string_mangler('Name of company'))
105
106 n_extra_rdn = copy.deepcopy(n)
107 n_extra_rdn.add_rdn().add_attr('organizationName',
108 valuetype,
109 string_mangler('Name of company'))
110
111 filename_base = 'ascii-' + valuetype + '-' + string_mangler.__name__
112
113 generate(n, filename_base + '.der')
114 generate(n_extra_attr, filename_base + '-extra_attr.der')
115 generate(n_extra_rdn, filename_base + '-extra_rdn.der')
116
117 for valuetype in ('UTF8', 'BMPSTRING', 'UNIVERSALSTRING'):
118 n=NameGenerator()
119 n.add_rdn().add_attr('countryName', 'PRINTABLESTRING', 'JP')
120 n.add_rdn().add_attr('localityName',
121 valuetype,
122 "\xe6\x9d\xb1\xe4\xba\xac",
123 "FORMAT:UTF8")
124
125 filename_base = 'unicode_bmp-' + valuetype + '-' + 'unmangled'
126 generate(n, filename_base + '.der')
127
128 for valuetype in ('UTF8', 'UNIVERSALSTRING'):
129 n=NameGenerator()
130 n.add_rdn().add_attr('countryName', 'PRINTABLESTRING', 'JP')
131 n.add_rdn().add_attr('localityName',
132 valuetype,
133 "\xf0\x9d\x90\x80\xf0\x9d\x90\x99",
134 "FORMAT:UTF8")
135
136 filename_base = 'unicode_supplementary-' + valuetype + '-' + 'unmangled'
137 generate(n, filename_base + '.der')
138
139 generate("""asn1 = SEQUENCE:rdnSequence
140 [rdnSequence]
141 rdn0 = SET:rdnSet0
142 [rdnSet0]
143 attrTypeAndValue0=SEQUENCE:attrTypeAndValueSequence0_0
144 [attrTypeAndValueSequence0_0]
145 type=OID:countryName
146 value=PRINTABLESTRING:"US"
147 extra=PRINTABLESTRING:"hello world"
148 """, "invalid-AttributeTypeAndValue-extradata.der")
149
150 generate("""asn1 = SEQUENCE:rdnSequence
151 [rdnSequence]
152 rdn0 = SET:rdnSet0
153 [rdnSet0]
154 attrTypeAndValue0=SEQUENCE:attrTypeAndValueSequence0_0
155 [attrTypeAndValueSequence0_0]
156 type=OID:countryName
157 """, "invalid-AttributeTypeAndValue-onlyOneElement.der")
158
159 generate("""asn1 = SEQUENCE:rdnSequence
160 [rdnSequence]
161 rdn0 = SET:rdnSet0
162 [rdnSet0]
163 attrTypeAndValue0=SEQUENCE:attrTypeAndValueSequence0_0
164 [attrTypeAndValueSequence0_0]
165 """, "invalid-AttributeTypeAndValue-empty.der")
166
167 generate("""asn1 = SEQUENCE:rdnSequence
168 [rdnSequence]
169 rdn0 = SET:rdnSet0
170 [rdnSet0]
171 attrTypeAndValue0=SEQUENCE:attrTypeAndValueSequence0_0
172 [attrTypeAndValueSequence0_0]
173 type=PRINTABLESTRING:"hello world"
174 value=PRINTABLESTRING:"US"
175 """, "invalid-AttributeTypeAndValue-badAttributeType.der")
176
177 generate("""asn1 = SEQUENCE:rdnSequence
178 [rdnSequence]
179 rdn0 = SET:rdnSet0
180 [rdnSet0]
181 attrTypeAndValue0=SET:attrTypeAndValueSequence0_0
182 [attrTypeAndValueSequence0_0]
183 type=OID:countryName
184 value=PRINTABLESTRING:"US"
185 """, "invalid-AttributeTypeAndValue-setNotSequence.der")
186
187 generate("""asn1 = SEQUENCE:rdnSequence
188 [rdnSequence]
189 rdn0 = SEQUENCE:rdnSet0
190 [rdnSet0]
191 attrTypeAndValue0=SEQUENCE:attrTypeAndValueSequence0_0
192 [attrTypeAndValueSequence0_0]
193 type=OID:countryName
194 value=PRINTABLESTRING:"US"
195 """, "invalid-RDN-sequenceInsteadOfSet.der")
196
197 generate("""asn1 = SEQUENCE:rdnSequence
198 [rdnSequence]
199 rdn0 = SET:rdnSet0
200 [rdnSet0]
201 """, "invalid-RDN-empty.der")
202
203 generate("""asn1 = SET:rdnSequence
204 [rdnSequence]
205 rdn0 = SET:rdnSet0
206 [rdnSet0]
207 attrTypeAndValue0=SEQUENCE:attrTypeAndValueSequence0_0
208 [attrTypeAndValueSequence0_0]
209 type=OID:countryName
210 value=PRINTABLESTRING:"US"
211 """, "invalid-Name-setInsteadOfSequence.der")
212
213 generate("""asn1 = SEQUENCE:rdnSequence
214 [rdnSequence]
215 """, "invalid-Name-empty.der")
216
217 # Minimal valid config. Copy and modify this one when generating new invalid
218 # configs.
219 generate("""asn1 = SEQUENCE:rdnSequence
220 [rdnSequence]
221 rdn0 = SET:rdnSet0
222 [rdnSet0]
223 attrTypeAndValue0=SEQUENCE:attrTypeAndValueSequence0_0
224 [attrTypeAndValueSequence0_0]
225 type=OID:countryName
226 value=PRINTABLESTRING:"US"
227 """, "valid-minimal.der")
228
229 if __name__ == '__main__':
230 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698