| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 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 |
} |