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,25 +74,39 @@ local function newcontext(cfg)
-- Mode
succ, msg = context.setmode(ctx, cfg.mode)
if not succ then return nil, msg end
-- Load the key
if cfg.key then
if cfg.password and
type(cfg.password) ~= "function" and
type(cfg.password) ~= "string"
then
return nil, "invalid password type"
-- 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
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
if cfg.key and context.checkkey then
succ = context.checkkey(ctx)
if not succ then return nil, "private key does not match public key" end
end
for i, certificate in pairs(cfg.certificates) do
local password = cfg.passwords[i]
local key = cfg.keys[i]
-- Load the key
if key then
if password and
type(password) ~= "function" and
type(password) ~= "string"
then
return nil, "invalid password type"
end
succ, msg = context.loadkey(ctx, key, password)
if not succ then return nil, msg end
end
-- Load the certificate(s)
if certificate then
succ, msg = context.loadcert(ctx, certificate)
if not succ then return nil, msg end
if key and context.checkkey then
succ = context.checkkey(ctx)
if not succ then return nil, "private key does not match public key" end
end
end
end
-- Load the CA certificates
if cfg.cafile or cfg.capath then