Skip to content

Commit

Permalink
[upstream_mtls] refactor to use tls module
Browse files Browse the repository at this point in the history
  • Loading branch information
tkan145 committed Oct 16, 2024
1 parent 39b31d0 commit a717b4f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions gateway/src/apicast/policy/upstream_mtls/upstream_mtls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local ffi = require "ffi"
local base = require "resty.core.base"
local data_url = require('resty.data_url')
local util = require 'apicast.util'
local tls = require 'resty.tls'

local C = ffi.C
local get_request = base.get_request
Expand Down Expand Up @@ -109,16 +110,16 @@ end
-- parse_* functions.
--- Public function to be able to unittest this.
function _M.set_certs(r, cert, key)
local val = C.ngx_http_apicast_ffi_set_proxy_cert_key(r, cert, key)
if val ~= ngx.OK then
ngx.log(ngx.ERR, "Certificate cannot be set correctly")
local ok, err = tls.set_upstream_cert_and_key(r, cert, key)
if ok ~= nil then
ngx.log(ngx.ERR, "Certificate cannot be set correctly, err: ", err)
end
end

function _M.set_ca_cert(r, store)
local val = C.ngx_http_apicast_ffi_set_proxy_ca_cert(r, store)
if val ~= ngx.OK then
ngx.log(ngx.WARN, "Cannot set a valid trusted CA store")
local ok, err = tls.set_upstream_ca_cert(r, store)
if ok ~= nil then
ngx.log(ngx.WARN, "Cannot set a valid trusted CA store, err: ", err)
return
end
end
Expand All @@ -141,9 +142,9 @@ function _M:balancer(context)
return
end

local val = C.ngx_http_apicast_ffi_set_ssl_verify(r, ffi.new("int", 1), ffi.new("int", 1))
if val ~= ngx.OK then
ngx.log(ngx.WARN, "Cannot verify SSL upstream connection")
local ok, err = tls.set_upstream_ssl_verify(r, true, 1)
if ok ~= nil then
ngx.log(ngx.WARN, "Cannot verify SSL upstream connection, err: ", err)
end

if not self.ca_store then
Expand Down

0 comments on commit a717b4f

Please sign in to comment.