aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-03-24 20:00:22 +0000
committerMatthew Wild <mwild1@gmail.com>2010-03-24 20:00:22 +0000
commit67a0c4e8db5af279127f5ee15a66b5ce0ea0d194 (patch)
tree3d52b8719948f050570e2e725940bf3f2a82f7f1
parent7fd387c3902484577be68c4365b8aea2e5c2dd8c (diff)
downloadprosody-67a0c4e8db5af279127f5ee15a66b5ce0ea0d194.tar.gz
prosody-67a0c4e8db5af279127f5ee15a66b5ce0ea0d194.zip
mod_tls: Add s2s_allow_encryption option which, when set to false, disabled TLS for s2s
-rw-r--r--plugins/mod_tls.lua45
1 files changed, 27 insertions, 18 deletions
diff --git a/plugins/mod_tls.lua b/plugins/mod_tls.lua
index 22819cd1..f68552fa 100644
--- a/plugins/mod_tls.lua
+++ b/plugins/mod_tls.lua
@@ -16,10 +16,13 @@ local secure_s2s_only = module:get_option("s2s_require_encryption");
local host = hosts[module.host];
+local starttls_attr = { xmlns = xmlns_starttls };
+
+--- Client-to-server TLS handling
module:add_handler("c2s_unauthed", "starttls", xmlns_starttls,
function (session, stanza)
if session.conn.starttls and host.ssl_ctx_in then
- session.send(st.stanza("proceed", { xmlns = xmlns_starttls }));
+ session.send(st.stanza("proceed", starttls_attr));
session:reset_stream();
if session.host and hosts[session.host].ssl_ctx_in then
session.conn.set_sslctx(hosts[session.host].ssl_ctx_in);
@@ -29,15 +32,34 @@ module:add_handler("c2s_unauthed", "starttls", xmlns_starttls,
session.secure = false;
else
session.log("warn", "Attempt to start TLS, but TLS is not available on this connection");
- (session.sends2s or session.send)(st.stanza("failure", { xmlns = xmlns_starttls }));
+ (session.sends2s or session.send)(st.stanza("failure", starttls_attr));
session:close();
end
end);
-
+
+module:add_event_hook("stream-features",
+ function (session, features)
+ if session.conn.starttls then
+ features:tag("starttls", starttls_attr);
+ if secure_auth_only then
+ features:tag("required"):up():up();
+ else
+ features:up();
+ end
+ end
+ end);
+---
+
+-- Stop here if the user doesn't want to allow s2s encryption
+if module:get_option("s2s_allow_encryption") == false then
+ return;
+end
+
+--- Server-to-server TLS handling
module:add_handler("s2sin_unauthed", "starttls", xmlns_starttls,
function (session, stanza)
if session.conn.starttls and host.ssl_ctx_in then
- session.sends2s(st.stanza("proceed", { xmlns = xmlns_starttls }));
+ session.sends2s(st.stanza("proceed", starttls_attr));
session:reset_stream();
if session.to_host and hosts[session.to_host].ssl_ctx_in then
session.conn.set_sslctx(hosts[session.to_host].ssl_ctx_in);
@@ -47,25 +69,12 @@ module:add_handler("s2sin_unauthed", "starttls", xmlns_starttls,
session.secure = false;
else
session.log("warn", "Attempt to start TLS, but TLS is not available on this s2s connection");
- (session.sends2s or session.send)(st.stanza("failure", { xmlns = xmlns_starttls }));
+ (session.sends2s or session.send)(st.stanza("failure", starttls_attr));
session:close();
end
end);
-local starttls_attr = { xmlns = xmlns_starttls };
-module:add_event_hook("stream-features",
- function (session, features)
- if session.conn.starttls then
- features:tag("starttls", starttls_attr);
- if secure_auth_only then
- features:tag("required"):up():up();
- else
- features:up();
- end
- end
- end);
-
module:hook("s2s-stream-features",
function (data)
local session, features = data.session, data.features;