Skip to content

Commit 7789bd2

Browse files
committed
Limit OCSP answers to 1MB.
fixes #56
1 parent 3715351 commit 7789bd2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

acme/crypto.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"encoding/pem"
1515
"errors"
1616
"fmt"
17+
"io"
1718
"io/ioutil"
1819
"math/big"
1920
"net/http"
@@ -67,7 +68,7 @@ func GetOCSPForCert(bundle []byte) ([]byte, int, error) {
6768
}
6869
defer resp.Body.Close()
6970

70-
issuerBytes, err := ioutil.ReadAll(resp.Body)
71+
issuerBytes, err := ioutil.ReadAll(limitReader(resp.Body, 1024*1024))
7172
if err != nil {
7273
return nil, OCSPUnknown, err
7374
}
@@ -100,8 +101,8 @@ func GetOCSPForCert(bundle []byte) ([]byte, int, error) {
100101
return nil, OCSPUnknown, err
101102
}
102103
defer req.Body.Close()
103-
104-
ocspResBytes, err := ioutil.ReadAll(req.Body)
104+
105+
ocspResBytes, err := ioutil.ReadAll(limitReader(req.Body, 1024*1024))
105106
ocspRes, err := ocsp.ParseResponse(ocspResBytes, issuerCert)
106107
if err != nil {
107108
return nil, OCSPUnknown, err
@@ -312,3 +313,7 @@ func generateDerCert(privKey *rsa.PrivateKey, expiration time.Time, domain strin
312313

313314
return x509.CreateCertificate(rand.Reader, &template, &template, &privKey.PublicKey, privKey)
314315
}
316+
317+
func limitReader(rd io.ReadCloser, numBytes int64) io.ReadCloser {
318+
return http.MaxBytesReader(nil, rd, numBytes)
319+
}

0 commit comments

Comments
 (0)