Skip to content

Commit

Permalink
Split of lints into directories by source (#337)
Browse files Browse the repository at this point in the history
* initial pass at a dissection

* moving in new lints

* second pass on directories for lints

* lints in better shape

* make zlint work again

* tests pass.

* updating copyright while I'm making large sweeping changes

* missing an important file

* apparently a random util file wasn't go'fmted?????

* integration tests fixes

Co-authored-by: Daniel McCarney <[email protected]>
  • Loading branch information
zakird and cpu authored Jan 2, 2020
1 parent 0ab41f2 commit e3ad0f9
Show file tree
Hide file tree
Showing 540 changed files with 5,363 additions and 4,355 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2017 Regents of the University of Michigan
Copyright 2020 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.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Example:
```go
func TestBasicConstNotCritical(t *testing.T) {
// Only need to change these two values and the lint name
inputPath := "../testlint/testCerts/caBasicConstNotCrit.pem"
inputPath := "../../testlint/testCerts/caBasicConstNotCrit.pem"
expected := Error
out, _ := Lints["e_basic_constraints_not_critical"].ExecuteTest(ReadCertificate(inputPath))
if out.Result != expected {
Expand Down Expand Up @@ -216,7 +216,7 @@ another CA/project that uses zlint.
License and Copyright
---------------------

ZMap Copyright 2019 Regents of the University of Michigan
ZMap Copyright 2020 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
Expand Down
18 changes: 9 additions & 9 deletions benchmarks_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* ZLint Copyright 2018 Regents of the University of Michigan
* ZLint Copyright 2020 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
Expand All @@ -19,12 +19,12 @@ import (
"testing"

"github.com/zmap/zcrypto/x509"
"github.com/zmap/zlint/lints"
"github.com/zmap/zlint/lint"
)

var (
globalLintResult *ResultSet
globalSingleLintResult *lints.LintResult
globalSingleLintResult *lint.LintResult
)

const bigCertificatePem = `-----BEGIN CERTIFICATE-----
Expand Down Expand Up @@ -111,10 +111,10 @@ func BenchmarkZlint(b *testing.B) {

b.Run("Fast lints", func(b *testing.B) {
globalLintResult = &ResultSet{}
globalLintResult.Results = make(map[string]*lints.LintResult, len(lints.Lints))
globalLintResult.Results = make(map[string]*lint.LintResult, len(lint.Lints))
b.ResetTimer()
for i := 0; i < b.N; i++ {
for key, value := range lints.Lints {
for key, value := range lint.Lints {
switch key {
case "w_dnsname_underscore_in_trd", "e_dnsname_underscore_in_sld", "e_dnsname_hyphen_in_sld",
"w_dnsname_wildcard_left_of_public_suffix", "w_san_iana_pub_suffix_empty":
Expand All @@ -131,10 +131,10 @@ func BenchmarkZlint(b *testing.B) {

b.Run("Fastest lints", func(b *testing.B) {
globalLintResult = &ResultSet{}
globalLintResult.Results = make(map[string]*lints.LintResult, len(lints.Lints))
globalLintResult.Results = make(map[string]*lint.LintResult, len(lint.Lints))
b.ResetTimer()
for i := 0; i < b.N; i++ {
for key, value := range lints.Lints {
for key, value := range lint.Lints {
switch key {
case "w_dnsname_underscore_in_trd", "e_dnsname_underscore_in_sld", "e_dnsname_hyphen_in_sld",
"w_dnsname_wildcard_left_of_public_suffix", "w_san_iana_pub_suffix_empty",
Expand All @@ -157,13 +157,13 @@ func BenchmarkZlint(b *testing.B) {
}
})

for key, value := range lints.Lints {
for key, value := range lint.Lints {
b.Run(key, func(b *testing.B) {
if !value.Lint.CheckApplies(x509Cert) {
b.Skip("Check doesn't apply")
}

var result *lints.LintResult
var result *lint.LintResult
for i := 0; i < b.N; i++ {
result = value.Lint.Execute(x509Cert)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/zlint-gtld-update/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* ZLint Copyright 2018 Regents of the University of Michigan
* ZLint Copyright 2020 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
Expand Down Expand Up @@ -69,7 +69,7 @@ var (
// This file was generated by zlint-gtld-update.
/*
* ZLint Copyright 2018 Regents of the University of Michigan
* ZLint Copyright 2020 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
Expand Down
24 changes: 12 additions & 12 deletions cmd/zlint/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* ZLint Copyright 2017 Regents of the University of Michigan
* ZLint Copyright 2020 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
Expand Down Expand Up @@ -29,7 +29,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/zmap/zcrypto/x509"
"github.com/zmap/zlint"
"github.com/zmap/zlint/lints"
"github.com/zmap/zlint/lint"
)

var ( // flags
Expand Down Expand Up @@ -65,8 +65,8 @@ func main() {
}

if listLintsSchema {
names := make([]string, 0, len(lints.Lints))
for lintName := range lints.Lints {
names := make([]string, 0, len(lint.Lints))
for lintName := range lint.Lints {
names = append(names, lintName)
}
sort.Strings(names)
Expand All @@ -83,7 +83,7 @@ func main() {

var inform = strings.ToLower(format)
if flag.NArg() < 1 || flag.Arg(0) == "-" {
lint(os.Stdin, inform)
doLint(os.Stdin, inform)
} else {
for _, filePath := range flag.Args() {
var inputFile *os.File
Expand All @@ -100,13 +100,13 @@ func main() {
fileInform = "pem"
}

lint(inputFile, fileInform)
doLint(inputFile, fileInform)
inputFile.Close()
}
}
}

func lint(inputFile *os.File, inform string) {
func doLint(inputFile *os.File, inform string) {
fileBytes, err := ioutil.ReadAll(inputFile)
if err != nil {
log.Fatalf("unable to read file %s: %s", inputFile.Name(), err)
Expand Down Expand Up @@ -173,17 +173,17 @@ func includeLints() {
var includesMap = make(map[string]struct{}, len(includes))
for _, includeName := range includes {
includeName = strings.TrimSpace(includeName)
if _, ok := lints.Lints[includeName]; !ok {
if _, ok := lint.Lints[includeName]; !ok {
log.Fatalf("unknown lint %q in include list", includeName)
}

includesMap[includeName] = struct{}{}
}

// clear all initialized lints except for includes
for lintName := range lints.Lints {
for lintName := range lint.Lints {
if _, ok := includesMap[lintName]; !ok {
delete(lints.Lints, lintName)
delete(lint.Lints, lintName)
}
}
}
Expand All @@ -202,10 +202,10 @@ func excludeLints() {

// exclude lints
for excludeName := range excludesMap {
if _, ok := lints.Lints[excludeName]; !ok {
if _, ok := lint.Lints[excludeName]; !ok {
log.Fatalf("unknown lint %q in exclude list", excludeName)
}

delete(lints.Lints, excludeName)
delete(lint.Lints, excludeName)
}
}
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ require (
github.com/sirupsen/logrus v1.3.0
github.com/weppos/publicsuffix-go v0.4.0
github.com/zmap/zcrypto v0.0.0-20191112190257-7f2fe6faf8cf
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
golang.org/x/net v0.0.0-20190620200207-3b0461eec859
golang.org/x/text v0.3.0
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4 // indirect
)

go 1.13
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,23 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4 h1:Toz2IK7k8rbltAXwNAxKcn9OzqyNfMUhUNjz3sL0NMk=
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2 changes: 1 addition & 1 deletion gofmt_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* ZLint Copyright 2018 Regents of the University of Michigan
* ZLint Copyright 2020 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
Expand Down
4 changes: 2 additions & 2 deletions integration/corpus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"testing"

"github.com/zmap/zlint"
"github.com/zmap/zlint/lints"
"github.com/zmap/zlint/lint"
)

// lintCertificate lints the provided work item's certificate to produce
Expand All @@ -22,7 +22,7 @@ func lintCertificate(work workItem) certResult {
// Lint the certiifcate to produce a full result set
cr := certResult{
Fingerprint: work.Fingerprint,
LintSummary: make(map[string]lints.LintStatus),
LintSummary: make(map[string]lint.LintStatus),
}
resultSet := zlint.LintCertificateFiltered(work.Certificate, lintFilter)
for lintName, r := range resultSet.Results {
Expand Down
14 changes: 7 additions & 7 deletions integration/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package integration
import (
"fmt"

"github.com/zmap/zlint/lints"
"github.com/zmap/zlint/lint"
)

type resultCount struct {
Expand All @@ -27,15 +27,15 @@ func (r resultCount) String() string {
}

// Inc increases the resultCount count for the given lint status level.
func (r *resultCount) Inc(status lints.LintStatus) {
func (r *resultCount) Inc(status lint.LintStatus) {
switch status {
case lints.Notice:
case lint.Notice:
r.NoticeCount++
case lints.Warn:
case lint.Warn:
r.WarnCount++
case lints.Error:
case lint.Error:
r.ErrCount++
case lints.Fatal:
case lint.Fatal:
r.FatalCount++
}
}
Expand All @@ -46,7 +46,7 @@ func (r *resultCount) Inc(status lints.LintStatus) {
type certResult struct {
Fingerprint string
Result resultCount
LintSummary map[string]lints.LintStatus
LintSummary map[string]lint.LintStatus
}

func (cr certResult) String() string {
Expand Down
4 changes: 2 additions & 2 deletions lints/base.go → lint/base.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package lints
package lint

/*
* ZLint Copyright 2017 Regents of the University of Michigan
* ZLint Copyright 2020 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
Expand Down
26 changes: 5 additions & 21 deletions lints/base_test.go → lint/base_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package lints
package lint

/*
* ZLint Copyright 2017 Regents of the University of Michigan
* ZLint Copyright 2020 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
Expand All @@ -17,6 +17,8 @@ package lints
import (
"testing"
"time"

"github.com/zmap/zlint/util"
)

func TestAllLintsHaveNameDescriptionSource(t *testing.T) {
Expand All @@ -43,7 +45,7 @@ func TestAllLintsHaveSource(t *testing.T) {

func TestLintCheckEffective(t *testing.T) {
l := Lint{}
c := ReadCertificate("../testlint/testCerts/caBasicConstCrit.pem")
c := util.ReadCertificate("../testlint/testCerts/caBasicConstCrit.pem")

l.EffectiveDate = time.Time{}
if l.CheckEffective(c) != true {
Expand All @@ -58,21 +60,3 @@ func TestLintCheckEffective(t *testing.T) {
t.Errorf("EffectiveDate of 3000 should be false")
}
}

func TestLintExecute(t *testing.T) {
c := ReadCertificate("../testlint/testCerts/goodRsaExp.pem")
lint := Lint{}

lint.Lint = &dsaParamsMissing{}
res := lint.Execute(c)
if res.Status != NA {
t.Errorf("Expected NA, got %s", res.Status)
}

lint.Lint = &rsaParsedTestsExpBounds{}
lint.EffectiveDate = time.Unix(32503680000, 0)
res = lint.Execute(c)
if res.Status != NE {
t.Errorf("Expected NE, got %s", res.Status)
}
}
4 changes: 2 additions & 2 deletions lints/result.go → lint/result.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package lints
package lint

/*
* ZLint Copyright 2017 Regents of the University of Michigan
* ZLint Copyright 2020 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
Expand Down
2 changes: 1 addition & 1 deletion lints/result_test.go → lint/result_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lints
package lint

import (
"encoding/json"
Expand Down
Loading

0 comments on commit e3ad0f9

Please sign in to comment.