Skip to content

Commit

Permalink
gofmt code
Browse files Browse the repository at this point in the history
  • Loading branch information
tnarg999 committed Sep 14, 2020
1 parent d3442a2 commit 60446d7
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 44 deletions.
22 changes: 11 additions & 11 deletions linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@ var StatusIntMap = map[int]string{

// LintStruct defines the struct of a lint
type LintStruct struct {
Info string // description of the lint
Source string // source of the lint
Info string // description of the lint
Source string // source of the lint
Exec func(resp *ocsp.Response, leafCert *x509.Certificate) (LintStatus, string) // the linting function itself
}

// Lints is the global array of lints that are to be tested (TODO: change to a map)
var Lints = []*LintStruct{
&LintStruct{
{
"Check response signature",
"Apple Lints 10 & 12",
CheckSignature,
},
&LintStruct{
{
"Check response producedAt date",
"Apple Lints 03 & 05",
LintProducedAtDate,
},
&LintStruct{
{
"Check response thisUpdate date",
"Apple Lints 03 & 05",
LintThisUpdateDate,
},
&LintStruct{
{
"Check response nextUpdate date",
"Apple Lint 04",
LintNextUpdateDate,
Expand All @@ -54,14 +54,14 @@ type LintStatus string
const (
Passed LintStatus = "PASSED" // lint passed
Failed LintStatus = "FAILED" // lint failed
Error LintStatus = "ERROR" // encountered error while running lint
Error LintStatus = "ERROR" // encountered error while running lint
)

// LintResult defines the struct of the result of a Lint
type LintResult struct {
Lint *LintStruct
Lint *LintStruct
Status LintStatus
Info string
Info string
}

// LinterInterface is an interface containing the functions that are exported from this file
Expand Down Expand Up @@ -104,9 +104,9 @@ func (l Linter) LintOCSPResp(resp *ocsp.Response, leafCert *x509.Certificate, ve
for _, lint := range Lints {
status, info := lint.Exec(resp, leafCert)
results = append(results, &LintResult{
Lint: lint,
Lint: lint,
Status: status,
Info: info,
Info: info,
})
}

Expand Down
36 changes: 18 additions & 18 deletions linter/lintfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (
)

const (
ProducedAtLimitSubscriber = "96h" // 4 days
ThisUpdateLimitSubscriber = "96h" // 4 days
ProducedAtLimitCA = "8760h" // 365 days
ThisUpdateLimitCA = "8760h" // 365 days
NextUpdateLimitSubscriber = "240h" // 10 days
ProducedAtLimitSubscriber = "96h" // 4 days
ThisUpdateLimitSubscriber = "96h" // 4 days
ProducedAtLimitCA = "8760h" // 365 days
ThisUpdateLimitCA = "8760h" // 365 days
NextUpdateLimitSubscriber = "240h" // 10 days
)

// DurationToString is a map mapping durations to more readable strings
var DurationToString = map[string]string {
var DurationToString = map[string]string{
ProducedAtLimitSubscriber: "4 days",
ProducedAtLimitCA: "365 days",
ProducedAtLimitCA: "365 days",
NextUpdateLimitSubscriber: "10 days",
}

Expand All @@ -35,7 +35,7 @@ func CheckSignature(resp *ocsp.Response, leafCert *x509.Certificate) (LintStatus
if algo == x509.SHA1WithRSA || algo == x509.DSAWithSHA1 || algo == x509.ECDSAWithSHA1 {
return Failed, "OCSP Response is signed with an algorithm that uses SHA1"
}

return Passed, "OCSP Response is signed with an algorithm that does not use SHA1"
}

Expand All @@ -57,11 +57,11 @@ func LintProducedAtDate(resp *ocsp.Response, leafCert *x509.Certificate) (LintSt
}

if time.Since(resp.ProducedAt) > limit {
return Failed, fmt.Sprintf("OCSP Response producedAt date %s for %s is more than %s in the past",
return Failed, fmt.Sprintf("OCSP Response producedAt date %s for %s is more than %s in the past",
resp.ProducedAt, certType, DurationToString[producedAtLimit])
}

return Passed, fmt.Sprintf("OCSP Response producedAt date %s for %s is within %s in the past",
return Passed, fmt.Sprintf("OCSP Response producedAt date %s for %s is within %s in the past",
resp.ProducedAt, certType, DurationToString[producedAtLimit])
}

Expand All @@ -82,14 +82,14 @@ func LintThisUpdateDate(resp *ocsp.Response, leafCert *x509.Certificate) (LintSt
}

if time.Since(resp.ThisUpdate) > limit {
return Failed, fmt.Sprintf("OCSP Response thisUpdate date %s for %s is more than %s in the past",
return Failed, fmt.Sprintf("OCSP Response thisUpdate date %s for %s is more than %s in the past",
resp.ThisUpdate, certType, DurationToString[thisUpdateLimit])

}

return Passed, fmt.Sprintf("OCSP Response thisUpdate date %s for %s is within %s in the past",
return Passed, fmt.Sprintf("OCSP Response thisUpdate date %s for %s is within %s in the past",
resp.ThisUpdate, certType, DurationToString[thisUpdateLimit])

}

// LintNextUpdateDate checks that an OCSP Response NextUpdate date is no more than NextUpdateLimitSubscriber in the past
Expand All @@ -105,12 +105,12 @@ func LintNextUpdateDate(resp *ocsp.Response, leafCert *x509.Certificate) (LintSt
}

if resp.NextUpdate.Sub(resp.ThisUpdate) > limit {
return Failed, fmt.Sprintf("OCSP Response NextUpdate date %s is more than %s after ThisUpdate date %s",
return Failed, fmt.Sprintf("OCSP Response NextUpdate date %s is more than %s after ThisUpdate date %s",
resp.NextUpdate, DurationToString[NextUpdateLimitSubscriber], resp.ThisUpdate)

}

return Passed, fmt.Sprintf("OCSP Response NextUpdate date %s is within %s after ThisUpdate date %s",
return Passed, fmt.Sprintf("OCSP Response NextUpdate date %s is within %s after ThisUpdate date %s",
resp.NextUpdate, DurationToString[NextUpdateLimitSubscriber], resp.ThisUpdate)

}
2 changes: 1 addition & 1 deletion linter/lintfuncs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ func TestLintNextUpdateDate(t *testing.T) {
if status != Failed {
t.Errorf("Lint should have failed, instead got status %s: %s", status, info)
}
})
})
}
Binary file modified ocsp_status
Binary file not shown.
6 changes: 3 additions & 3 deletions ocsp_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func checkFromURL(tools ocsptools.ToolsInterface, linter linter.LinterInterface,
return err
}

leafCert := certChain[0] // the certificate we want to send to the CA
leafCert := certChain[0] // the certificate we want to send to the CA

issuerCert, err := tools.ParseCertificateFile(issuerFile)
if err != nil {
Expand Down Expand Up @@ -144,7 +144,7 @@ func main() {

tools := ocsptools.Tools{}
linter := linter.Linter{}

if *inresp && *incert {
panic("This tool can only parse one file format at a time. Please use only one of -inresp or -incert.")
}
Expand Down Expand Up @@ -183,7 +183,7 @@ func main() {
if err == nil {
continue
}
fmt.Printf("Validation failed for sending OCSP Request encoded with SHA256: %s \n\n" , err.Error())
fmt.Printf("Validation failed for sending OCSP Request encoded with SHA256: %s \n\n", err.Error())

err = checkFromCert(tools, linter, arg, iFile, *isPost, ocspURL, *dir, crypto.SHA1, *verbose)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions ocsp_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
)

const (
Resp = "./testdata/resps/oldfbresp" // sample response file
Resp = "./testdata/resps/oldfbresp" // sample response file
Cert = "./testdata/certs/google.der" // sample certificate file
URL = "google.com:443" // sample URL
URL = "google.com:443" // sample URL
)

// TestMain sets up the testing framework
Expand Down
2 changes: 1 addition & 1 deletion ocsptools/helpers/ocsp_tools_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

const (
RespTimeLimit = "10s" // Time limit for OCSP response to be served
TimeoutInSeconds = 20 // Time limit for http response before timeout
TimeoutInSeconds = 20 // Time limit for http response before timeout
)

// HelpersInterface is an interface for the functions that can be used from this file
Expand Down
4 changes: 2 additions & 2 deletions ocsptools/helpers/ocsp_tools_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
)

const (
GoodCert = "../../testdata/certs/google.der" // good certificate
GoodCert = "../../testdata/certs/google.der" // good certificate
GoodIssuerCert = "../../testdata/certs/googleissuer.der" // issuer certificate for good certificate
URL = "google.com:443" // sample URL
URL = "google.com:443" // sample URL
)

// TestCreateOCSPReq tests CreateOCSPReq, which builds an OCSP request to check
Expand Down
2 changes: 1 addition & 1 deletion ocsptools/ocsp_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (t Tools) ParseCertificateFile(certFile string) (*x509.Certificate, error)
if certFile == "" {
return nil, nil
}

cert, err := ioutil.ReadFile(certFile)
if err != nil {
return nil, fmt.Errorf("Error reading certificate file: %w", err)
Expand Down
10 changes: 5 additions & 5 deletions ocsptools/ocsp_tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
)

const (
GoodResp = "../testdata/resps/oldfbresp" // good response
GoodCert = "../testdata/certs/google.der" // good certificate
GoodResp = "../testdata/resps/oldfbresp" // good response
GoodCert = "../testdata/certs/google.der" // good certificate
GoodIssuerCert = "../testdata/certs/googleissuer.der" // issuer certificate for good certificate
NoIssuerURLCert = "../testdata/certs/rootcert.der" // certificate with no issuer URL field
BadPath = "blah///blah/blah.blah" // bad file path
URL = "google.com:443" // sample URL
NoIssuerURLCert = "../testdata/certs/rootcert.der" // certificate with no issuer URL field
BadPath = "blah///blah/blah.blah" // bad file path
URL = "google.com:443" // sample URL
)

// TestReadOCSPResp tests ReadOCSPResp, which reads and parses an OCSP response file
Expand Down

0 comments on commit 60446d7

Please sign in to comment.