1#!/usr/bin/env python 2# Copyright 2016 The Chromium Authors 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# https://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16"""Certificates for testing issuer lookup. 17 18 Root 19 /| | |\\ 20 / | | | \\ 21 / | | | \\ 22 / | | | \\ 23 / | | | \\ 24 v v v v v 25 I1_1 i1_2 I2 I3_1 I3_2 26 | | | | | 27 | | | | | 28 | | | | | 29 | | | | | 30 v v v | | 31 C1 C2 D E1 E2 32 33I1 (i1_1.pem) and i1 (i1_2.pem) have subjects that are equal after 34normalization. 35 36I3_1 and I3_2 have subjects that are exactly equal. 37 38C1 and C2 should (attempt to) chain up through both I1 and i1, since I1 and i1 39have the same the name (after normalization). 40 41E1 and E3 should (attempt to) chain up through both I3 intermediates. 42""" 43 44import os 45import sys 46sys.path += ['..'] 47 48import gencerts 49 50 51def write_cert_to_file(cert, filename): 52 gencerts.write_string_to_file( 53 "Generated by %s.\n" 54 "Refer to generator script docstring for details.\n%s" % ( 55 sys.argv[0], cert.get_cert_pem()), 56 filename) 57 58 59# Self-signed root certificate 60root = gencerts.create_self_signed_root_certificate('Root') 61write_cert_to_file(root, 'root.pem') 62 63 64# Intermediate certificates 65i1_1 = gencerts.create_intermediate_certificate('I1', root) 66write_cert_to_file(i1_1, 'i1_1.pem') 67 68# same name (after normalization), different key 69i1_2 = gencerts.create_intermediate_certificate('i1', root) 70write_cert_to_file(i1_2, 'i1_2.pem') 71 72# different name 73i2 = gencerts.create_intermediate_certificate('I2', root) 74write_cert_to_file(i2, 'i2.pem') 75 76# Two intermediates with exactly the same name. 77i3_1 = gencerts.create_intermediate_certificate('I3', root) 78write_cert_to_file(i3_1, 'i3_1.pem') 79i3_2 = gencerts.create_intermediate_certificate('I3', root) 80write_cert_to_file(i3_2, 'i3_2.pem') 81 82# target certs 83 84c1 = gencerts.create_end_entity_certificate('C1', i1_1) 85write_cert_to_file(c1, 'c1.pem') 86 87c2 = gencerts.create_end_entity_certificate('C2', i1_2) 88write_cert_to_file(c2, 'c2.pem') 89 90d = gencerts.create_end_entity_certificate('D', i2) 91write_cert_to_file(d, 'd.pem') 92 93e1 = gencerts.create_end_entity_certificate('E1', i3_1) 94write_cert_to_file(e1, 'e1.pem') 95 96e2 = gencerts.create_end_entity_certificate('E2', i3_2) 97write_cert_to_file(e2, 'e2.pem') 98 99