Debian Codegraph @

v3/lints/rfc/lint_ext_san_dns_not_ia5_string.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 SANDNSNotIA5String struct{}
24
25 /********************************************************************
26 RFC 5280: 4.2.1.6
27 When the subjectAltName extension contains a domain name system
28 label, the domain name MUST be stored in the dNSName (an IA5String).
29 The name MUST be in the "preferred name syntax", as specified by
30 Section 3.5 of [RFC1034] and as modified by Section 2.1 of
31 [RFC1123]. Note that while uppercase and lowercase letters are
32 allowed in domain names, no significance is attached to the case. In
33 addition, while the string " " is a legal domain name, subjectAltName
34 extensions with a dNSName of " " MUST NOT be used. Finally, the use
35 of the DNS representation for Internet mail addresses
36 (subscriber.example.com instead of [email protected]) MUST NOT
37 be used; such identities are to be encoded as rfc822Name. Rules for
38 encoding internationalized domain names are specified in Section 7.2.
39 ********************************************************************/
40
41 func init() {
42 lint.RegisterCertificateLint(&lint.CertificateLint{
43 LintMetadata: lint.LintMetadata{
44 Name: "e_ext_san_dns_not_ia5_string",
45 Description: "dNSNames MUST be IA5 strings",
46 Citation: "RFC 5280: 4.2.1.6",
47 Source: lint.RFC5280,
48 EffectiveDate: util.RFC2459Date,
49 },
50 Lint: NewSANDNSNotIA5String,
51 })
52 }
53
54 func NewSANDNSNotIA5String() lint.LintInterface {
55 return &SANDNSNotIA5String{}
56 }
57
58 func (l *SANDNSNotIA5String) CheckApplies(c *x509.Certificate) bool {
59 return util.IsExtInCert(c, util.SubjectAlternateNameOID)
60 }
61
62 func (l *SANDNSNotIA5String) Execute(c *x509.Certificate) *lint.LintResult {
63 ext := util.GetExtFromCert(c, util.SubjectAlternateNameOID)
64 if ext == nil {
65 return &lint.LintResult{Status: lint.Fatal}
66 }
67 ok, err := util.AllAlternateNameWithTagAreIA5(ext, util.DNSNameTag)
68 if err != nil {
69 return &lint.LintResult{Status: lint.Fatal}
70 }
71 if ok {
72 return &lint.LintResult{Status: lint.Pass}
73 } else {
74 return &lint.LintResult{Status: lint.Error}
75 }
76 }