Debian Codegraph @

v3/lints/community/lint_san_dns_name_duplicate.go

raw symbols SCIP
1 /*
2 * ZLint Copyright 2024 Regents of the University of Michigan
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy
6 * of the License at http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11 * implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15 package community
16
17 import (
18 "strings"
19
20 "github.com/zmap/zcrypto/x509"
21 "github.com/zmap/zlint/v3/lint"
22 "github.com/zmap/zlint/v3/util"
23 )
24
25 type SANDNSDuplicate struct{}
26
27 func init() {
28 lint.RegisterCertificateLint(&lint.CertificateLint{
29 LintMetadata: lint.LintMetadata{
30 Name: "n_san_dns_name_duplicate",
31 Description: "SAN DNSName contains duplicate values",
32 Citation: "awslabs certlint",
33 Source: lint.Community,
34 EffectiveDate: util.ZeroDate,
35 },
36 Lint: NewSANDNSDuplicate,
37 })
38 }
39
40 func NewSANDNSDuplicate() lint.LintInterface {
41 return &SANDNSDuplicate{}
42 }
43
44 func (l *SANDNSDuplicate) CheckApplies(c *x509.Certificate) bool {
45 return util.IsExtInCert(c, util.SubjectAlternateNameOID)
46 }
47
48 func (l *SANDNSDuplicate) Execute(c *x509.Certificate) *lint.LintResult {
49 checkedDNSNames := map[string]struct{}{}
50 for _, dns := range c.DNSNames {
51 normalizedDNSName := strings.ToLower(dns)
52 if _, isPresent := checkedDNSNames[normalizedDNSName]; isPresent {
53 return &lint.LintResult{Status: lint.Notice}
54 }
55
56 checkedDNSNames[normalizedDNSName] = struct{}{}
57 }
58
59 return &lint.LintResult{Status: lint.Pass}
60 }