equal
deleted
inserted
replaced
31 module "sasl" |
31 module "sasl" |
32 |
32 |
33 local function new_plain(realm, password_handler) |
33 local function new_plain(realm, password_handler) |
34 local object = { mechanism = "PLAIN", realm = realm, password_handler = password_handler} |
34 local object = { mechanism = "PLAIN", realm = realm, password_handler = password_handler} |
35 function object.feed(self, message) |
35 function object.feed(self, message) |
36 |
36 |
37 if message == "" or message == nil then return "failure", "malformed-request" end |
37 if message == "" or message == nil then return "failure", "malformed-request" end |
38 local response = message |
38 local response = message |
39 local authorization = s_match(response, "([^&%z]+)") |
39 local authorization = s_match(response, "([^&%z]+)") |
40 local authentication = s_match(response, "%z([^&%z]+)%z") |
40 local authentication = s_match(response, "%z([^&%z]+)%z") |
41 local password = s_match(response, "%z[^&%z]+%z([^&%z]+)") |
41 local password = s_match(response, "%z[^&%z]+%z([^&%z]+)") |
227 -- calculate rspauth |
227 -- calculate rspauth |
228 A2 = ":"..protocol.."/"..domain; |
228 A2 = ":"..protocol.."/"..domain; |
229 |
229 |
230 HA1 = md5(A1, true); |
230 HA1 = md5(A1, true); |
231 HA2 = md5(A2, true); |
231 HA2 = md5(A2, true); |
232 |
232 |
233 KD = HA1..":"..response["nonce"]..":"..response["nc"]..":"..response["cnonce"]..":"..response["qop"]..":"..HA2 |
233 KD = HA1..":"..response["nonce"]..":"..response["nc"]..":"..response["cnonce"]..":"..response["qop"]..":"..HA2 |
234 local rspauth = md5(KD, true); |
234 local rspauth = md5(KD, true); |
235 self.authenticated = true; |
235 self.authenticated = true; |
236 return "challenge", serialize({rspauth = rspauth}); |
236 return "challenge", serialize({rspauth = rspauth}); |
237 else |
237 else |