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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: net/data/verify_name_match_unittest/scripts/generate-names.py
diff --git a/net/data/verify_name_match_unittest/scripts/generate-names.py b/net/data/verify_name_match_unittest/scripts/generate-names.py
new file mode 100755
index 0000000000000000000000000000000000000000..eba5d3e7355b9ae0f78c56b1d7aa8c0402c29ad8
--- /dev/null
+++ b/net/data/verify_name_match_unittest/scripts/generate-names.py
@@ -0,0 +1,113 @@
+#!/usr/bin/env python
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import copy
+import os
+import subprocess
+import tempfile
+
+
+class RDN:
+ def __init__(self):
+ self.attrs = []
+
+ def add_attr(self, attr_type, attr_value_type, attr_value):
+ self.attrs.append((attr_type, attr_value_type, attr_value))
+ return self
+
+ def __str__(self):
+ s = ''
+ for n, attr in enumerate(self.attrs):
+ s += 'attrTypeAndValue%i=SEQUENCE:attrTypeAndValueSequence%i_%i\n' % (
+ n, id(self), n)
+
+ s += '\n'
+ for n, attr in enumerate(self.attrs):
+ s += '[attrTypeAndValueSequence%i_%i]\n' % (id(self), n)
+ # Note the quotes around the string value here, which is necessary for
+ # trailing whitespace to be included by openssl.
+ s += 'type=OID:%s\nvalue=%s:"%s"\n' % attr
+
+ return s
+
+
+class NameGenerator:
+ def __init__(self):
+ self.rdns = []
+
+ def add_rdn(self):
+ rdn = RDN()
+ self.rdns.append(rdn)
+ return rdn
+
+ def __str__(self):
+ s = 'asn1 = SEQUENCE:rdnSequence\n\n[rdnSequence]\n'
+ for n, rdn in enumerate(self.rdns):
+ s += 'rdn%i = SET:rdnSet%i\n' % (n, n)
+
+ s += '\n'
+
+ for n, rdn in enumerate(self.rdns):
+ s += '[rdnSet%i]\n%s\n' % (n, rdn)
+
+ return s
+
+ def generate(self, outfn):
+ f = tempfile.NamedTemporaryFile()
+ f.write(str(self))
+ f.flush()
+ subprocess.check_call(['openssl', 'asn1parse', '-genconf', f.name, '-noout',
+ '-out', outfn])
+ f.close()
+
+
+def unmangled(s):
+ return s
+
+
+def extra_whitespace(s):
+ return ' ' + s.replace(' ', ' ') + ' '
+
+
+def case_swap(s):
+ return s.swapcase()
+
+
+def main():
+ output_path = '../names'
+ for valuetype in ('PRINTABLESTRING', 'T61STRING', 'UTF8', 'BMPSTRING',
+ 'UNIVERSALSTRING'):
+ for string_mangler in (unmangled, extra_whitespace, case_swap):
+ n=NameGenerator()
+ n.add_rdn().add_attr('countryName', 'PRINTABLESTRING', 'US')
+ n.add_rdn().add_attr('stateOrProvinceName',
+ valuetype,
+ string_mangler('New York'))
+ n.add_rdn().add_attr('localityName',
+ valuetype,
+ string_mangler("ABCDEFGHIJKLMNOPQRSTUVWXYZ "
+ "abcdefghijklmnopqrstuvwxyz "
+ "0123456789 '()+,-./:=?"))
+
+ n_extra_attr = copy.deepcopy(n)
+ n_extra_attr.rdns[-1].add_attr('organizationName',
+ valuetype,
+ string_mangler('Name of company'))
+
+ n_extra_rdn = copy.deepcopy(n)
+ n_extra_rdn.add_rdn().add_attr('organizationName',
+ valuetype,
+ string_mangler('Name of company'))
+
+ filename_base = os.path.join(
+ output_path, 'ascii-' + valuetype + '-' + string_mangler.__name__)
+
+ n.generate(filename_base + '.der')
+ n_extra_attr.generate(filename_base + '-extra_attr.der')
+ n_extra_rdn.generate(filename_base + '-extra_rdn.der')
+
+
+if __name__ == '__main__':
+ main()

Powered by Google App Engine
This is Rietveld 408576698