|
| 1 | +package cabf_smime_br |
| 2 | + |
| 3 | +/* |
| 4 | + * ZLint Copyright 2021 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 | + "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 | +// mailboxValidatedEnforceSubjectFieldRestrictions - linter to enforce MAY/SHALL NOT requirements for mailbox validated SMIME certificates |
| 26 | +type mailboxValidatedEnforceSubjectFieldRestrictions struct { |
| 27 | + forbiddenSubjectFields map[string]string |
| 28 | + allowedSubjectFields map[string]string |
| 29 | +} |
| 30 | + |
| 31 | +func init() { |
| 32 | + lint.RegisterCertificateLint(&lint.CertificateLint{ |
| 33 | + LintMetadata: lint.LintMetadata{ |
| 34 | + Name: "e_mailbox_validated_enforce_subject_field_restrictions", |
| 35 | + Description: "SMIME certificates complying to mailbox validated profiles MAY only contain commonName, serialNumber or emailAddress attributes in the Subject DN", |
| 36 | + Citation: "SMIME BRs: 7.1.4.2.3", |
| 37 | + Source: lint.CABFSMIMEBaselineRequirements, |
| 38 | + EffectiveDate: util.CABF_SMIME_BRs_1_0_0_Date, |
| 39 | + }, |
| 40 | + Lint: func() lint.CertificateLintInterface { |
| 41 | + return NewMailboxValidatedEnforceSubjectFieldRestrictions() |
| 42 | + }, |
| 43 | + }) |
| 44 | +} |
| 45 | + |
| 46 | +// NewMailboxValidatedEnforceSubjectFieldRestrictions creates a new linter to enforce MAY/SHALL NOT field requirements for mailbox validated SMIME certs |
| 47 | +func NewMailboxValidatedEnforceSubjectFieldRestrictions() lint.LintInterface { |
| 48 | + return &mailboxValidatedEnforceSubjectFieldRestrictions{ |
| 49 | + forbiddenSubjectFields: map[string]string{ |
| 50 | + "0.9.2342.19200300.100.1.25": "subject:domainComponent", |
| 51 | + "1.3.6.1.4.1.311.60.2.1.1": "subject:jurisdictionLocality", |
| 52 | + "1.3.6.1.4.1.311.60.2.1.2": "subject:jurisdictionProvince", |
| 53 | + "1.3.6.1.4.1.311.60.2.1.3": "subject:jurisdictionCountry", |
| 54 | + "2.5.4.4": "subject:surname", |
| 55 | + "2.5.4.6": "subject:countryName", |
| 56 | + "2.5.4.7": "subject:localityName", |
| 57 | + "2.5.4.8": "subject:stateOrProvinceName", |
| 58 | + "2.5.4.9": "subject:streetAddress", |
| 59 | + "2.5.4.10": "subject:organizationName", |
| 60 | + "2.5.4.11": "subject:organizationalUnitName", |
| 61 | + "2.5.4.12": "subject:title", |
| 62 | + "2.5.4.17": "subject:postalCode", |
| 63 | + "2.5.4.42": "subject:givenName", |
| 64 | + "2.5.4.65": "subject:pseudonym", |
| 65 | + "2.5.4.97": "subject:organizationIdentifier", |
| 66 | + }, |
| 67 | + allowedSubjectFields: map[string]string{ |
| 68 | + "1.2.840.113549.1.9.1": "subject:emailAddress", |
| 69 | + "2.5.4.3": "subject:commonName", |
| 70 | + "2.5.4.5": "subject:serialNumber", |
| 71 | + }, |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +// CheckApplies returns true if the provided certificate contains one-or-more of the following SMIME BR policy identifiers: |
| 76 | +// - Mailbox Validated Legacy |
| 77 | +// - Mailbox Validated Multipurpose |
| 78 | +// - Mailbox Validated Strict |
| 79 | +func (l *mailboxValidatedEnforceSubjectFieldRestrictions) CheckApplies(c *x509.Certificate) bool { |
| 80 | + return util.IsMailboxValidatedCertificate(c) |
| 81 | +} |
| 82 | + |
| 83 | +// Execute applies the requirements on what fields are allowed for mailbox validated SMIME certificates |
| 84 | +func (l *mailboxValidatedEnforceSubjectFieldRestrictions) Execute(c *x509.Certificate) *lint.LintResult { |
| 85 | + for _, rdnSeq := range c.Subject.OriginalRDNS { |
| 86 | + for _, field := range rdnSeq { |
| 87 | + oidStr := field.Type.String() |
| 88 | + |
| 89 | + if _, ok := l.allowedSubjectFields[oidStr]; !ok { |
| 90 | + if fieldName, knownField := l.forbiddenSubjectFields[oidStr]; knownField { |
| 91 | + return &lint.LintResult{Status: lint.Error, Details: fmt.Sprintf("subject DN contains forbidden field: %s (%s)", fieldName, oidStr)} |
| 92 | + } |
| 93 | + return &lint.LintResult{Status: lint.Error, Details: fmt.Sprintf("subject DN contains forbidden field: %s", oidStr)} |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + return &lint.LintResult{Status: lint.Pass} |
| 99 | +} |
0 commit comments