Skip to content

feature: support custom trusted CA store for cosocket TLS handshake.#2495

Merged
zhuizhuhaomeng merged 3 commits intoopenresty:masterfrom
findns94:feat/support_trusted_cert
May 2, 2026
Merged

feature: support custom trusted CA store for cosocket TLS handshake.#2495
zhuizhuhaomeng merged 3 commits intoopenresty:masterfrom
findns94:feat/support_trusted_cert

Conversation

@findns94
Copy link
Copy Markdown
Contributor

@findns94 findns94 commented Apr 29, 2026

Adds the cosocket-level plumbing for a new tcpsock:settrustedstore(store) method, allowing Lua code to supply a per-handshake X509_STORE that overrides lua_ssl_trusted_certificate for the upcoming sslhandshake(). This is needed for use cases where the set of trusted CAs is determined at request time (e.g. per-tenant mTLS upstreams).

  • a new X509_STORE *ssl_trusted_store field on ngx_http_lua_socket_tcp_upstream_t, used as a one-shot slot consumed by the handshake;
  • the FFI entry point ngx_http_lua_ffi_socket_tcp_settrustedstore() that validates the cosocket state and stores the pointer on the upstream;
  • SSL_set1_verify_cert_store() invocation inside ngx_http_lua_ffi_socket_tcp_sslhandshake() when a store has been set, with the slot cleared after use so it cannot leak across handshakes.

The matching tcpsock:settrustedstore() Lua wrapper will land in lua-resty-core in a separate change.

Related lua-resty-core PR: openresty/lua-resty-core#525

I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.

Comment thread doc/HttpLuaModule.wiki Outdated
* [[#tcpsock:bind|bind]]
* [[#tcpsock:connect|connect]]
* [[#tcpsock:setclientcert|setclientcert]]
* [[#tcpsock:settrustedstore|settrustedstore]]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update the README.markdown rather than the wiki

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I moved the doc to the README.markdown now.

Adds the cosocket-level plumbing for a new tcpsock:settrustedstore(store)
method, allowing Lua code to supply a per-handshake X509_STORE that
overrides lua_ssl_trusted_certificate for the upcoming sslhandshake().
This is needed for use cases where the set of trusted CAs is determined
at request time (e.g. per-tenant mTLS upstreams).

* a new X509_STORE *ssl_trusted_store field on
  ngx_http_lua_socket_tcp_upstream_t, used as a one-shot slot consumed
  by the handshake;
* the FFI entry point ngx_http_lua_ffi_socket_tcp_settrustedstore() that
  validates the cosocket state and stores the pointer on the upstream;
* SSL_set1_verify_cert_store() invocation inside
  ngx_http_lua_ffi_socket_tcp_sslhandshake() when a store has been set,
  with the slot cleared after use so it cannot leak across handshakes.

The matching tcpsock:settrustedstore() Lua wrapper will land in
lua-resty-core in a separate change.

Signed-off-by: Walker Zhao <walker.zhao@konghq.com>
@findns94 findns94 force-pushed the feat/support_trusted_cert branch from 5bac2d8 to 0110e9f Compare April 30, 2026 03:10
@zhuizhuhaomeng zhuizhuhaomeng merged commit 5de0120 into openresty:master May 2, 2026
3 checks passed
@zhuizhuhaomeng
Copy link
Copy Markdown
Contributor

@findns94 I have fixed some issues and merge this PR.
I hope you can add this feature for stream-lua-nginx-module also.

@findns94
Copy link
Copy Markdown
Contributor Author

findns94 commented May 3, 2026

@findns94 I have fixed some issues and merge this PR. I hope you can add this feature for stream-lua-nginx-module also.

Thanks! I will prepare a PR for stream-lua-nginx-module in a few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants