github.com/zmap/zlint@v1.1.0/lints/lint_ext_name_constraints_not_critical.go (about) 1 package lints 2 3 /* 4 * ZLint Copyright 2018 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 /************************************************************************ 18 Restrictions are defined in terms of permitted or excluded name 19 subtrees. Any name matching a restriction in the excludedSubtrees 20 field is invalid regardless of information appearing in the 21 permittedSubtrees. Conforming CAs MUST mark this extension as 22 critical and SHOULD NOT impose name constraints on the x400Address, 23 ediPartyName, or registeredID name forms. Conforming CAs MUST NOT 24 issue certificates where name constraints is an empty sequence. That 25 is, either the permittedSubtrees field or the excludedSubtrees MUST 26 be present. 27 ************************************************************************/ 28 29 import ( 30 "github.com/zmap/zcrypto/x509" 31 "github.com/zmap/zlint/util" 32 ) 33 34 type nameConstraintCrit struct{} 35 36 func (l *nameConstraintCrit) Initialize() error { 37 return nil 38 } 39 40 func (l *nameConstraintCrit) CheckApplies(c *x509.Certificate) bool { 41 return util.IsExtInCert(c, util.NameConstOID) 42 } 43 44 func (l *nameConstraintCrit) Execute(c *x509.Certificate) *LintResult { 45 e := util.GetExtFromCert(c, util.NameConstOID) 46 if e.Critical { 47 return &LintResult{Status: Pass} 48 } else { 49 return &LintResult{Status: Error} 50 } 51 } 52 53 func init() { 54 RegisterLint(&Lint{ 55 Name: "e_ext_name_constraints_not_critical", 56 Description: "If it is included, conforming CAs MUST mark the name constrains extension as critical", 57 Citation: "RFC 5280: 4.2.1.10", 58 Source: RFC5280, 59 EffectiveDate: util.RFC2459Date, 60 Lint: &nameConstraintCrit{}, 61 }) 62 }