Skip to content

Commit

Permalink
fix(set_upstream_ssl_trusted_store) use correct type for
Browse files Browse the repository at this point in the history
resty.openssl.x509.store object checks
  • Loading branch information
dndx committed Jun 3, 2020
1 parent 521a88e commit 853d58b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ resty.kong.tls.set\_upstream\_ssl\_trusted\_store
Set upstream ssl verification trusted store of current request. Global setting set by
`proxy_ssl_trusted_certificate` will be overwritten for the current request.

`store` is a `X509_STORE*` cdata that can be created by
`store` is a table object that can be created by
[resty.openssl.x509.store.new](https://github.com/fffonion/lua-resty-openssl#storenew).

On success, this function returns `true` and future handshakes with upstream servers
Expand Down
39 changes: 22 additions & 17 deletions lualib/resty/kong/tls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,28 +200,33 @@ if ngx.config.subsystem == "http" then
error("unknown return code: " .. tostring(ret))
end

function _M.set_upstream_ssl_trusted_store(store)
if not ALLOWED_PHASES[get_phase()] then
error("API disabled in the current context", 2)
end
do
local store_lib = require("resty.openssl.x509.store")

if type(store) ~= 'cdata' then
error("store expects a cdata object but found " .. type(store), 2)
end
function _M.set_upstream_ssl_trusted_store(store)
if not ALLOWED_PHASES[get_phase()] then
error("API disabled in the current context", 2)
end

local r = get_request()
if not store_lib.istype(store) then
error("store expects a resty.openssl.x509.store" ..
" object but found " .. type(store), 2)
end

local ret = C.ngx_http_lua_kong_ffi_set_upstream_ssl_trusted_store(
r, store)
if ret == NGX_OK then
return true
end
local r = get_request()

if ret == NGX_ERROR then
return nil, "error while setting upstream trusted store"
end
local ret = C.ngx_http_lua_kong_ffi_set_upstream_ssl_trusted_store(
r, store.ctx)
if ret == NGX_OK then
return true
end

error("unknown return code: " .. tostring(ret))
if ret == NGX_ERROR then
return nil, "error while setting upstream trusted store"
end

error("unknown return code: " .. tostring(ret))
end
end

function _M.set_upstream_ssl_verify(verify)
Expand Down
6 changes: 3 additions & 3 deletions t/002-upstream-tls.t
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ X509_check_host(): match
f:close()
assert(s:add(x509.new(cert_data)))
end
local ok, err = tls.set_upstream_ssl_trusted_store(s.ctx)
local ok, err = tls.set_upstream_ssl_trusted_store(s)
if not ok then
ngx.say("set_upstream_ssl_trusted_store failed: ", err)
end
Expand Down Expand Up @@ -718,7 +718,7 @@ upstream SSL certificate verify error: (2:unable to get issuer certificate)
f:close()
assert(s:add(x509.new(cert_data)))
end
local ok, err = tls.set_upstream_ssl_trusted_store(s.ctx)
local ok, err = tls.set_upstream_ssl_trusted_store(s)
if not ok then
ngx.say("set_upstream_ssl_trusted_store failed: ", err)
end
Expand Down Expand Up @@ -786,7 +786,7 @@ X509_check_host(): match
assert(s:add(x509.new(cert_data)))
end
for i=0,3 do
local ok, err = tls.set_upstream_ssl_trusted_store(s.ctx)
local ok, err = tls.set_upstream_ssl_trusted_store(s)
if not ok then
ngx.say("set_upstream_ssl_trusted_store failed: ", err)
return
Expand Down

0 comments on commit 853d58b

Please sign in to comment.