Software / code / prosody
Comparison
util/sasl.lua @ 5841:1b0c7e7c6be8
Only advertise mechanisms needing channel binding if a channel binding backend is avaliable.
| author | Tobias Markmann <tm@ayena.de> |
|---|---|
| date | Mon, 07 Feb 2011 13:24:42 +0100 |
| parent | 5831:aa4bdabd3c0f |
| child | 5843:fb6573e191cf |
comparison
equal
deleted
inserted
replaced
| 5840:4b484e8feafc | 5841:1b0c7e7c6be8 |
|---|---|
| 16 local t_insert = table.insert; | 16 local t_insert = table.insert; |
| 17 local type = type | 17 local type = type |
| 18 local setmetatable = setmetatable; | 18 local setmetatable = setmetatable; |
| 19 local assert = assert; | 19 local assert = assert; |
| 20 local require = require; | 20 local require = require; |
| 21 local print = print | |
| 21 | 22 |
| 22 module "sasl" | 23 module "sasl" |
| 23 | 24 |
| 24 --[[ | 25 --[[ |
| 25 Authentication Backend Prototypes: | 26 Authentication Backend Prototypes: |
| 42 | 43 |
| 43 local method = {}; | 44 local method = {}; |
| 44 method.__index = method; | 45 method.__index = method; |
| 45 local mechanisms = {}; | 46 local mechanisms = {}; |
| 46 local backend_mechanism = {}; | 47 local backend_mechanism = {}; |
| 48 local mechanism_channelbindings = {}; | |
| 47 | 49 |
| 48 -- register a new SASL mechanims | 50 -- register a new SASL mechanims |
| 49 local function registerMechanism(name, backends, f) | 51 local function registerMechanism(name, backends, f, cb_backends) |
| 50 assert(type(name) == "string", "Parameter name MUST be a string."); | 52 assert(type(name) == "string", "Parameter name MUST be a string."); |
| 51 assert(type(backends) == "string" or type(backends) == "table", "Parameter backends MUST be either a string or a table."); | 53 assert(type(backends) == "string" or type(backends) == "table", "Parameter backends MUST be either a string or a table."); |
| 52 assert(type(f) == "function", "Parameter f MUST be a function."); | 54 assert(type(f) == "function", "Parameter f MUST be a function."); |
| 55 if cb_backends then assert(type(cb_backends) == "table"); end | |
| 53 mechanisms[name] = f | 56 mechanisms[name] = f |
| 57 if cb_backends then | |
| 58 mechanism_channelbindings[name] = {}; | |
| 59 for _, cb_name in ipairs(cb_backends) do | |
| 60 mechanism_channelbindings[name][cb_name] = true; | |
| 61 end | |
| 62 end | |
| 54 for _, backend_name in ipairs(backends) do | 63 for _, backend_name in ipairs(backends) do |
| 55 if backend_mechanism[backend_name] == nil then backend_mechanism[backend_name] = {}; end | 64 if backend_mechanism[backend_name] == nil then backend_mechanism[backend_name] = {}; end |
| 56 t_insert(backend_mechanism[backend_name], name); | 65 t_insert(backend_mechanism[backend_name], name); |
| 57 end | 66 end |
| 58 end | 67 end |
| 84 return new(self.realm, self.profile) | 93 return new(self.realm, self.profile) |
| 85 end | 94 end |
| 86 | 95 |
| 87 -- get a list of possible SASL mechanims to use | 96 -- get a list of possible SASL mechanims to use |
| 88 function method:mechanisms() | 97 function method:mechanisms() |
| 89 return self.mechs; | 98 local current_mechs = {}; |
| 99 for mech, _ in pairs(self.mechs) do | |
| 100 if mechanism_channelbindings[mech] and self.profile.cb then | |
| 101 local ok = false; | |
| 102 for cb_name, _ in pairs(self.profile.cb) do | |
| 103 if mechanism_channelbindings[mech][cb_name] then | |
| 104 ok = true; | |
| 105 end | |
| 106 end | |
| 107 if ok == true then current_mechs[mech] = true; end | |
| 108 else | |
| 109 current_mechs[mech] = true; | |
| 110 end | |
| 111 end | |
| 112 return current_mechs; | |
| 90 end | 113 end |
| 91 | 114 |
| 92 -- select a mechanism to use | 115 -- select a mechanism to use |
| 93 function method:select(mechanism) | 116 function method:select(mechanism) |
| 94 if not self.selected and self.mechs[mechanism] then | 117 if not self.selected and self.mechs[mechanism] then |