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