Repository navigation
feature: add request SSL_CTX getter to the FFI API. - #2546
Merged
zhuizhuhaomeng merged 1 commit intoNov 8, 2026
Merged
Conversation
Export ngx_http_lua_ffi_get_req_ssl_ctx so Lua libraries can access Nginx's downstream session context without an auxiliary C module or version-dependent FFI structure layouts. Return the borrowed session_ctx, which can differ from SSL_get_SSL_CTX after SNI selection. Return explicit errors for missing request or SSL context state. Cover NULL and plain requests, certificate and content phases, repeated reads, and SNI selection with distinct default and active context settings. Validation: Nginx 1.31.8 / OpenSSL 3.5.9 build, 24 new assertions, 300 existing SSL C API assertions, and invalid-state C probes pass.
This was referenced Nov 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Export
ngx_http_lua_ffi_get_req_ssl_ctx(r, err)to let Lua libraries obtain the downstream request'sSSL_CTX*without lua-resty-openssl-aux-module or direct FFI access to Nginx structure layouts.The getter returns Nginx's borrowed
r->connection->ssl->session_ctx. It deliberately preserves this context when SNI switches the active context returned bySSL_get_SSL_CTX(). Missing request/connection/SSL state returnsNULLwithbad request; a missing session context returnsNULLwithbad ssl context. The getter does not allocate, free, or change ownership of the context.Tests cover NULL requests, plain connections, valid TLS access during certificate and content phases, repeated reads, and SNI selecting a different active context. The SNI case asserts distinct verify-depth values for the original and active contexts.
Validation on the local HTTP + stream build with Nginx 1.31.8 and OpenSSL 3.5.9:
t/198-request-ssl-ctx.t: 24 assertions passed.t/140-ssl-c-api.t: 300 assertions passed.git diff --checkpassed.This PR adds the C FFI export; a lua-resty-core wrapper can consume it separately.