Comparison

util/sasl/plain.lua @ 5301:6279caf921f1

util.sasl.{plain,scram,digest-md5}: nodeprep username before passing to callbacks, so callbacks don't have to.
author Waqas Hussain <waqas20@gmail.com>
date Tue, 22 Jan 2013 08:21:05 +0500
parent 5240:864b27ddaa10
child 6777:5de6b93d0190
comparison
equal deleted inserted replaced
5300:fcb1be0b4a5c 5301:6279caf921f1
11 -- 11 --
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. 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.
13 13
14 local s_match = string.match; 14 local s_match = string.match;
15 local saslprep = require "util.encodings".stringprep.saslprep; 15 local saslprep = require "util.encodings".stringprep.saslprep;
16 local nodeprep = require "util.encodings".stringprep.nodeprep;
16 local log = require "util.logger".init("sasl"); 17 local log = require "util.logger".init("sasl");
17 18
18 module "sasl.plain" 19 module "sasl.plain"
19 20
20 -- ================================ 21 -- ================================
52 if (not password) or (password == "") or (not authentication) or (authentication == "") then 53 if (not password) or (password == "") or (not authentication) or (authentication == "") then
53 log("debug", "Username or password violates SASLprep."); 54 log("debug", "Username or password violates SASLprep.");
54 return "failure", "malformed-request", "Invalid username or password."; 55 return "failure", "malformed-request", "Invalid username or password.";
55 end 56 end
56 57
58 local _nodeprep = self.profile.nodeprep;
59 if _nodeprep ~= false then
60 authentication = (_nodeprep or nodeprep)(authentication);
61 if not authentication or authentication == "" then
62 return "failure", "malformed-request", "Invalid username or password."
63 end
64 end
65
57 local correct, state = false, false; 66 local correct, state = false, false;
58 if self.profile.plain then 67 if self.profile.plain then
59 local correct_password; 68 local correct_password;
60 correct_password, state = self.profile.plain(self, authentication, self.realm); 69 correct_password, state = self.profile.plain(self, authentication, self.realm);
61 correct = (correct_password == password); 70 correct = (correct_password == password);