Debian Codegraph @

v3/lints/rfc/lint_name_constraint_maximum_not_absent.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 nameConstraintMax struct{}
24
25 /************************************************************************
26 RFC 5280: 4.2.1.10
27 Within this profile, the minimum and maximum fields are not used with
28 any name forms, thus, the minimum MUST be zero, and maximum MUST be
29 absent. However, if an application encounters a critical name
30 constraints extension that specifies other values for minimum or
31 maximum for a name form that appears in a subsequent certificate, the
32 application MUST either process these fields or reject the
33 certificate.
34 ************************************************************************/
35
36 func init() {
37 lint.RegisterCertificateLint(&lint.CertificateLint{
38 LintMetadata: lint.LintMetadata{
39 Name: "e_name_constraint_maximum_not_absent",
40 Description: "Within the name constraints name form, the maximum field is not used and therefore MUST be absent",
41 Citation: "RFC 5280: 4.2.1.10",
42 Source: lint.RFC5280,
43 EffectiveDate: util.RFC2459Date,
44 },
45 Lint: NewNameConstraintMax,
46 })
47 }
48
49 func NewNameConstraintMax() lint.LintInterface {
50 return &nameConstraintMax{}
51 }
52
53 func (l *nameConstraintMax) CheckApplies(c *x509.Certificate) bool {
54 return util.IsExtInCert(c, util.NameConstOID)
55 }
56
57 //nolint:gocyclo
58 func (l *nameConstraintMax) Execute(c *x509.Certificate) *lint.LintResult {
59 for _, i := range c.PermittedDNSNames {
60 if i.Max != 0 {
61 return &lint.LintResult{Status: lint.Error}
62 }
63 }
64 for _, i := range c.ExcludedDNSNames {
65 if i.Max != 0 {
66 return &lint.LintResult{Status: lint.Error}
67 }
68 }
69 for _, i := range c.PermittedDNSNames {
70 if i.Max != 0 {
71 return &lint.LintResult{Status: lint.Error}
72 }
73 }
74 for _, i := range c.ExcludedEmailAddresses {
75 if i.Max != 0 {
76 return &lint.LintResult{Status: lint.Error}
77 }
78 }
79 for _, i := range c.PermittedIPAddresses {
80 if i.Max != 0 {
81 return &lint.LintResult{Status: lint.Error}
82 }
83 }
84 for _, i := range c.ExcludedIPAddresses {
85 if i.Max != 0 {
86 return &lint.LintResult{Status: lint.Error}
87 }
88 }
89 for _, i := range c.PermittedDirectoryNames {
90 if i.Max != 0 {
91 return &lint.LintResult{Status: lint.Error}
92 }
93 }
94 for _, i := range c.ExcludedDirectoryNames {
95 if i.Max != 0 {
96 return &lint.LintResult{Status: lint.Error}
97 }
98 }
99 for _, i := range c.PermittedEdiPartyNames {
100 if i.Max != 0 {
101 return &lint.LintResult{Status: lint.Error}
102 }
103 }
104 for _, i := range c.ExcludedEdiPartyNames {
105 if i.Max != 0 {
106 return &lint.LintResult{Status: lint.Error}
107 }
108 }
109 for _, i := range c.PermittedRegisteredIDs {
110 if i.Max != 0 {
111 return &lint.LintResult{Status: lint.Error}
112 }
113 }
114 for _, i := range c.ExcludedRegisteredIDs {
115 if i.Max != 0 {
116 return &lint.LintResult{Status: lint.Error}
117 }
118 }
119 for _, i := range c.PermittedX400Addresses {
120 if i.Max != 0 {
121 return &lint.LintResult{Status: lint.Error}
122 }
123 }
124 for _, i := range c.ExcludedX400Addresses {
125 if i.Max != 0 {
126 return &lint.LintResult{Status: lint.Error}
127 }
128 }
129 return &lint.LintResult{Status: lint.Pass}
130 }