Software / code / verse
Comparison
plugins/tls.lua @ 67:8154b72591d5
verse.plugins.tls: self -> stream
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 11 May 2010 23:19:01 +0100 |
| parent | 66:cd66229bdd7f |
| child | 197:7e98cf2c1d8d |
comparison
equal
deleted
inserted
replaced
| 66:cd66229bdd7f | 67:8154b72591d5 |
|---|---|
| 6 if stream.authenticated then return; end | 6 if stream.authenticated then return; end |
| 7 if features_stanza:get_child("starttls", xmlns_tls) and stream.conn.starttls then | 7 if features_stanza:get_child("starttls", xmlns_tls) and stream.conn.starttls then |
| 8 stream:debug("Negotiating TLS..."); | 8 stream:debug("Negotiating TLS..."); |
| 9 stream:send(st.stanza("starttls", { xmlns = xmlns_tls })); | 9 stream:send(st.stanza("starttls", { xmlns = xmlns_tls })); |
| 10 return true; | 10 return true; |
| 11 elseif not stream.conn.starttls and not self.secure then | 11 elseif not stream.conn.starttls and not stream.secure then |
| 12 stream:warn("SSL libary (LuaSec) not loaded, so TLS not available"); | 12 stream:warn("SSL libary (LuaSec) not loaded, so TLS not available"); |
| 13 elseif not self.secure then | 13 elseif not stream.secure then |
| 14 stream:debug("Server doesn't offer TLS :("); | 14 stream:debug("Server doesn't offer TLS :("); |
| 15 end | 15 end |
| 16 end | 16 end |
| 17 local function handle_tls(tls_status) | 17 local function handle_tls(tls_status) |
| 18 if tls_status.name == "proceed" then | 18 if tls_status.name == "proceed" then |
| 20 stream.conn:starttls({mode="client", protocol="sslv23", options="no_sslv2"}, true); | 20 stream.conn:starttls({mode="client", protocol="sslv23", options="no_sslv2"}, true); |
| 21 end | 21 end |
| 22 end | 22 end |
| 23 local function handle_status(new_status) | 23 local function handle_status(new_status) |
| 24 if new_status == "ssl-handshake-complete" then | 24 if new_status == "ssl-handshake-complete" then |
| 25 self.secure = true; | 25 stream.secure = true; |
| 26 stream:debug("Re-opening stream..."); | 26 stream:debug("Re-opening stream..."); |
| 27 stream:reopen(); | 27 stream:reopen(); |
| 28 end | 28 end |
| 29 end | 29 end |
| 30 stream:hook("stream-features", handle_features, 400); | 30 stream:hook("stream-features", handle_features, 400); |