Software /
code /
prosody
Diff
plugins/mod_tls.lua @ 2625:03287c06d986
mod_tls: Refactor to simplify detection of whether we can do TLS on a connection
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 12 Feb 2010 21:57:46 +0000 |
parent | 2623:1d34b45dec15 |
child | 2635:e79057cf2538 |
line wrap: on
line diff
--- a/plugins/mod_tls.lua Sat Feb 13 02:55:24 2010 +0500 +++ b/plugins/mod_tls.lua Fri Feb 12 21:57:46 2010 +0000 @@ -24,10 +24,19 @@ local host = hosts[module.host]; +local function can_do_tls(session) + if session.type == "c2s_unauthed" then + return session.username and session.conn.starttls and host.ssl_ctx_in; + elseif session.type == "s2sin_unauthed" then + return origin.to_host and origin.conn.starttls and host.ssl_ctx_in; + end + return false; +end + -- Hook <starttls/> module:hook("stanza/urn:ietf:params:xml:ns:xmpp-tls:starttls", function(event) local origin = event.origin; - if origin.conn.starttls then + if can_do_tls(origin) then (origin.sends2s or origin.send)(starttls_proceed); origin:reset_stream(); local host = origin.to_host or origin.host; @@ -46,13 +55,13 @@ -- Advertize stream feature module:hook("stream-features", function(event) local origin, features = event.origin, event.features; - if not origin.username and origin.conn.starttls and host.ssl_ctx_in then + if can_do_tls(origin) then features:add_child(c2s_feature); end end); module:hook("s2s-stream-features", function(event) local origin, features = event.origin, event.features; - if origin.to_host and origin.type ~= "s2sin" and origin.conn.starttls and host.ssl_ctx_in then + if can_do_tls(origin) then features:add_child(s2s_feature); end end); @@ -66,6 +75,7 @@ return true; end end, 500); + module:hook_stanza(xmlns_starttls, "proceed", function (session, stanza) module:log("debug", "Proceeding with TLS on s2sout..."); session:reset_stream();