Skip to content

Commit 8613f4a

Browse files
committed
Configurable HTTP proxy for OCSP requests (close #267)
1 parent 8578566 commit 8613f4a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

config.go

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"io/fs"
3030
weakrand "math/rand"
3131
"net"
32+
"net/http"
3233
"net/url"
3334
"strings"
3435
"time"
@@ -1173,6 +1174,10 @@ type OCSPConfig struct {
11731174
// embedded in certificates. Mapping to an empty
11741175
// URL will disable OCSP from that responder.
11751176
ResponderOverrides map[string]string
1177+
1178+
// Optionally specify a function that can return the URL
1179+
// for an HTTP proxy to use for OCSP-related HTTP requests.
1180+
HTTPProxy func(*http.Request) (*url.URL, error)
11761181
}
11771182

11781183
// certIssueLockOp is the name of the operation used

ocsp.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,24 @@ func getOCSPForCert(ocspConfig OCSPConfig, bundle []byte) ([]byte, *ocsp.Respons
168168
return nil, nil, fmt.Errorf("override disables querying OCSP responder: %v", issuedCert.OCSPServer[0])
169169
}
170170

171+
// configure HTTP client if necessary
172+
httpClient := http.DefaultClient
173+
if ocspConfig.HTTPProxy != nil {
174+
httpClient = &http.Client{
175+
Transport: &http.Transport{
176+
Proxy: ocspConfig.HTTPProxy,
177+
},
178+
Timeout: 30 * time.Second,
179+
}
180+
}
181+
182+
// get issuer certificate if needed
171183
if len(certificates) == 1 {
172184
if len(issuedCert.IssuingCertificateURL) == 0 {
173185
return nil, nil, fmt.Errorf("no URL to issuing certificate")
174186
}
175187

176-
resp, err := http.Get(issuedCert.IssuingCertificateURL[0])
188+
resp, err := httpClient.Get(issuedCert.IssuingCertificateURL[0])
177189
if err != nil {
178190
return nil, nil, fmt.Errorf("getting issuer certificate: %v", err)
179191
}
@@ -202,7 +214,7 @@ func getOCSPForCert(ocspConfig OCSPConfig, bundle []byte) ([]byte, *ocsp.Respons
202214
}
203215

204216
reader := bytes.NewReader(ocspReq)
205-
req, err := http.Post(respURL, "application/ocsp-request", reader)
217+
req, err := httpClient.Post(respURL, "application/ocsp-request", reader)
206218
if err != nil {
207219
return nil, nil, fmt.Errorf("making OCSP request: %v", err)
208220
}

0 commit comments

Comments
 (0)