util/sasl.lua

changeset 1723
2145daff1a65
parent 1722
132c41aa0680
child 1724
7682a34c13d0
equal deleted inserted replaced
1722:132c41aa0680 1723:2145daff1a65
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 saslprep = require "utii.encodings".stringprep.saslprep; 23 local saslprep = require "util.encodings".stringprep.saslprep;
24 local s_match = string.match; 24 local s_match = string.match;
25 local gmatch = string.gmatch 25 local gmatch = string.gmatch
26 local string = string 26 local string = string
27 local math = require "math" 27 local math = require "math"
28 local type = type 28 local type = type
35 local object = { mechanism = "PLAIN", realm = realm, password_handler = password_handler} 35 local object = { mechanism = "PLAIN", realm = realm, password_handler = password_handler}
36 function object.feed(self, message) 36 function object.feed(self, message)
37 37
38 if message == "" or message == nil then return "failure", "malformed-request" end 38 if message == "" or message == nil then return "failure", "malformed-request" end
39 local response = message 39 local response = message
40 local authorization = s_match(response, "([^&%z]+)") 40 local authorization = s_match(response, "([^%z]+)")
41 local authentication = s_match(response, "%z([^&%z]+)%z") 41 local authentication = s_match(response, "%z([^%z]+)%z")
42 local password = s_match(response, "%z[^&%z]+%z([^&%z]+)") 42 local password = s_match(response, "%z[^%z]+%z([^%z]+)")
43 authorization, authentication, password = saslprep(authorization), saslprep(authentication), saslprep(password); 43 authorization, authentication, password = saslprep(authorization), saslprep(authentication), saslprep(password);
44 44
45 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
46 46
47 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")

mercurial