Software / code / verse
Comparison
plugins/tls.lua @ 61:6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 11 May 2010 22:41:09 +0100 |
| child | 63:311e61176159 |
comparison
equal
deleted
inserted
replaced
| 60:1f47ddab3499 | 61:6adddfdf974b |
|---|---|
| 1 local st = require "util.stanza"; | |
| 2 local xmlns_tls = "urn:ietf:params:xml:ns:xmpp-tls"; | |
| 3 | |
| 4 function verse.plugins.tls(stream) | |
| 5 local function handle_features(features_stanza) | |
| 6 if stream.authenticated then return; end | |
| 7 if features_stanza:get_child("starttls", xmlns_tls) then | |
| 8 stream:debug("Negotiating TLS..."); | |
| 9 stream:send(st.stanza("starttls", { xmlns = xmlns_tls })); | |
| 10 return true; | |
| 11 else | |
| 12 stream:debug("Server doesn't offer TLS :("); | |
| 13 end | |
| 14 end | |
| 15 local function handle_tls(tls_status) | |
| 16 if tls_status.name == "proceed" then | |
| 17 stream:debug("Server says proceed, handshake starting..."); | |
| 18 stream.conn:starttls({mode="client", protocol="sslv23", options="no_sslv2"}, true); | |
| 19 end | |
| 20 end | |
| 21 local function handle_status(new_status) | |
| 22 if new_status == "ssl-handshake-complete" then | |
| 23 stream:debug("Re-opening stream..."); | |
| 24 stream:reopen(); | |
| 25 end | |
| 26 end | |
| 27 stream:hook("stream-features", handle_features, 400); | |
| 28 stream:hook("stream/"..xmlns_tls, handle_tls); | |
| 29 stream:hook("status", handle_status, 400); | |
| 30 end |