github.com/zmap/zlint@v1.1.0/lints/lint_ext_cert_policy_explicit_text_not_utf8.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 An explicitText field includes the textual statement directly in 19 the certificate. The explicitText field is a string with a 20 maximum size of 200 characters. Conforming CAs SHOULD use the 21 UTF8String encoding for explicitText. VisibleString or BMPString 22 are acceptable but less preferred alternatives. Conforming CAs 23 MUST NOT encode explicitText as IA5String. The explicitText string 24 SHOULD NOT include any control characters (e.g., U+0000 to U+001F 25 and U+007F to U+009F). When the UTF8String or BMPString encoding 26 is used, all character sequences SHOULD be normalized according 27 to Unicode normalization form C (NFC) [NFC]. 28 *******************************************************************/ 29 30 import ( 31 "github.com/zmap/zcrypto/x509" 32 "github.com/zmap/zlint/util" 33 ) 34 35 type explicitTextUtf8 struct{} 36 37 func (l *explicitTextUtf8) Initialize() error { 38 return nil 39 } 40 41 func (l *explicitTextUtf8) CheckApplies(c *x509.Certificate) bool { 42 for _, text := range c.ExplicitTexts { 43 if text != nil { 44 return true 45 } 46 } 47 return false 48 } 49 50 func (l *explicitTextUtf8) Execute(c *x509.Certificate) *LintResult { 51 for _, firstLvl := range c.ExplicitTexts { 52 for _, text := range firstLvl { 53 if text.Tag != 12 { 54 return &LintResult{Status: Warn} 55 } 56 } 57 } 58 return &LintResult{Status: Pass} 59 } 60 61 func init() { 62 RegisterLint(&Lint{ 63 Name: "w_ext_cert_policy_explicit_text_not_utf8", 64 Description: "Compliant certificates should use the utf8string encoding for explicitText", 65 Citation: "RFC 6818: 3", 66 Source: RFC5280, 67 EffectiveDate: util.RFC6818Date, 68 Lint: &explicitTextUtf8{}, 69 }) 70 }