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

chore: export the set cert/key process so we can hook it #8228

Merged
merged 1 commit into from
Nov 3, 2022
Merged
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
40 changes: 25 additions & 15 deletions apisix/ssl/router/radixtree_sni.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,30 @@ local function set_pem_ssl_key(sni, cert, pkey)
end


-- export the set cert/key process so we can hook it in the other plugins
function _M.set_cert_and_key(sni, value)
local ok, err = set_pem_ssl_key(sni, value.cert, value.key)
if not ok then
return false, err
end

-- multiple certificates support.
if value.certs then
for i = 1, #value.certs do
local cert = value.certs[i]
local key = value.keys[i]

ok, err = set_pem_ssl_key(sni, cert, key)
if not ok then
return false, err
end
end
end

return true
end


function _M.match_and_set(api_ctx, match_only)
local err
if not radixtree_router or
Expand Down Expand Up @@ -182,25 +206,11 @@ function _M.match_and_set(api_ctx, match_only)

ngx_ssl.clear_certs()

ok, err = set_pem_ssl_key(sni, matched_ssl.value.cert,
matched_ssl.value.key)
ok, err = _M.set_cert_and_key(sni, matched_ssl.value)
if not ok then
return false, err
end

-- multiple certificates support.
if matched_ssl.value.certs then
for i = 1, #matched_ssl.value.certs do
local cert = matched_ssl.value.certs[i]
local key = matched_ssl.value.keys[i]

ok, err = set_pem_ssl_key(sni, cert, key)
if not ok then
return false, err
end
end
end

if matched_ssl.value.client then
local ca_cert = matched_ssl.value.client.ca
local depth = matched_ssl.value.client.depth
Expand Down