From 1e72875d5263b9478b257b27a3784dcd7fc4dcc3 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Sat, 15 Jan 2011 17:59:15 +0100 Subject: Check whether we support the proposed channel binding type. --- util/sasl.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'util/sasl.lua') diff --git a/util/sasl.lua b/util/sasl.lua index 93b79a86..37a234c9 100644 --- a/util/sasl.lua +++ b/util/sasl.lua @@ -27,6 +27,17 @@ Authentication Backend Prototypes: state = false : disabled state = true : enabled state = nil : non-existant + +Channel Binding: + +To enable support of channel binding in some mechanisms you need to provide appropriate callbacks in a table +at profile.cb. + +Example: + profile.cb["tls-unique"] = function(self) + return self.user + end + ]] local method = {}; -- cgit v1.2.3 From 0435f611fd9e7794b8f42699c35ceee01dd28d1f Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Mon, 17 Jan 2011 16:50:21 +0100 Subject: util.sasl: New method to add channel binding handler to a SASL instance. --- util/sasl.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'util/sasl.lua') diff --git a/util/sasl.lua b/util/sasl.lua index 37a234c9..cd0a1d64 100644 --- a/util/sasl.lua +++ b/util/sasl.lua @@ -70,6 +70,15 @@ function new(realm, profile) return setmetatable({ profile = profile, realm = realm, mechs = mechanisms }, method); end +-- add a channel binding handler +function method:add_cb_handler(name, f) + if type(self.profile.cb) ~= "table" then + self.profile.cb = {}; + end + self.profile.cb[name] = f; + return self; +end + -- get a fresh clone with the same realm and profile function method:clean_clone() return new(self.realm, self.profile) -- cgit v1.2.3 From 0a2715f365f2dc28c33933d486fecdb64daf7a89 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Mon, 7 Feb 2011 13:24:42 +0100 Subject: Only advertise mechanisms needing channel binding if a channel binding backend is avaliable. --- util/sasl.lua | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'util/sasl.lua') diff --git a/util/sasl.lua b/util/sasl.lua index cd0a1d64..393a0919 100644 --- a/util/sasl.lua +++ b/util/sasl.lua @@ -18,6 +18,7 @@ local type = type local setmetatable = setmetatable; local assert = assert; local require = require; +local print = print module "sasl" @@ -44,13 +45,21 @@ local method = {}; method.__index = method; local mechanisms = {}; local backend_mechanism = {}; +local mechanism_channelbindings = {}; -- register a new SASL mechanims -local function registerMechanism(name, backends, f) +local function registerMechanism(name, backends, f, cb_backends) assert(type(name) == "string", "Parameter name MUST be a string."); assert(type(backends) == "string" or type(backends) == "table", "Parameter backends MUST be either a string or a table."); assert(type(f) == "function", "Parameter f MUST be a function."); + if cb_backends then assert(type(cb_backends) == "table"); end mechanisms[name] = f + if cb_backends then + mechanism_channelbindings[name] = {}; + for _, cb_name in ipairs(cb_backends) do + mechanism_channelbindings[name][cb_name] = true; + end + end for _, backend_name in ipairs(backends) do if backend_mechanism[backend_name] == nil then backend_mechanism[backend_name] = {}; end t_insert(backend_mechanism[backend_name], name); @@ -86,7 +95,21 @@ end -- get a list of possible SASL mechanims to use function method:mechanisms() - return self.mechs; + local current_mechs = {}; + for mech, _ in pairs(self.mechs) do + if mechanism_channelbindings[mech] and self.profile.cb then + local ok = false; + for cb_name, _ in pairs(self.profile.cb) do + if mechanism_channelbindings[mech][cb_name] then + ok = true; + end + end + if ok == true then current_mechs[mech] = true; end + else + current_mechs[mech] = true; + end + end + return current_mechs; end -- select a mechanism to use -- cgit v1.2.3