0.3->0.4
[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                         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 local starttls_attr = { xmlns = xmlns_starttls };
29 module:add_event_hook("stream-features", 
30                 function (session, features)                                                                                            
31                         if session.conn.starttls then
32                                 features:tag("starttls", starttls_attr):up();
33                         end
34                 end);