github.com/zmap/zlint@v1.1.0/lints/lint_cert_unique_identifier_version_not_2_or_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 RFC 5280: 4.1.2.8 19 These fields MUST only appear if the version is 2 or 3 (Section 4.1.2.1). 20 These fields MUST NOT appear if the version is 1. The subject and issuer 21 unique identifiers are present in the certificate to handle the possibility 22 of reuse of subject and/or issuer names over time. This profile RECOMMENDS 23 that names not be reused for different entities and that Internet certificates 24 not make use of unique identifiers. CAs conforming to this profile MUST NOT 25 generate certificates with unique identifiers. Applications conforming to 26 this profile SHOULD be capable of parsing certificates that include unique 27 identifiers, but there are no processing requirements associated with the 28 unique identifiers. 29 ****************************************************************************/ 30 31 import ( 32 "github.com/zmap/zcrypto/x509" 33 "github.com/zmap/zlint/util" 34 ) 35 36 type certUniqueIdVersion struct{} 37 38 func (l *certUniqueIdVersion) Initialize() error { 39 return nil 40 } 41 42 func (l *certUniqueIdVersion) CheckApplies(c *x509.Certificate) bool { 43 return c.IssuerUniqueId.Bytes != nil || c.SubjectUniqueId.Bytes != nil 44 } 45 46 func (l *certUniqueIdVersion) Execute(c *x509.Certificate) *LintResult { 47 if (c.Version) != 2 && (c.Version) != 3 { 48 return &LintResult{Status: Error} 49 } else { 50 return &LintResult{Status: Pass} 51 } 52 } 53 54 func init() { 55 RegisterLint(&Lint{ 56 Name: "e_cert_unique_identifier_version_not_2_or_3", 57 Description: "Unique identifiers MUST only appear if the X.509 version is 2 or 3", 58 Citation: "RFC 5280: 4.1.2.8", 59 Source: RFC5280, 60 EffectiveDate: util.RFC5280Date, 61 Lint: &certUniqueIdVersion{}, 62 }) 63 }