Comparison

core/componentmanager.lua @ 2323:b7f683c55a44

componentmanager: Set ssl_ctx[_in] for components correctly, and use global SSL context if available
author Matthew Wild <mwild1@gmail.com>
date Fri, 04 Dec 2009 18:59:28 +0000
parent 2075:b4bfa6cb3d83
child 2447:9eb539222f22
child 2923:b7049746bd29
comparison
equal deleted inserted replaced
2322:548a4fc54a74 2323:b7f683c55a44
12 local modulemanager = require "core.modulemanager"; 12 local modulemanager = require "core.modulemanager";
13 local jid_split = require "util.jid".split; 13 local jid_split = require "util.jid".split;
14 local fire_event = require "core.eventmanager".fire_event; 14 local fire_event = require "core.eventmanager".fire_event;
15 local events_new = require "util.events".new; 15 local events_new = require "util.events".new;
16 local st = require "util.stanza"; 16 local st = require "util.stanza";
17 local hosts = hosts; 17 local prosody, hosts = prosody, prosody.hosts;
18 local ssl = ssl;
18 19
19 local pairs, type, tostring = pairs, type, tostring; 20 local pairs, setmetatable, type, tostring = pairs, setmetatable, type, tostring;
20 21
21 local components = {}; 22 local components = {};
22 23
23 local disco_items = require "util.multitable".new(); 24 local disco_items = require "util.multitable".new();
24 local NULL = {}; 25 local NULL = {};
71 end 72 end
72 end 73 end
73 74
74 function create_component(host, component, events) 75 function create_component(host, component, events)
75 -- TODO check for host well-formedness 76 -- TODO check for host well-formedness
76 local ssl_ctx; 77 local ssl_ctx, ssl_ctx_in;
77 if host then 78 if host and ssl then
78 -- We need to find SSL context to use... 79 -- We need to find SSL context to use...
79 -- Discussion in prosody@ concluded that 80 -- Discussion in prosody@ concluded that
80 -- 1 level back is usually enough by default 81 -- 1 level back is usually enough by default
81 local base_host = host:gsub("^[^%.]+%.", ""); 82 local base_host = host:gsub("^[^%.]+%.", "");
82 if hosts[base_host] then 83 if hosts[base_host] then
83 ssl_ctx = hosts[base_host].ssl_ctx; 84 ssl_ctx = hosts[base_host].ssl_ctx;
85 ssl_ctx_in = hosts[base_host].ssl_ctx_in;
86 elseif prosody.global_ssl_ctx then
87 -- We have no cert, and no parent host to borrow a cert from
88 -- Use global/default cert if there is one
89 ssl_ctx = ssl.newcontext(prosody.global_ssl_ctx);
90 ssl_ctx_in = ssl.newcontext(setmetatable({ mode = "server" }, { __index = prosody.global_ssl_ctx }));
84 end 91 end
85 end 92 end
86 return { type = "component", host = host, connected = true, s2sout = {}, 93 return { type = "component", host = host, connected = true, s2sout = {},
87 ssl_ctx = ssl_ctx, events = events or events_new() }; 94 ssl_ctx = ssl_ctx, ssl_ctx_in = ssl_ctx_in, events = events or events_new() };
88 end 95 end
89 96
90 function register_component(host, component, session) 97 function register_component(host, component, session)
91 if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then 98 if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then
92 local old_events = hosts[host] and hosts[host].events; 99 local old_events = hosts[host] and hosts[host].events;