| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 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 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 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 |
} |