Debian Codegraph @

v3/lints/rfc/lint_ext_policy_map_any_policy.go

raw symbols SCIP
1 package rfc
2
3 /*
4 * ZLint Copyright 2024 Regents of the University of Michigan
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 * use this file except in compliance with the License. You may obtain a copy
8 * of the License at http://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
13 * implied. See the License for the specific language governing
14 * permissions and limitations under the License.
15 */
16
17 import (
18 "github.com/zmap/zcrypto/x509"
19 "github.com/zmap/zlint/v3/lint"
20 "github.com/zmap/zlint/v3/util"
21 )
22
23 type policyMapAnyPolicy struct{}
24
25 /********************************************************************
26 RFC 5280: 4.2.1.5
27 Each issuerDomainPolicy named in the policy mappings extension SHOULD
28 also be asserted in a certificate policies extension in the same
29 certificate. Policies MUST NOT be mapped either to or from the
30 special value anyPolicy (Section 4.2.1.4).
31 ********************************************************************/
32
33 func init() {
34 lint.RegisterCertificateLint(&lint.CertificateLint{
35 LintMetadata: lint.LintMetadata{
36 Name: "e_ext_policy_map_any_policy",
37 Description: "Policies must not be mapped to or from the anyPolicy value",
38 Citation: "RFC 5280: 4.2.1.5",
39 Source: lint.RFC5280,
40 EffectiveDate: util.RFC3280Date,
41 },
42 Lint: NewPolicyMapAnyPolicy,
43 })
44 }
45
46 func NewPolicyMapAnyPolicy() lint.LintInterface {
47 return &policyMapAnyPolicy{}
48 }
49
50 func (l *policyMapAnyPolicy) CheckApplies(c *x509.Certificate) bool {
51 return util.IsExtInCert(c, util.PolicyMapOID)
52 }
53
54 func (l *policyMapAnyPolicy) Execute(c *x509.Certificate) *lint.LintResult {
55 extPolMap := util.GetExtFromCert(c, util.PolicyMapOID)
56 polMap, err := util.GetMappedPolicies(extPolMap)
57 if err != nil {
58 return &lint.LintResult{Status: lint.Fatal}
59 }
60
61 for _, pair := range polMap {
62 if util.AnyPolicyOID.Equal(pair[0]) || util.AnyPolicyOID.Equal(pair[1]) {
63 return &lint.LintResult{Status: lint.Error}
64 }
65 }
66 return &lint.LintResult{Status: lint.Pass}
67 }