@@ -23,6 +23,7 @@ local get_phase = ngx.get_phase
2323local type = type
2424local error = error
2525local tostring = tostring
26+ local concat = table.concat
2627local C = ffi .C
2728local ffi_cast = ffi .cast
2829local SOCKET_CTX_INDEX = 1
@@ -41,6 +42,8 @@ local kong_lua_kong_ffi_set_upstream_client_cert_and_key
4142local kong_lua_kong_ffi_set_upstream_ssl_trusted_store
4243local kong_lua_kong_ffi_set_upstream_ssl_verify
4344local kong_lua_kong_ffi_set_upstream_ssl_verify_depth
45+ local kong_lua_kong_ffi_set_upstream_ssl_sans_dnsnames
46+ local kong_lua_kong_ffi_set_upstream_ssl_sans_uris
4447local kong_lua_kong_ffi_get_socket_ssl
4548local kong_lua_kong_ffi_get_request_ssl
4649local kong_lua_kong_ffi_disable_http2_alpn
@@ -60,6 +63,10 @@ if subsystem == "http" then
6063 int verify);
6164 int ngx_http_lua_kong_ffi_set_upstream_ssl_verify_depth(ngx_http_request_t *r,
6265 int depth);
66+ int ngx_http_lua_kong_ffi_set_upstream_ssl_sans_dnsnames(ngx_http_request_t *r,
67+ const char *input, size_t input_len);
68+ int ngx_http_lua_kong_ffi_set_upstream_ssl_sans_uris(ngx_http_request_t *r,
69+ const char *input, size_t input_len);
6370 int ngx_http_lua_kong_ffi_get_socket_ssl(ngx_http_lua_socket_tcp_upstream_t *u,
6471 void **ssl_conn);
6572 int ngx_http_lua_kong_ffi_get_request_ssl(ngx_http_request_t *r,
@@ -73,6 +80,8 @@ if subsystem == "http" then
7380 kong_lua_kong_ffi_set_upstream_ssl_trusted_store = C .ngx_http_lua_kong_ffi_set_upstream_ssl_trusted_store
7481 kong_lua_kong_ffi_set_upstream_ssl_verify = C .ngx_http_lua_kong_ffi_set_upstream_ssl_verify
7582 kong_lua_kong_ffi_set_upstream_ssl_verify_depth = C .ngx_http_lua_kong_ffi_set_upstream_ssl_verify_depth
83+ kong_lua_kong_ffi_set_upstream_ssl_sans_dnsnames = C .ngx_http_lua_kong_ffi_set_upstream_ssl_sans_dnsnames
84+ kong_lua_kong_ffi_set_upstream_ssl_sans_uris = C .ngx_http_lua_kong_ffi_set_upstream_ssl_sans_uris
7685 kong_lua_kong_ffi_get_socket_ssl = C .ngx_http_lua_kong_ffi_get_socket_ssl
7786 kong_lua_kong_ffi_get_request_ssl = C .ngx_http_lua_kong_ffi_get_request_ssl
7887 kong_lua_kong_ffi_disable_http2_alpn = C .ngx_http_lua_ffi_disable_http2_alpn
@@ -94,6 +103,10 @@ elseif subsystem == 'stream' then
94103 int verify);
95104 int ngx_stream_lua_kong_ffi_set_upstream_ssl_verify_depth(ngx_stream_lua_request_t *r,
96105 int depth);
106+ int ngx_stream_lua_kong_ffi_set_upstream_ssl_sans_dnsnames(ngx_stream_lua_request_t *r,
107+ const char *input, size_t input_len);
108+ int ngx_stream_lua_kong_ffi_set_upstream_ssl_sans_uris(ngx_stream_lua_request_t *r,
109+ const char *input, size_t input_len);
97110 int ngx_stream_lua_kong_get_socket_ssl(ngx_stream_lua_socket_tcp_upstream_t *u,
98111 void **ssl_conn);
99112 ]] )
@@ -104,6 +117,8 @@ elseif subsystem == 'stream' then
104117 kong_lua_kong_ffi_set_upstream_ssl_trusted_store = C .ngx_stream_lua_kong_ffi_set_upstream_ssl_trusted_store
105118 kong_lua_kong_ffi_set_upstream_ssl_verify = C .ngx_stream_lua_kong_ffi_set_upstream_ssl_verify
106119 kong_lua_kong_ffi_set_upstream_ssl_verify_depth = C .ngx_stream_lua_kong_ffi_set_upstream_ssl_verify_depth
120+ kong_lua_kong_ffi_set_upstream_ssl_sans_dnsnames = C .ngx_stream_lua_kong_ffi_set_upstream_ssl_sans_dnsnames
121+ kong_lua_kong_ffi_set_upstream_ssl_sans_uris = C .ngx_stream_lua_kong_ffi_set_upstream_ssl_sans_uris
107122 kong_lua_kong_ffi_get_socket_ssl = C .ngx_stream_lua_kong_get_socket_ssl
108123 kong_lua_kong_ffi_get_request_ssl = function ()
109124 error (" API not available for the current subsystem" )
338353 error (" unknown return code: " .. tostring (ret ))
339354 end
340355
356+ function _M .set_upstream_ssl_sans_dnsnames (sans )
357+ if not ALLOWED_PHASES [get_phase ()] then
358+ error (" API disabled in the current context" , 2 )
359+ end
360+
361+ if type (sans ) ~= " table" then
362+ error (" incorrect argument, expects an array, got " ..
363+ type (sans ), 2 )
364+ end
365+
366+ if # sans == 0 then
367+ error (" incorrect argument, the value can not be an empty array" , 2 )
368+ end
369+
370+ local r = get_request ()
371+
372+ local ssl_sans = concat (sans , " " )
373+ local ret = kong_lua_kong_ffi_set_upstream_ssl_sans_dnsnames (r , ssl_sans , # ssl_sans )
374+ if ret == NGX_OK then
375+ return true
376+ end
377+
378+ if ret == NGX_ERROR then
379+ return nil , " error while setting upstream SSL dnsnames SANs"
380+ end
381+
382+ error (" unknown return code: " .. tostring (ret ))
383+ end
384+
385+ function _M .set_upstream_ssl_sans_uris (uris )
386+ if not ALLOWED_PHASES [get_phase ()] then
387+ error (" API disabled in the current context" , 2 )
388+ end
389+
390+ if type (uris ) ~= " table" then
391+ error (" incorrect argument, expects an array, got " ..
392+ type (uris ), 2 )
393+ end
394+
395+ if # uris == 0 then
396+ error (" incorrect argument, the value can not be an empty array" , 2 )
397+ end
398+
399+ local r = get_request ()
400+
401+ local ssl_sans = concat (uris , " " )
402+ local ret = kong_lua_kong_ffi_set_upstream_ssl_sans_uris (r , ssl_sans , # ssl_sans )
403+ if ret == NGX_OK then
404+ return true
405+ end
406+
407+ if ret == NGX_ERROR then
408+ return nil , " error while setting upstream SSL URIs SANs"
409+ end
410+
411+ error (" unknown return code: " .. tostring (ret ))
412+ end
413+
341414 function _M .disable_http2_alpn ()
342415 if get_phase () ~= " ssl_client_hello" then
343416 error (" API disabled in the current context" )
0 commit comments