github.com/zmap/zlint@v1.1.0/lints/lint_ext_cert_policy_explicit_text_not_nfc.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 When the UTF8String encoding is used, all character sequences SHOULD be 19 normalized according to Unicode normalization form C (NFC) [NFC]. 20 ************************************************/ 21 22 import ( 23 "github.com/zmap/zcrypto/x509" 24 "github.com/zmap/zlint/util" 25 "golang.org/x/text/unicode/norm" 26 ) 27 28 type ExtCertPolicyExplicitTextNotNFC struct{} 29 30 func (l *ExtCertPolicyExplicitTextNotNFC) Initialize() error { 31 return nil 32 } 33 34 func (l *ExtCertPolicyExplicitTextNotNFC) CheckApplies(c *x509.Certificate) bool { 35 for _, text := range c.ExplicitTexts { 36 if text != nil { 37 return true 38 } 39 } 40 return false 41 } 42 43 func (l *ExtCertPolicyExplicitTextNotNFC) Execute(c *x509.Certificate) *LintResult { 44 for _, firstLvl := range c.ExplicitTexts { 45 for _, text := range firstLvl { 46 if text.Tag == 12 || text.Tag == 30 { 47 if !norm.NFC.IsNormal(text.Bytes) { 48 return &LintResult{Status: Warn} 49 } 50 } 51 } 52 } 53 return &LintResult{Status: Pass} 54 } 55 56 func init() { 57 RegisterLint(&Lint{ 58 Name: "w_ext_cert_policy_explicit_text_not_nfc", 59 Description: "When utf8string or bmpstring encoding is used for explicitText field in certificate policy, it SHOULD be normalized by NFC format", 60 Citation: "RFC6181 3", 61 Source: RFC5280, 62 EffectiveDate: util.RFC6818Date, 63 Lint: &ExtCertPolicyExplicitTextNotNFC{}, 64 }) 65 }