Annotate

plugins/mod_tls.lua @ 99:ba08b8a4eeef

Abstract connections with "connection listeners" - Added connlistener for xmppclient - SASL/TLS now use a new session:reset_stream() method - main.lua on its way to being a bit neater
author Matthew Wild <mwild1@gmail.com>
date Wed, 22 Oct 2008 17:36:21 +0100
parent 69:5b664c8fef86
child 120:ef964468f174
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
69
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local st = require "util.stanza";
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local send = require "core.sessionmanager".send_to_session;
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local sm_bind_resource = require "core.sessionmanager".bind_resource;
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
99
ba08b8a4eeef Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents: 69
diff changeset
6 local sessions = sessions;
ba08b8a4eeef Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents: 69
diff changeset
7
69
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local usermanager_validate_credentials = require "core.usermanager".validate_credentials;
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local t_concat, t_insert = table.concat, table.insert;
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local tostring = tostring;
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local log = require "util.logger".init("mod_starttls");
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local xmlns_starttls ='urn:ietf:params:xml:ns:xmpp-tls';
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 local new_connhandler = require "net.connhandlers".new;
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 add_handler("c2s_unauthed", "starttls", xmlns_starttls,
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 function (session, stanza)
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 if session.conn.starttls then
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 send(session, st.stanza("proceed", { xmlns = xmlns_starttls }));
99
ba08b8a4eeef Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents: 69
diff changeset
22 -- FIXME: I'm commenting the below, not sure why it was necessary
ba08b8a4eeef Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents: 69
diff changeset
23 -- sessions[session.conn] = nil;
ba08b8a4eeef Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents: 69
diff changeset
24 session:reset_stream();
ba08b8a4eeef Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents: 69
diff changeset
25 session.conn.starttls();
ba08b8a4eeef Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents: 69
diff changeset
26 session.log("info", "TLS negotiation started...");
ba08b8a4eeef Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents: 69
diff changeset
27 else
ba08b8a4eeef Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents: 69
diff changeset
28 -- FIXME: What reply?
ba08b8a4eeef Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents: 69
diff changeset
29 session.log("warn", "Attempt to start TLS, but TLS is not available on this connection");
69
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 end
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 end);
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 add_event_hook("stream-features",
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 function (session, features)
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 if session.conn.starttls then
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 t_insert(features, "<starttls xmlns='"..xmlns_starttls.."'/>");
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 end
5b664c8fef86 forgot to commit mod_tls, oops :)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 end);