Skip to content

Commit

Permalink
addressed review comments and hint to citation from zmap#795
Browse files Browse the repository at this point in the history
  • Loading branch information
mtgag committed Feb 29, 2024
1 parent ccfd13d commit 632fda5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
16 changes: 7 additions & 9 deletions v3/lints/cabf_smime_br/lint_single_email_subject_if_present.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func init() {
LintMetadata: lint.LintMetadata{
Name: "e_single_email_subject_if_present",
Description: "If present, the subject:emailAddress SHALL contain a single Mailbox Address",
Citation: "7.1.4.2.h",
Citation: "7.1.4.2.2.h",
Source: lint.CABFSMIMEBaselineRequirements,
EffectiveDate: util.CABF_SMIME_BRs_1_0_0_Date,
},
Lint: func() lint.LintInterface { return &singleEmailSubjectIfPresent{} },
Lint: NewSingleEmailSubjectIfPresent,
})
}

Expand All @@ -43,20 +43,18 @@ func NewSingleEmailSubjectIfPresent() lint.LintInterface {
}

func (l *singleEmailSubjectIfPresent) CheckApplies(c *x509.Certificate) bool {
return util.IsSubscriberCert(c) && c.Subject.EmailAddress != nil && util.IsSMIMEBRCertificate(c)
emailAddress := c.Subject.EmailAddress
return util.IsSubscriberCert(c) && emailAddress != nil && len(emailAddress) != 0 && util.IsSMIMEBRCertificate(c)
}

func (l *singleEmailSubjectIfPresent) Execute(c *x509.Certificate) *lint.LintResult {
for _, email := range c.Subject.EmailAddress {
_, err := mail.ParseAddress(email)
if err != nil {
if _, err := mail.ParseAddress(email); err != nil {
return &lint.LintResult{
Status: lint.Error,
Details: fmt.Sprintf("subject:emailAddress was present and contained an invalid email address (%s)", email),
LintMetadata: lint.LintMetadata{},
Status: lint.Error,
Details: fmt.Sprintf("subject:emailAddress was present and contained an invalid email address (%s)", email),
}
}
}

return &lint.LintResult{Status: lint.Pass}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ func TestSingleEmailSubjectIfPresent(t *testing.T) {
ExpectedResult lint.LintStatus
}{
{
Name: "Error - email address present in subjectDN with multiple values",
Name: "error - email address present in subjectDN with multiple values",
InputFilename: "smime/twoEmailAddressesInSubjectDN.pem",
ExpectedResult: lint.Error,
},
{
Name: "Error - email address present in subjectDN with one value",
Name: "pass - email address present in subjectDN with one value",
InputFilename: "smime/oneEmailAddressInSubjectDN.pem",
ExpectedResult: lint.Pass,
},
{
Name: "Error - no email address present in subjectDN",
Name: "na - no email address present in subjectDN",
InputFilename: "smime/noEmailAddressInSubjectDN.pem",
ExpectedResult: lint.NA,
},
Expand Down

0 comments on commit 632fda5

Please sign in to comment.