|
| 1 | +/* |
| 2 | + * ZLint Copyright 2023 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 | + |
| 20 | + "github.com/zmap/zcrypto/x509" |
| 21 | + "github.com/zmap/zlint/v3/lint" |
| 22 | + "github.com/zmap/zlint/v3/util" |
| 23 | +) |
| 24 | + |
| 25 | +func init() { |
| 26 | + lint.RegisterLint(&lint.Lint{ |
| 27 | + Name: "e_single_email_if_present", |
| 28 | + Description: "If present, the subject:emailAddress SHALL contain a single Mailbox Address", |
| 29 | + Citation: "7.1.4.2.h", |
| 30 | + Source: lint.CABFSMIMEBaselineRequirements, |
| 31 | + EffectiveDate: util.CABF_SMIME_BRs_1_0_0_Date, |
| 32 | + Lint: func() lint.LintInterface { return &singleEmailIfPresent{} }, |
| 33 | + }) |
| 34 | +} |
| 35 | + |
| 36 | +type singleEmailIfPresent struct{} |
| 37 | + |
| 38 | +func NewSingleEmailIfPresent() lint.LintInterface { |
| 39 | + return &singleEmailIfPresent{} |
| 40 | +} |
| 41 | + |
| 42 | +func (l *singleEmailIfPresent) CheckApplies(c *x509.Certificate) bool { |
| 43 | + return util.IsSubscriberCert(c) && c.EmailAddresses != nil && len(c.EmailAddresses) != 0 |
| 44 | +} |
| 45 | + |
| 46 | +func (l *singleEmailIfPresent) Execute(c *x509.Certificate) *lint.LintResult { |
| 47 | + if len(c.EmailAddresses) == 1 { |
| 48 | + return &lint.LintResult{ |
| 49 | + Status: lint.Pass, |
| 50 | + } |
| 51 | + } else { |
| 52 | + return &lint.LintResult{ |
| 53 | + Status: lint.Error, |
| 54 | + Details: fmt.Sprintf("subject:emailAddress was present and containted %d names (%s)", len(c.EmailAddresses), c.EmailAddresses), |
| 55 | + LintMetadata: lint.LintMetadata{}, |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments