1#!/usr/bin/env python 2# Copyright 2016 The Chromium Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6"""Certificates for testing issuer lookup. 7 8 Root 9 /| | |\\ 10 / | | | \\ 11 / | | | \\ 12 / | | | \\ 13 / | | | \\ 14 v v v v v 15 I1_1 i1_2 I2 I3_1 I3_2 16 | | | | | 17 | | | | | 18 | | | | | 19 | | | | | 20 v v v | | 21 C1 C2 D E1 E2 22 23I1 (i1_1.pem) and i1 (i1_2.pem) have subjects that are equal after 24normalization. 25 26I3_1 and I3_2 have subjects that are exactly equal. 27 28C1 and C2 should (attempt to) chain up through both I1 and i1, since I1 and i1 29have the same the name (after normalization). 30 31E1 and E3 should (attempt to) chain up through both I3 intermediates. 32""" 33 34import os 35import sys 36sys.path += ['..'] 37 38import gencerts 39 40 41def write_cert_to_file(cert, filename): 42 gencerts.write_string_to_file( 43 "Generated by %s.\n" 44 "Refer to generator script docstring for details.\n%s" % ( 45 sys.argv[0], cert.get_cert_pem()), 46 filename) 47 48 49# Self-signed root certificate 50root = gencerts.create_self_signed_root_certificate('Root') 51write_cert_to_file(root, 'root.pem') 52 53 54# Intermediate certificates 55i1_1 = gencerts.create_intermediate_certificate('I1', root) 56write_cert_to_file(i1_1, 'i1_1.pem') 57 58# same name (after normalization), different key 59i1_2 = gencerts.create_intermediate_certificate('i1', root) 60write_cert_to_file(i1_2, 'i1_2.pem') 61 62# different name 63i2 = gencerts.create_intermediate_certificate('I2', root) 64write_cert_to_file(i2, 'i2.pem') 65 66# Two intermediates with exactly the same name. 67i3_1 = gencerts.create_intermediate_certificate('I3', root) 68write_cert_to_file(i3_1, 'i3_1.pem') 69i3_2 = gencerts.create_intermediate_certificate('I3', root) 70write_cert_to_file(i3_2, 'i3_2.pem') 71 72# target certs 73 74c1 = gencerts.create_end_entity_certificate('C1', i1_1) 75write_cert_to_file(c1, 'c1.pem') 76 77c2 = gencerts.create_end_entity_certificate('C2', i1_2) 78write_cert_to_file(c2, 'c2.pem') 79 80d = gencerts.create_end_entity_certificate('D', i2) 81write_cert_to_file(d, 'd.pem') 82 83e1 = gencerts.create_end_entity_certificate('E1', i3_1) 84write_cert_to_file(e1, 'e1.pem') 85 86e2 = gencerts.create_end_entity_certificate('E2', i3_2) 87write_cert_to_file(e2, 'e2.pem') 88 89