Software /
code /
verse
File
plugins/tls.lua @ 62:d4b6f9e33c6e
verse.client: Load TLS along with other core plugins
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 11 May 2010 23:05:26 +0100 |
parent | 61:6adddfdf974b |
child | 63:311e61176159 |
line wrap: on
line source
local st = require "util.stanza"; local xmlns_tls = "urn:ietf:params:xml:ns:xmpp-tls"; function verse.plugins.tls(stream) local function handle_features(features_stanza) if stream.authenticated then return; end if features_stanza:get_child("starttls", xmlns_tls) then stream:debug("Negotiating TLS..."); stream:send(st.stanza("starttls", { xmlns = xmlns_tls })); return true; else stream:debug("Server doesn't offer TLS :("); end end local function handle_tls(tls_status) if tls_status.name == "proceed" then stream:debug("Server says proceed, handshake starting..."); stream.conn:starttls({mode="client", protocol="sslv23", options="no_sslv2"}, true); end end local function handle_status(new_status) if new_status == "ssl-handshake-complete" then stream:debug("Re-opening stream..."); stream:reopen(); end end stream:hook("stream-features", handle_features, 400); stream:hook("stream/"..xmlns_tls, handle_tls); stream:hook("status", handle_status, 400); end