github.com/zmap/zlint@v1.1.0/lints/lint_qcstatem_qctype_web.go (about)

     1  /*
     2   * ZLint Copyright 2017 Regents of the University of Michigan
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
     5   * use this file except in compliance with the License. You may obtain a copy
     6   * of the License at http://www.apache.org/licenses/LICENSE-2.0
     7   *
     8   * Unless required by applicable law or agreed to in writing, software
     9   * distributed under the License is distributed on an "AS IS" BASIS,
    10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    11   * implied. See the License for the specific language governing
    12   * permissions and limitations under the License.
    13   */
    14  
    15  package lints
    16  
    17  import (
    18  	"encoding/asn1"
    19  	"fmt"
    20  	"github.com/zmap/zcrypto/x509"
    21  	"github.com/zmap/zlint/util"
    22  )
    23  
    24  type qcStatemQctypeWeb struct{}
    25  
    26  func (this *qcStatemQctypeWeb) getStatementOid() *asn1.ObjectIdentifier {
    27  	return &util.IdEtsiQcsQcType
    28  }
    29  
    30  func (l *qcStatemQctypeWeb) Initialize() error {
    31  	return nil
    32  }
    33  
    34  func (l *qcStatemQctypeWeb) CheckApplies(c *x509.Certificate) bool {
    35  	if !util.IsExtInCert(c, util.QcStateOid) {
    36  		return false
    37  	}
    38  	if util.ParseQcStatem(util.GetExtFromCert(c, util.QcStateOid).Value, *l.getStatementOid()).IsPresent() {
    39  		return true
    40  	}
    41  	return false
    42  }
    43  
    44  func (l *qcStatemQctypeWeb) Execute(c *x509.Certificate) *LintResult {
    45  
    46  	errString := ""
    47  	wrnString := ""
    48  	ext := util.GetExtFromCert(c, util.QcStateOid)
    49  	s := util.ParseQcStatem(ext.Value, *l.getStatementOid())
    50  	errString += s.GetErrorInfo()
    51  	if len(errString) == 0 {
    52  		qcType := s.(util.Etsi423QcType)
    53  		if len(qcType.TypeOids) == 0 {
    54  			errString += "no QcType present, sequence of OIDs is empty"
    55  		}
    56  		found := false
    57  		for _, t := range qcType.TypeOids {
    58  
    59  			if t.Equal(util.IdEtsiQcsQctWeb) {
    60  				found = true
    61  			}
    62  		}
    63  		if found != true {
    64  			wrnString += fmt.Sprintf("etsi Type does not indicate certificate as a 'web' certificate")
    65  
    66  		}
    67  	}
    68  
    69  	if len(errString) == 0 {
    70  		if len(wrnString) == 0 {
    71  			return &LintResult{Status: Pass}
    72  		} else {
    73  			return &LintResult{Status: Warn, Details: wrnString}
    74  		}
    75  	} else {
    76  		return &LintResult{Status: Error, Details: errString}
    77  	}
    78  }
    79  
    80  func init() {
    81  	RegisterLint(&Lint{
    82  		Name:          "w_qcstatem_qctype_web",
    83  		Description:   "Checks that a QC Statement of the type Id-etsi-qcs-QcType features features at least the type IdEtsiQcsQctWeb",
    84  		Citation:      "ETSI EN 319 412 - 5 V2.2.1 (2017 - 11) / Section 4.2.3",
    85  		Source:        EtsiEsi,
    86  		EffectiveDate: util.EtsiEn319_412_5_V2_2_1_Date,
    87  		Lint:          &qcStatemQctypeWeb{},
    88  	})
    89  }