Skip to content

Commit

Permalink
fix: update
Browse files Browse the repository at this point in the history
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
  • Loading branch information
JeyJeyGao committed Sep 18, 2024
1 parent 0653b0b commit cf4bb29
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions revocation/crl/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import (
const (
// DefaultMaxAge is the default maximum age of the CRLs cache.
// If the CRL is older than DefaultMaxAge, it will be considered as expired.
//
// reference: Baseline Requirements for Code-Signing Certificates
// 4.9.7 CRL issuance frequency: https://cabforum.org/uploads/Baseline-Requirements-for-the-Issuance-and-Management-of-Code-Signing.v3.9.pdf
DefaultMaxAge = 24 * 7 * time.Hour
)

Expand Down
10 changes: 5 additions & 5 deletions revocation/crl/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import (
"github.com/notaryproject/notation-core-go/revocation/crl/cache"
)

// maxCRLSize is the maximum size of CRL in bytes
// MaxCRLSize is the maximum size of CRL in bytes
//
// CRL examples: https://chasersystems.com/blog/an-analysis-of-certificate-revocation-list-sizes/
const maxCRLSize = 32 * 1024 * 1024 // 32 MiB
const MaxCRLSize = 32 * 1024 * 1024 // 32 MiB

// Fetcher is an interface that specifies methods used for fetching CRL
// from the given URL
Expand Down Expand Up @@ -135,12 +135,12 @@ func download(ctx context.Context, crlURL string, client *http.Client) (bundle *
return nil, fmt.Errorf("failed to download with status code: %d", resp.StatusCode)
}
// read with size limit
data, err := io.ReadAll(io.LimitReader(resp.Body, maxCRLSize))
data, err := io.ReadAll(io.LimitReader(resp.Body, MaxCRLSize))
if err != nil {
return nil, fmt.Errorf("failed to read CRL response: %w", err)
}
if len(data) == maxCRLSize {
return nil, fmt.Errorf("CRL size exceeds the limit: %d", maxCRLSize)
if len(data) == MaxCRLSize {
return nil, fmt.Errorf("CRL size exceeds the limit: %d", MaxCRLSize)
}

// parse CRL and create bundle
Expand Down
2 changes: 1 addition & 1 deletion revocation/crl/fetcher/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func TestDownload(t *testing.T) {

t.Run("exceed the size limit", func(t *testing.T) {
_, err := download(context.Background(), "http://example.com", &http.Client{
Transport: expectedRoundTripperMock{Body: make([]byte, maxCRLSize+1)},
Transport: expectedRoundTripperMock{Body: make([]byte, MaxCRLSize+1)},
})
if err == nil {
t.Fatal("expected error")
Expand Down

0 comments on commit cf4bb29

Please sign in to comment.