From 7565573fec1be97e8d23f29092992773fd6be05a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 5 Feb 2015 15:10:23 +0100 Subject: certmanager: Early return from the entire module if LuaSec is unavailable --- core/certmanager.lua | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'core') diff --git a/core/certmanager.lua b/core/certmanager.lua index b2c358fe..a9b4018f 100644 --- a/core/certmanager.lua +++ b/core/certmanager.lua @@ -6,10 +6,20 @@ -- COPYING file in the source package for more information. -- +local softreq = require"util.dependencies".softreq; +local ssl = softreq"ssl"; +if not ssl then + return { + create_context = function () + return nil, "LuaSec (required for encryption) was not found"; + end; + reload_ssl_config = function () end; + } +end + local configmanager = require "core.configmanager"; local log = require "util.logger".init("certmanager"); -local ssl = _G.ssl; -local ssl_newcontext = ssl and ssl.newcontext; +local ssl_newcontext = ssl.newcontext; local new_config = require"util.sslconfig".new; local tostring = tostring; @@ -23,12 +33,10 @@ local resolve_path = require"util.paths".resolve_relative_path; local config_path = prosody.paths.config; local luasec_has_noticket, luasec_has_verifyext, luasec_has_no_compression; -if ssl then - local luasec_major, luasec_minor = ssl._VERSION:match("^(%d+)%.(%d+)"); - luasec_has_noticket = tonumber(luasec_major)>0 or tonumber(luasec_minor)>=4; - luasec_has_verifyext = tonumber(luasec_major)>0 or tonumber(luasec_minor)>=5; - luasec_has_no_compression = tonumber(luasec_major)>0 or tonumber(luasec_minor)>=5; -end +local luasec_major, luasec_minor = ssl._VERSION:match("^(%d+)%.(%d+)"); +luasec_has_noticket = tonumber(luasec_major)>0 or tonumber(luasec_minor)>=4; +luasec_has_verifyext = tonumber(luasec_major)>0 or tonumber(luasec_minor)>=5; +luasec_has_no_compression = tonumber(luasec_major)>0 or tonumber(luasec_minor)>=5; module "certmanager" @@ -39,7 +47,7 @@ local global_ssl_config = configmanager.get("*", "ssl"); local core_defaults = { capath = "/etc/ssl/certs"; protocol = "tlsv1+"; - verify = (ssl and ssl.x509 and { "peer", "client_once", }) or "none"; + verify = (ssl.x509 and { "peer", "client_once", }) or "none"; options = { cipher_server_preference = true; no_ticket = luasec_has_noticket; @@ -56,7 +64,7 @@ local path_options = { -- These we pass through resolve_path() key = true, certificate = true, cafile = true, capath = true, dhparam = true } -if ssl and not luasec_has_verifyext and ssl.x509 then +if not luasec_has_verifyext and ssl.x509 then -- COMPAT mw/luasec-hg for i=1,#core_defaults.verifyext do -- Remove lsec_ prefix core_defaults.verify[#core_defaults.verify+1] = core_defaults.verifyext[i]:sub(6); @@ -64,8 +72,6 @@ if ssl and not luasec_has_verifyext and ssl.x509 then end function create_context(host, mode, ...) - if not ssl then return nil, "LuaSec (required for encryption) was not found"; end - local cfg = new_config(); cfg:apply(core_defaults); cfg:apply(global_ssl_config); -- cgit v1.2.3 From fb96020a96a45c0980b980cce62f1cabcff53b00 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 5 Feb 2015 15:14:35 +0100 Subject: certmanager: Add locals for ssl.context and ssl.x509 --- core/certmanager.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/certmanager.lua b/core/certmanager.lua index a9b4018f..8bdb6b82 100644 --- a/core/certmanager.lua +++ b/core/certmanager.lua @@ -19,6 +19,8 @@ end local configmanager = require "core.configmanager"; local log = require "util.logger".init("certmanager"); +local ssl_context = ssl.context or softreq"ssl.context"; +local ssl_x509 = ssl.x509 or softreq"ssl.x509"; local ssl_newcontext = ssl.newcontext; local new_config = require"util.sslconfig".new; @@ -47,7 +49,7 @@ local global_ssl_config = configmanager.get("*", "ssl"); local core_defaults = { capath = "/etc/ssl/certs"; protocol = "tlsv1+"; - verify = (ssl.x509 and { "peer", "client_once", }) or "none"; + verify = (ssl_x509 and { "peer", "client_once", }) or "none"; options = { cipher_server_preference = true; no_ticket = luasec_has_noticket; @@ -64,7 +66,7 @@ local path_options = { -- These we pass through resolve_path() key = true, certificate = true, cafile = true, capath = true, dhparam = true } -if not luasec_has_verifyext and ssl.x509 then +if not luasec_has_verifyext and ssl_x509 then -- COMPAT mw/luasec-hg for i=1,#core_defaults.verifyext do -- Remove lsec_ prefix core_defaults.verify[#core_defaults.verify+1] = core_defaults.verifyext[i]:sub(6); @@ -114,7 +116,7 @@ function create_context(host, mode, ...) -- of it ourselves (W/A for #x) if ctx and user_ssl_config.ciphers then local success; - success, err = ssl.context.setcipher(ctx, user_ssl_config.ciphers); + success, err = ssl_context.setcipher(ctx, user_ssl_config.ciphers); if not success then ctx = nil; end end -- cgit v1.2.3 From bf57457852e5e629a179266be549784c6ac0aeda Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 5 Feb 2015 16:20:50 +0100 Subject: certmanager: Improve "detection" of features that depend on LuaSec version --- core/certmanager.lua | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'core') diff --git a/core/certmanager.lua b/core/certmanager.lua index 8bdb6b82..3de3f7f7 100644 --- a/core/certmanager.lua +++ b/core/certmanager.lua @@ -34,11 +34,16 @@ local prosody = prosody; local resolve_path = require"util.paths".resolve_relative_path; local config_path = prosody.paths.config; -local luasec_has_noticket, luasec_has_verifyext, luasec_has_no_compression; local luasec_major, luasec_minor = ssl._VERSION:match("^(%d+)%.(%d+)"); -luasec_has_noticket = tonumber(luasec_major)>0 or tonumber(luasec_minor)>=4; -luasec_has_verifyext = tonumber(luasec_major)>0 or tonumber(luasec_minor)>=5; -luasec_has_no_compression = tonumber(luasec_major)>0 or tonumber(luasec_minor)>=5; +local luasec_version = luasec_major * 100 + luasec_minor; +local luasec_has = { + -- TODO If LuaSec ever starts exposing these things itself, use that instead + cipher_server_preference = true; + no_ticket = luasec_version >= 4; + no_compression = luasec_version >= 5; + single_dh_use = luasec_version >= 5; + single_ecdh_use = luasec_version >= 5; +}; module "certmanager" @@ -51,12 +56,11 @@ local core_defaults = { protocol = "tlsv1+"; verify = (ssl_x509 and { "peer", "client_once", }) or "none"; options = { - cipher_server_preference = true; - no_ticket = luasec_has_noticket; - no_compression = luasec_has_no_compression and configmanager.get("*", "ssl_compression") ~= true; - -- Has no_compression? Then it has these too... - single_dh_use = luasec_has_no_compression; - single_ecdh_use = luasec_has_no_compression; + cipher_server_preference = luasec_has.cipher_server_preference; + no_ticket = luasec_has.no_ticket; + no_compression = luasec_has.no_compression and configmanager.get("*", "ssl_compression") ~= true; + single_dh_use = luasec_has.single_dh_use; + single_ecdh_use = luasec_has.single_ecdh_use; }; verifyext = { "lsec_continue", "lsec_ignore_purpose" }; curve = "secp384r1"; @@ -151,7 +155,7 @@ end function reload_ssl_config() global_ssl_config = configmanager.get("*", "ssl"); - if luasec_has_no_compression then + if luasec_has.no_compression then core_defaults.options.no_compression = configmanager.get("*", "ssl_compression") ~= true; end end -- cgit v1.2.3 From 3581c7106770298b5e813bbbf8e20b22d125476f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 5 Feb 2015 16:56:28 +0100 Subject: certmanager: Options that appear to be available since LuaSec 0.2 --- core/certmanager.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/certmanager.lua b/core/certmanager.lua index 3de3f7f7..d92e5fc1 100644 --- a/core/certmanager.lua +++ b/core/certmanager.lua @@ -38,11 +38,11 @@ local luasec_major, luasec_minor = ssl._VERSION:match("^(%d+)%.(%d+)"); local luasec_version = luasec_major * 100 + luasec_minor; local luasec_has = { -- TODO If LuaSec ever starts exposing these things itself, use that instead - cipher_server_preference = true; + cipher_server_preference = >= 2; no_ticket = luasec_version >= 4; no_compression = luasec_version >= 5; - single_dh_use = luasec_version >= 5; - single_ecdh_use = luasec_version >= 5; + single_dh_use = luasec_version >= 2; + single_ecdh_use = luasec_version >= 2; }; module "certmanager" -- cgit v1.2.3 From 664c92cddeaa7ec7e83ff29a62d6f5f701d0ae33 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 5 Feb 2015 16:59:34 +0100 Subject: certmanager: Limit certificate chain depth to 9 --- core/certmanager.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'core') diff --git a/core/certmanager.lua b/core/certmanager.lua index d92e5fc1..9a0c3deb 100644 --- a/core/certmanager.lua +++ b/core/certmanager.lua @@ -53,6 +53,7 @@ local global_ssl_config = configmanager.get("*", "ssl"); -- Built-in defaults local core_defaults = { capath = "/etc/ssl/certs"; + depth = 9; protocol = "tlsv1+"; verify = (ssl_x509 and { "peer", "client_once", }) or "none"; options = { -- cgit v1.2.3 From f71511593905934d2311b214b867a63a5e06d541 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 5 Feb 2015 17:21:05 +0100 Subject: certmanager: Fix previous commit --- core/certmanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/certmanager.lua b/core/certmanager.lua index 9a0c3deb..e016aa97 100644 --- a/core/certmanager.lua +++ b/core/certmanager.lua @@ -38,7 +38,7 @@ local luasec_major, luasec_minor = ssl._VERSION:match("^(%d+)%.(%d+)"); local luasec_version = luasec_major * 100 + luasec_minor; local luasec_has = { -- TODO If LuaSec ever starts exposing these things itself, use that instead - cipher_server_preference = >= 2; + cipher_server_preference = luasec_version >= 2; no_ticket = luasec_version >= 4; no_compression = luasec_version >= 5; single_dh_use = luasec_version >= 2; -- cgit v1.2.3 From b7a38c8c93f8e6bee2579de6b9468fbb68c14589 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 5 Feb 2015 17:23:53 +0100 Subject: certmanager: Fix compat for MattJs old LuaSec fork --- core/certmanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/certmanager.lua b/core/certmanager.lua index e016aa97..b40c13c1 100644 --- a/core/certmanager.lua +++ b/core/certmanager.lua @@ -71,7 +71,7 @@ local path_options = { -- These we pass through resolve_path() key = true, certificate = true, cafile = true, capath = true, dhparam = true } -if not luasec_has_verifyext and ssl_x509 then +if luasec_version < 5 and ssl_x509 then -- COMPAT mw/luasec-hg for i=1,#core_defaults.verifyext do -- Remove lsec_ prefix core_defaults.verify[#core_defaults.verify+1] = core_defaults.verifyext[i]:sub(6); -- cgit v1.2.3