diff options
author | Matthew Wild <mwild1@gmail.com> | 2010-02-12 21:57:46 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2010-02-12 21:57:46 +0000 |
commit | 8d64ab2d1fd2d4f0e3150fcdfd037a9771a2e419 (patch) | |
tree | ba95f5638a84b2f18a815ba06b1c5d6903d5e26f | |
parent | a66f328e17994928d8eb26d6699e1e2d6fe4228b (diff) | |
download | prosody-8d64ab2d1fd2d4f0e3150fcdfd037a9771a2e419.tar.gz prosody-8d64ab2d1fd2d4f0e3150fcdfd037a9771a2e419.zip |
mod_tls: Refactor to simplify detection of whether we can do TLS on a connection
-rw-r--r-- | plugins/mod_tls.lua | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/plugins/mod_tls.lua b/plugins/mod_tls.lua index 3e3bd554..8f688d61 100644 --- a/plugins/mod_tls.lua +++ b/plugins/mod_tls.lua @@ -24,10 +24,19 @@ local global_ssl_ctx = prosody.global_ssl_ctx; 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 @@ end); -- 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 @@ module:hook_stanza("http://etherx.jabber.org/streams", "features", function (ses 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(); |