Comparison

plugins/mod_tls.lua @ 12207:65e252940337

mod_s2s: Retrieve TLS context for outgoing Direct TLS connections from mod_tls So that the same TLS context is used for both Direct TLS and starttls, since they are supposed to be functionally identical apart from the few extra round trips. A new event is added because the 's2s-created' event fires much later, after a connection has already been established, where we need the TLS context before that.
author Kim Alvefur <zash@zash.se>
date Fri, 21 Jan 2022 18:42:38 +0100
parent 11766:6ad335cd43f9
child 12211:5c2ae28f536e
comparison
equal deleted inserted replaced
12206:77ac0d96ac24 12207:65e252940337
77 end 77 end
78 78
79 module:hook_global("config-reloaded", module.load); 79 module:hook_global("config-reloaded", module.load);
80 80
81 local function can_do_tls(session) 81 local function can_do_tls(session)
82 if not session.conn.starttls then 82 if session.conn and not session.conn.starttls then
83 if not session.secure then 83 if not session.secure then
84 session.log("debug", "Underlying connection does not support STARTTLS"); 84 session.log("debug", "Underlying connection does not support STARTTLS");
85 end 85 end
86 return false; 86 return false;
87 elseif session.ssl_ctx ~= nil then 87 elseif session.ssl_ctx ~= nil then
113 session.log("debug", "Should be able to do TLS but no context available"); 113 session.log("debug", "Should be able to do TLS but no context available");
114 return false; 114 return false;
115 end 115 end
116 return session.ssl_ctx; 116 return session.ssl_ctx;
117 end 117 end
118
119 module:hook("s2sout-created", function (event)
120 -- Initialize TLS context for outgoing connections
121 can_do_tls(event.session);
122 end);
118 123
119 -- Hook <starttls/> 124 -- Hook <starttls/>
120 module:hook("stanza/urn:ietf:params:xml:ns:xmpp-tls:starttls", function(event) 125 module:hook("stanza/urn:ietf:params:xml:ns:xmpp-tls:starttls", function(event)
121 local origin = event.origin; 126 local origin = event.origin;
122 if can_do_tls(origin) then 127 if can_do_tls(origin) then