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