| 1 |
package cabf_smime_br |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
import ( |
| 18 |
"fmt" |
| 19 |
|
| 20 |
"github.com/zmap/zcrypto/encoding/asn1" |
| 21 |
"github.com/zmap/zcrypto/x509" |
| 22 |
"github.com/zmap/zlint/v3/lint" |
| 23 |
"github.com/zmap/zlint/v3/util" |
| 24 |
) |
| 25 |
|
| 26 |
type keyIdentifier struct { |
| 27 |
KeyIdentifier asn1.RawValue `asn1:"optional,tag:0"` |
| 28 |
AuthorityCertIssuer asn1.RawValue `asn1:"optional,tag:1"` |
| 29 |
AuthorityCertSerialNumber asn1.RawValue `asn1:"optional,tag:2"` |
| 30 |
} |
| 31 |
|
| 32 |
type authorityKeyIdentifierCorrect struct{} |
| 33 |
|
| 34 |
func init() { |
| 35 |
lint.RegisterCertificateLint(&lint.CertificateLint{ |
| 36 |
LintMetadata: lint.LintMetadata{ |
| 37 |
Name: "e_authority_key_identifier_correct", |
| 38 |
Description: "authorityKeyIdentifier SHALL be present. This extension SHALL NOT be marked critical. The keyIdentifier field SHALL be present. authorityCertIssuer and authorityCertSerialNumber fields SHALL NOT be present.", |
| 39 |
Citation: "7.1.2.3.g", |
| 40 |
Source: lint.CABFSMIMEBaselineRequirements, |
| 41 |
EffectiveDate: util.CABF_SMIME_BRs_1_0_0_Date, |
| 42 |
}, |
| 43 |
Lint: NewAuthorityKeyIdentifierCorrect, |
| 44 |
}) |
| 45 |
} |
| 46 |
|
| 47 |
func NewAuthorityKeyIdentifierCorrect() lint.LintInterface { |
| 48 |
return &authorityKeyIdentifierCorrect{} |
| 49 |
} |
| 50 |
|
| 51 |
func (l *authorityKeyIdentifierCorrect) CheckApplies(c *x509.Certificate) bool { |
| 52 |
return util.IsSubscriberCert(c) && util.IsSMIMEBRCertificate(c) |
| 53 |
} |
| 54 |
|
| 55 |
func (l *authorityKeyIdentifierCorrect) Execute(c *x509.Certificate) *lint.LintResult { |
| 56 |
ext := util.GetExtFromCert(c, util.AuthkeyOID) |
| 57 |
if ext == nil { |
| 58 |
return &lint.LintResult{Status: lint.Error, Details: "missing authorityKeyIdentifier"} |
| 59 |
} |
| 60 |
if ext.Critical { |
| 61 |
return &lint.LintResult{Status: lint.Error, Details: "authorityKeyIdentifier is critical"} |
| 62 |
} |
| 63 |
|
| 64 |
var keyID keyIdentifier |
| 65 |
if _, err := asn1.Unmarshal(ext.Value, &keyID); err != nil { |
| 66 |
return &lint.LintResult{ |
| 67 |
Status: lint.Fatal, |
| 68 |
Details: fmt.Sprintf("error unmarshalling authority key identifier extension: %v", err), |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
hasKeyID := len(keyID.KeyIdentifier.Bytes) > 0 |
| 73 |
hasCertIssuer := len(keyID.AuthorityCertIssuer.Bytes) > 0 |
| 74 |
hasCertSerial := len(keyID.AuthorityCertSerialNumber.Bytes) > 0 |
| 75 |
if !hasKeyID { |
| 76 |
return &lint.LintResult{Status: lint.Error, Details: "keyIdentifier not present"} |
| 77 |
} |
| 78 |
if hasCertIssuer { |
| 79 |
return &lint.LintResult{Status: lint.Error, Details: "authorityCertIssuer is present"} |
| 80 |
} |
| 81 |
if hasCertSerial { |
| 82 |
return &lint.LintResult{Status: lint.Error, Details: "authorityCertSerialNumber is present"} |
| 83 |
} |
| 84 |
return &lint.LintResult{Status: lint.Pass} |
| 85 |
} |