Software /
code /
prosody
Annotate
plugins/mod_legacyauth.lua @ 1216:fd8ce71bc72b
mod_saslauth, mod_legacyauth: Deny logins to unsecure sessions when require_encryption config option is true
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 29 May 2009 14:33:55 +0100 |
parent | 1042:a3d77353c18a |
child | 1218:8e02c10c9e60 |
rev | line source |
---|---|
896 | 1 -- Prosody IM v0.4 |
760
90ce865eebd8
Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
90ce865eebd8
Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
4 -- |
758 | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
7 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
8 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
9 |
30 | 10 |
11 local st = require "util.stanza"; | |
12 local t_concat = table.concat; | |
13 | |
1216
fd8ce71bc72b
mod_saslauth, mod_legacyauth: Deny logins to unsecure sessions when require_encryption config option is true
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
14 local config = require "core.configmanager"; |
fd8ce71bc72b
mod_saslauth, mod_legacyauth: Deny logins to unsecure sessions when require_encryption config option is true
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
15 local secure_auth_only = config.get(module:get_host(), "core", "require_encryption"); |
fd8ce71bc72b
mod_saslauth, mod_legacyauth: Deny logins to unsecure sessions when require_encryption config option is true
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
16 |
1042
a3d77353c18a
mod_*: Fix a load of global accesses
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
17 local sessionmanager = require "core.sessionmanager"; |
a3d77353c18a
mod_*: Fix a load of global accesses
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
18 local usermanager = require "core.usermanager"; |
a3d77353c18a
mod_*: Fix a load of global accesses
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
19 |
541
3521e0851c9e
Change modules to use the new add_feature module API method.
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
20 module:add_feature("jabber:iq:auth"); |
891
236d1ce9fa99
mod_legacyauth: Added stream feature: <auth xmlns='http://jabber.org/features/iq-auth'/>
Waqas Hussain <waqas20@gmail.com>
parents:
760
diff
changeset
|
21 module:add_event_hook("stream-features", function (session, features) |
236d1ce9fa99
mod_legacyauth: Added stream feature: <auth xmlns='http://jabber.org/features/iq-auth'/>
Waqas Hussain <waqas20@gmail.com>
parents:
760
diff
changeset
|
22 if not session.username then features:tag("auth", {xmlns='http://jabber.org/features/iq-auth'}):up(); end |
236d1ce9fa99
mod_legacyauth: Added stream feature: <auth xmlns='http://jabber.org/features/iq-auth'/>
Waqas Hussain <waqas20@gmail.com>
parents:
760
diff
changeset
|
23 end); |
421
63be85693710
Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents:
308
diff
changeset
|
24 |
438
193f9dd64f17
Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents:
421
diff
changeset
|
25 module:add_iq_handler("c2s_unauthed", "jabber:iq:auth", |
30 | 26 function (session, stanza) |
1216
fd8ce71bc72b
mod_saslauth, mod_legacyauth: Deny logins to unsecure sessions when require_encryption config option is true
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
27 if secure_auth_only and not session.secure then |
fd8ce71bc72b
mod_saslauth, mod_legacyauth: Deny logins to unsecure sessions when require_encryption config option is true
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
28 session.send(st.error_reply(stanza, "modify", "not-acceptable", "Encryption (SSL or TLS) is required to connect to this server")); |
fd8ce71bc72b
mod_saslauth, mod_legacyauth: Deny logins to unsecure sessions when require_encryption config option is true
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
29 return true; |
fd8ce71bc72b
mod_saslauth, mod_legacyauth: Deny logins to unsecure sessions when require_encryption config option is true
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
30 end |
fd8ce71bc72b
mod_saslauth, mod_legacyauth: Deny logins to unsecure sessions when require_encryption config option is true
Matthew Wild <mwild1@gmail.com>
parents:
1042
diff
changeset
|
31 |
30 | 32 local username = stanza.tags[1]:child_with_name("username"); |
33 local password = stanza.tags[1]:child_with_name("password"); | |
34 local resource = stanza.tags[1]:child_with_name("resource"); | |
35 if not (username and password and resource) then | |
36 local reply = st.reply(stanza); | |
308
6345cf3e994a
Fixed mod_legacyauth to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
304
diff
changeset
|
37 session.send(reply:query("jabber:iq:auth") |
30 | 38 :tag("username"):up() |
39 :tag("password"):up() | |
40 :tag("resource"):up()); | |
41 return true; | |
42 else | |
43 username, password, resource = t_concat(username), t_concat(password), t_concat(resource); | |
44 local reply = st.reply(stanza); | |
45 require "core.usermanager" | |
46 if usermanager.validate_credentials(session.host, username, password) then | |
47 -- Authentication successful! | |
38 | 48 local success, err = sessionmanager.make_authenticated(session, username); |
49 if success then | |
304
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
50 local err_type, err_msg; |
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
51 success, err_type, err, err_msg = sessionmanager.bind_resource(session, resource); |
38 | 52 if not success then |
304
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
53 session.send(st.error_reply(stanza, err_type, err, err_msg)); |
38 | 54 return true; |
55 end | |
30 | 56 end |
308
6345cf3e994a
Fixed mod_legacyauth to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
304
diff
changeset
|
57 session.send(st.reply(stanza)); |
30 | 58 return true; |
59 else | |
60 local reply = st.reply(stanza); | |
61 reply.attr.type = "error"; | |
62 reply:tag("error", { code = "401", type = "auth" }) | |
63 :tag("not-authorized", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" }); | |
308
6345cf3e994a
Fixed mod_legacyauth to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
304
diff
changeset
|
64 session.send(reply); |
30 | 65 return true; |
66 end | |
67 end | |
68 | |
438
193f9dd64f17
Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents:
421
diff
changeset
|
69 end); |