Software / code / prosody
Annotate
util/sasl.lua @ 13801:a5d5fefb8b68 13.0
mod_tls: Enable Prosody's certificate checking for incoming s2s connections (fixes #1916) (thanks Damian, Zash)
Various options in Prosody allow control over the behaviour of the certificate
verification process For example, some deployments choose to allow falling
back to traditional "dialback" authentication (XEP-0220), while others verify
via DANE, hard-coded fingerprints, or other custom plugins.
Implementing this flexibility requires us to override OpenSSL's default
certificate verification, to allow Prosody to verify the certificate itself,
apply custom policies and make decisions based on the outcome.
To enable our custom logic, we have to suppress OpenSSL's default behaviour of
aborting the connection with a TLS alert message. With LuaSec, this can be
achieved by using the verifyext "lsec_continue" flag.
We also need to use the lsec_ignore_purpose flag, because XMPP s2s uses server
certificates as "client" certificates (for mutual TLS verification in outgoing
s2s connections).
Commit 99d2100d2918 moved these settings out of the defaults and into mod_s2s,
because we only really need these changes for s2s, and they should be opt-in,
rather than automatically applied to all TLS services we offer.
That commit was incomplete, because it only added the flags for incoming
direct TLS connections. StartTLS connections are handled by mod_tls, which was
not applying the lsec_* flags. It previously worked because they were already
in the defaults.
This resulted in incoming s2s connections with "invalid" certificates being
aborted early by OpenSSL, even if settings such as `s2s_secure_auth = false`
or DANE were present in the config.
Outgoing s2s connections inherit verify "none" from the defaults, which means
OpenSSL will receive the cert but will not terminate the connection when it is
deemed invalid. This means we don't need lsec_continue there, and we also
don't need lsec_ignore_purpose (because the remote peer is a "server").
Wondering why we can't just use verify "none" for incoming s2s? It's because
in that mode, OpenSSL won't request a certificate from the peer for incoming
connections. Setting verify "peer" is how you ask OpenSSL to request a
certificate from the client, but also what triggers its built-in verification.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 01 Apr 2025 17:26:56 +0100 |
| parent | 13758:fc97319ef48e |
| rev | line source |
|---|---|
| 896 | 1 -- sasl.lua v0.4 |
|
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2873
diff
changeset
|
2 -- Copyright (C) 2008-2010 Tobias Markmann |
|
1585
edc066730d11
Switch to using a more generic credentials_callback/handler for SASL auth.
nick@lupine.me.uk
parents:
1518
diff
changeset
|
3 -- |
|
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
508
diff
changeset
|
4 -- All rights reserved. |
|
1585
edc066730d11
Switch to using a more generic credentials_callback/handler for SASL auth.
nick@lupine.me.uk
parents:
1518
diff
changeset
|
5 -- |
|
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
508
diff
changeset
|
6 -- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
|
1585
edc066730d11
Switch to using a more generic credentials_callback/handler for SASL auth.
nick@lupine.me.uk
parents:
1518
diff
changeset
|
7 -- |
|
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
508
diff
changeset
|
8 -- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
|
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
508
diff
changeset
|
9 -- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. |
|
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
508
diff
changeset
|
10 -- * Neither the name of Tobias Markmann nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. |
|
1585
edc066730d11
Switch to using a more generic credentials_callback/handler for SASL auth.
nick@lupine.me.uk
parents:
1518
diff
changeset
|
11 -- |
|
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
508
diff
changeset
|
12 -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
508
diff
changeset
|
13 |
|
15
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
14 |
|
2176
aaf2b2df61f7
Mostly making the code run; includes fixing typos and so on.
Tobias Markmann <tm@ayena.de>
parents:
2175
diff
changeset
|
15 local pairs, ipairs = pairs, ipairs; |
|
3441
d4f89802cf1e
util.sasl, util.sasl_cyrus: Removed a ton of unused variables.
Waqas Hussain <waqas20@gmail.com>
parents:
3427
diff
changeset
|
16 local t_insert = table.insert; |
|
276
30893439d5d1
Some early attempts on DIGEST-MD5.
Tobias Markmann <tm@ayena.de>
parents:
50
diff
changeset
|
17 local type = type |
|
2175
3ca8755581a1
Initial commit of the SASL redesign.
Tobias Markmann <tm@ayena.de>
parents:
1585
diff
changeset
|
18 local setmetatable = setmetatable; |
|
3ca8755581a1
Initial commit of the SASL redesign.
Tobias Markmann <tm@ayena.de>
parents:
1585
diff
changeset
|
19 local assert = assert; |
|
2187
f0a85d11823e
Getting PLAIN mechanism work with the new API.
Tobias Markmann <tm@ayena.de>
parents:
2186
diff
changeset
|
20 local require = require; |
|
276
30893439d5d1
Some early attempts on DIGEST-MD5.
Tobias Markmann <tm@ayena.de>
parents:
50
diff
changeset
|
21 |
|
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6036
diff
changeset
|
22 local _ENV = nil; |
|
8555
4f0f5b49bb03
vairious: Add annotation when an empty environment is set [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8382
diff
changeset
|
23 -- luacheck: std none |
| 38 | 24 |
| 2177 | 25 --[[ |
| 26 Authentication Backend Prototypes: | |
|
1585
edc066730d11
Switch to using a more generic credentials_callback/handler for SASL auth.
nick@lupine.me.uk
parents:
1518
diff
changeset
|
27 |
|
2188
1fd38975addd
Add support for plain profile in digest-md5 implementation.
Tobias Markmann <tm@ayena.de>
parents:
2187
diff
changeset
|
28 state = false : disabled |
|
1fd38975addd
Add support for plain profile in digest-md5 implementation.
Tobias Markmann <tm@ayena.de>
parents:
2187
diff
changeset
|
29 state = true : enabled |
|
11727
f3aee8a825cc
Fix various spelling errors (thanks codespell)
Kim Alvefur <zash@zash.se>
parents:
10723
diff
changeset
|
30 state = nil : non-existent |
|
5829
40c16475194e
Check whether we support the proposed channel binding type.
Tobias Markmann <tm@ayena.de>
parents:
3550
diff
changeset
|
31 |
|
40c16475194e
Check whether we support the proposed channel binding type.
Tobias Markmann <tm@ayena.de>
parents:
3550
diff
changeset
|
32 Channel Binding: |
|
40c16475194e
Check whether we support the proposed channel binding type.
Tobias Markmann <tm@ayena.de>
parents:
3550
diff
changeset
|
33 |
|
40c16475194e
Check whether we support the proposed channel binding type.
Tobias Markmann <tm@ayena.de>
parents:
3550
diff
changeset
|
34 To enable support of channel binding in some mechanisms you need to provide appropriate callbacks in a table |
|
40c16475194e
Check whether we support the proposed channel binding type.
Tobias Markmann <tm@ayena.de>
parents:
3550
diff
changeset
|
35 at profile.cb. |
|
40c16475194e
Check whether we support the proposed channel binding type.
Tobias Markmann <tm@ayena.de>
parents:
3550
diff
changeset
|
36 |
|
40c16475194e
Check whether we support the proposed channel binding type.
Tobias Markmann <tm@ayena.de>
parents:
3550
diff
changeset
|
37 Example: |
|
40c16475194e
Check whether we support the proposed channel binding type.
Tobias Markmann <tm@ayena.de>
parents:
3550
diff
changeset
|
38 profile.cb["tls-unique"] = function(self) |
|
40c16475194e
Check whether we support the proposed channel binding type.
Tobias Markmann <tm@ayena.de>
parents:
3550
diff
changeset
|
39 return self.user |
|
40c16475194e
Check whether we support the proposed channel binding type.
Tobias Markmann <tm@ayena.de>
parents:
3550
diff
changeset
|
40 end |
|
40c16475194e
Check whether we support the proposed channel binding type.
Tobias Markmann <tm@ayena.de>
parents:
3550
diff
changeset
|
41 |
| 2177 | 42 ]] |
|
1585
edc066730d11
Switch to using a more generic credentials_callback/handler for SASL auth.
nick@lupine.me.uk
parents:
1518
diff
changeset
|
43 |
|
2176
aaf2b2df61f7
Mostly making the code run; includes fixing typos and so on.
Tobias Markmann <tm@ayena.de>
parents:
2175
diff
changeset
|
44 local method = {}; |
|
aaf2b2df61f7
Mostly making the code run; includes fixing typos and so on.
Tobias Markmann <tm@ayena.de>
parents:
2175
diff
changeset
|
45 method.__index = method; |
|
8382
e5d00bf4a4d5
util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
46 local registered_mechanisms = {}; |
|
2175
3ca8755581a1
Initial commit of the SASL redesign.
Tobias Markmann <tm@ayena.de>
parents:
1585
diff
changeset
|
47 local backend_mechanism = {}; |
|
5841
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
48 local mechanism_channelbindings = {}; |
|
1585
edc066730d11
Switch to using a more generic credentials_callback/handler for SASL auth.
nick@lupine.me.uk
parents:
1518
diff
changeset
|
49 |
| 13060 | 50 -- register a new SASL mechanism |
|
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6036
diff
changeset
|
51 local function registerMechanism(name, backends, f, cb_backends) |
|
2175
3ca8755581a1
Initial commit of the SASL redesign.
Tobias Markmann <tm@ayena.de>
parents:
1585
diff
changeset
|
52 assert(type(name) == "string", "Parameter name MUST be a string."); |
|
3ca8755581a1
Initial commit of the SASL redesign.
Tobias Markmann <tm@ayena.de>
parents:
1585
diff
changeset
|
53 assert(type(backends) == "string" or type(backends) == "table", "Parameter backends MUST be either a string or a table."); |
|
3ca8755581a1
Initial commit of the SASL redesign.
Tobias Markmann <tm@ayena.de>
parents:
1585
diff
changeset
|
54 assert(type(f) == "function", "Parameter f MUST be a function."); |
|
5841
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
55 if cb_backends then assert(type(cb_backends) == "table"); end |
|
8382
e5d00bf4a4d5
util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
56 registered_mechanisms[name] = f |
|
5841
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
57 if cb_backends then |
|
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
58 mechanism_channelbindings[name] = {}; |
|
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
59 for _, cb_name in ipairs(cb_backends) do |
|
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
60 mechanism_channelbindings[name][cb_name] = true; |
|
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
61 end |
|
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
62 end |
|
2176
aaf2b2df61f7
Mostly making the code run; includes fixing typos and so on.
Tobias Markmann <tm@ayena.de>
parents:
2175
diff
changeset
|
63 for _, backend_name in ipairs(backends) do |
|
aaf2b2df61f7
Mostly making the code run; includes fixing typos and so on.
Tobias Markmann <tm@ayena.de>
parents:
2175
diff
changeset
|
64 if backend_mechanism[backend_name] == nil then backend_mechanism[backend_name] = {}; end |
|
aaf2b2df61f7
Mostly making the code run; includes fixing typos and so on.
Tobias Markmann <tm@ayena.de>
parents:
2175
diff
changeset
|
65 t_insert(backend_mechanism[backend_name], name); |
|
aaf2b2df61f7
Mostly making the code run; includes fixing typos and so on.
Tobias Markmann <tm@ayena.de>
parents:
2175
diff
changeset
|
66 end |
|
15
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
67 end |
|
1585
edc066730d11
Switch to using a more generic credentials_callback/handler for SASL auth.
nick@lupine.me.uk
parents:
1518
diff
changeset
|
68 |
|
2175
3ca8755581a1
Initial commit of the SASL redesign.
Tobias Markmann <tm@ayena.de>
parents:
1585
diff
changeset
|
69 -- create a new SASL object which can be used to authenticate clients |
|
13758
fc97319ef48e
util.sasl: Preserve 'userdata' field between clones
Matthew Wild <mwild1@gmail.com>
parents:
13060
diff
changeset
|
70 local function new(realm, profile, userdata) |
|
3986
671a660b20f9
util.sasl: Cache the calculated mechanisms set for SASL profiles (profile.mechanisms table).
Waqas Hussain <waqas20@gmail.com>
parents:
3550
diff
changeset
|
71 local mechanisms = profile.mechanisms; |
|
671a660b20f9
util.sasl: Cache the calculated mechanisms set for SASL profiles (profile.mechanisms table).
Waqas Hussain <waqas20@gmail.com>
parents:
3550
diff
changeset
|
72 if not mechanisms then |
|
671a660b20f9
util.sasl: Cache the calculated mechanisms set for SASL profiles (profile.mechanisms table).
Waqas Hussain <waqas20@gmail.com>
parents:
3550
diff
changeset
|
73 mechanisms = {}; |
|
8382
e5d00bf4a4d5
util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
74 for backend in pairs(profile) do |
|
3986
671a660b20f9
util.sasl: Cache the calculated mechanisms set for SASL profiles (profile.mechanisms table).
Waqas Hussain <waqas20@gmail.com>
parents:
3550
diff
changeset
|
75 if backend_mechanism[backend] then |
|
671a660b20f9
util.sasl: Cache the calculated mechanisms set for SASL profiles (profile.mechanisms table).
Waqas Hussain <waqas20@gmail.com>
parents:
3550
diff
changeset
|
76 for _, mechanism in ipairs(backend_mechanism[backend]) do |
|
671a660b20f9
util.sasl: Cache the calculated mechanisms set for SASL profiles (profile.mechanisms table).
Waqas Hussain <waqas20@gmail.com>
parents:
3550
diff
changeset
|
77 mechanisms[mechanism] = true; |
|
671a660b20f9
util.sasl: Cache the calculated mechanisms set for SASL profiles (profile.mechanisms table).
Waqas Hussain <waqas20@gmail.com>
parents:
3550
diff
changeset
|
78 end |
|
3549
395d5bb5266e
util.sasl, util.sasl_cyrus: Load mechanisms list early rather than lazily, as they are always loaded anyway.
Waqas Hussain <waqas20@gmail.com>
parents:
3442
diff
changeset
|
79 end |
|
395d5bb5266e
util.sasl, util.sasl_cyrus: Load mechanisms list early rather than lazily, as they are always loaded anyway.
Waqas Hussain <waqas20@gmail.com>
parents:
3442
diff
changeset
|
80 end |
|
3986
671a660b20f9
util.sasl: Cache the calculated mechanisms set for SASL profiles (profile.mechanisms table).
Waqas Hussain <waqas20@gmail.com>
parents:
3550
diff
changeset
|
81 profile.mechanisms = mechanisms; |
|
3549
395d5bb5266e
util.sasl, util.sasl_cyrus: Load mechanisms list early rather than lazily, as they are always loaded anyway.
Waqas Hussain <waqas20@gmail.com>
parents:
3442
diff
changeset
|
82 end |
|
13758
fc97319ef48e
util.sasl: Preserve 'userdata' field between clones
Matthew Wild <mwild1@gmail.com>
parents:
13060
diff
changeset
|
83 return setmetatable({ |
|
fc97319ef48e
util.sasl: Preserve 'userdata' field between clones
Matthew Wild <mwild1@gmail.com>
parents:
13060
diff
changeset
|
84 profile = profile, |
|
fc97319ef48e
util.sasl: Preserve 'userdata' field between clones
Matthew Wild <mwild1@gmail.com>
parents:
13060
diff
changeset
|
85 realm = realm, |
|
fc97319ef48e
util.sasl: Preserve 'userdata' field between clones
Matthew Wild <mwild1@gmail.com>
parents:
13060
diff
changeset
|
86 mechs = mechanisms, |
|
fc97319ef48e
util.sasl: Preserve 'userdata' field between clones
Matthew Wild <mwild1@gmail.com>
parents:
13060
diff
changeset
|
87 userdata = userdata |
|
fc97319ef48e
util.sasl: Preserve 'userdata' field between clones
Matthew Wild <mwild1@gmail.com>
parents:
13060
diff
changeset
|
88 }, method); |
|
2201
49e4838f9755
Enable restriction of supported mechanisms in the SASL library.
Tobias Markmann <tm@ayena.de>
parents:
2198
diff
changeset
|
89 end |
|
1585
edc066730d11
Switch to using a more generic credentials_callback/handler for SASL auth.
nick@lupine.me.uk
parents:
1518
diff
changeset
|
90 |
|
5831
aa4bdabd3c0f
util.sasl: New method to add channel binding handler to a SASL instance.
Tobias Markmann <tm@ayena.de>
parents:
5829
diff
changeset
|
91 -- add a channel binding handler |
|
aa4bdabd3c0f
util.sasl: New method to add channel binding handler to a SASL instance.
Tobias Markmann <tm@ayena.de>
parents:
5829
diff
changeset
|
92 function method:add_cb_handler(name, f) |
|
aa4bdabd3c0f
util.sasl: New method to add channel binding handler to a SASL instance.
Tobias Markmann <tm@ayena.de>
parents:
5829
diff
changeset
|
93 if type(self.profile.cb) ~= "table" then |
|
aa4bdabd3c0f
util.sasl: New method to add channel binding handler to a SASL instance.
Tobias Markmann <tm@ayena.de>
parents:
5829
diff
changeset
|
94 self.profile.cb = {}; |
|
aa4bdabd3c0f
util.sasl: New method to add channel binding handler to a SASL instance.
Tobias Markmann <tm@ayena.de>
parents:
5829
diff
changeset
|
95 end |
|
aa4bdabd3c0f
util.sasl: New method to add channel binding handler to a SASL instance.
Tobias Markmann <tm@ayena.de>
parents:
5829
diff
changeset
|
96 self.profile.cb[name] = f; |
|
aa4bdabd3c0f
util.sasl: New method to add channel binding handler to a SASL instance.
Tobias Markmann <tm@ayena.de>
parents:
5829
diff
changeset
|
97 return self; |
|
aa4bdabd3c0f
util.sasl: New method to add channel binding handler to a SASL instance.
Tobias Markmann <tm@ayena.de>
parents:
5829
diff
changeset
|
98 end |
|
aa4bdabd3c0f
util.sasl: New method to add channel binding handler to a SASL instance.
Tobias Markmann <tm@ayena.de>
parents:
5829
diff
changeset
|
99 |
|
3427
046a8cf304dd
util.sasl: Removed method:forbidden() and its side effects.
Waqas Hussain <waqas20@gmail.com>
parents:
3373
diff
changeset
|
100 -- get a fresh clone with the same realm and profile |
|
2241
ac3bd7c42c8b
util.sasl: Adding clean_clone() method.
Tobias Markmann <tm@ayena.de>
parents:
2212
diff
changeset
|
101 function method:clean_clone() |
|
13758
fc97319ef48e
util.sasl: Preserve 'userdata' field between clones
Matthew Wild <mwild1@gmail.com>
parents:
13060
diff
changeset
|
102 return new(self.realm, self.profile, self.userdata) |
|
276
30893439d5d1
Some early attempts on DIGEST-MD5.
Tobias Markmann <tm@ayena.de>
parents:
50
diff
changeset
|
103 end |
|
30893439d5d1
Some early attempts on DIGEST-MD5.
Tobias Markmann <tm@ayena.de>
parents:
50
diff
changeset
|
104 |
|
12387
05c250fa335a
Spelling: Fix various spelling mistakes (thanks timeless)
Kim Alvefur <zash@zash.se>
parents:
11727
diff
changeset
|
105 -- get a list of possible SASL mechanisms to use |
|
2175
3ca8755581a1
Initial commit of the SASL redesign.
Tobias Markmann <tm@ayena.de>
parents:
1585
diff
changeset
|
106 function method:mechanisms() |
|
5841
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
107 local current_mechs = {}; |
|
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
108 for mech, _ in pairs(self.mechs) do |
|
6036
f9e108f7db21
util.sasl: Fix logic for when mechanisms with channel binding support are offered
Kim Alvefur <zash@zash.se>
parents:
5863
diff
changeset
|
109 if mechanism_channelbindings[mech] then |
|
f9e108f7db21
util.sasl: Fix logic for when mechanisms with channel binding support are offered
Kim Alvefur <zash@zash.se>
parents:
5863
diff
changeset
|
110 if self.profile.cb then |
|
f9e108f7db21
util.sasl: Fix logic for when mechanisms with channel binding support are offered
Kim Alvefur <zash@zash.se>
parents:
5863
diff
changeset
|
111 local ok = false; |
|
f9e108f7db21
util.sasl: Fix logic for when mechanisms with channel binding support are offered
Kim Alvefur <zash@zash.se>
parents:
5863
diff
changeset
|
112 for cb_name, _ in pairs(self.profile.cb) do |
|
f9e108f7db21
util.sasl: Fix logic for when mechanisms with channel binding support are offered
Kim Alvefur <zash@zash.se>
parents:
5863
diff
changeset
|
113 if mechanism_channelbindings[mech][cb_name] then |
|
f9e108f7db21
util.sasl: Fix logic for when mechanisms with channel binding support are offered
Kim Alvefur <zash@zash.se>
parents:
5863
diff
changeset
|
114 ok = true; |
|
f9e108f7db21
util.sasl: Fix logic for when mechanisms with channel binding support are offered
Kim Alvefur <zash@zash.se>
parents:
5863
diff
changeset
|
115 end |
|
5841
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
116 end |
|
6036
f9e108f7db21
util.sasl: Fix logic for when mechanisms with channel binding support are offered
Kim Alvefur <zash@zash.se>
parents:
5863
diff
changeset
|
117 if ok == true then current_mechs[mech] = true; end |
|
5841
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
118 end |
|
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
119 else |
|
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
120 current_mechs[mech] = true; |
|
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
121 end |
|
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
122 end |
|
1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
Tobias Markmann <tm@ayena.de>
parents:
5831
diff
changeset
|
123 return current_mechs; |
|
276
30893439d5d1
Some early attempts on DIGEST-MD5.
Tobias Markmann <tm@ayena.de>
parents:
50
diff
changeset
|
124 end |
|
30893439d5d1
Some early attempts on DIGEST-MD5.
Tobias Markmann <tm@ayena.de>
parents:
50
diff
changeset
|
125 |
|
2175
3ca8755581a1
Initial commit of the SASL redesign.
Tobias Markmann <tm@ayena.de>
parents:
1585
diff
changeset
|
126 -- select a mechanism to use |
|
2176
aaf2b2df61f7
Mostly making the code run; includes fixing typos and so on.
Tobias Markmann <tm@ayena.de>
parents:
2175
diff
changeset
|
127 function method:select(mechanism) |
|
3550
5e5d136d9de0
util.sasl, util.sasl_cyrus: Mechanism selection cleaned up to be more consistent.
Waqas Hussain <waqas20@gmail.com>
parents:
3549
diff
changeset
|
128 if not self.selected and self.mechs[mechanism] then |
|
5e5d136d9de0
util.sasl, util.sasl_cyrus: Mechanism selection cleaned up to be more consistent.
Waqas Hussain <waqas20@gmail.com>
parents:
3549
diff
changeset
|
129 self.selected = mechanism; |
|
5e5d136d9de0
util.sasl, util.sasl_cyrus: Mechanism selection cleaned up to be more consistent.
Waqas Hussain <waqas20@gmail.com>
parents:
3549
diff
changeset
|
130 return true; |
|
2185
e92339c48ee6
Fail if mechanism has already been selected.
Tobias Markmann <tm@ayena.de>
parents:
2184
diff
changeset
|
131 end |
|
799
b7ea802f3527
Adding inital support for ANONYMOUS mechanism in SASL.
Tobias Markmann <tm@ayena.de>
parents:
760
diff
changeset
|
132 end |
|
b7ea802f3527
Adding inital support for ANONYMOUS mechanism in SASL.
Tobias Markmann <tm@ayena.de>
parents:
760
diff
changeset
|
133 |
|
2176
aaf2b2df61f7
Mostly making the code run; includes fixing typos and so on.
Tobias Markmann <tm@ayena.de>
parents:
2175
diff
changeset
|
134 -- feed new messages to process into the library |
|
aaf2b2df61f7
Mostly making the code run; includes fixing typos and so on.
Tobias Markmann <tm@ayena.de>
parents:
2175
diff
changeset
|
135 function method:process(message) |
|
2188
1fd38975addd
Add support for plain profile in digest-md5 implementation.
Tobias Markmann <tm@ayena.de>
parents:
2187
diff
changeset
|
136 --if message == "" or message == nil then return "failure", "malformed-request" end |
|
8382
e5d00bf4a4d5
util: Various minor changes to please [luacheck]
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
137 return registered_mechanisms[self.selected](self, message); |
|
15
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
138 end |
|
799
b7ea802f3527
Adding inital support for ANONYMOUS mechanism in SASL.
Tobias Markmann <tm@ayena.de>
parents:
760
diff
changeset
|
139 |
|
2186
1112871916eb
Move each mechanism in an own file.
Tobias Markmann <tm@ayena.de>
parents:
2185
diff
changeset
|
140 -- load the mechanisms |
|
12975
d10957394a3c
util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12911
diff
changeset
|
141 require "prosody.util.sasl.plain" .init(registerMechanism); |
|
d10957394a3c
util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12911
diff
changeset
|
142 require "prosody.util.sasl.anonymous" .init(registerMechanism); |
|
d10957394a3c
util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12911
diff
changeset
|
143 require "prosody.util.sasl.oauthbearer" .init(registerMechanism); |
|
d10957394a3c
util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12911
diff
changeset
|
144 require "prosody.util.sasl.scram" .init(registerMechanism); |
|
d10957394a3c
util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12911
diff
changeset
|
145 require "prosody.util.sasl.external" .init(registerMechanism); |
|
15
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
146 |
|
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6036
diff
changeset
|
147 return { |
|
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6036
diff
changeset
|
148 registerMechanism = registerMechanism; |
|
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6036
diff
changeset
|
149 new = new; |
|
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6036
diff
changeset
|
150 }; |