Software /
code /
verse
Annotate
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 |
rev | line source |
---|---|
61
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local st = require "util.stanza"; |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local xmlns_tls = "urn:ietf:params:xml:ns:xmpp-tls"; |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 function verse.plugins.tls(stream) |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local function handle_features(features_stanza) |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 if stream.authenticated then return; end |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 if features_stanza:get_child("starttls", xmlns_tls) then |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 stream:debug("Negotiating TLS..."); |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 stream:send(st.stanza("starttls", { xmlns = xmlns_tls })); |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 return true; |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 else |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 stream:debug("Server doesn't offer TLS :("); |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 end |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 end |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local function handle_tls(tls_status) |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 if tls_status.name == "proceed" then |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 stream:debug("Server says proceed, handshake starting..."); |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 stream.conn:starttls({mode="client", protocol="sslv23", options="no_sslv2"}, true); |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 end |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 local function handle_status(new_status) |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 if new_status == "ssl-handshake-complete" then |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 stream:debug("Re-opening stream..."); |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 stream:reopen(); |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 end |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 end |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 stream:hook("stream-features", handle_features, 400); |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 stream:hook("stream/"..xmlns_tls, handle_tls); |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 stream:hook("status", handle_status, 400); |
6adddfdf974b
verse.plugins.tls: Support for TLS encryption! (thanks Azelphur for the final push)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 end |