Enable multiple SSL certificates (issue 27)

This commit is contained in:
Jeremy List 2019-02-22 13:39:15 +13:00
parent ef342a7cda
commit ff868e4a06

View File

@ -74,26 +74,40 @@ 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
for _, prop in pairs({ "key", "certificate", "password" }) do
if not cfg[prop .. "s"] then
if cfg[prop] then
cfg[prop .. "s"] = { cfg[prop] }
else
cfg[prop .. "s"] = {}
end
end
end
for i, certificate in pairs(cfg.certificates) do
local password = cfg.passwords[i]
local key = cfg.keys[i]
-- Load the key -- Load the key
if cfg.key then if key then
if cfg.password and if password and
type(cfg.password) ~= "function" and type(password) ~= "function" and
type(cfg.password) ~= "string" type(password) ~= "string"
then then
return nil, "invalid password type" return nil, "invalid password type"
end end
succ, msg = context.loadkey(ctx, cfg.key, cfg.password) succ, msg = context.loadkey(ctx, key, password)
if not succ then return nil, msg end if not succ then return nil, msg end
end end
-- Load the certificate -- Load the certificate(s)
if cfg.certificate then if certificate then
succ, msg = context.loadcert(ctx, cfg.certificate) succ, msg = context.loadcert(ctx, certificate)
if not succ then return nil, msg end if not succ then return nil, msg end
if cfg.key and context.checkkey then if 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
end end
end
-- Load the CA certificates -- Load the CA certificates
if cfg.cafile or cfg.capath then if cfg.cafile or cfg.capath then
succ, msg = context.locations(ctx, cfg.cafile, cfg.capath) succ, msg = context.locations(ctx, cfg.cafile, cfg.capath)