Merge with waqas
[prosody.git] / plugins / mod_tls.lua
index a2667ff6b7be4d632af9d09a5ba319a1c4137ba6..c79227e1748bb673a278cb09d6a736afc6fafcab 100644 (file)
@@ -6,6 +6,8 @@
 -- COPYING file in the source package for more information.
 --
 
+local config = require "core.configmanager";
+local create_context = require "core.certmanager".create_context;
 local st = require "util.stanza";
 
 local secure_auth_only = module:get_option("c2s_require_encryption") or module:get_option("require_encryption");
@@ -87,3 +89,19 @@ module:hook_stanza(xmlns_starttls, "proceed", function (session, stanza)
        session.secure = false;
        return true;
 end);
+
+function module.load()
+       local global_ssl_config = config.get("*", "core", "ssl");
+       local ssl_config = config.get(module.host, "core", "ssl");
+       local base_host = module.host:match("%.(.*)");
+       if ssl_config == global_ssl_config and hosts[base_host] then
+               ssl_config = config.get(base_host, "core", "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
+end
+
+function module.unload()
+       host.ssl_ctx = nil;
+       host.ssl_ctx_in = nil;
+end