Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues/320: Limit size of certificate allowed for download #321

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
Most recent version is listed first.


# v0.0.64
- ong/acme: Limit size of certificate allowed for download: https://github.com/komuw/ong/pull/321

# v0.0.63
- ong/middleware: Log unexpected http HOST header: https://github.com/komuw/ong/pull/315
- Update dependencies: https://github.com/komuw/ong/pull/318
Expand Down
6 changes: 5 additions & 1 deletion internal/acme/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const (
// ACME clients must have the Content-Type header field set to "application/jose+json"
// https://datatracker.ietf.org/doc/html/rfc8555#section-6.2
contentType = "application/jose+json"

maxNumOfCertsInChain = 5
maxCertSize = 3072 * 4 // around 2048 when base64 encoded, multiply by 4 as a buffer.
maxCertChainSize = maxNumOfCertsInChain * maxCertSize
)

// getEcdsaPrivKey reads a private key from disk(or generates) one.
Expand Down Expand Up @@ -807,7 +811,7 @@ func downloadCertificate(ctx context.Context, o order, newNonceURL, kid string,
defer func() { _ = res.Body.Close() }()

if res.StatusCode == http.StatusOK {
c, errD := io.ReadAll(res.Body)
c, errD := io.ReadAll(io.LimitReader(res.Body, maxCertChainSize))
if errD != nil {
return nil, errD
}
Expand Down
2 changes: 1 addition & 1 deletion internal/acme/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func certFromDisk(certPath string) (*tls.Certificate, error) {
}

func certFromReader(r io.Reader) (*tls.Certificate, error) {
data, err := io.ReadAll(r)
data, err := io.ReadAll(io.LimitReader(r, maxCertChainSize))
if err != nil {
return nil, err
}
Expand Down