Skip to content

Commit

Permalink
chore: export the set cert/key process so we can hook it (#8228)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander authored Nov 3, 2022
1 parent b31fdfa commit eef518f
Showing 1 changed file with 25 additions and 15 deletions.
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

0 comments on commit eef518f

Please sign in to comment.