This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[luadist-git] add luasec-0.4-Darwin-x86_64
- Loading branch information
0 parents
commit 9046301
Showing
32 changed files
with
2,835 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
type = "x86_64" | ||
arch = "Darwin" | ||
author = "Bruno Silvestre" | ||
depends = { | ||
[[luasocket~>2.0]], | ||
[[openssl ~>1.0]], | ||
[[lua ~>5.1]], | ||
} | ||
|
||
desc = "LuaSec is a binding for OpenSSL library to provide TLS/SSL communication. It takes an already established TCP connection and creates a secure session between the peers." | ||
version = "0.4" | ||
maintainer = "Peter Drahoš" | ||
files = { | ||
Runtime = { | ||
[[lib/lua/ssl.so]], | ||
[[lib/lua/ssl.lua]], | ||
[[lib/lua/ssl/https.lua]], | ||
} | ||
, | ||
Example = { | ||
[[share/luasec/example//certs/clientA.cnf]], | ||
[[share/luasec/example//certs/clientA.sh]], | ||
[[share/luasec/example//certs/clientB.cnf]], | ||
[[share/luasec/example//certs/clientB.sh]], | ||
[[share/luasec/example//certs/rootA.cnf]], | ||
[[share/luasec/example//certs/rootA.sh]], | ||
[[share/luasec/example//certs/rootB.cnf]], | ||
[[share/luasec/example//certs/rootB.sh]], | ||
[[share/luasec/example//certs/serverA.cnf]], | ||
[[share/luasec/example//certs/serverA.sh]], | ||
[[share/luasec/example//certs/serverB.cnf]], | ||
[[share/luasec/example//certs/serverB.sh]], | ||
[[share/luasec/example//key/genkey.sh]], | ||
[[share/luasec/example//key/loadkey.lua]], | ||
[[share/luasec/example//loop/client.lua]], | ||
[[share/luasec/example//loop/server.lua]], | ||
[[share/luasec/example//loop-gc/client.lua]], | ||
[[share/luasec/example//loop-gc/server.lua]], | ||
[[share/luasec/example//oneshot/client.lua]], | ||
[[share/luasec/example//oneshot/server.lua]], | ||
[[share/luasec/example//README]], | ||
[[share/luasec/example//want/client.lua]], | ||
[[share/luasec/example//want/server.lua]], | ||
[[share/luasec/example//wantread/client.lua]], | ||
[[share/luasec/example//wantread/server.lua]], | ||
[[share/luasec/example//wantwrite/client.lua]], | ||
[[share/luasec/example//wantwrite/server.lua]], | ||
} | ||
, | ||
Data = { | ||
[[share/luasec/LICENSE]], | ||
} | ||
, | ||
} | ||
|
||
license = "MIT/X11" | ||
name = "luasec" | ||
url = "http://www.inf.puc-rio.br/~brunoos/luasec/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
------------------------------------------------------------------------------ | ||
-- LuaSec 0.4 | ||
-- Copyright (C) 2006-2009 Bruno Silvestre | ||
-- | ||
------------------------------------------------------------------------------ | ||
|
||
module("ssl", package.seeall) | ||
|
||
require("ssl.core") | ||
require("ssl.context") | ||
|
||
|
||
_VERSION = "0.4" | ||
_COPYRIGHT = "LuaSec 0.4 - Copyright (C) 2006-2009 Bruno Silvestre\n" .. | ||
"LuaSocket 2.0.2 - Copyright (C) 2004-2007 Diego Nehab" | ||
|
||
-- Export functions | ||
rawconnection = core.rawconnection | ||
rawcontext = context.rawcontext | ||
|
||
-- | ||
-- | ||
-- | ||
local function optexec(func, param, ctx) | ||
if param then | ||
if type(param) == "table" then | ||
return func(ctx, unpack(param)) | ||
else | ||
return func(ctx, param) | ||
end | ||
end | ||
return true | ||
end | ||
|
||
-- | ||
-- | ||
-- | ||
function newcontext(cfg) | ||
local succ, msg, ctx | ||
-- Create the context | ||
ctx, msg = context.create(cfg.protocol) | ||
if not ctx then return nil, msg end | ||
-- Mode | ||
succ, msg = context.setmode(ctx, cfg.mode) | ||
if not succ then return nil, msg end | ||
-- Load the key | ||
if cfg.key then | ||
succ, msg = context.loadkey(ctx, cfg.key, cfg.password) | ||
if not succ then return nil, msg end | ||
end | ||
-- Load the certificate | ||
if cfg.certificate then | ||
succ, msg = context.loadcert(ctx, cfg.certificate) | ||
if not succ then return nil, msg end | ||
end | ||
-- Load the CA certificates | ||
if cfg.cafile or cfg.capath then | ||
succ, msg = context.locations(ctx, cfg.cafile, cfg.capath) | ||
if not succ then return nil, msg end | ||
end | ||
-- Set the verification options | ||
succ, msg = optexec(context.setverify, cfg.verify, ctx) | ||
if not succ then return nil, msg end | ||
-- Set SSL options | ||
succ, msg = optexec(context.setoptions, cfg.options, ctx) | ||
if not succ then return nil, msg end | ||
-- Set the depth for certificate verification | ||
if cfg.depth then | ||
succ, msg = context.setdepth(ctx, cfg.depth) | ||
if not succ then return nil, msg end | ||
end | ||
return ctx | ||
end | ||
|
||
-- | ||
-- | ||
-- | ||
function wrap(sock, cfg) | ||
local ctx, msg | ||
if type(cfg) == "table" then | ||
ctx, msg = newcontext(cfg) | ||
if not ctx then return nil, msg end | ||
else | ||
ctx = cfg | ||
end | ||
local s, msg = core.create(ctx) | ||
if s then | ||
core.setfd(s, sock:getfd()) | ||
sock:setfd(core.invalidfd) | ||
return s | ||
end | ||
return nil, msg | ||
end |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
---------------------------------------------------------------------------- | ||
-- LuaSec 0.4 | ||
-- Copyright (C) 2009 PUC-Rio | ||
-- | ||
-- Author: Pablo Musa | ||
-- Author: Tomas Guisasola | ||
--------------------------------------------------------------------------- | ||
|
||
local socket = require("socket") | ||
local ssl = require("ssl") | ||
local ltn12 = require("ltn12") | ||
local http = require("socket.http") | ||
local url = require("socket.url") | ||
|
||
local table = require("table") | ||
local string = require("string") | ||
|
||
local try = socket.try | ||
local type = type | ||
local pairs = pairs | ||
local getmetatable = getmetatable | ||
|
||
module("ssl.https") | ||
|
||
_VERSION = "0.4" | ||
_COPYRIGHT = "LuaSec 0.4 - Copyright (C) 2009 PUC-Rio" | ||
|
||
-- Default settings | ||
PORT = 443 | ||
|
||
local cfg = { | ||
protocol = "tlsv1", | ||
options = "all", | ||
verify = "none", | ||
} | ||
|
||
-------------------------------------------------------------------- | ||
-- Auxiliar Functions | ||
-------------------------------------------------------------------- | ||
|
||
-- Insert default HTTPS port. | ||
local function default_https_port(u) | ||
return url.build(url.parse(u, {port = PORT})) | ||
end | ||
|
||
-- Convert an URL to a table according to Luasocket needs. | ||
local function urlstring_totable(url, body, result_table) | ||
url = { | ||
url = default_https_port(url), | ||
method = body and "POST" or "GET", | ||
sink = ltn12.sink.table(result_table) | ||
} | ||
if body then | ||
url.source = ltn12.source.string(body) | ||
url.headers = { | ||
["content-length"] = #body, | ||
["content-type"] = "application/x-www-form-urlencoded", | ||
} | ||
end | ||
return url | ||
end | ||
|
||
-- Forward calls to the real connection object. | ||
local function reg(conn) | ||
local mt = getmetatable(conn.sock).__index | ||
for name, method in pairs(mt) do | ||
if type(method) == "function" then | ||
conn[name] = function (self, ...) | ||
return method(self.sock, ...) | ||
end | ||
end | ||
end | ||
end | ||
|
||
-- Return a function which performs the SSL/TLS connection. | ||
local function tcp(params) | ||
params = params or {} | ||
-- Default settings | ||
for k, v in pairs(cfg) do | ||
params[k] = params[k] or v | ||
end | ||
-- Force client mode | ||
params.mode = "client" | ||
-- 'create' function for LuaSocket | ||
return function () | ||
local conn = {} | ||
conn.sock = try(socket.tcp()) | ||
local st = getmetatable(conn.sock).__index.settimeout | ||
function conn:settimeout(...) | ||
return st(self.sock, ...) | ||
end | ||
-- Replace TCP's connection function | ||
function conn:connect(host, port) | ||
try(self.sock:connect(host, port)) | ||
self.sock = try(ssl.wrap(self.sock, params)) | ||
try(self.sock:dohandshake()) | ||
reg(self, getmetatable(self.sock)) | ||
return 1 | ||
end | ||
return conn | ||
end | ||
end | ||
|
||
-------------------------------------------------------------------- | ||
-- Main Function | ||
-------------------------------------------------------------------- | ||
|
||
-- Make a HTTP request over secure connection. This function receives | ||
-- the same parameters of LuaSocket's HTTP module (except 'proxy' and | ||
-- 'redirect') plus LuaSec parameters. | ||
-- | ||
-- @param url mandatory (string or table) | ||
-- @param body optional (string) | ||
-- @return (string if url == string or 1), code, headers, status | ||
-- | ||
function request(url, body) | ||
local result_table = {} | ||
local stringrequest = type(url) == "string" | ||
if stringrequest then | ||
url = urlstring_totable(url, body, result_table) | ||
else | ||
url.url = default_https_port(url.url) | ||
end | ||
if http.PROXY or url.proxy then | ||
return nil, "proxy not supported" | ||
elseif url.redirect then | ||
return nil, "redirect not supported" | ||
elseif url.create then | ||
return nil, "create function not permitted" | ||
end | ||
-- New 'create' function to establish a secure connection | ||
url.create = tcp(url) | ||
local res, code, headers, status = http.request(url) | ||
if res and stringrequest then | ||
return table.concat(result_table), code, headers, status | ||
end | ||
return res, code, headers, status | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
LuaSec 0.4 license | ||
Copyright (C) 2006-2009 Bruno Silvestre, PUC-Rio | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
---------------------------------------------------------------------- | ||
|
||
LuaSocket 2.0.2 license | ||
Copyright � 2004-2007 Diego Nehab | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Directories: | ||
------------ | ||
* certs | ||
Contains scripts to generate the certificates used by the examples. | ||
Generate Root CA 'A' and 'B' first, then the servers and clients. | ||
|
||
* oneshot | ||
A simple connection example. | ||
|
||
* loop | ||
Test successive connections between the server and the client | ||
(to check memory leak). | ||
|
||
* loop-gc | ||
Same of above, but the connection is not explicit closed, the gabage | ||
collector is encharge of that. | ||
|
||
* wantread | ||
Test timeout in handshake() and receive(). | ||
|
||
* wantwrite | ||
Test timeout in send(). | ||
|
||
* want | ||
Test want(). | ||
|
||
* key | ||
Test encrypted private key. |
Oops, something went wrong.