github.com/zmap/zlint@v1.1.0/lints/lint_cert_extensions_version_not_3.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  4.1.2.1.  Version
    19     This field describes the version of the encoded certificate. When
    20     extensions are used, as expected in this profile, version MUST be 3
    21     (value is 2). If no extensions are present, but a UniqueIdentifier
    22     is present, the version SHOULD be 2 (value is 1); however, the version
    23     MAY be 3.  If only basic fields are present, the version SHOULD be 1
    24     (the value is omitted from the certificate as the default value);
    25     however, the version MAY be 2 or 3.
    26  
    27     Implementations SHOULD be prepared to accept any version certificate.
    28     At a minimum, conforming implementations MUST recognize version 3 certificates.
    29  4.1.2.9.  Extensions
    30     This field MUST only appear if the version is 3 (Section 4.1.2.1).
    31     If present, this field is a SEQUENCE of one or more certificate
    32     extensions. The format and content of certificate extensions in the
    33     Internet PKI are defined in Section 4.2.
    34  ************************************************/
    35  
    36  import (
    37  	"github.com/zmap/zcrypto/x509"
    38  	"github.com/zmap/zlint/util"
    39  )
    40  
    41  type CertExtensionsVersonNot3 struct{}
    42  
    43  func (l *CertExtensionsVersonNot3) Initialize() error {
    44  	return nil
    45  }
    46  
    47  func (l *CertExtensionsVersonNot3) CheckApplies(cert *x509.Certificate) bool {
    48  	return true
    49  }
    50  
    51  func (l *CertExtensionsVersonNot3) Execute(cert *x509.Certificate) *LintResult {
    52  	if cert.Version != 3 && len(cert.Extensions) != 0 {
    53  		return &LintResult{Status: Error}
    54  	}
    55  	return &LintResult{Status: Pass}
    56  }
    57  
    58  func init() {
    59  	RegisterLint(&Lint{
    60  		Name:          "e_cert_extensions_version_not_3",
    61  		Description:   "The extensions field MUST only appear in version 3 certificates",
    62  		Citation:      "RFC 5280: 4.1.2.9",
    63  		Source:        RFC5280,
    64  		EffectiveDate: util.RFC2459Date,
    65  		Lint:          &CertExtensionsVersonNot3{},
    66  	})
    67  }