mirror of
https://github.com/brunoos/luasec.git
synced 2025-07-16 22:09:45 +02:00
Compare commits
40 Commits
luasec-dev
...
ocsp
Author | SHA1 | Date | |
---|---|---|---|
7ce63ad392 | |||
a3e74db781 | |||
cdcf5fdb30 | |||
bdbc67b188 | |||
359151144b | |||
d6b2fd7d35 | |||
d5df315617 | |||
34252fb10a | |||
711a98b760 | |||
4894c2f6a4 | |||
ae774258c5 | |||
de393417b7 | |||
22eadbd20e | |||
63e35c161f | |||
c6704919bd | |||
d7ccfad97f | |||
43feb51c5e | |||
860b2a8b5f | |||
caeaa5ffda | |||
9d84469912 | |||
87e51d99ea | |||
7898bd2043 | |||
c810df6839 | |||
1e2f342006 | |||
8ef33e33cf | |||
3490d8d1c0 | |||
86c8fa40c9 | |||
4903e2f2c1 | |||
2480572bdf | |||
c26513f4f7 | |||
f64e660de0 | |||
8722f83e8f | |||
a2dcfffcfa | |||
18fa0118be | |||
9f3a97e397 | |||
daf728fec2 | |||
57f2f1363f | |||
79c629956e | |||
5ffe22e98e | |||
6359275c5f |
50
CHANGELOG
50
CHANGELOG
@ -1,16 +1,48 @@
|
|||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 1.0.1
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
|
||||||
|
* Fix luaL_buffinit() can use the stack and broke buffer_meth_receive()
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 1.0
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
|
||||||
|
* Add cert:getsignaturename()
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 0.9
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
|
||||||
|
* Add DNS-based Authentication of Named Entities (DANE) support
|
||||||
|
* Add __close() metamethod
|
||||||
|
* Fix deprecation warnings with OpenSSL 1.1
|
||||||
|
* Fix special case listing of TLS 1.3 EC curves
|
||||||
|
* Fix general_name leak in cert:extensions()
|
||||||
|
* Fix unexported 'ssl.config' table
|
||||||
|
* Replace $(LD) with $(CCLD) variable
|
||||||
|
* Remove multiple definitions of 'ssl_options' variable
|
||||||
|
* Use tag in git format: v0.9
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
LuaSec 0.8.2
|
LuaSec 0.8.2
|
||||||
---------------
|
---------------
|
||||||
This version includes:
|
This version includes:
|
||||||
|
|
||||||
* Fix unexported 'ssl.config' table
|
* Fix unexported 'ssl.config' table (backported)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
LuaSec 0.8.1
|
LuaSec 0.8.1
|
||||||
---------------
|
---------------
|
||||||
This version includes:
|
This version includes:
|
||||||
|
|
||||||
* Fix another memory leak when get certficate extensions
|
* Fix general_name leak in cert:extensions() (backported)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
LuaSec 0.8
|
LuaSec 0.8
|
||||||
@ -26,6 +58,20 @@ This version includes:
|
|||||||
* Fix invalid reference to Lua state
|
* Fix invalid reference to Lua state
|
||||||
* Fix memory leak when get certficate extensions
|
* Fix memory leak when get certficate extensions
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 0.7.2
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
* Fix unexported 'ssl.config' table (backported)
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
LuaSec 0.7.1
|
||||||
|
---------------
|
||||||
|
This version includes:
|
||||||
|
|
||||||
|
* Fix general_name leak in cert:extensions() (backported)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
LuaSec 0.7
|
LuaSec 0.7
|
||||||
---------------
|
---------------
|
||||||
|
2
INSTALL
2
INSTALL
@ -1,4 +1,4 @@
|
|||||||
LuaSec 0.8.2
|
LuaSec 1.0.1
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* OpenSSL options:
|
* OpenSSL options:
|
||||||
|
4
LICENSE
4
LICENSE
@ -1,5 +1,5 @@
|
|||||||
LuaSec 0.8.2 license
|
LuaSec 1.0.1 license
|
||||||
Copyright (C) 2006-2019 Bruno Silvestre, UFG
|
Copyright (C) 2006-2021 Bruno Silvestre, UFG
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
LuaSec 0.8.2
|
LuaSec 1.0.1
|
||||||
===============
|
===============
|
||||||
LuaSec depends on OpenSSL, and integrates with LuaSocket to make it
|
LuaSec depends on OpenSSL, and integrates with LuaSocket to make it
|
||||||
easy to add secure connections to any Lua applications or scripts.
|
easy to add secure connections to any Lua applications or scripts.
|
||||||
|
|
||||||
Important: This version requires at least OpenSSL 1.0.2.
|
|
||||||
For old versions of OpenSSL, use LuaSec 0.7.
|
|
||||||
|
|
||||||
Documentation: https://github.com/brunoos/luasec/wiki
|
Documentation: https://github.com/brunoos/luasec/wiki
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package = "LuaSec"
|
package = "LuaSec"
|
||||||
version = "0.8.2-1"
|
version = "1.0.1-1"
|
||||||
source = {
|
source = {
|
||||||
url = "https://github.com/brunoos/luasec/archive/luasec-0.8.2.tar.gz",
|
url = "git://github.com/brunoos/luasec",
|
||||||
dir = "luasec-luasec-0.8.2"
|
tag = "v1.0.1",
|
||||||
}
|
}
|
||||||
description = {
|
description = {
|
||||||
summary = "A binding for OpenSSL library to provide TLS/SSL communication over LuaSocket.",
|
summary = "A binding for OpenSSL library to provide TLS/SSL communication over LuaSocket.",
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env sh
|
||||||
./rootA.sh
|
./rootA.sh
|
||||||
./rootB.sh
|
./rootB.sh
|
||||||
./clientA.sh
|
./clientA.sh
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
openssl req -newkey rsa:2048 -sha256 -keyout clientAkey.pem -out clientAreq.pem \
|
openssl req -newkey rsa:2048 -sha256 -keyout clientAkey.pem -out clientAreq.pem \
|
||||||
-nodes -config ./clientA.cnf -days 365 -batch
|
-nodes -config ./clientA.cnf -days 365 -batch
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
openssl req -newkey rsa:2048 -sha256 -keyout clientBkey.pem -out clientBreq.pem \
|
openssl req -newkey rsa:2048 -sha256 -keyout clientBkey.pem -out clientBreq.pem \
|
||||||
-nodes -config ./clientB.cnf -days 365 -batch
|
-nodes -config ./clientB.cnf -days 365 -batch
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
openssl req -newkey rsa:2048 -sha256 -keyout rootAkey.pem -out rootAreq.pem -nodes -config ./rootA.cnf -days 365 -batch
|
openssl req -newkey rsa:2048 -sha256 -keyout rootAkey.pem -out rootAreq.pem -nodes -config ./rootA.cnf -days 365 -batch
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
openssl req -newkey rsa:2048 -sha256 -keyout rootBkey.pem -out rootBreq.pem -nodes -config ./rootB.cnf -days 365 -batch
|
openssl req -newkey rsa:2048 -sha256 -keyout rootBkey.pem -out rootBreq.pem -nodes -config ./rootB.cnf -days 365 -batch
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
openssl req -newkey rsa:2048 -keyout serverAkey.pem -out serverAreq.pem \
|
openssl req -newkey rsa:2048 -keyout serverAkey.pem -out serverAreq.pem \
|
||||||
-config ./serverA.cnf -nodes -days 365 -batch
|
-config ./serverA.cnf -nodes -days 365 -batch
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
openssl req -newkey rsa:2048 -keyout serverBkey.pem -out serverBreq.pem \
|
openssl req -newkey rsa:2048 -keyout serverBkey.pem -out serverBreq.pem \
|
||||||
-config ./serverB.cnf -nodes -days 365 -batch
|
-config ./serverB.cnf -nodes -days 365 -batch
|
||||||
|
40
samples/dane/client.lua
Normal file
40
samples/dane/client.lua
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
local socket = require "socket";
|
||||||
|
local ssl = require "ssl";
|
||||||
|
|
||||||
|
local dns = require "lunbound".new();
|
||||||
|
|
||||||
|
|
||||||
|
local cfg = {
|
||||||
|
protocol = "tlsv1_2",
|
||||||
|
mode = "client",
|
||||||
|
ciphers = "DEFAULT",
|
||||||
|
capath = "/etc/ssl/certs",
|
||||||
|
verify = "peer",
|
||||||
|
dane = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
local function daneconnect(host, port)
|
||||||
|
port = port or "443";
|
||||||
|
local conn = ssl.wrap(socket.connect(host, port), cfg);
|
||||||
|
|
||||||
|
local tlsa = dns:resolve("_" .. port .. "._tcp." .. host, 52);
|
||||||
|
assert(tlsa.secure, "Insecure DNS");
|
||||||
|
|
||||||
|
assert(conn:setdane(host));
|
||||||
|
for i = 1, tlsa.n do
|
||||||
|
local usage, selector, mtype = tlsa[i] :byte(1, 3);
|
||||||
|
assert(conn:settlsa(usage, selector, mtype, tlsa[i] :sub(4, - 1)));
|
||||||
|
end
|
||||||
|
|
||||||
|
assert(conn:dohandshake());
|
||||||
|
return conn;
|
||||||
|
end
|
||||||
|
|
||||||
|
if not ... then
|
||||||
|
print("Usage: client.lua example.com [port]");
|
||||||
|
return os.exit(1);
|
||||||
|
end
|
||||||
|
local conn = daneconnect(...);
|
||||||
|
|
||||||
|
print(conn:getpeerverification());
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
openssl dhparam -2 -out dh-512.pem -outform PEM 512
|
openssl dhparam -2 -out dh-512.pem -outform PEM 512
|
||||||
openssl dhparam -2 -out dh-1024.pem -outform PEM 1024
|
openssl dhparam -2 -out dh-1024.pem -outform PEM 1024
|
||||||
|
2
samples/key/genkey.sh
Normal file → Executable file
2
samples/key/genkey.sh
Normal file → Executable file
@ -1,3 +1,3 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
openssl genrsa -des3 -out key.pem -passout pass:foobar 2048
|
openssl genrsa -des3 -out key.pem -passout pass:foobar 2048
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
mkdir -p certs
|
mkdir -p certs
|
||||||
|
|
||||||
|
54
samples/ocsp/client.lua
Normal file
54
samples/ocsp/client.lua
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
--
|
||||||
|
-- Public domain
|
||||||
|
--
|
||||||
|
local socket = require("socket")
|
||||||
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
local ocsp = ssl.ocsp
|
||||||
|
|
||||||
|
-- Parameters
|
||||||
|
-- * status:
|
||||||
|
-- * nil (no status was sent by server)
|
||||||
|
-- * ocsp.status.successful
|
||||||
|
-- * ocsp.status.malformedrequest
|
||||||
|
-- * ocsp.status.internalerror
|
||||||
|
-- * ocsp.status.trylater
|
||||||
|
-- * ocsp.status.sigrequired
|
||||||
|
-- * ocsp.status.unauthorized
|
||||||
|
--
|
||||||
|
-- Returns
|
||||||
|
-- * nil: on error
|
||||||
|
-- * true: status was accepted (continue the handshake)
|
||||||
|
-- * false: status not accepted (handshake stops with error)
|
||||||
|
--
|
||||||
|
local callback = function(status)
|
||||||
|
print("Status: ", status)
|
||||||
|
print("---")
|
||||||
|
|
||||||
|
if status == nil then
|
||||||
|
print("[WARN] No OCSP response")
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return (status == ocsp.status.successful)
|
||||||
|
end
|
||||||
|
|
||||||
|
local params = {
|
||||||
|
mode = "client",
|
||||||
|
protocol = "tlsv1_2",
|
||||||
|
verify = "none",
|
||||||
|
options = "all",
|
||||||
|
ocsp = callback,
|
||||||
|
}
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local peer = socket.tcp()
|
||||||
|
peer:connect("127.0.0.1", 8443)
|
||||||
|
|
||||||
|
peer = assert(ssl.wrap(peer, params))
|
||||||
|
assert(peer:dohandshake())
|
||||||
|
|
||||||
|
print(peer:receive())
|
||||||
|
print("------------")
|
||||||
|
peer:close()
|
||||||
|
end
|
89
samples/ocsp/server.lua
Normal file
89
samples/ocsp/server.lua
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
--
|
||||||
|
-- Public domain
|
||||||
|
--
|
||||||
|
local socket = require("socket")
|
||||||
|
local ssl = require("ssl")
|
||||||
|
|
||||||
|
local mime = require("mime")
|
||||||
|
local ltn12 = require("ltn12")
|
||||||
|
local http = require("socket.http")
|
||||||
|
|
||||||
|
local ocsp = ssl.ocsp
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local response
|
||||||
|
|
||||||
|
function loadresponse(certfile, cafile)
|
||||||
|
local f = io.open(cafile)
|
||||||
|
local ca = f:read("*a")
|
||||||
|
ca = ssl.loadcertificate(ca)
|
||||||
|
f:close()
|
||||||
|
|
||||||
|
f = io.open(certfile)
|
||||||
|
local cert = f:read("*a")
|
||||||
|
cert = ssl.loadcertificate(cert)
|
||||||
|
f:close()
|
||||||
|
|
||||||
|
local res = {}
|
||||||
|
local req = ocsp.buildrequest(cert, ca)
|
||||||
|
req = mime.b64(req)
|
||||||
|
|
||||||
|
local a, b = http.request {
|
||||||
|
url = "http://zerossl.ocsp.sectigo.com/" .. req,
|
||||||
|
method = "GET",
|
||||||
|
sink = ltn12.sink.table(res),
|
||||||
|
header = {
|
||||||
|
["Content-Type"] = "application/ocsp-request",
|
||||||
|
["Host"] = "zerossl.ocsp.sectigo.com",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
response = table.concat(res)
|
||||||
|
|
||||||
|
local thisupd, nextupd = ocsp.responsetime(response)
|
||||||
|
print("This update: ", thisupd)
|
||||||
|
print("Next update: ", nextupd)
|
||||||
|
end
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local cafile = "ca.pem"
|
||||||
|
local certfile = "server.pem"
|
||||||
|
|
||||||
|
-- Remember to update 'response' before 'next update'
|
||||||
|
local callback = function()
|
||||||
|
if not response then
|
||||||
|
loadresponse(certfile, cafile)
|
||||||
|
end
|
||||||
|
return response
|
||||||
|
end
|
||||||
|
|
||||||
|
local params = {
|
||||||
|
mode = "server",
|
||||||
|
protocol = "any",
|
||||||
|
key = "server.key",
|
||||||
|
certificate = certfile,
|
||||||
|
verify = "none",
|
||||||
|
options = "all",
|
||||||
|
ocsp = callback,
|
||||||
|
}
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local ctx = assert(ssl.newcontext(params))
|
||||||
|
|
||||||
|
local server = socket.tcp()
|
||||||
|
server:setoption('reuseaddr', true)
|
||||||
|
assert(server:bind("127.0.0.1", 8443))
|
||||||
|
server:listen()
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local peer = server:accept()
|
||||||
|
peer = assert(ssl.wrap(peer, ctx))
|
||||||
|
local succ = peer:dohandshake()
|
||||||
|
if succ then
|
||||||
|
peer:send("OCSP test\n")
|
||||||
|
peer:close()
|
||||||
|
end
|
||||||
|
end
|
@ -25,7 +25,7 @@ MAC_LDFLAGS=-bundle -undefined dynamic_lookup $(LIBDIR)
|
|||||||
|
|
||||||
INSTALL = install
|
INSTALL = install
|
||||||
CC ?= cc
|
CC ?= cc
|
||||||
LD ?= $(MYENV) cc
|
CCLD ?= $(MYENV) $(CC)
|
||||||
CFLAGS += $(MYCFLAGS)
|
CFLAGS += $(MYCFLAGS)
|
||||||
LDFLAGS += $(MYLDFLAGS)
|
LDFLAGS += $(MYLDFLAGS)
|
||||||
|
|
||||||
@ -52,15 +52,15 @@ luasocket:
|
|||||||
@cd luasocket && $(MAKE)
|
@cd luasocket && $(MAKE)
|
||||||
|
|
||||||
$(CMOD): $(EXTRA) $(OBJS)
|
$(CMOD): $(EXTRA) $(OBJS)
|
||||||
$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
|
$(CCLD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
cd luasocket && $(MAKE) clean
|
cd luasocket && $(MAKE) clean
|
||||||
rm -f $(OBJS) $(CMOD)
|
rm -f $(OBJS) $(CMOD)
|
||||||
|
|
||||||
options.o: options.c options.h
|
options.o: options.h options.c
|
||||||
ec.o: ec.c ec.h
|
ec.o: ec.c ec.h
|
||||||
x509.o: x509.c x509.h compat.h
|
x509.o: x509.c x509.h compat.h
|
||||||
context.o: context.c context.h ec.h compat.h
|
context.o: context.c context.h ec.h compat.h options.h
|
||||||
ssl.o: ssl.c ssl.h context.h x509.h compat.h
|
ssl.o: ssl.c ssl.h context.h x509.h compat.h
|
||||||
config.o: config.c ec.h options.h compat.h
|
config.o: config.c ec.h options.h compat.h
|
||||||
|
30
src/compat.h
30
src/compat.h
@ -1,19 +1,25 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.8.2
|
* LuaSec 1.0.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre
|
* Copyright (C) 2006-2021 Bruno Silvestre
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef LSEC_COMPAT_H
|
#ifndef LSEC_COMPAT_H
|
||||||
#define LSEC_COMPAT_H
|
#define LSEC_COMPAT_H
|
||||||
|
|
||||||
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#define LSEC_API __declspec(dllexport)
|
#define LSEC_API __declspec(dllexport)
|
||||||
#else
|
#else
|
||||||
#define LSEC_API extern
|
#define LSEC_API extern
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#if (LUA_VERSION_NUM == 501)
|
#if (LUA_VERSION_NUM == 501)
|
||||||
|
|
||||||
#define luaL_testudata(L, ud, tname) lsec_testudata(L, ud, tname)
|
#define luaL_testudata(L, ud, tname) lsec_testudata(L, ud, tname)
|
||||||
@ -28,4 +34,24 @@
|
|||||||
#define setfuncs(L, R) luaL_setfuncs(L, R, 0)
|
#define setfuncs(L, R) luaL_setfuncs(L, R, 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if (!defined(LIBRESSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER >= 0x1010000fL))
|
||||||
|
#define LSEC_ENABLE_DANE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if !((defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER < 0x2070000fL)) || (OPENSSL_VERSION_NUMBER < 0x1010000fL))
|
||||||
|
#define LSEC_API_OPENSSL_1_1_0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if !defined(LIBRESSL_VERSION_NUMBER) && ((OPENSSL_VERSION_NUMBER & 0xFFFFF000L) == 0x10101000L)
|
||||||
|
#define LSEC_OPENSSL_1_1_1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
20
src/config.c
20
src/config.c
@ -1,7 +1,7 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.8.2
|
* LuaSec 1.0.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre.
|
* Copyright (C) 2006-2021 Bruno Silvestre.
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ LSEC_API int luaopen_ssl_config(lua_State *L)
|
|||||||
lua_pushstring(L, "tlsv1_2");
|
lua_pushstring(L, "tlsv1_2");
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
lua_rawset(L, -3);
|
lua_rawset(L, -3);
|
||||||
#if defined(TLS1_3_VERSION)
|
#ifdef TLS1_3_VERSION
|
||||||
lua_pushstring(L, "tlsv1_3");
|
lua_pushstring(L, "tlsv1_3");
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
lua_rawset(L, -3);
|
lua_rawset(L, -3);
|
||||||
@ -74,6 +74,20 @@ LSEC_API int luaopen_ssl_config(lua_State *L)
|
|||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
lua_rawset(L, -3);
|
lua_rawset(L, -3);
|
||||||
|
|
||||||
|
#ifdef LSEC_ENABLE_DANE
|
||||||
|
// DANE
|
||||||
|
lua_pushstring(L, "dane");
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef OPENSSL_NO_OCSP
|
||||||
|
// OCSP
|
||||||
|
lua_pushstring(L, "ocsp");
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef OPENSSL_NO_EC
|
#ifndef OPENSSL_NO_EC
|
||||||
lua_pushstring(L, "curves_list");
|
lua_pushstring(L, "curves_list");
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
|
291
src/context.c
291
src/context.c
@ -1,9 +1,9 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.8.2
|
* LuaSec 1.0.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2019 Kim Alvefur, Paul Aurich, Tobias Markmann,
|
* Copyright (C) 2014-2021 Kim Alvefur, Paul Aurich, Tobias Markmann,
|
||||||
* Matthew Wild.
|
* Matthew Wild.
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre.
|
* Copyright (C) 2006-2021 Bruno Silvestre.
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -17,12 +17,19 @@
|
|||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
#include <openssl/x509.h>
|
#include <openssl/x509.h>
|
||||||
#include <openssl/x509v3.h>
|
#include <openssl/x509v3.h>
|
||||||
|
#include <openssl/dh.h>
|
||||||
|
|
||||||
|
#ifndef OPENSSL_NO_OCSP
|
||||||
|
#include <openssl/ocsp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
|
|
||||||
|
#include "compat.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
#include "x509.h"
|
||||||
|
|
||||||
#ifndef OPENSSL_NO_EC
|
#ifndef OPENSSL_NO_EC
|
||||||
#include <openssl/ec.h>
|
#include <openssl/ec.h>
|
||||||
@ -59,7 +66,7 @@ static int set_option_flag(const char *opt, unsigned long *flag)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2070000fL) || (OPENSSL_VERSION_NUMBER < 0x1010000fL)
|
#ifndef LSEC_API_OPENSSL_1_1_0
|
||||||
/**
|
/**
|
||||||
* Find the protocol.
|
* Find the protocol.
|
||||||
*/
|
*/
|
||||||
@ -331,7 +338,7 @@ static int create(lua_State *L)
|
|||||||
ERR_reason_error_string(ERR_get_error()));
|
ERR_reason_error_string(ERR_get_error()));
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
#if ! ((defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2070000fL) || (OPENSSL_VERSION_NUMBER < 0x1010000fL))
|
#ifdef LSEC_API_OPENSSL_1_1_0
|
||||||
SSL_CTX_set_min_proto_version(ctx->context, vmin);
|
SSL_CTX_set_min_proto_version(ctx->context, vmin);
|
||||||
SSL_CTX_set_max_proto_version(ctx->context, vmax);
|
SSL_CTX_set_max_proto_version(ctx->context, vmax);
|
||||||
#endif
|
#endif
|
||||||
@ -612,7 +619,9 @@ static int set_curves_list(lua_State *L)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(LIBRESSL_VERSION_NUMBER) || !defined(LSEC_API_OPENSSL_1_1_0)
|
||||||
(void)SSL_CTX_set_ecdh_auto(ctx, 1);
|
(void)SSL_CTX_set_ecdh_auto(ctx, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
@ -703,6 +712,211 @@ static int set_alpn_cb(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef OPENSSL_NO_OCSP
|
||||||
|
static int ocsp_server_cb(SSL *ssl, void *arg)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
BIO *bio;
|
||||||
|
const char *data;
|
||||||
|
unsigned char *r = NULL;
|
||||||
|
OCSP_RESPONSE *resp = NULL;
|
||||||
|
p_context ctx = (p_context)arg;
|
||||||
|
lua_State *L = ctx->L;
|
||||||
|
|
||||||
|
// Retrieve the callback
|
||||||
|
luaL_getmetatable(L, "SSL:OCSP:Registry");
|
||||||
|
lua_pushlightuserdata(L, ctx->context);
|
||||||
|
lua_rawget(L, -2);
|
||||||
|
|
||||||
|
lua_call(L, 0, 1);
|
||||||
|
if (lua_type(L, -1) != LUA_TSTRING) {
|
||||||
|
return SSL_TLSEXT_ERR_NOACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
data = lua_tostring(L, -1);
|
||||||
|
len = (int)lua_rawlen(L, -1);
|
||||||
|
|
||||||
|
bio = BIO_new_mem_buf(data, len);
|
||||||
|
if (bio == NULL)
|
||||||
|
return SSL_TLSEXT_ERR_NOACK;
|
||||||
|
|
||||||
|
resp = d2i_OCSP_RESPONSE_bio(bio, NULL);
|
||||||
|
BIO_free(bio);
|
||||||
|
if (resp == NULL)
|
||||||
|
return SSL_TLSEXT_ERR_NOACK;
|
||||||
|
|
||||||
|
len = i2d_OCSP_RESPONSE(resp, &r);
|
||||||
|
if (len <= 0) {
|
||||||
|
OCSP_RESPONSE_free(resp);
|
||||||
|
return SSL_TLSEXT_ERR_NOACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSL_set_tlsext_status_ocsp_resp(ssl, r, len);
|
||||||
|
OCSP_RESPONSE_free(resp);
|
||||||
|
return SSL_TLSEXT_ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ocsp_client_cb(SSL *ssl, void *arg)
|
||||||
|
{
|
||||||
|
long len;
|
||||||
|
const unsigned char *b;
|
||||||
|
OCSP_RESPONSE *ocsp = NULL;
|
||||||
|
p_context ctx = (p_context)arg;
|
||||||
|
lua_State *L = ctx->L;
|
||||||
|
|
||||||
|
// Retrieve the callback
|
||||||
|
luaL_getmetatable(L, "SSL:OCSP:Registry");
|
||||||
|
lua_pushlightuserdata(L, ctx->context);
|
||||||
|
lua_rawget(L, -2);
|
||||||
|
|
||||||
|
len = SSL_get_tlsext_status_ocsp_resp(ssl, &b);
|
||||||
|
if (len == -1)
|
||||||
|
lua_pushnil(L);
|
||||||
|
else {
|
||||||
|
ocsp = d2i_OCSP_RESPONSE(NULL, &b, len);
|
||||||
|
lua_pushinteger(L, OCSP_response_status(ocsp));
|
||||||
|
OCSP_RESPONSE_free(ocsp);
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_call(L, 1, 1);
|
||||||
|
return (lua_type(L, -1) != LUA_TBOOLEAN) ? -1 : (int)lua_toboolean(L, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int set_ocsp_cb(lua_State *L)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
p_context ctx = checkctx(L, 1);
|
||||||
|
|
||||||
|
luaL_getmetatable(L, "SSL:OCSP:Registry");
|
||||||
|
lua_pushlightuserdata(L, (void*)ctx->context);
|
||||||
|
lua_pushvalue(L, 2);
|
||||||
|
lua_settable(L, -3);
|
||||||
|
|
||||||
|
ret = (int)SSL_CTX_set_tlsext_status_type(ctx->context, TLSEXT_STATUSTYPE_ocsp);
|
||||||
|
if (ret == 0) {
|
||||||
|
lua_pushboolean(L, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx->mode == LSEC_MODE_CLIENT)
|
||||||
|
ret = (int)SSL_CTX_set_tlsext_status_cb(ctx->context, ocsp_client_cb);
|
||||||
|
else
|
||||||
|
ret = (int)SSL_CTX_set_tlsext_status_cb(ctx->context, ocsp_server_cb);
|
||||||
|
|
||||||
|
if (ret == 0) {
|
||||||
|
lua_pushboolean(L, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = (int)SSL_CTX_set_tlsext_status_arg(ctx->context, ctx);
|
||||||
|
lua_pushboolean(L, ret == 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ocsp_build_request(lua_State *L)
|
||||||
|
{
|
||||||
|
long len;
|
||||||
|
BIO *bio;
|
||||||
|
X509 *cert;
|
||||||
|
X509 *issuer;
|
||||||
|
OCSP_CERTID *cid;
|
||||||
|
OCSP_REQUEST *req;
|
||||||
|
char *buf;
|
||||||
|
|
||||||
|
cert = lsec_checkx509(L, 1);
|
||||||
|
issuer = lsec_checkx509(L, 2);
|
||||||
|
|
||||||
|
req = OCSP_REQUEST_new();
|
||||||
|
if (req == NULL) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cid = OCSP_cert_to_id(NULL, cert, issuer);
|
||||||
|
if (cid == NULL) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OCSP_request_add0_id(req, cid) == NULL) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bio = BIO_new(BIO_s_mem());
|
||||||
|
i2d_OCSP_REQUEST_bio(bio, req);
|
||||||
|
len = BIO_get_mem_data(bio, &buf);
|
||||||
|
lua_pushlstring(L, buf, len);
|
||||||
|
|
||||||
|
BIO_free(bio);
|
||||||
|
OCSP_REQUEST_free(req);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ocsp_response_time(lua_State *L)
|
||||||
|
{
|
||||||
|
long len;
|
||||||
|
BIO *bio;
|
||||||
|
char *buf;
|
||||||
|
int reason;
|
||||||
|
OCSP_BASICRESP *bs;
|
||||||
|
OCSP_SINGLERESP *sr;
|
||||||
|
OCSP_RESPONSE *res;
|
||||||
|
ASN1_GENERALIZEDTIME *revtime, *thisupd, *nextupd;
|
||||||
|
|
||||||
|
buf = (char*)lua_tostring(L, 1);
|
||||||
|
len = (long)lua_rawlen(L, 1);
|
||||||
|
|
||||||
|
res = d2i_OCSP_RESPONSE(NULL, (const unsigned char**)&buf, (int)len);
|
||||||
|
if (res == NULL) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
bs = OCSP_response_get1_basic(res);
|
||||||
|
if (bs == NULL) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
sr = OCSP_resp_get0(bs, 0);
|
||||||
|
OCSP_single_get0_status(sr, &reason, &revtime, &thisupd, &nextupd);
|
||||||
|
|
||||||
|
bio = BIO_new(BIO_s_mem());
|
||||||
|
ASN1_GENERALIZEDTIME_print(bio, thisupd);
|
||||||
|
len = BIO_get_mem_data(bio, &buf);
|
||||||
|
lua_pushlstring(L, buf, len);
|
||||||
|
BIO_free(bio);
|
||||||
|
|
||||||
|
bio = BIO_new(BIO_s_mem());
|
||||||
|
ASN1_GENERALIZEDTIME_print(bio, nextupd);
|
||||||
|
len = BIO_get_mem_data(bio, &buf);
|
||||||
|
lua_pushlstring(L, buf, len);
|
||||||
|
BIO_free(bio);
|
||||||
|
|
||||||
|
OCSP_BASICRESP_free(bs);
|
||||||
|
OCSP_RESPONSE_free(res);
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(LSEC_ENABLE_DANE)
|
||||||
|
/*
|
||||||
|
* DANE
|
||||||
|
*/
|
||||||
|
static int set_dane(lua_State *L)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
SSL_CTX *ctx = lsec_checkcontext(L, 1);
|
||||||
|
ret = SSL_CTX_dane_enable(ctx);
|
||||||
|
lua_pushboolean(L, (ret > 0));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Package functions
|
* Package functions
|
||||||
@ -722,12 +936,16 @@ static luaL_Reg funcs[] = {
|
|||||||
{"setverify", set_verify},
|
{"setverify", set_verify},
|
||||||
{"setoptions", set_options},
|
{"setoptions", set_options},
|
||||||
{"setmode", set_mode},
|
{"setmode", set_mode},
|
||||||
|
|
||||||
#if !defined(OPENSSL_NO_EC)
|
#if !defined(OPENSSL_NO_EC)
|
||||||
{"setcurve", set_curve},
|
{"setcurve", set_curve},
|
||||||
{"setcurveslist", set_curves_list},
|
{"setcurveslist", set_curves_list},
|
||||||
|
#endif
|
||||||
|
#if defined(LSEC_ENABLE_DANE)
|
||||||
|
{"setdane", set_dane},
|
||||||
|
#endif
|
||||||
|
#if !defined(OPENSSL_NO_OCSP)
|
||||||
|
{"setocspcb", set_ocsp_cb},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -753,6 +971,10 @@ static int meth_destroy(lua_State *L)
|
|||||||
lua_pushlightuserdata(L, (void*)ctx->context);
|
lua_pushlightuserdata(L, (void*)ctx->context);
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
|
luaL_getmetatable(L, "SSL:OCSP:Registry");
|
||||||
|
lua_pushlightuserdata(L, (void*)ctx->context);
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_settable(L, -3);
|
||||||
|
|
||||||
SSL_CTX_free(ctx->context);
|
SSL_CTX_free(ctx->context);
|
||||||
ctx->context = NULL;
|
ctx->context = NULL;
|
||||||
@ -828,6 +1050,7 @@ static int meth_set_verify_ext(lua_State *L)
|
|||||||
* Context metamethods.
|
* Context metamethods.
|
||||||
*/
|
*/
|
||||||
static luaL_Reg meta[] = {
|
static luaL_Reg meta[] = {
|
||||||
|
{"__close", meth_destroy},
|
||||||
{"__gc", meth_destroy},
|
{"__gc", meth_destroy},
|
||||||
{"__tostring", meth_tostring},
|
{"__tostring", meth_tostring},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
@ -889,6 +1112,55 @@ void *lsec_testudata (lua_State *L, int ud, const char *tname) {
|
|||||||
|
|
||||||
/*------------------------------ Initialization ------------------------------*/
|
/*------------------------------ Initialization ------------------------------*/
|
||||||
|
|
||||||
|
#ifndef OPENSSL_NO_OCSP
|
||||||
|
struct ocsp_status_response_s {
|
||||||
|
const char *name;
|
||||||
|
int value;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct ocsp_status_response_s ocsp_status_response_t;
|
||||||
|
|
||||||
|
static ocsp_status_response_t status_response[] = {
|
||||||
|
{"successful", OCSP_RESPONSE_STATUS_SUCCESSFUL},
|
||||||
|
{"malformedrequest", OCSP_RESPONSE_STATUS_MALFORMEDREQUEST},
|
||||||
|
{"internalerror", OCSP_RESPONSE_STATUS_INTERNALERROR},
|
||||||
|
{"trylater", OCSP_RESPONSE_STATUS_TRYLATER},
|
||||||
|
{"sigrequired", OCSP_RESPONSE_STATUS_SIGREQUIRED},
|
||||||
|
{"unauthorized", OCSP_RESPONSE_STATUS_UNAUTHORIZED},
|
||||||
|
{NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
static luaL_Reg ocsp_funcs[] = {
|
||||||
|
{"buildrequest", ocsp_build_request},
|
||||||
|
{"responsetime", ocsp_response_time},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OCSP module
|
||||||
|
*/
|
||||||
|
LSEC_API int luaopen_ssl_context_ocsp(lua_State *L)
|
||||||
|
{
|
||||||
|
ocsp_status_response_t *ptr;
|
||||||
|
|
||||||
|
luaL_newlib(L, ocsp_funcs);
|
||||||
|
|
||||||
|
lua_pushstring(L, "status");
|
||||||
|
lua_newtable(L);
|
||||||
|
for (ptr = status_response; ptr->name; ptr++) {
|
||||||
|
lua_pushstring(L, ptr->name);
|
||||||
|
lua_pushinteger(L, ptr->value);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
}
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registre the module.
|
* Registre the module.
|
||||||
*/
|
*/
|
||||||
@ -897,6 +1169,7 @@ LSEC_API int luaopen_ssl_context(lua_State *L)
|
|||||||
luaL_newmetatable(L, "SSL:DH:Registry"); /* Keep all DH callbacks */
|
luaL_newmetatable(L, "SSL:DH:Registry"); /* Keep all DH callbacks */
|
||||||
luaL_newmetatable(L, "SSL:ALPN:Registry"); /* Keep all ALPN callbacks */
|
luaL_newmetatable(L, "SSL:ALPN:Registry"); /* Keep all ALPN callbacks */
|
||||||
luaL_newmetatable(L, "SSL:Verify:Registry"); /* Keep all verify flags */
|
luaL_newmetatable(L, "SSL:Verify:Registry"); /* Keep all verify flags */
|
||||||
|
luaL_newmetatable(L, "SSL:OCSP:Registry"); /* Keep all OCSP callbacks */
|
||||||
luaL_newmetatable(L, "SSL:Context");
|
luaL_newmetatable(L, "SSL:Context");
|
||||||
setfuncs(L, meta);
|
setfuncs(L, meta);
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
#define LSEC_CONTEXT_H
|
#define LSEC_CONTEXT_H
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.8.2
|
* LuaSec 1.0.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre
|
* Copyright (C) 2006-2021 Bruno Silvestre
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
27
src/ec.c
27
src/ec.c
@ -56,25 +56,24 @@ void lsec_load_curves(lua_State *L)
|
|||||||
lua_pushnumber(L, curves[i].nid);
|
lua_pushnumber(L, curves[i].nid);
|
||||||
lua_rawset(L, -3);
|
lua_rawset(L, -3);
|
||||||
break;
|
break;
|
||||||
#ifdef NID_X25519
|
|
||||||
case NID_X25519:
|
|
||||||
lua_pushstring(L, "X25519");
|
|
||||||
lua_pushnumber(L, curves[i].nid);
|
|
||||||
lua_rawset(L, -3);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#ifdef NID_X448
|
|
||||||
case NID_X448:
|
|
||||||
lua_pushstring(L, "X448");
|
|
||||||
lua_pushnumber(L, curves[i].nid);
|
|
||||||
lua_rawset(L, -3);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(curves);
|
free(curves);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* These are special so are manually added here */
|
||||||
|
#ifdef NID_X25519
|
||||||
|
lua_pushstring(L, "X25519");
|
||||||
|
lua_pushnumber(L, NID_X25519);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef NID_X448
|
||||||
|
lua_pushstring(L, "X448");
|
||||||
|
lua_pushnumber(L, NID_X448);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
#endif
|
||||||
|
|
||||||
lua_rawset(L, LUA_REGISTRYINDEX);
|
lua_rawset(L, LUA_REGISTRYINDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
src/ec.h
4
src/ec.h
@ -1,7 +1,7 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.8.2
|
* LuaSec 1.0.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre
|
* Copyright (C) 2006-2021 Bruno Silvestre
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
-- LuaSec 0.8.2
|
-- LuaSec 1.0.1
|
||||||
-- Copyright (C) 2009-2019 PUC-Rio
|
-- Copyright (C) 2009-2021 PUC-Rio
|
||||||
--
|
--
|
||||||
-- Author: Pablo Musa
|
-- Author: Pablo Musa
|
||||||
-- Author: Tomas Guisasola
|
-- Author: Tomas Guisasola
|
||||||
@ -18,8 +18,8 @@ local try = socket.try
|
|||||||
-- Module
|
-- Module
|
||||||
--
|
--
|
||||||
local _M = {
|
local _M = {
|
||||||
_VERSION = "0.8.2",
|
_VERSION = "1.0.1",
|
||||||
_COPYRIGHT = "LuaSec 0.8.2 - Copyright (C) 2009-2019 PUC-Rio",
|
_COPYRIGHT = "LuaSec 1.0.1 - Copyright (C) 2009-2021 PUC-Rio",
|
||||||
PORT = 443,
|
PORT = 443,
|
||||||
TIMEOUT = 60
|
TIMEOUT = 60
|
||||||
}
|
}
|
||||||
|
@ -107,10 +107,16 @@ int buffer_meth_send(lua_State *L, p_buffer buf) {
|
|||||||
* object:receive() interface
|
* object:receive() interface
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
int buffer_meth_receive(lua_State *L, p_buffer buf) {
|
int buffer_meth_receive(lua_State *L, p_buffer buf) {
|
||||||
int err = IO_DONE, top = lua_gettop(L);
|
|
||||||
luaL_Buffer b;
|
luaL_Buffer b;
|
||||||
size_t size;
|
size_t size;
|
||||||
const char *part = luaL_optlstring(L, 3, "", &size);
|
const char *part;
|
||||||
|
int err = IO_DONE;
|
||||||
|
int top = lua_gettop(L);
|
||||||
|
if (top < 3) {
|
||||||
|
lua_settop(L, 3);
|
||||||
|
top = 3;
|
||||||
|
}
|
||||||
|
part = luaL_optlstring(L, 3, "", &size);
|
||||||
#ifdef LUASOCKET_DEBUG
|
#ifdef LUASOCKET_DEBUG
|
||||||
p_timeout tm = timeout_markstart(buf->tm);
|
p_timeout tm = timeout_markstart(buf->tm);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.8.2
|
* LuaSec 1.0.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre
|
* Copyright (C) 2006-2021 Bruno Silvestre
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
#define LSEC_OPTIONS_H
|
#define LSEC_OPTIONS_H
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.8.2
|
* LuaSec 1.0.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre
|
* Copyright (C) 2006-2021 Bruno Silvestre
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ end
|
|||||||
local function generate(options, version)
|
local function generate(options, version)
|
||||||
print([[
|
print([[
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.8.2
|
* LuaSec 1.0.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre
|
* Copyright (C) 2006-2021 Bruno Silvestre
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
53
src/ssl.c
53
src/ssl.c
@ -1,9 +1,9 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.8.2
|
* LuaSec 1.0.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2019 Kim Alvefur, Paul Aurich, Tobias Markmann,
|
* Copyright (C) 2014-2021 Kim Alvefur, Paul Aurich, Tobias Markmann,
|
||||||
* Matthew Wild.
|
* Matthew Wild.
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre.
|
* Copyright (C) 2006-2021 Bruno Silvestre.
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -18,6 +18,7 @@
|
|||||||
#include <openssl/x509v3.h>
|
#include <openssl/x509v3.h>
|
||||||
#include <openssl/x509_vfy.h>
|
#include <openssl/x509_vfy.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
|
#include <openssl/dh.h>
|
||||||
|
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
@ -32,7 +33,7 @@
|
|||||||
#include "ssl.h"
|
#include "ssl.h"
|
||||||
|
|
||||||
|
|
||||||
#if (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2070000fL) || (OPENSSL_VERSION_NUMBER < 0x1010000fL)
|
#ifndef LSEC_API_OPENSSL_1_1_0
|
||||||
#define SSL_is_server(s) (s->server)
|
#define SSL_is_server(s) (s->server)
|
||||||
#define SSL_up_ref(ssl) CRYPTO_add(&(ssl)->references, 1, CRYPTO_LOCK_SSL)
|
#define SSL_up_ref(ssl) CRYPTO_add(&(ssl)->references, 1, CRYPTO_LOCK_SSL)
|
||||||
#define X509_up_ref(c) CRYPTO_add(&c->references, 1, CRYPTO_LOCK_X509)
|
#define X509_up_ref(c) CRYPTO_add(&c->references, 1, CRYPTO_LOCK_X509)
|
||||||
@ -47,6 +48,11 @@ static int lsec_socket_error()
|
|||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
return WSAGetLastError();
|
return WSAGetLastError();
|
||||||
#else
|
#else
|
||||||
|
#if defined(LSEC_OPENSSL_1_1_1)
|
||||||
|
// Bug in OpenSSL 1.1.1
|
||||||
|
if (errno == 0)
|
||||||
|
return LSEC_IO_SSL;
|
||||||
|
#endif
|
||||||
return errno;
|
return errno;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -818,7 +824,7 @@ static int meth_getalpn(lua_State *L)
|
|||||||
|
|
||||||
static int meth_copyright(lua_State *L)
|
static int meth_copyright(lua_State *L)
|
||||||
{
|
{
|
||||||
lua_pushstring(L, "LuaSec 0.8.2 - Copyright (C) 2006-2019 Bruno Silvestre, UFG"
|
lua_pushstring(L, "LuaSec 1.0.1 - Copyright (C) 2006-2021 Bruno Silvestre, UFG"
|
||||||
#if defined(WITH_LUASOCKET)
|
#if defined(WITH_LUASOCKET)
|
||||||
"\nLuaSocket 3.0-RC1 - Copyright (C) 2004-2013 Diego Nehab"
|
"\nLuaSocket 3.0-RC1 - Copyright (C) 2004-2013 Diego Nehab"
|
||||||
#endif
|
#endif
|
||||||
@ -826,6 +832,34 @@ static int meth_copyright(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(LSEC_ENABLE_DANE)
|
||||||
|
static int meth_dane(lua_State *L)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
||||||
|
ret = SSL_dane_enable(ssl->ssl, luaL_checkstring(L, 2));
|
||||||
|
lua_pushboolean(L, (ret > 0));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int meth_tlsa(lua_State *L)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
size_t len;
|
||||||
|
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
||||||
|
uint8_t usage = (uint8_t)luaL_checkinteger(L, 2);
|
||||||
|
uint8_t selector = (uint8_t)luaL_checkinteger(L, 3);
|
||||||
|
uint8_t mtype = (uint8_t)luaL_checkinteger(L, 4);
|
||||||
|
unsigned char *data = (unsigned char*)luaL_checklstring(L, 5, &len);
|
||||||
|
|
||||||
|
ERR_clear_error();
|
||||||
|
ret = SSL_dane_tlsa_add(ssl->ssl, usage, selector, mtype, data, len);
|
||||||
|
lua_pushboolean(L, (ret > 0));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -850,6 +884,10 @@ static luaL_Reg methods[] = {
|
|||||||
{"settimeout", meth_settimeout},
|
{"settimeout", meth_settimeout},
|
||||||
{"sni", meth_sni},
|
{"sni", meth_sni},
|
||||||
{"want", meth_want},
|
{"want", meth_want},
|
||||||
|
#if defined(LSEC_ENABLE_DANE)
|
||||||
|
{"setdane", meth_dane},
|
||||||
|
{"settlsa", meth_tlsa},
|
||||||
|
#endif
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -857,6 +895,7 @@ static luaL_Reg methods[] = {
|
|||||||
* SSL metamethods.
|
* SSL metamethods.
|
||||||
*/
|
*/
|
||||||
static luaL_Reg meta[] = {
|
static luaL_Reg meta[] = {
|
||||||
|
{"__close", meth_destroy},
|
||||||
{"__gc", meth_destroy},
|
{"__gc", meth_destroy},
|
||||||
{"__tostring", meth_tostring},
|
{"__tostring", meth_tostring},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
@ -880,6 +919,7 @@ static luaL_Reg funcs[] = {
|
|||||||
*/
|
*/
|
||||||
LSEC_API int luaopen_ssl_core(lua_State *L)
|
LSEC_API int luaopen_ssl_core(lua_State *L)
|
||||||
{
|
{
|
||||||
|
#ifndef LSEC_API_OPENSSL_1_1_0
|
||||||
/* Initialize SSL */
|
/* Initialize SSL */
|
||||||
if (!SSL_library_init()) {
|
if (!SSL_library_init()) {
|
||||||
lua_pushstring(L, "unable to initialize SSL library");
|
lua_pushstring(L, "unable to initialize SSL library");
|
||||||
@ -887,6 +927,7 @@ LSEC_API int luaopen_ssl_core(lua_State *L)
|
|||||||
}
|
}
|
||||||
OpenSSL_add_all_algorithms();
|
OpenSSL_add_all_algorithms();
|
||||||
SSL_load_error_strings();
|
SSL_load_error_strings();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(WITH_LUASOCKET)
|
#if defined(WITH_LUASOCKET)
|
||||||
/* Initialize internal library */
|
/* Initialize internal library */
|
||||||
@ -905,7 +946,7 @@ LSEC_API int luaopen_ssl_core(lua_State *L)
|
|||||||
luaL_newlib(L, funcs);
|
luaL_newlib(L, funcs);
|
||||||
|
|
||||||
lua_pushstring(L, "SOCKET_INVALID");
|
lua_pushstring(L, "SOCKET_INVALID");
|
||||||
lua_pushnumber(L, SOCKET_INVALID);
|
lua_pushinteger(L, SOCKET_INVALID);
|
||||||
lua_rawset(L, -3);
|
lua_rawset(L, -3);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
#define LSEC_SSL_H
|
#define LSEC_SSL_H
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.8.2
|
* LuaSec 1.0.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2019 Bruno Silvestre
|
* Copyright (C) 2006-2021 Bruno Silvestre
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
24
src/ssl.lua
24
src/ssl.lua
@ -1,7 +1,7 @@
|
|||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- LuaSec 0.8.2
|
-- LuaSec 1.0.1
|
||||||
--
|
--
|
||||||
-- Copyright (C) 2006-2019 Bruno Silvestre
|
-- Copyright (C) 2006-2021 Bruno Silvestre
|
||||||
--
|
--
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -10,6 +10,11 @@ local context = require("ssl.context")
|
|||||||
local x509 = require("ssl.x509")
|
local x509 = require("ssl.x509")
|
||||||
local config = require("ssl.config")
|
local config = require("ssl.config")
|
||||||
|
|
||||||
|
local ocsp
|
||||||
|
if config.capabilities.ocsp then
|
||||||
|
ocsp = require("ssl.context.ocsp")
|
||||||
|
end
|
||||||
|
|
||||||
local unpack = table.unpack or unpack
|
local unpack = table.unpack or unpack
|
||||||
|
|
||||||
-- We must prevent the contexts to be collected before the connections,
|
-- We must prevent the contexts to be collected before the connections,
|
||||||
@ -201,6 +206,18 @@ local function newcontext(cfg)
|
|||||||
if not succ then return nil, msg end
|
if not succ then return nil, msg end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if config.capabilities.dane and cfg.dane then
|
||||||
|
context.setdane(ctx)
|
||||||
|
end
|
||||||
|
|
||||||
|
if config.capabilities.ocsp and cfg.ocsp then
|
||||||
|
msg = "error setting OCSP"
|
||||||
|
succ = type(cfg.ocsp) == "function"
|
||||||
|
if not succ then return nil, msg end
|
||||||
|
succ = context.setocspcb(ctx, cfg.ocsp)
|
||||||
|
if not succ then return nil, msg end
|
||||||
|
end
|
||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -267,9 +284,10 @@ core.setmethod("info", info)
|
|||||||
--
|
--
|
||||||
|
|
||||||
local _M = {
|
local _M = {
|
||||||
_VERSION = "0.8.2",
|
_VERSION = "1.0.1",
|
||||||
_COPYRIGHT = core.copyright(),
|
_COPYRIGHT = core.copyright(),
|
||||||
config = config,
|
config = config,
|
||||||
|
ocsp = ocsp,
|
||||||
loadcertificate = x509.load,
|
loadcertificate = x509.load,
|
||||||
newcontext = newcontext,
|
newcontext = newcontext,
|
||||||
wrap = wrap,
|
wrap = wrap,
|
||||||
|
57
src/x509.c
57
src/x509.c
@ -1,7 +1,7 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.8.2
|
* LuaSec 1.0.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2019 Kim Alvefur, Paul Aurich, Tobias Markmann
|
* Copyright (C) 2014-2021 Kim Alvefur, Paul Aurich, Tobias Markmann
|
||||||
* Matthew Wild, Bruno Silvestre.
|
* Matthew Wild, Bruno Silvestre.
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
@ -33,16 +33,12 @@
|
|||||||
#include "x509.h"
|
#include "x509.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
#ifndef LSEC_API_OPENSSL_1_1_0
|
||||||
* ASN1_STRING_data is deprecated in OpenSSL 1.1.0
|
#define X509_get0_notBefore X509_get_notBefore
|
||||||
*/
|
#define X509_get0_notAfter X509_get_notAfter
|
||||||
#if OPENSSL_VERSION_NUMBER>=0x1010000fL && !defined(LIBRESSL_VERSION_NUMBER)
|
#define ASN1_STRING_get0_data ASN1_STRING_data
|
||||||
#define LSEC_ASN1_STRING_data(x) ASN1_STRING_get0_data(x)
|
|
||||||
#else
|
|
||||||
#define LSEC_ASN1_STRING_data(x) ASN1_STRING_data(x)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static const char* hex_tab = "0123456789abcdef";
|
static const char* hex_tab = "0123456789abcdef";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,8 +153,7 @@ static void push_asn1_string(lua_State* L, ASN1_STRING *string, int encode)
|
|||||||
}
|
}
|
||||||
switch (encode) {
|
switch (encode) {
|
||||||
case LSEC_AI5_STRING:
|
case LSEC_AI5_STRING:
|
||||||
lua_pushlstring(L, (char*)LSEC_ASN1_STRING_data(string),
|
lua_pushlstring(L, (char*)ASN1_STRING_get0_data(string), ASN1_STRING_length(string));
|
||||||
ASN1_STRING_length(string));
|
|
||||||
break;
|
break;
|
||||||
case LSEC_UTF8_STRING:
|
case LSEC_UTF8_STRING:
|
||||||
len = ASN1_STRING_to_UTF8(&data, string);
|
len = ASN1_STRING_to_UTF8(&data, string);
|
||||||
@ -174,7 +169,7 @@ static void push_asn1_string(lua_State* L, ASN1_STRING *string, int encode)
|
|||||||
/**
|
/**
|
||||||
* Return a human readable time.
|
* Return a human readable time.
|
||||||
*/
|
*/
|
||||||
static int push_asn1_time(lua_State *L, ASN1_UTCTIME *tm)
|
static int push_asn1_time(lua_State *L, const ASN1_UTCTIME *tm)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
long size;
|
long size;
|
||||||
@ -193,7 +188,7 @@ static void push_asn1_ip(lua_State *L, ASN1_STRING *string)
|
|||||||
{
|
{
|
||||||
int af;
|
int af;
|
||||||
char dst[INET6_ADDRSTRLEN];
|
char dst[INET6_ADDRSTRLEN];
|
||||||
unsigned char *ip = (unsigned char*)LSEC_ASN1_STRING_data(string);
|
unsigned char *ip = (unsigned char*)ASN1_STRING_get0_data(string);
|
||||||
switch(ASN1_STRING_length(string)) {
|
switch(ASN1_STRING_length(string)) {
|
||||||
case 4:
|
case 4:
|
||||||
af = AF_INET;
|
af = AF_INET;
|
||||||
@ -490,10 +485,13 @@ static int meth_digest(lua_State* L)
|
|||||||
*/
|
*/
|
||||||
static int meth_valid_at(lua_State* L)
|
static int meth_valid_at(lua_State* L)
|
||||||
{
|
{
|
||||||
|
int nb, na;
|
||||||
X509* cert = lsec_checkx509(L, 1);
|
X509* cert = lsec_checkx509(L, 1);
|
||||||
time_t time = luaL_checkinteger(L, 2);
|
time_t time = luaL_checkinteger(L, 2);
|
||||||
lua_pushboolean(L, (X509_cmp_time(X509_get_notAfter(cert), &time) >= 0
|
nb = X509_cmp_time(X509_get0_notBefore(cert), &time);
|
||||||
&& X509_cmp_time(X509_get_notBefore(cert), &time) <= 0));
|
time -= 1;
|
||||||
|
na = X509_cmp_time(X509_get0_notAfter(cert), &time);
|
||||||
|
lua_pushboolean(L, nb == -1 && na == 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,7 +519,7 @@ static int meth_serial(lua_State *L)
|
|||||||
static int meth_notbefore(lua_State *L)
|
static int meth_notbefore(lua_State *L)
|
||||||
{
|
{
|
||||||
X509* cert = lsec_checkx509(L, 1);
|
X509* cert = lsec_checkx509(L, 1);
|
||||||
return push_asn1_time(L, X509_get_notBefore(cert));
|
return push_asn1_time(L, X509_get0_notBefore(cert));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -530,7 +528,7 @@ static int meth_notbefore(lua_State *L)
|
|||||||
static int meth_notafter(lua_State *L)
|
static int meth_notafter(lua_State *L)
|
||||||
{
|
{
|
||||||
X509* cert = lsec_checkx509(L, 1);
|
X509* cert = lsec_checkx509(L, 1);
|
||||||
return push_asn1_time(L, X509_get_notAfter(cert));
|
return push_asn1_time(L, X509_get0_notAfter(cert));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -623,7 +621,11 @@ cleanup:
|
|||||||
*/
|
*/
|
||||||
static int meth_destroy(lua_State* L)
|
static int meth_destroy(lua_State* L)
|
||||||
{
|
{
|
||||||
X509_free(lsec_checkx509(L, 1));
|
p_x509 px = lsec_checkp_x509(L, 1);
|
||||||
|
if (px->cert) {
|
||||||
|
X509_free(px->cert);
|
||||||
|
px->cert = NULL;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -653,6 +655,21 @@ static int meth_set_encode(lua_State* L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get signature name.
|
||||||
|
*/
|
||||||
|
static int meth_get_sinagure_name(lua_State* L)
|
||||||
|
{
|
||||||
|
p_x509 px = lsec_checkp_x509(L, 1);
|
||||||
|
int nid = X509_get_signature_nid(px->cert);
|
||||||
|
const char *name = OBJ_nid2sn(nid);
|
||||||
|
if (!name)
|
||||||
|
lua_pushnil(L);
|
||||||
|
else
|
||||||
|
lua_pushstring(L, name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static int load_cert(lua_State* L)
|
static int load_cert(lua_State* L)
|
||||||
@ -681,6 +698,7 @@ static luaL_Reg methods[] = {
|
|||||||
{"digest", meth_digest},
|
{"digest", meth_digest},
|
||||||
{"setencode", meth_set_encode},
|
{"setencode", meth_set_encode},
|
||||||
{"extensions", meth_extensions},
|
{"extensions", meth_extensions},
|
||||||
|
{"getsignaturename", meth_get_sinagure_name},
|
||||||
{"issuer", meth_issuer},
|
{"issuer", meth_issuer},
|
||||||
{"notbefore", meth_notbefore},
|
{"notbefore", meth_notbefore},
|
||||||
{"notafter", meth_notafter},
|
{"notafter", meth_notafter},
|
||||||
@ -697,6 +715,7 @@ static luaL_Reg methods[] = {
|
|||||||
* X509 metamethods.
|
* X509 metamethods.
|
||||||
*/
|
*/
|
||||||
static luaL_Reg meta[] = {
|
static luaL_Reg meta[] = {
|
||||||
|
{"__close", meth_destroy},
|
||||||
{"__gc", meth_destroy},
|
{"__gc", meth_destroy},
|
||||||
{"__tostring", meth_tostring},
|
{"__tostring", meth_tostring},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* LuaSec 0.8.2
|
* LuaSec 1.0.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2019 Kim Alvefur, Paul Aurich, Tobias Markmann
|
* Copyright (C) 2014-2021 Kim Alvefur, Paul Aurich, Tobias Markmann
|
||||||
* Matthew Wild, Bruno Silvestre.
|
* Matthew Wild, Bruno Silvestre.
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
|
Reference in New Issue
Block a user