Skip to content

Commit 99691c5

Browse files
author
Tuure Vartiainen
committed
doc: updated the documentation to contain a better example of using ssl_psk_by_lua_block.
1 parent b961ef4 commit 99691c5

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

README.markdown

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,7 @@ ssl_psk_by_lua_block
25812581
This directive runs user Lua code when NGINX is about to start the SSL handshake for the downstream
25822582
SSL (https) connections using TLS-PSK and is meant for setting the TLS pre-shared key on a per-request basis.
25832583

2584-
The [ngx.ssl](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md)
2584+
The [ngx.ssl](https://github.com/vartiait/lua-resty-core/blob/ssl-psk/lib/ngx/ssl.md)
25852585
Lua module provided by the [lua-resty-core](https://github.com/openresty/lua-resty-core/#readme)
25862586
library is particularly useful in this context. You can use the Lua API offered by this Lua module
25872587
to set the TLS pre-shared key for the current SSL connection being initiated.
@@ -2603,7 +2603,25 @@ at the same time:
26032603
ssl_psk_identity_hint Test_TLS-PSK_Identity_Hint;
26042604
26052605
ssl_psk_by_lua_block {
2606-
print("About to initiate a new TLS-PSK handshake!")
2606+
local ssl = require "ngx.ssl"
2607+
2608+
local psk_identity, err = ssl.get_psk_identity()
2609+
if not psk_identity then
2610+
ngx.log(ngx.ERR, "Failed to get TLS-PSK Identity: ", err)
2611+
return ngx.ERROR
2612+
end
2613+
2614+
print("Client TLS-PSK Identity: ", psk_identity)
2615+
2616+
local psk_key = "psk_test_key"
2617+
2618+
local ok, err = ssl.set_psk_key(psk_key)
2619+
if not ok then
2620+
ngx.log(ngx.ERR, "Failed to set TLS-PSK key: ", err)
2621+
return ngx.ERROR
2622+
end
2623+
2624+
return ngx.OK
26072625
}
26082626
26092627
location / {

doc/HttpLuaModule.wiki

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,7 @@ This directive was first introduced in the <code>v0.10.0</code> release.
21702170
This directive runs user Lua code when NGINX is about to start the SSL handshake for the downstream
21712171
SSL (https) connections using TLS-PSK and is meant for setting the TLS pre-shared key on a per-request basis.
21722172
2173-
The [https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md ngx.ssl]
2173+
The [https://github.com/vartiait/lua-resty-core/blob/ssl-psk/lib/ngx/ssl.md ngx.ssl]
21742174
Lua module provided by the [https://github.com/openresty/lua-resty-core/#readme lua-resty-core]
21752175
library is particularly useful in this context. You can use the Lua API offered by this Lua module
21762176
to set the TLS pre-shared key for the current SSL connection being initiated.
@@ -2191,7 +2191,25 @@ at the same time:
21912191
ssl_psk_identity_hint Test_TLS-PSK_Identity_Hint;
21922192
21932193
ssl_psk_by_lua_block {
2194-
print("About to initiate a new TLS-PSK handshake!")
2194+
local ssl = require "ngx.ssl"
2195+
2196+
local psk_identity, err = ssl.get_psk_identity()
2197+
if not psk_identity then
2198+
ngx.log(ngx.ERR, "Failed to get TLS-PSK Identity: ", err)
2199+
return ngx.ERROR
2200+
end
2201+
2202+
print("Client TLS-PSK Identity: ", psk_identity)
2203+
2204+
local psk_key = "psk_test_key"
2205+
2206+
local ok, err = ssl.set_psk_key(psk_key)
2207+
if not ok then
2208+
ngx.log(ngx.ERR, "Failed to set TLS-PSK key: ", err)
2209+
return ngx.ERROR
2210+
end
2211+
2212+
return ngx.OK
21952213
}
21962214
21972215
location / {

0 commit comments

Comments
 (0)