From aed197a99e17d2b388ca4959ba25fe467fd060d6 Mon Sep 17 00:00:00 2001 From: BJ Cardon Date: Thu, 28 Mar 2024 13:46:20 -0600 Subject: [PATCH 1/2] update subject_dn_not_printable_characters lint to handle BMPString appropriately --- .../rfc/lint_subject_dn_not_printable_characters.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/v3/lints/rfc/lint_subject_dn_not_printable_characters.go b/v3/lints/rfc/lint_subject_dn_not_printable_characters.go index d3a04187e..1da9365e8 100644 --- a/v3/lints/rfc/lint_subject_dn_not_printable_characters.go +++ b/v3/lints/rfc/lint_subject_dn_not_printable_characters.go @@ -15,8 +15,6 @@ package rfc import ( - "unicode/utf8" - "github.com/zmap/zcrypto/encoding/asn1" "github.com/zmap/zcrypto/x509" "github.com/zmap/zlint/v3/lint" @@ -59,15 +57,20 @@ func (l *subjectDNNotPrintableCharacters) Execute(c *x509.Certificate) *lint.Lin for _, attrTypeAndValueSet := range rdnSequence { for _, attrTypeAndValue := range attrTypeAndValueSet { bytes := attrTypeAndValue.Value.Bytes - for len(bytes) > 0 { - r, size := utf8.DecodeRune(bytes) + runes := []rune{} + if attrTypeAndValue.Value.Tag == tagBMPString { + runestr, _ := util.ParseBMPString(bytes) + runes = []rune(runestr) + } else { + runes = []rune(string(bytes)) + } + for _, r := range runes { if r < 0x20 { return &lint.LintResult{Status: lint.Error} } if r >= 0x7F && r <= 0x9F { return &lint.LintResult{Status: lint.Error} } - bytes = bytes[size:] } } } From 7d833aaa68f9dcc71d07c89e881aa3017e3a39f4 Mon Sep 17 00:00:00 2001 From: BJ Cardon Date: Thu, 28 Mar 2024 13:50:58 -0600 Subject: [PATCH 2/2] fix linting problem --- v3/lints/rfc/lint_subject_dn_not_printable_characters.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v3/lints/rfc/lint_subject_dn_not_printable_characters.go b/v3/lints/rfc/lint_subject_dn_not_printable_characters.go index 1da9365e8..6d151ddd4 100644 --- a/v3/lints/rfc/lint_subject_dn_not_printable_characters.go +++ b/v3/lints/rfc/lint_subject_dn_not_printable_characters.go @@ -57,7 +57,7 @@ func (l *subjectDNNotPrintableCharacters) Execute(c *x509.Certificate) *lint.Lin for _, attrTypeAndValueSet := range rdnSequence { for _, attrTypeAndValue := range attrTypeAndValueSet { bytes := attrTypeAndValue.Value.Bytes - runes := []rune{} + var runes []rune if attrTypeAndValue.Value.Tag == tagBMPString { runestr, _ := util.ParseBMPString(bytes) runes = []rune(runestr)