sessionmanager, s2smanager: Give sessions dummy data handlers that log when data...
[prosody.git] / plugins / mod_tls.lua
index c2f83a3a059e0e52c99f6aeabded5d893150dffe..49ee18c9e4461444fc8a76b726ec9348f345b42e 100644 (file)
@@ -19,12 +19,16 @@ module:add_handler("c2s_unauthed", "starttls", xmlns_starttls,
                        if session.conn.starttls then
                                session.send(st.stanza("proceed", { xmlns = xmlns_starttls }));
                                session:reset_stream();
+                               if session.host and hosts[session.host].ssl_ctx_in then
+                                       session.conn.set_sslctx(hosts[session.host].ssl_ctx_in);
+                               end
                                session.conn.starttls();
                                session.log("info", "TLS negotiation started...");
                                session.secure = false;
                        else
-                               -- FIXME: What reply?
                                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:close();
                        end
                end);
                
@@ -33,12 +37,16 @@ module:add_handler("s2sin_unauthed", "starttls", xmlns_starttls,
                        if session.conn.starttls then
                                session.sends2s(st.stanza("proceed", { xmlns = xmlns_starttls }));
                                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);
+                               end
                                session.conn.starttls();
                                session.log("info", "TLS negotiation started for incoming s2s...");
                                session.secure = false;
                        else
-                               -- FIXME: What reply?
                                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:close();
                        end
                end);
 
@@ -56,12 +64,11 @@ module:add_event_hook("stream-features",
                        end
                end);
 
-module:add_event_hook("s2s-stream-features", 
-               function (session, features)
-                       -- This hook is possibly called once per host (at least if the
-                       -- remote server does not specify a to/from.
-                       if session.to_host and session.conn.starttls and not features:child_with_ns(xmlns_starttls) then
-                               features:tag("starttls", starttls_attr):up();
+module:hook("s2s-stream-features", 
+               function (data)
+                       local session, features = data.session, data.features;
+                       if session.to_host and session.conn.starttls then
+                               features:tag("starttls", starttls_attr);
                                if secure_s2s_only then
                                        features:tag("required"):up():up();
                                else
@@ -74,7 +81,7 @@ module:add_event_hook("s2s-stream-features",
 module:hook_stanza(xmlns_stream, "features",
                function (session, stanza)
                        module:log("debug", "Received features element");
-                       if stanza:child_with_ns(xmlns_starttls) then
+                       if session.conn.starttls and stanza:child_with_ns(xmlns_starttls) then
                                module:log("%s is offering TLS, taking up the offer...", session.to_host);
                                session.sends2s("<starttls xmlns='"..xmlns_starttls.."'/>");
                                return true;