Skip to content

Commit 666dd10

Browse files
authored
Merge pull request #133 from Unknown22/master
Requests for SSL certs handle proxy
2 parents c2b6402 + 14ace6d commit 666dd10

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,16 @@ cjson and dkjson json adapters are supplied, but custom external adapters may al
299299
auto_ssl:set("json_adapter", "resty.auto-ssl.json_adapters.dkjson")
300300
```
301301

302+
### `proxy_addr`
303+
304+
The `proxy_addr` specify address of proxy which will be used for requests to issue SSL certificates.
305+
306+
*Example:*
307+
308+
```lua
309+
auto_ssl:set("proxy_addr", "http://localhost:3128")
310+
```
311+
302312
## `ssl_certificate` Configuration
303313

304314
The `ssl_certificate` function accepts an optional table of configuration options. These options can be used to customize and control the SSL behavior on a per nginx `server` basis. Some built-in options may control the default behavior of lua-resty-auto-ssl, but any other custom data can be given as options, which will then be passed along to the [`allow_domain`](#allow_domain) and [`request_domain`](#request_domain) callback functions.

lib/resty/auto-ssl/ssl_certificate.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ local function get_cert_der(auto_ssl_instance, domain, ssl_options)
156156
return nil, "failed to get or issue certificate"
157157
end
158158

159-
local function get_ocsp_response(fullchain_der)
159+
local function get_ocsp_response(fullchain_der, auto_ssl_instance)
160160
-- Pull the OCSP URL to hit out of the certificate chain.
161161
local ocsp_url, ocsp_responder_err = ocsp.get_ocsp_responder_from_der_chain(fullchain_der)
162162
if not ocsp_url then
@@ -172,6 +172,12 @@ local function get_ocsp_response(fullchain_der)
172172
-- Make the OCSP request against the OCSP server.
173173
local httpc = http.new()
174174
httpc:set_timeout(10000)
175+
if (auto_ssl_instance:get("proxy_addr") ~= nil) then
176+
httpc:set_proxy_options({
177+
http_proxy = auto_ssl_instance:get("proxy_addr")
178+
})
179+
end
180+
175181
local res, req_err = httpc:request_uri(ocsp_url, {
176182
method = "POST",
177183
body = ocsp_req,
@@ -202,7 +208,7 @@ local function get_ocsp_response(fullchain_der)
202208
return ocsp_resp
203209
end
204210

205-
local function set_ocsp_stapling(domain, cert_der)
211+
local function set_ocsp_stapling(domain, cert_der, auto_ssl_instance)
206212
-- Fetch the OCSP stapling response from the cache, or make the request to
207213
-- fetch it.
208214
local ocsp_resp = ngx.shared.auto_ssl:get("domain:ocsp:" .. domain)
@@ -215,7 +221,7 @@ local function set_ocsp_stapling(domain, cert_der)
215221
end
216222

217223
local ocsp_response_err
218-
ocsp_resp, ocsp_response_err = get_ocsp_response(cert_der["fullchain_der"])
224+
ocsp_resp, ocsp_response_err = get_ocsp_response(cert_der["fullchain_der"], auto_ssl_instance)
219225
if ocsp_response_err then
220226
return false, "failed to get ocsp response: " .. (ocsp_response_err or "")
221227
end
@@ -250,7 +256,7 @@ local function set_response_cert(auto_ssl_instance, domain, cert_der)
250256
end
251257

252258
-- Set OCSP stapling.
253-
ok, err = set_ocsp_stapling(domain, cert_der)
259+
ok, err = set_ocsp_stapling(domain, cert_der, auto_ssl_instance)
254260
if not ok then
255261
ngx.log(auto_ssl_instance:get("ocsp_stapling_error_level"), "auto-ssl: failed to set ocsp stapling for ", domain, " - continuing anyway - ", err)
256262
end

0 commit comments

Comments
 (0)