Debian Codegraph @

v3/lints/cabf_smime_br/lint_single_email_if_present.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 cabf_smime_br
16
17 import (
18 "fmt"
19 "net/mail"
20
21 "github.com/zmap/zcrypto/x509"
22 "github.com/zmap/zlint/v3/lint"
23 "github.com/zmap/zlint/v3/util"
24 )
25
26 /*************************************************************************
27 7.1.4.2.1 Subject alternative name extension
28
29 All Mailbox Addresses in the subject field or entries of type dirName of this extension SHALL be
30 repeated as rfc822Name or otherName values of type id-on-SmtpUTF8Mailbox in this
31 extension.
32
33 7.1.4.2.2 Subject distinguished name fields
34
35 h. Certificate Field: subject:emailAddress (1.2.840.113549.1.9.1) Contents: If present, the
36 subject:emailAddress SHALL contain a single Mailbox Address as verified under
37 Section 3.2.2.
38
39 Combining these requirements, this lint checks for malformed email addresses in SAN entries
40 covering the case of a non-single Mailbox Address.
41 *************************************************************************/
42
43 func init() {
44 lint.RegisterCertificateLint(&lint.CertificateLint{
45 LintMetadata: lint.LintMetadata{
46 Name: "e_single_email_if_present",
47 Description: "If present, the subject:emailAddress SHALL contain a single Mailbox Address. All Mailbox Addresses in the subject field SHALL be repeated as rfc822Name or otherName values of type id-on-SmtpUTF8Mailbox in SAN extension.",
48 Citation: "7.1.4.2.1 and 7.1.4.2.2.h",
49 Source: lint.CABFSMIMEBaselineRequirements,
50 EffectiveDate: util.CABF_SMIME_BRs_1_0_0_Date,
51 },
52 Lint: NewSingleEmailIfPresent,
53 })
54 }
55
56 type singleEmailIfPresent struct{}
57
58 func NewSingleEmailIfPresent() lint.LintInterface {
59 return &singleEmailIfPresent{}
60 }
61
62 func (l *singleEmailIfPresent) CheckApplies(c *x509.Certificate) bool {
63 addresses := c.EmailAddresses
64 return util.IsSubscriberCert(c) && addresses != nil && len(addresses) != 0 && util.IsSMIMEBRCertificate(c)
65 }
66
67 func (l *singleEmailIfPresent) Execute(c *x509.Certificate) *lint.LintResult {
68 for _, email := range c.EmailAddresses {
69 if _, err := mail.ParseAddress(email); err != nil {
70 return &lint.LintResult{
71 Status: lint.Error,
72 Details: fmt.Sprintf("san:emailAddress was present and contained an invalid email address (%s)", email),
73 }
74 }
75 }
76 return &lint.LintResult{Status: lint.Pass}
77 }