Skip to content

Commit 3515bb1

Browse files
committed
Only check allow_domain when we don't already have a cert
The allow_domain check might be somewhat costly - involving e.g. an external HTTP request to query a central registry. Make it so that this gets only done before requesting new certificates, not for every HTTPS connection.
1 parent 8227d90 commit 3515bb1

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/resty/auto-ssl/ssl_certificate.lua

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ local function get_cert(auto_ssl_instance, domain)
112112
return convert_to_der_and_cache(domain, fullchain_pem, privkey_pem, false)
113113
end
114114

115+
-- Check to ensure the domain is one we allow for handling SSL.
116+
local allow_domain = auto_ssl_instance:get("allow_domain")
117+
if not allow_domain(domain) then
118+
return nil, nil, nil, "domain not allowed"
119+
end
120+
115121
-- Finally, issue a new certificate if one hasn't been found yet.
116122
fullchain_pem, privkey_pem = issue_cert(auto_ssl_instance, storage, domain)
117123
if fullchain_pem and privkey_pem then
@@ -243,13 +249,6 @@ local function do_ssl(auto_ssl_instance, ssl_options)
243249
return
244250
end
245251

246-
-- Check to ensure the domain is one we allow for handling SSL.
247-
local allow_domain = auto_ssl_instance:get("allow_domain")
248-
if not allow_domain(domain) then
249-
ngx.log(ngx.NOTICE, "auto-ssl: domain not allowed - using fallback - ", domain)
250-
return
251-
end
252-
253252
-- Get or issue the certificate for this domain.
254253
local fullchain_der, privkey_der, newly_issued, get_cert_err = get_cert(auto_ssl_instance, domain)
255254
if get_cert_err then

0 commit comments

Comments
 (0)