Debian Codegraph @

v3/lints/cabf_smime_br/lint_key_usage_criticality.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 "github.com/zmap/zcrypto/x509"
19 "github.com/zmap/zlint/v3/lint"
20 "github.com/zmap/zlint/v3/util"
21 )
22
23 func init() {
24 lint.RegisterCertificateLint(&lint.CertificateLint{
25 LintMetadata: lint.LintMetadata{
26 Name: "w_key_usage_criticality",
27 Description: "keyUsage... This extension SHOULD be marked critical",
28 Citation: "7.1.2.3.e",
29 Source: lint.CABFSMIMEBaselineRequirements,
30 EffectiveDate: util.CABF_SMIME_BRs_1_0_0_Date,
31 },
32 Lint: NewKeyUsageCriticality,
33 })
34 }
35
36 type keyUsageCriticality struct{}
37
38 func NewKeyUsageCriticality() lint.LintInterface {
39 return &keyUsageCriticality{}
40 }
41
42 func (l *keyUsageCriticality) CheckApplies(c *x509.Certificate) bool {
43 return util.IsSubscriberCert(c) && util.IsSMIMEBRCertificate(c) && util.IsExtInCert(c, util.KeyUsageOID)
44
45 }
46
47 func (l *keyUsageCriticality) Execute(c *x509.Certificate) *lint.LintResult {
48 kuExt := util.GetExtFromCert(c, util.KeyUsageOID)
49 if !kuExt.Critical {
50 return &lint.LintResult{Status: lint.Warn}
51 }
52
53 return &lint.LintResult{Status: lint.Pass}
54 }