1#!/usr/bin/env python3 2# Copyright 2023 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"""Certificate chain with inhibitPolicyMapping=0 on the root, and an 6intermediate that uses policy mappings. Should fail if the policyConstraints on 7the root are enforced.""" 8 9import sys 10sys.path += ['../..'] 11 12import gencerts 13 14# Self-signed root certificate. 15root = gencerts.create_self_signed_root_certificate('Root') 16root.get_extensions().set_property('policyConstraints', 17 'critical,inhibitPolicyMapping:0') 18 19# Intermediate certificate. 20intermediate = gencerts.create_intermediate_certificate('Intermediate', root) 21intermediate.get_extensions().set_property('policyConstraints', 22 'critical,requireExplicitPolicy:0') 23 24intermediate.get_extensions().set_property('certificatePolicies', 25 'critical,1.2.3.4') 26 27intermediate.get_extensions().set_property('policyMappings', 28 'critical,@policy_mappings') 29policy_mappings = intermediate.config.get_section('policy_mappings') 30policy_mappings.set_property('1.2.3.4', '1.2.3.5') 31 32# Target certificate. 33target = gencerts.create_end_entity_certificate('Target', intermediate) 34target.get_extensions().set_property('certificatePolicies', 'critical,1.2.3.5') 35 36chain = [target, intermediate, root] 37gencerts.write_chain(__doc__, chain, 'chain.pem') 38