mirror of
https://github.com/brunoos/luasec.git
synced 2024-12-27 04:58:20 +01:00
Fix PSK samples
This commit is contained in:
parent
6708ccc381
commit
b321ba8fab
@ -4,13 +4,20 @@
|
|||||||
local socket = require("socket")
|
local socket = require("socket")
|
||||||
local ssl = require("ssl")
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
-- @param hint (nil | string)
|
||||||
|
-- @param max_identity_len (number)
|
||||||
|
-- @param max_psk_len (number)
|
||||||
|
-- @return identity (string)
|
||||||
|
-- @return PSK (string)
|
||||||
|
local function pskcb(hint, max_identity_len, max_psk_len)
|
||||||
|
print(string.format("PSK Callback: hint=%q, max_identity_len=%d, max_psk_len=%d", hint, max_identity_len, max_psk_len))
|
||||||
|
return "abcd", "1234"
|
||||||
|
end
|
||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "client",
|
mode = "client",
|
||||||
protocol = "tlsv1_2",
|
protocol = "tlsv1_2",
|
||||||
psk = function(hint, max_psk_len)
|
psk = pskcb,
|
||||||
print("PSK Callback: hint=", hint, ", max_psk_len=", max_psk_len)
|
|
||||||
return "abcd", "1234"
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local peer = socket.tcp()
|
local peer = socket.tcp()
|
||||||
|
@ -4,17 +4,22 @@
|
|||||||
local socket = require("socket")
|
local socket = require("socket")
|
||||||
local ssl = require("ssl")
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
-- @param identity (string)
|
||||||
|
-- @param max_psk_len (number)
|
||||||
|
-- @return psk (string)
|
||||||
|
local function pskcb(identity, max_psk_len)
|
||||||
|
print(string.format("PSK Callback: identity=%q, max_psk_len=%d", identity, max_psk_len))
|
||||||
|
if identity == "abcd" then
|
||||||
|
return "1234"
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
local params = {
|
local params = {
|
||||||
mode = "server",
|
mode = "server",
|
||||||
protocol = "any",
|
protocol = "any",
|
||||||
options = "all",
|
options = "all",
|
||||||
psk = function(identity, max_psk_len)
|
psk = pskcb,
|
||||||
print("PSK Callback: identity=", identity, ", max_psk_len=", max_psk_len)
|
|
||||||
if identity == "abcd" then
|
|
||||||
return "1234"
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user