mod_tls: Log error when TLS initialization fails
[prosody.git] / plugins / mod_tls.lua
index cace2d693efb530b26eadb633342aa101d55533c..54c69873aa20d359606756b1054cb5dbc438f1d0 100644 (file)
@@ -25,6 +25,7 @@ if secure_s2s_only then s2s_feature:tag("required"):up(); end
 
 local global_ssl_ctx = prosody.global_ssl_ctx;
 
+local hosts = prosody.hosts;
 local host = hosts[module.host];
 
 local function can_do_tls(session)
@@ -75,7 +76,7 @@ end);
 module:hook_stanza("http://etherx.jabber.org/streams", "features", function (session, stanza)
        module:log("debug", "Received features element");
        if can_do_tls(session) and stanza:child_with_ns(xmlns_starttls) then
-               module:log("%s is offering TLS, taking up the offer...", session.to_host);
+               module:log("debug", "%s is offering TLS, taking up the offer...", session.to_host);
                session.sends2s("<starttls xmlns='"..xmlns_starttls.."'/>");
                return true;
        end
@@ -90,14 +91,21 @@ module:hook_stanza(xmlns_starttls, "proceed", function (session, stanza)
        return true;
 end);
 
+local function assert_log(ret, err)
+       if not ret then
+               module:log("error", "Unable to initialize TLS: %s", err);
+       end
+       return ret;
+end
+
 function module.load()
-       local ssl_config = config.rawget(module.host, "core", "ssl");
+       local ssl_config = config.rawget(module.host, "ssl");
        if not ssl_config then
                local base_host = module.host:match("%.(.*)");
-               ssl_config = config.get(base_host, "core", "ssl");
+               ssl_config = config.get(base_host, "ssl");
        end
-       host.ssl_ctx = create_context(host.host, "client", ssl_config); -- for outgoing connections
-       host.ssl_ctx_in = create_context(host.host, "server", ssl_config); -- for incoming connections
+       host.ssl_ctx = assert_log(create_context(host.host, "client", ssl_config)); -- for outgoing connections
+       host.ssl_ctx_in = assert_log(create_context(host.host, "server", ssl_config)); -- for incoming connections
 end
 
 function module.unload()