@@ -1076,6 +1076,9 @@ Directives
10761076* [ lua_need_request_body] ( #lua_need_request_body )
10771077* [ ssl_certificate_by_lua_block] ( #ssl_certificate_by_lua_block )
10781078* [ ssl_certificate_by_lua_file] ( #ssl_certificate_by_lua_file )
1079+ * [ ssl_psk_by_lua_block] ( #ssl_psk_by_lua_block )
1080+ * [ ssl_psk_by_lua_file] ( #ssl_psk_by_lua_file )
1081+ * [ ssl_psk_identity_hint] ( #ssl_psk_identity_hint )
10791082* [ ssl_session_fetch_by_lua_block] ( #ssl_session_fetch_by_lua_block )
10801083* [ ssl_session_fetch_by_lua_file] ( #ssl_session_fetch_by_lua_file )
10811084* [ ssl_session_store_by_lua_block] ( #ssl_session_store_by_lua_block )
@@ -1094,6 +1097,8 @@ Directives
10941097* [ lua_ssl_protocols] ( #lua_ssl_protocols )
10951098* [ lua_ssl_trusted_certificate] ( #lua_ssl_trusted_certificate )
10961099* [ lua_ssl_verify_depth] ( #lua_ssl_verify_depth )
1100+ * [ lua_ssl_psk_identity] ( #lua_ssl_psk_identity )
1101+ * [ lua_ssl_psk_key] ( #lua_ssl_psk_key )
10971102* [ lua_http10_buffering] ( #lua_http10_buffering )
10981103* [ rewrite_by_lua_no_postpone] ( #rewrite_by_lua_no_postpone )
10991104* [ access_by_lua_no_postpone] ( #access_by_lua_no_postpone )
@@ -2564,6 +2569,108 @@ This directive was first introduced in the `v0.10.0` release.
25642569
25652570[ Back to TOC] ( #directives )
25662571
2572+ ssl_psk_by_lua_block
2573+ --------------------
2574+
2575+ ** syntax:** * ssl_psk_by_lua_block { lua-script }*
2576+
2577+ ** context:** * server*
2578+
2579+ ** phase:** * right-before-SSL-handshake*
2580+
2581+ This directive runs user Lua code when NGINX is about to start the SSL handshake for the downstream
2582+ SSL (https) connections using TLS-PSK and is meant for setting the TLS pre-shared key on a per-request basis.
2583+
2584+ The [ ngx.ssl] ( https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md )
2585+ Lua module provided by the [ lua-resty-core] ( https://github.com/openresty/lua-resty-core/#readme )
2586+ library is particularly useful in this context. You can use the Lua API offered by this Lua module
2587+ to set the TLS pre-shared key for the current SSL connection being initiated.
2588+
2589+ This Lua handler does not run at all, however, when NGINX/OpenSSL successfully resumes
2590+ the SSL session via SSL session IDs or TLS session tickets for the current SSL connection. In
2591+ other words, this Lua handler only runs when NGINX has to initiate a full SSL handshake.
2592+
2593+ Below is a trivial example using the
2594+ [ ngx.ssl] ( https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md ) module
2595+ at the same time:
2596+
2597+ ``` nginx
2598+
2599+ server {
2600+ listen 443 ssl;
2601+ server_name test.com;
2602+
2603+ ssl_psk_identity_hint Test_TLS-PSK_Identity_Hint;
2604+
2605+ ssl_psk_by_lua_block {
2606+ print("About to initiate a new TLS-PSK handshake!")
2607+ }
2608+
2609+ location / {
2610+ root html;
2611+ }
2612+ }
2613+ ```
2614+
2615+ See more complicated examples in the [ ngx.ssl] ( https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md )
2616+ Lua module's official documentation.
2617+
2618+ Uncaught Lua exceptions in the user Lua code immediately abort the current SSL session, so does the
2619+ [ ngx.exit] ( #ngxexit ) call with an error code like ` ngx.ERROR ` .
2620+
2621+ This Lua code execution context * does not* support yielding, so Lua APIs that may yield
2622+ (like cosockets, sleeping, and "light threads")
2623+ are disabled in this context.
2624+
2625+ Note, however, you still need to configure the [ ssl_certificate] ( http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_certificate ) and
2626+ [ ssl_certificate_key] ( http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_certificate_key )
2627+ directives even though you will not use this static certificate and private key at all. This is
2628+ because the NGINX core requires their appearance otherwise you are seeing the following error
2629+ while starting NGINX:
2630+
2631+
2632+ nginx: [emerg] no ssl configured for the server
2633+
2634+
2635+ Furthermore, one needs at least OpenSSL 1.0.0 for this directive to work.
2636+
2637+ This directive was first introduced in the ` v0.XX.YY ` release.
2638+
2639+ [ Back to TOC] ( #directives )
2640+
2641+ ssl_psk_by_lua_file
2642+ -------------------
2643+
2644+ ** syntax:** * ssl_psk_by_lua_file < ; path-to-lua-script-file> ; *
2645+
2646+ ** context:** * server*
2647+
2648+ ** phase:** * right-before-SSL-handshake*
2649+
2650+ Equivalent to [ ssl_psk_by_lua_block] ( #ssl_psk_by_lua_block ) , except that the file specified by ` <path-to-lua-script-file> ` contains the Lua code, or, as from the ` v0.5.0rc32 ` release, the [ Lua/LuaJIT bytecode] ( #lualuajit-bytecode-support ) to be executed.
2651+
2652+ When a relative path like ` foo/bar.lua ` is given, they will be turned into the absolute path relative to the ` server prefix ` path determined by the ` -p PATH ` command-line option while starting the Nginx server.
2653+
2654+ This directive was first introduced in the ` v0.XX.YY ` release.
2655+
2656+ [ Back to TOC] ( #directives )
2657+
2658+ ssl_psk_identity_hint
2659+ ---------------------
2660+
2661+ ** syntax:** * ssl_psk_identity_hint < ; tls_psk_identity_hint> ; *
2662+
2663+ ** default:** * no*
2664+
2665+ ** context:** * http, server*
2666+
2667+ Specifies the TLS-PSK identity hint string which NGINX will send to a client during
2668+ the SSL handshake for the downstream SSL (https) connections.
2669+
2670+ This directive was first introduced in the ` v0.XX.YY ` release.
2671+
2672+ [ Back to TOC] ( #directives )
2673+
25672674ssl_session_fetch_by_lua_block
25682675------------------------------
25692676
@@ -2958,6 +3065,36 @@ See also [lua_ssl_trusted_certificate](#lua_ssl_trusted_certificate).
29583065
29593066[ Back to TOC] ( #directives )
29603067
3068+ lua_ssl_psk_identity
3069+ --------------------
3070+
3071+ ** syntax:** * lua_ssl_psk_identity < ; tls_psk_identity> ; *
3072+
3073+ ** default:** * no*
3074+
3075+ ** context:** * http, server, location*
3076+
3077+ Specifies the TLS-PSK identity string which NGINX will send to a SSL/TLS server in the [ tcpsock: sslhandshake ] ( #tcpsocksslhandshake ) method.
3078+
3079+ This directive was first introduced in the ` v0.XX.YY ` release.
3080+
3081+ [ Back to TOC] ( #directives )
3082+
3083+ lua_ssl_psk_key
3084+ ---------------
3085+
3086+ ** syntax:** * lua_ssl_psk_key < ; tls_psk_key> ; *
3087+
3088+ ** default:** * no*
3089+
3090+ ** context:** * http, server, location*
3091+
3092+ Specifies the TLS-PSK key string which NGINX will try use with a SSL/TLS server in the [ tcpsock: sslhandshake ] ( #tcpsocksslhandshake ) method.
3093+
3094+ This directive was first introduced in the ` v0.XX.YY ` release.
3095+
3096+ [ Back to TOC] ( #directives )
3097+
29613098lua_http10_buffering
29623099--------------------
29633100
0 commit comments