Skip to content

Commit

Permalink
Correct lint attribution for dnsname_etc lints and limit scope to jus…
Browse files Browse the repository at this point in the history
…t DNS SAN entries (#609)

Adding an RFC5280 specific version that does not check for CommonName of the dnsname lints that are already present in CABF lints
  • Loading branch information
christopher-henderson committed Sep 26, 2021
1 parent 74dfff2 commit b4060ec
Show file tree
Hide file tree
Showing 11 changed files with 518 additions and 0 deletions.
9 changes: 9 additions & 0 deletions v3/integration/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@
"e_dnsname_empty_label": {
"ErrCount": 11
},
"e_rfc_dnsname_empty_label": {
"ErrCount": 10
},
"e_dnsname_hyphen_in_sld": {},
"e_dnsname_label_too_long": {},
"e_dnsname_left_label_wildcard_correct": {
Expand All @@ -317,6 +320,9 @@
"e_dnsname_underscore_in_sld": {
"ErrCount": 1
},
"e_rfc_dnsname_underscore_in_sld": {
"ErrCount": 1
},
"e_dnsname_wildcard_only_in_left_label": {},
"e_dsa_correct_order_in_subgroup": {},
"e_dsa_improper_modulus_or_divisor_size": {},
Expand Down Expand Up @@ -670,6 +676,9 @@
"w_dnsname_underscore_in_trd": {
"WarnCount": 339
},
"w_rfc_dnsname_underscore_in_trd": {
"WarnCount": 339
},
"w_eku_critical_improperly": {},
"w_ext_aia_access_location_missing": {
"WarnCount": 284
Expand Down
63 changes: 63 additions & 0 deletions v3/lints/rfc/lint_dnsname_contains_empty_label.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package rfc

/*
* ZLint Copyright 2021 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import (
"strings"

"github.com/zmap/zcrypto/x509"
"github.com/zmap/zlint/v3/lint"
"github.com/zmap/zlint/v3/util"
)

type DNSNameEmptyLabel struct{}

func init() {
lint.RegisterLint(&lint.Lint{
Name: "e_rfc_dnsname_empty_label",
Description: "DNSNames should not have an empty label.",
Citation: "RFC5280: 4.2.1.6",
Source: lint.RFC5280,
EffectiveDate: util.RFC5280Date,
Lint: NewDNSNameEmptyLabel,
})
}

func NewDNSNameEmptyLabel() lint.LintInterface {
return &DNSNameEmptyLabel{}
}

func (l *DNSNameEmptyLabel) CheckApplies(c *x509.Certificate) bool {
return util.IsSubscriberCert(c) && util.DNSNamesExist(c)
}

func domainHasEmptyLabel(domain string) bool {
labels := strings.Split(domain, ".")
for _, elem := range labels {
if elem == "" {
return true
}
}
return false
}

func (l *DNSNameEmptyLabel) Execute(c *x509.Certificate) *lint.LintResult {
for _, dns := range c.DNSNames {
if domainHasEmptyLabel(dns) {
return &lint.LintResult{Status: lint.Error}
}
}
return &lint.LintResult{Status: lint.Pass}
}
40 changes: 40 additions & 0 deletions v3/lints/rfc/lint_dnsname_contains_empty_label_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package rfc

/*
* ZLint Copyright 2021 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import (
"testing"

"github.com/zmap/zlint/v3/lint"
"github.com/zmap/zlint/v3/test"
)

func TestDNSNameEmptyLabel(t *testing.T) {
inputPath := "dnsNameEmptyLabel.pem"
expected := lint.Error
out := test.TestLint("e_rfc_dnsname_empty_label", inputPath)
if out.Status != expected {
t.Errorf("%s: expected %s, got %s", inputPath, expected, out.Status)
}
}

func TestDNSNameNotEmptyLabel(t *testing.T) {
inputPath := "dnsNameNotEmptyLabel.pem"
expected := lint.Pass
out := test.TestLint("e_rfc_dnsname_empty_label", inputPath)
if out.Status != expected {
t.Errorf("%s: expected %s, got %s", inputPath, expected, out.Status)
}
}
58 changes: 58 additions & 0 deletions v3/lints/rfc/lint_dnsname_hyphen_in_sld.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package rfc

/*
* ZLint Copyright 2021 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import (
"strings"

"github.com/zmap/zcrypto/x509"
"github.com/zmap/zlint/v3/lint"
"github.com/zmap/zlint/v3/util"
)

type DNSNameHyphenInSLD struct{}

func init() {
lint.RegisterLint(&lint.Lint{
Name: "e_rfc_dnsname_hyphen_in_sld",
Description: "DNSName should not have a hyphen beginning or ending the SLD",
Citation: "RFC5280: 4.2.1.6",
Source: lint.RFC5280,
EffectiveDate: util.RFC5280Date,
Lint: NewDNSNameHyphenInSLD,
})
}

func NewDNSNameHyphenInSLD() lint.LintInterface {
return &DNSNameHyphenInSLD{}
}

func (l *DNSNameHyphenInSLD) CheckApplies(c *x509.Certificate) bool {
return util.IsSubscriberCert(c) && util.DNSNamesExist(c)
}

func (l *DNSNameHyphenInSLD) Execute(c *x509.Certificate) *lint.LintResult {
parsedSANDNSNames := c.GetParsedDNSNames(false)
for i := range c.GetParsedDNSNames(false) {
if parsedSANDNSNames[i].ParseError != nil {
return &lint.LintResult{Status: lint.NA}
}
if strings.HasPrefix(parsedSANDNSNames[i].ParsedDomain.SLD, "-") ||
strings.HasSuffix(parsedSANDNSNames[i].ParsedDomain.SLD, "-") {
return &lint.LintResult{Status: lint.Error}
}
}
return &lint.LintResult{Status: lint.Pass}
}
58 changes: 58 additions & 0 deletions v3/lints/rfc/lint_dnsname_hyphen_in_sld_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package rfc

/*
* ZLint Copyright 2021 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import (
"testing"

"github.com/zmap/zlint/v3/lint"
"github.com/zmap/zlint/v3/test"
)

func TestDNSNameHyphenBeginningSLD(t *testing.T) {
inputPath := "dnsNameHyphenBeginningSLD.pem"
expected := lint.Error
out := test.TestLint("e_rfc_dnsname_hyphen_in_sld", inputPath)
if out.Status != expected {
t.Errorf("%s: expected %s, got %s", inputPath, expected, out.Status)
}
}

func TestDNSNameHyphenEndingSLD(t *testing.T) {
inputPath := "dnsNameHyphenEndingSLD.pem"
expected := lint.Error
out := test.TestLint("e_rfc_dnsname_hyphen_in_sld", inputPath)
if out.Status != expected {
t.Errorf("%s: expected %s, got %s", inputPath, expected, out.Status)
}
}

func TestDNSNameNoHyphenInSLD(t *testing.T) {
inputPath := "dnsNameWildcardCorrect.pem"
expected := lint.Pass
out := test.TestLint("e_rfc_dnsname_hyphen_in_sld", inputPath)
if out.Status != expected {
t.Errorf("%s: expected %s, got %s", inputPath, expected, out.Status)
}
}

func TestDNSNamePrivatePublicSuffixNoHyphenInSLD(t *testing.T) {
inputPath := "dnsNamePrivatePublicSuffix.pem"
expected := lint.Pass
out := test.TestLint("e_rfc_dnsname_hyphen_in_sld", inputPath)
if out.Status != expected {
t.Errorf("%s: expected %s, got %s", inputPath, expected, out.Status)
}
}
64 changes: 64 additions & 0 deletions v3/lints/rfc/lint_dnsname_label_too_long.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package rfc

/*
* ZLint Copyright 2021 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import (
"strings"

"github.com/zmap/zcrypto/x509"
"github.com/zmap/zlint/v3/lint"
"github.com/zmap/zlint/v3/util"
)

type DNSNameLabelLengthTooLong struct{}

func init() {
lint.RegisterLint(&lint.Lint{
Name: "e_rfc_dnsname_label_too_long",
Description: "DNSName labels MUST be less than or equal to 63 characters",
Citation: "RFC 5280: 4.2.1.6, citing RFC 1035",
Source: lint.RFC5280,
EffectiveDate: util.RFC5280Date,
Lint: NewDNSNameLabelLengthTooLong,
})
}

func NewDNSNameLabelLengthTooLong() lint.LintInterface {
return &DNSNameLabelLengthTooLong{}
}

func (l *DNSNameLabelLengthTooLong) CheckApplies(c *x509.Certificate) bool {
return util.IsSubscriberCert(c) && util.DNSNamesExist(c)
}

func labelLengthTooLong(domain string) bool {
labels := strings.Split(domain, ".")
for _, label := range labels {
if len(label) > 63 {
return true
}
}
return false
}

func (l *DNSNameLabelLengthTooLong) Execute(c *x509.Certificate) *lint.LintResult {
for _, dns := range c.DNSNames {
labelTooLong := labelLengthTooLong(dns)
if labelTooLong {
return &lint.LintResult{Status: lint.Error}
}
}
return &lint.LintResult{Status: lint.Pass}
}
31 changes: 31 additions & 0 deletions v3/lints/rfc/lint_dnsname_label_too_long_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package rfc

/*
* ZLint Copyright 2021 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import (
"testing"

"github.com/zmap/zlint/v3/lint"
"github.com/zmap/zlint/v3/test"
)

func TestDNSNameLabelTooLong(t *testing.T) {
inputPath := "dnsNameLabelTooLong.pem"
expected := lint.Error
out := test.TestLint("e_rfc_dnsname_label_too_long", inputPath)
if out.Status != expected {
t.Errorf("%s: expected %s, got %s", inputPath, expected, out.Status)
}
}
Loading

0 comments on commit b4060ec

Please sign in to comment.