github.com/zmap/zlint@v1.1.0/lints/lint_ca_subject_field_empty.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.6 19 The subject field identifies the entity associated with the public 20 key stored in the subject public key field. The subject name MAY be 21 carried in the subject field and/or the subjectAltName extension. If 22 the subject is a CA (e.g., the basic constraints extension, as 23 discussed in Section 4.2.1.9, is present and the value of cA is 24 TRUE), then the subject field MUST be populated with a non-empty 25 distinguished name matching the contents of the issuer field (Section 26 4.1.2.4) in all certificates issued by the subject CA. 27 ************************************************/ 28 29 import ( 30 "github.com/zmap/zcrypto/x509" 31 "github.com/zmap/zlint/util" 32 ) 33 34 type caSubjectEmpty struct{} 35 36 func (l *caSubjectEmpty) Initialize() error { 37 return nil 38 } 39 40 func (l *caSubjectEmpty) CheckApplies(c *x509.Certificate) bool { 41 return c.IsCA 42 } 43 44 func (l *caSubjectEmpty) Execute(c *x509.Certificate) *LintResult { 45 if &c.Subject != nil && util.NotAllNameFieldsAreEmpty(&c.Subject) { 46 return &LintResult{Status: Pass} 47 } else { 48 return &LintResult{Status: Error} 49 } 50 } 51 52 func init() { 53 RegisterLint(&Lint{ 54 Name: "e_ca_subject_field_empty", 55 Description: "CA Certificates subject field MUST not be empty and MUST have a non-empty distingushed name", 56 Citation: "RFC 5280: 4.1.2.6", 57 Source: RFC5280, 58 EffectiveDate: util.RFC2459Date, 59 Lint: &caSubjectEmpty{}, 60 }) 61 }