luadtls is a lua binding for tinydtls library .
luadtls contains 2 modules :
dtls.core
which is a direct binding of dtls.c from tinydtls. see dtls.c usage.dtls
to easily secure an UDP socket from luasocket with DTLS.
A dtls
/luasocket
sample :
local dtls = require 'dtls'
local socket = require 'socket'
-- create UDP socket
local udp = socket.udp();
udp:setsockname('*', 5683)
-- change UDP socket in DTLS socket
dtls.wrap(udp, {security = "PSK", identity = "Client_identity", key = "secretPSK"})
-- DTLS handshake in automaticaly do at first sendto
udp:sendto("my clear data","127.0.0.1", 5684)
repeat
local data, host, port, msg = udp:receivefrom()
-- receive clear data
print ("receive clear data",data, host, port)
until false
More samples available in sample folder.
Get the code : (--recursive
is need because of use of git submodule.)
git clone --recursive git@github.com:sbernard31/luadtls.git luadtls
Compile it : (You need lua header files from package liblua5.1-0-dev
and the tools cmake
and autoconf
-_-! ...)
mkdir [builddir]
cd [builddir]
cmake [luadtls source directory]
make
Test it : (Lua 5.1 and luasocket is needed, you can use californium.sandium server implementation to test.)
lua -e "package.path = './?/init.lua;' .. package.path" sample.lua
luadtls binding is still in development. For now, it is only compatible with Lua 5.1 and linux.