TLS/SASL no longer should include the connhandler module
[prosody.git] / plugins / mod_tls.lua
1
2 local st = require "util.stanza";
3 local send = require "core.sessionmanager".send_to_session;
4 local sm_bind_resource = require "core.sessionmanager".bind_resource;
5
6 local sessions = sessions;
7
8 local usermanager_validate_credentials = require "core.usermanager".validate_credentials;
9 local t_concat, t_insert = table.concat, table.insert;
10 local tostring = tostring;
11
12 local log = require "util.logger".init("mod_starttls");
13
14 local xmlns_starttls ='urn:ietf:params:xml:ns:xmpp-tls';
15
16 add_handler("c2s_unauthed", "starttls", xmlns_starttls,
17                 function (session, stanza)
18                         if session.conn.starttls then
19                                 send(session, st.stanza("proceed", { xmlns = xmlns_starttls }));
20                                 -- FIXME: I'm commenting the below, not sure why it was necessary
21                                 -- sessions[session.conn] = nil;
22                                 session:reset_stream();
23                                 session.conn.starttls();
24                                 session.log("info", "TLS negotiation started...");
25                         else
26                                 -- FIXME: What reply?
27                                 session.log("warn", "Attempt to start TLS, but TLS is not available on this connection");
28                         end
29                 end);
30                 
31 add_event_hook("stream-features", 
32                                         function (session, features)                                                                                            
33                                                 if session.conn.starttls then
34                                                         t_insert(features, "<starttls xmlns='"..xmlns_starttls.."'/>");
35                                                 end
36                                         end);