-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct lint attribution for dnsname_etc lints and limit scope to jus…
…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
1 parent
74dfff2
commit b4060ec
Showing
11 changed files
with
518 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.