Skip to content

moteus/lua-lluv-ssl

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

lua-lluv-ssl

Licence Build Status

SSL/TLS sockets for lluv library

###Create SSL context

local ctx = ssl.context{ -- LuaSec compatiable table
  protocol = "tlsv1_2", -- ... and other options
  key      =  ...
  cafile   =  ...
  verify   =  ...
  options  =  ...
}

###Client

local client = ctx:client()

-- Client side do SSL handshake automatically
client:connect("127.0.0.1", 8881, function(cli, err)
  if err then return cli:close() end
  -- work with connection
  ...
end)

###Server

local server = ctx:server() 

server:bind("127.0.0.1", 8881):listen(function(srv, err)
  if err then return print("Listen error", err) end
  local cli = srv:accept()

  -- call SSL/TLS handshake
  cli:handshake(function(cli, err)
    if err then return cli:close() end
    -- work with connection
    ...
  end)
end)

###LuaSocket client

ut.corun(function()
  local cli = socket.ssl(ctx)
  cli:connect("127.0.0.1", 8881)
  -- work with connection
  ...
end)

###LuaSocket server

ut.corun(function()
  local srv = socket.ssl(ctx, true)
  srv:bind("127.0.0.1", 8881)
  while true do
    local cli, err = srv:accept()
    if cli then
      -- work with connection
      ...
    end
  end
end)