14 |
14 |
15 local md5 = require "util.hashes".md5; |
15 local md5 = require "util.hashes".md5; |
16 local log = require "util.logger".init("sasl"); |
16 local log = require "util.logger".init("sasl"); |
17 local tostring = tostring; |
17 local tostring = tostring; |
18 local st = require "util.stanza"; |
18 local st = require "util.stanza"; |
19 local generate_uuid = require "util.uuid".generate; |
|
20 local pairs, ipairs = pairs, ipairs; |
19 local pairs, ipairs = pairs, ipairs; |
21 local t_insert, t_concat = table.insert, table.concat; |
20 local t_insert, t_concat = table.insert, table.concat; |
22 local to_byte, to_char = string.byte, string.char; |
|
23 local to_unicode = require "util.encodings".idna.to_unicode; |
21 local to_unicode = require "util.encodings".idna.to_unicode; |
24 local s_match = string.match; |
22 local s_match = string.match; |
25 local gmatch = string.gmatch |
23 local gmatch = string.gmatch |
26 local string = string |
24 local string = string |
27 local math = require "math" |
25 local math = require "math" |
39 local array = require "util.array" |
37 local array = require "util.array" |
40 module "sasl" |
38 module "sasl" |
41 |
39 |
42 --[[ |
40 --[[ |
43 Authentication Backend Prototypes: |
41 Authentication Backend Prototypes: |
|
42 |
|
43 state = false : disabled |
|
44 state = true : enabled |
|
45 state = nil : non-existant |
44 |
46 |
45 plain: |
47 plain: |
46 function(username, realm) |
48 function(username, realm) |
47 return password, state; |
49 return password, state; |
48 end |
50 end |
115 return true; |
117 return true; |
116 end |
118 end |
117 |
119 |
118 -- feed new messages to process into the library |
120 -- feed new messages to process into the library |
119 function method:process(message) |
121 function method:process(message) |
120 if message == "" or message == nil then return "failure", "malformed-request" end |
122 --if message == "" or message == nil then return "failure", "malformed-request" end |
121 return self.mech_i(self, message); |
123 return self.mech_i(self, message); |
122 end |
124 end |
123 |
125 |
124 -- load the mechanisms |
126 -- load the mechanisms |
125 m = require "util.sasl.plain" |
127 load_mechs = {"plain", "digest-md5"} |
126 m.init(registerMechanism) |
128 for _, mech in ipairs(load_mechs) do |
127 --dofile "util/sasl/digest-md5.lua" |
129 local name = "util.sasl."..mech; |
128 --dofile "util/sasl/scram.lua" |
130 local m = require(name); |
|
131 m.init(registerMechanism) |
|
132 end |
129 |
133 |
130 return _M; |
134 return _M; |