generate-certs.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env python
  2. # Copyright 2016 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. """Certificates for testing issuer lookup.
  6. Root
  7. /| | |\\
  8. / | | | \\
  9. / | | | \\
  10. / | | | \\
  11. / | | | \\
  12. v v v v v
  13. I1_1 i1_2 I2 I3_1 I3_2
  14. | | | | |
  15. | | | | |
  16. | | | | |
  17. | | | | |
  18. v v v | |
  19. C1 C2 D E1 E2
  20. I1 (i1_1.pem) and i1 (i1_2.pem) have subjects that are equal after
  21. normalization.
  22. I3_1 and I3_2 have subjects that are exactly equal.
  23. C1 and C2 should (attempt to) chain up through both I1 and i1, since I1 and i1
  24. have the same the name (after normalization).
  25. E1 and E3 should (attempt to) chain up through both I3 intermediates.
  26. """
  27. import os
  28. import sys
  29. sys.path += ['..']
  30. import gencerts
  31. def write_cert_to_file(cert, filename):
  32. gencerts.write_string_to_file(
  33. "Generated by %s.\n"
  34. "Refer to generator script docstring for details.\n%s" % (
  35. sys.argv[0], cert.get_cert_pem()),
  36. filename)
  37. # Self-signed root certificate
  38. root = gencerts.create_self_signed_root_certificate('Root')
  39. write_cert_to_file(root, 'root.pem')
  40. # Intermediate certificates
  41. i1_1 = gencerts.create_intermediate_certificate('I1', root)
  42. write_cert_to_file(i1_1, 'i1_1.pem')
  43. # same name (after normalization), different key
  44. i1_2 = gencerts.create_intermediate_certificate('i1', root)
  45. write_cert_to_file(i1_2, 'i1_2.pem')
  46. # different name
  47. i2 = gencerts.create_intermediate_certificate('I2', root)
  48. write_cert_to_file(i2, 'i2.pem')
  49. # Two intermediates with exactly the same name.
  50. i3_1 = gencerts.create_intermediate_certificate('I3', root)
  51. write_cert_to_file(i3_1, 'i3_1.pem')
  52. i3_2 = gencerts.create_intermediate_certificate('I3', root)
  53. write_cert_to_file(i3_2, 'i3_2.pem')
  54. # target certs
  55. c1 = gencerts.create_end_entity_certificate('C1', i1_1)
  56. write_cert_to_file(c1, 'c1.pem')
  57. c2 = gencerts.create_end_entity_certificate('C2', i1_2)
  58. write_cert_to_file(c2, 'c2.pem')
  59. d = gencerts.create_end_entity_certificate('D', i2)
  60. write_cert_to_file(d, 'd.pem')
  61. e1 = gencerts.create_end_entity_certificate('E1', i3_1)
  62. write_cert_to_file(e1, 'e1.pem')
  63. e2 = gencerts.create_end_entity_certificate('E2', i3_2)
  64. write_cert_to_file(e2, 'e2.pem')