sessionmanager, mod_tls: Mark a session as secure when TLS is active
[prosody.git] / plugins / mod_tls.lua
1 -- Prosody IM v0.4
2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
4 -- 
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9
10
11 local st = require "util.stanza";
12
13 local xmlns_starttls ='urn:ietf:params:xml:ns:xmpp-tls';
14
15 module:add_handler("c2s_unauthed", "starttls", xmlns_starttls,
16                 function (session, stanza)
17                         if session.conn.starttls then
18                                 session.send(st.stanza("proceed", { xmlns = xmlns_starttls }));
19                                 session:reset_stream();
20                                 session.conn.starttls();
21                                 session.log("info", "TLS negotiation started...");
22                                 session.secure = false;
23                         else
24                                 -- FIXME: What reply?
25                                 session.log("warn", "Attempt to start TLS, but TLS is not available on this connection");
26                         end
27                 end);
28                 
29 local starttls_attr = { xmlns = xmlns_starttls };
30 module:add_event_hook("stream-features", 
31                 function (session, features)                                                                                            
32                         if session.conn.starttls then
33                                 features:tag("starttls", starttls_attr):up();
34                         end
35                 end);