| 1 |
package rfc |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
import ( |
| 18 |
"github.com/zmap/zcrypto/encoding/asn1" |
| 19 |
"github.com/zmap/zcrypto/x509" |
| 20 |
"github.com/zmap/zlint/v3/lint" |
| 21 |
"github.com/zmap/zlint/v3/util" |
| 22 |
) |
| 23 |
|
| 24 |
type pathLenIncluded struct{} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
func init() { |
| 34 |
lint.RegisterCertificateLint(&lint.CertificateLint{ |
| 35 |
LintMetadata: lint.LintMetadata{ |
| 36 |
Name: "e_path_len_constraint_improperly_included", |
| 37 |
Description: "CAs MUST NOT include the pathLenConstraint field unless the CA boolean is asserted and the keyCertSign bit is set", |
| 38 |
Citation: "RFC 5280: 4.2.1.9", |
| 39 |
Source: lint.RFC5280, |
| 40 |
EffectiveDate: util.RFC3280Date, |
| 41 |
}, |
| 42 |
Lint: NewPathLenIncluded, |
| 43 |
}) |
| 44 |
} |
| 45 |
|
| 46 |
func NewPathLenIncluded() lint.LintInterface { |
| 47 |
return &pathLenIncluded{} |
| 48 |
} |
| 49 |
|
| 50 |
func (l *pathLenIncluded) CheckApplies(cert *x509.Certificate) bool { |
| 51 |
return util.IsExtInCert(cert, util.BasicConstOID) |
| 52 |
} |
| 53 |
|
| 54 |
func (l *pathLenIncluded) Execute(cert *x509.Certificate) *lint.LintResult { |
| 55 |
bc := util.GetExtFromCert(cert, util.BasicConstOID) |
| 56 |
var seq asn1.RawValue |
| 57 |
var isCa bool |
| 58 |
_, err := asn1.Unmarshal(bc.Value, &seq) |
| 59 |
if err != nil { |
| 60 |
return &lint.LintResult{Status: lint.Fatal} |
| 61 |
} |
| 62 |
if len(seq.Bytes) == 0 { |
| 63 |
return &lint.LintResult{Status: lint.Pass} |
| 64 |
} |
| 65 |
rest, err := asn1.UnmarshalWithParams(seq.Bytes, &isCa, "optional") |
| 66 |
if err != nil { |
| 67 |
return &lint.LintResult{Status: lint.Fatal} |
| 68 |
} |
| 69 |
keyUsageValue := util.IsExtInCert(cert, util.KeyUsageOID) |
| 70 |
if len(rest) > 0 && (!cert.IsCA || !keyUsageValue || (keyUsageValue && cert.KeyUsage&x509.KeyUsageCertSign == 0)) { |
| 71 |
return &lint.LintResult{Status: lint.Error} |
| 72 |
} |
| 73 |
return &lint.LintResult{Status: lint.Pass} |
| 74 |
} |