mirror of
https://github.com/brunoos/luasec.git
synced 2024-12-27 04:58:20 +01:00
PR feedback (Data structure)
This commit is contained in:
parent
ff868e4a06
commit
143ccf1323
38
src/ssl.lua
38
src/ssl.lua
@ -74,35 +74,37 @@ local function newcontext(cfg)
|
|||||||
-- Mode
|
-- Mode
|
||||||
succ, msg = context.setmode(ctx, cfg.mode)
|
succ, msg = context.setmode(ctx, cfg.mode)
|
||||||
if not succ then return nil, msg end
|
if not succ then return nil, msg end
|
||||||
-- Wrap singular certificate, key, etc in tables if necessary
|
if not cfg.certificates then
|
||||||
|
cfg.certificates = {}
|
||||||
|
end
|
||||||
|
local singularcertificate = {}
|
||||||
|
local singularexists = false
|
||||||
for _, prop in pairs({ "key", "certificate", "password" }) do
|
for _, prop in pairs({ "key", "certificate", "password" }) do
|
||||||
if not cfg[prop .. "s"] then
|
if cfg[prop] then
|
||||||
if cfg[prop] then
|
singularexists = true
|
||||||
cfg[prop .. "s"] = { cfg[prop] }
|
singularcertificate[prop] = cfg[prop]
|
||||||
else
|
|
||||||
cfg[prop .. "s"] = {}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i, certificate in pairs(cfg.certificates) do
|
if singularexists then
|
||||||
local password = cfg.passwords[i]
|
table.insert(crt.certificates, singularcertificate)
|
||||||
local key = cfg.keys[i]
|
end
|
||||||
|
for _, certificate in pairs(cfg.certificates) do
|
||||||
-- Load the key
|
-- Load the key
|
||||||
if key then
|
if certificate.key then
|
||||||
if password and
|
if certificate.password and
|
||||||
type(password) ~= "function" and
|
type(certificate.password) ~= "function" and
|
||||||
type(password) ~= "string"
|
type(certificate.password) ~= "string"
|
||||||
then
|
then
|
||||||
return nil, "invalid password type"
|
return nil, "invalid password type"
|
||||||
end
|
end
|
||||||
succ, msg = context.loadkey(ctx, key, password)
|
succ, msg = context.loadkey(ctx, certificate.key, certificate.password)
|
||||||
if not succ then return nil, msg end
|
if not succ then return nil, msg end
|
||||||
end
|
end
|
||||||
-- Load the certificate(s)
|
-- Load the certificate(s)
|
||||||
if certificate then
|
if certificate.certificate then
|
||||||
succ, msg = context.loadcert(ctx, certificate)
|
succ, msg = context.loadcert(ctx, certificate.certificate)
|
||||||
if not succ then return nil, msg end
|
if not succ then return nil, msg end
|
||||||
if key and context.checkkey then
|
if certificate.key and context.checkkey then
|
||||||
succ = context.checkkey(ctx)
|
succ = context.checkkey(ctx)
|
||||||
if not succ then return nil, "private key does not match public key" end
|
if not succ then return nil, "private key does not match public key" end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user