Skip to content

Commit af9d005

Browse files
catbro666pintsized
authored andcommitted
fix: use the correct chain path and add ffi.cast
1 parent a4873ce commit af9d005

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/resty/http_connect.lua

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local ngx_log = ngx.log
66
local ngx_WARN = ngx.WARN
77
local to_hex = require("resty.string").to_hex
88
local ffi_gc = ffi.gc
9+
local ffi_cast = ffi.cast
910
local string_format = string.format
1011

1112
--[[
@@ -167,7 +168,7 @@ local function connect(self, options)
167168
local cert_hash
168169
if ssl and ssl_client_cert and ssl_client_priv_key then
169170
local status, res = xpcall(function()
170-
local chain = require("resty.openssl.chain")
171+
local chain = require("resty.openssl.x509.chain")
171172
local x509 = require("resty.openssl.x509")
172173
local pkey = require("resty.openssl.pkey")
173174
return { chain, x509, pkey }
@@ -178,7 +179,9 @@ local function connect(self, options)
178179
local x509 = res[2]
179180
local pkey = res[3]
180181

181-
local cert_chain, err = chain.dup(ssl_client_cert)
182+
183+
-- convert from `void*` to `OPENSSL_STACK*`
184+
local cert_chain, err = chain.dup(ffi_cast("OPENSSL_STACK*", ssl_client_cert))
182185
if not cert_chain then
183186
return nil, err
184187
end
@@ -192,7 +195,8 @@ local function connect(self, options)
192195
return nil, err
193196
end
194197

195-
local key, err = pkey.new(ssl_client_priv_key)
198+
-- convert from `void*` to `EVP_PKEY*`
199+
local key, err = pkey.new(ffi_cast("EVP_PKEY*", ssl_client_priv_key))
196200
if not key then
197201
return nil, err
198202
end
@@ -214,7 +218,7 @@ local function connect(self, options)
214218
end
215219

216220
else
217-
if type(res) == "string" and ngx_re_find(res, "module 'resty\\.openssl\\.(chain|x509|pkey)' not found") then
221+
if type(res) == "string" and ngx_re_find(res, "module 'resty\\.openssl\\..+' not found") then
218222
ngx_log(ngx_WARN, "can't use mTLS without module `lua-resty-openssl`, falling back to non-mTLS." .. res)
219223

220224
else

0 commit comments

Comments
 (0)