Skip to content

fix(ssl): prefer lua-resty-core SSL accessors - #243

Open
zhuizhuhaomeng wants to merge 2 commits into
fffonion:masterfrom
zhuizhuhaomeng:fix/prefer-resty-core-ssl
Open

zhuizhuhaomeng wants to merge 2 commits into
fffonion:masterfrom
zhuizhuhaomeng:fix/prefer-resty-core-ssl

Conversation

@zhuizhuhaomeng

@zhuizhuhaomeng zhuizhuhaomeng commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Prefer lua-resty-core APIs for downstream SSL/SSL_CTX pointers and cosocket SSL/SSL_CTX pointers in both HTTP and stream. Native operations work without initializing the auxiliary module or version-sensitive FFI structure layouts.

Use ngx.ssl.get_req_ssl_pointer(), ngx.ssl.get_req_ssl_ctx(), tcpsock:getsslpointer(), and tcpsock:getsslctx() when available. Cast returned pointers to the expected OpenSSL types and propagate native errors. Load the existing compatibility implementation lazily only when an API is unavailable. Also correct the auxiliary fallback's SSL_CTX getter mapping and include the legacy module in the rockspec.

The request SSL_CTX Lua API is added in lua-resty-core #548, backed by lua-nginx-module #2546 and stream-lua-nginx-module #420. It preserves Nginx session_ctx semantics after SNI selection. This consumer change retains its fallback on older core versions and binaries.

Validation:

  • All four SSL test files pass against the modified lua-resty-core and combined Nginx 1.31.8 / OpenSSL 3.5.9 build: 176 assertions.
  • The same suite passes on the older Nginx 1.27.1 / installed core combination: 176 assertions.
  • Selection tests cover native getters, pointer types, error propagation, missing modules/methods, partial C API availability, stream use, and the SSL_CTX fallback mapping.
  • Real HTTP and stream TLS probes verify request SSL/SSL_CTX and cosocket SSL/SSL_CTX access with legacy initialization explicitly forbidden.
  • Luacheck and git diff --check pass.

Use ngx.ssl.get_req_ssl_pointer and the cosocket getsslpointer and
getsslctx methods when supported by the running Nginx binary. Load
the existing auxiliary and FFI implementations only when needed,
preserving Nginx session_ctx semantics for downstream SSL_CTX access.

Correct the auxiliary SSL_CTX getter mapping and install the legacy
module through the rockspec. Cover native selection, pointer casts,
errors, partial availability, and HTTP/stream compatibility.

Validation: 164 SSL assertions pass on Nginx 1.27.1, including with
the C/Kong fallbacks disabled. Real HTTP and stream TLS probes and
luacheck also pass.
Use ngx.ssl.get_req_ssl_ctx when available, preserving the borrowed
SSL_CTX pointer type and propagating native errors without invoking a
legacy getter. Keep the existing fallback when the Lua API is absent.

Update the API-selection documentation and cover native request context
selection, error propagation, stream use, and absent-API fallback.

Validation: all 176 SSL assertions pass with the modified core and C
exports, and with the older Nginx/core installation. Real HTTP and stream
TLS probes pass with legacy initialization forbidden. Luacheck and
git diff --check pass.
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.

1 participant