github.com/zmap/zlint@v1.1.0/lints/lint_san_dns_name_duplicate.go (about) 1 /* 2 * ZLint Copyright 2017 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 lints 16 17 import ( 18 "strings" 19 20 "github.com/zmap/zcrypto/x509" 21 "github.com/zmap/zlint/util" 22 ) 23 24 type SANDNSDuplicate struct{} 25 26 func (l *SANDNSDuplicate) Initialize() error { 27 return nil 28 } 29 30 func (l *SANDNSDuplicate) CheckApplies(c *x509.Certificate) bool { 31 return util.IsExtInCert(c, util.SubjectAlternateNameOID) 32 } 33 34 func (l *SANDNSDuplicate) Execute(c *x509.Certificate) *LintResult { 35 checkedDNSNames := map[string]struct{}{} 36 for _, dns := range c.DNSNames { 37 normalizedDNSName := strings.ToLower(dns) 38 if _, isPresent := checkedDNSNames[normalizedDNSName]; isPresent { 39 return &LintResult{Status: Notice} 40 } 41 42 checkedDNSNames[normalizedDNSName] = struct{}{} 43 } 44 45 return &LintResult{Status: Pass} 46 } 47 48 func init() { 49 RegisterLint(&Lint{ 50 Name: "n_san_dns_name_duplicate", 51 Description: "SAN DNSName contains duplicate values", 52 Citation: "awslabs certlint", 53 Source: AWSLabs, 54 EffectiveDate: util.ZeroDate, 55 Lint: &SANDNSDuplicate{}, 56 }) 57 }