Comparison

util/sasl.lua @ 1720:c34409a5fdee

Do SASLprep for SASL PLAIN mechanism to be more conform with RFC 4616.
author Tobias Markmann <tm@ayena.de>
date Wed, 19 Aug 2009 21:34:28 +0200
parent 1518:9707dfa80980
child 1722:132c41aa0680
comparison
equal deleted inserted replaced
1643:4642dd87e390 1720:c34409a5fdee
18 local st = require "util.stanza"; 18 local st = require "util.stanza";
19 local generate_uuid = require "util.uuid".generate; 19 local generate_uuid = require "util.uuid".generate;
20 local t_insert, t_concat = table.insert, table.concat; 20 local t_insert, t_concat = table.insert, table.concat;
21 local to_byte, to_char = string.byte, string.char; 21 local to_byte, to_char = string.byte, string.char;
22 local to_unicode = require "util.encodings".idna.to_unicode; 22 local to_unicode = require "util.encodings".idna.to_unicode;
23 local u_e_saslprep = require "utii.encodings".stringprep.saslprep;
23 local s_match = string.match; 24 local s_match = string.match;
24 local gmatch = string.gmatch 25 local gmatch = string.gmatch
25 local string = string 26 local string = string
26 local math = require "math" 27 local math = require "math"
27 local type = type 28 local type = type
37 if message == "" or message == nil then return "failure", "malformed-request" end 38 if message == "" or message == nil then return "failure", "malformed-request" end
38 local response = message 39 local response = message
39 local authorization = s_match(response, "([^&%z]+)") 40 local authorization = s_match(response, "([^&%z]+)")
40 local authentication = s_match(response, "%z([^&%z]+)%z") 41 local authentication = s_match(response, "%z([^&%z]+)%z")
41 local password = s_match(response, "%z[^&%z]+%z([^&%z]+)") 42 local password = s_match(response, "%z[^&%z]+%z([^&%z]+)")
43 authorization, authentication, password = u_e_saslprep(authorization), u_e_saslprep(authentication), u_e_saslprep(password);
42 44
43 if authentication == nil or password == nil then return "failure", "malformed-request" end 45 if authentication == nil or password == nil then return "failure", "malformed-request" end
44 46
45 local password_encoding, correct_password = self.password_handler(authentication, self.realm, self.realm, "PLAIN") 47 local password_encoding, correct_password = self.password_handler(authentication, self.realm, self.realm, "PLAIN")
46 48
48 elseif correct_password == false then return "failure", "account-disabled" end 50 elseif correct_password == false then return "failure", "account-disabled" end
49 51
50 local claimed_password = "" 52 local claimed_password = ""
51 if password_encoding == nil then claimed_password = password 53 if password_encoding == nil then claimed_password = password
52 else claimed_password = password_encoding(password) end 54 else claimed_password = password_encoding(password) end
55 caimed_password = u_e_saslprep(claimed_password);
53 56
54 self.username = authentication 57 self.username = authentication
55 if claimed_password == correct_password then 58 if claimed_password == correct_password then
56 return "success" 59 return "success"
57 else 60 else