Initial commit of the SASL redesign.
[prosody.git] / util / sasl.lua
1 -- sasl.lua v0.4
2 -- Copyright (C) 2008-2009 Tobias Markmann
3 --
4 --    All rights reserved.
5 --
6 --    Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 --
8 --        * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 --        * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10 --        * Neither the name of Tobias Markmann nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
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.
13
14
15 local md5 = require "util.hashes".md5;
16 local log = require "util.logger".init("sasl");
17 local tostring = tostring;
18 local st = require "util.stanza";
19 local generate_uuid = require "util.uuid".generate;
20 local t_insert, t_concat = table.insert, table.concat;
21 local to_byte, to_char = string.byte, string.char;
22 local to_unicode = require "util.encodings".idna.to_unicode;
23 local s_match = string.match;
24 local gmatch = string.gmatch
25 local string = string
26 local math = require "math"
27 local type = type
28 local error = error
29 local print = print
30 local setmetatable = setmetatable;
31 local assert = assert;
32
33 module "sasl"
34
35 local method = {}
36 local mechanisms = {};
37 local backend_mechanism = {};
38
39 -- register a new SASL mechanims
40 local function registerMechanism(name, backends, f)
41         assert(type(name) == "string", "Parameter name MUST be a string.");
42         assert(type(backends) == "string" or type(backends) == "table", "Parameter backends MUST be either a string or a table.");
43         assert(type(f) == "function", "Parameter f MUST be a function.");
44         mechanism[name] = f
45         for _, backend_name in ipairs(backend)
46 end
47
48 -- create a new SASL object which can be used to authenticate clients
49 function new(realm, profile)
50         sasl_i = {};
51         
52         return setmetatable(sasl_i, method);
53 end
54
55 -- get a list of possible SASL mechanims to use
56 function method:mechanisms()
57
58 end
59
60 -- select a mechanism to use
61 function method.select( mechanism )
62
63 end
64
65 return _M;