Skip to content

feature: ngx_http_lua_ffi_ssl_set_ciphers().#2513

Open
climagabriel wants to merge 1 commit into
openresty:masterfrom
climagabriel:set-ciphers-ffi
Open

feature: ngx_http_lua_ffi_ssl_set_ciphers().#2513
climagabriel wants to merge 1 commit into
openresty:masterfrom
climagabriel:set-ciphers-ffi

Conversation

@climagabriel

Copy link
Copy Markdown
Contributor

Adds ngx_http_lua_ffi_ssl_set_ciphers() to set the connection's TLS <= 1.2 cipher list and/or TLS 1.3 ciphersuites from ssl_client_hello_by_lua*, e.g. keyed on the client hello server name. Complements ngx_http_lua_ffi_ssl_set_protocols().

Both strings are validated on a scratch SSL_CTX before being applied to the connection, because a failed SSL_set_cipher_list() still installs the parsed list on the connection (emptying the TLS <= 1.2 list on unknown tokens, see the check-after-install discussion in openssl/openssl#7759) and leaves the thread error queue dirty, which makes SSL_do_handshake() report failure after the callback returns (SSL_get_error() requires an empty queue).

The guarantee: if ngx_http_lua_ffi_ssl_set_ciphers returns NGX_ERROR for an invalid ciphers and/or ciphersuites string, the connection's SSL object is left exactly as it was -- cipher list, ciphersuites, and thread error queue all untouched -- so the handshake proceeds with whatever the connection already had, which is the default list inherited from the server's SSL_CTX (ssl_ciphers/ssl_conf_command).

Lua API + docs + tests: companion PR openresty/lua-resty-core (link in first comment).

Sets the connection's TLS <= 1.2 cipher list and/or TLS 1.3 ciphersuites
from ssl_client_hello_by_lua*, e.g. keyed on the client hello server name.

Both strings are validated on a scratch SSL_CTX before being applied to
the connection, because a failed SSL_set_cipher_list() still installs the
parsed list on the connection (emptying the TLS <= 1.2 list on unknown
tokens) and leaves the thread error queue dirty, which makes
SSL_do_handshake() report failure after the callback returns.

The guarantee: if ngx_http_lua_ffi_ssl_set_ciphers returns NGX_ERROR for
an invalid ciphers and/or ciphersuites string, the connection's SSL
object is left exactly as it was -- cipher list, ciphersuites, and thread
error queue all untouched -- so the handshake proceeds with whatever the
connection already had, which is the default list inherited from the
vhost's SSL_CTX (ssl_ciphers/ssl_conf_command).

See openssl/openssl#7759 for the check-after-
install behaviour of SSL_set_cipher_list() and
https://docs.openssl.org/3.0/man3/SSL_get_error/ for the empty-queue
requirement.
@climagabriel

Copy link
Copy Markdown
Contributor Author

Lua API + docs + tests: openresty/lua-resty-core#535

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant