certmanager, hostmanager, mod_tls: Move responsibility for creating per-host SSL...
authorMatthew Wild <mwild1@gmail.com>
Sat, 6 Nov 2010 18:28:15 +0000 (18:28 +0000)
committerMatthew Wild <mwild1@gmail.com>
Sat, 6 Nov 2010 18:28:15 +0000 (18:28 +0000)
core/certmanager.lua
core/hostmanager.lua
plugins/mod_tls.lua

index 3f7bb3484ea3b8f1581c60fadcde8f6c3ccbd338..79651242517ca8459da13d976d135bf6615eac45 100644 (file)
@@ -23,8 +23,8 @@ module "certmanager"
 local default_ssl_config = configmanager.get("*", "core", "ssl");
 local default_capath = "/etc/ssl/certs";
 
-function create_context(host, mode, config)
-       local user_ssl_config = config and config.core.ssl or default_ssl_config;
+function create_context(host, mode, user_ssl_config)
+       user_ssl_config = user_ssl_config or default_ssl_config;
 
        if not ssl then return nil, "LuaSec (required for encryption) was not found"; end
        if not user_ssl_config then return nil, "No SSL/TLS configuration present for "..host; end
index cc19fb91eced7e30c08e8c7f4181960924ec80f8..26a396912b1efc07a568ffa09499cb1c70fb5300 100644 (file)
@@ -6,9 +6,6 @@
 -- COPYING file in the source package for more information.
 --
 
-local ssl = ssl
-
-local certmanager = require "core.certmanager";
 local configmanager = require "core.configmanager";
 local modulemanager = require "core.modulemanager";
 local events_new = require "util.events".new;
@@ -65,9 +62,6 @@ function activate(host, host_config)
                end
        end
        
-       hosts[host].ssl_ctx = certmanager.create_context(host, "client", host_config); -- for outgoing connections
-       hosts[host].ssl_ctx_in = certmanager.create_context(host, "server", host_config); -- for incoming connections
-       
        log((hosts_loaded_once and "info") or "debug", "Activated host: %s", host);
        prosody_events.fire_event("host-activated", host, host_config);
 end
index a2667ff6b7be4d632af9d09a5ba319a1c4137ba6..fa7b4688dc66876499f92783caba475c8a297fe8 100644 (file)
@@ -6,6 +6,7 @@
 -- COPYING file in the source package for more information.
 --
 
+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 +88,14 @@ module:hook_stanza(xmlns_starttls, "proceed", function (session, stanza)
        session.secure = false;
        return true;
 end);
+
+function module.load()
+       local ssl_config = module:get_option("ssl");
+       host.ssl_ctx = create_context(host, "client", ssl_config); -- for outgoing connections
+       host.ssl_ctx_in = create_context(host, "server", ssl_config); -- for incoming connections
+end
+
+function module.unload()
+       host.ssl_ctx = nil;
+       host.ssl_ctx_in = nil;
+end