Changeset

449:c0a4a1e63d70

Completely switched to new hashes library from the old md5 library
author Waqas Hussain <waqas20@gmail.com>
date Fri, 28 Nov 2008 01:16:26 +0500
parents 448:2623519b25b0
children 450:e04c4052742c 452:613c5c6bdce4
files core/usermanager.lua plugins/mod_saslauth.lua util/dependencies.lua util/hashes.lua util/sasl.lua
diffstat 5 files changed, 12 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/core/usermanager.lua	Fri Nov 28 01:13:34 2008 +0500
+++ b/core/usermanager.lua	Fri Nov 28 01:16:26 2008 +0500
@@ -19,15 +19,12 @@
 		end
 	end
 	-- must do md5
-	if not hashes.md5 then
-		return nil, "Server misconfiguration, the md5 library is not available.";
-	end
 	-- make credentials md5
 	local pwd = credentials.password;
-	if not pwd then pwd = credentials.md5; else pwd = hashes.md5(pwd); end
+	if not pwd then pwd = credentials.md5; else pwd = hashes.md5(pwd, true); end
 	-- make password md5
 	if method == "PLAIN" then
-		password = hashes.md5(password or "");
+		password = hashes.md5(password or "", true);
 	elseif method ~= "DIGEST-MD5" then
 		return nil, "Unsupported auth method";
 	end
@@ -49,9 +46,7 @@
 
 function get_supported_methods(host)
 	local methods = {["PLAIN"] = true}; -- TODO this should be taken from the config
-	if hashes.md5 then
-		methods["DIGEST-MD5"] = true;
-	end
+	methods["DIGEST-MD5"] = true;
 	return methods;
 end
 
--- a/plugins/mod_saslauth.lua	Fri Nov 28 01:13:34 2008 +0500
+++ b/plugins/mod_saslauth.lua	Fri Nov 28 01:16:26 2008 +0500
@@ -8,6 +8,7 @@
 local t_concat, t_insert = table.concat, table.insert;
 local tostring = tostring;
 local jid_split = require "util.jid".split
+local md5 = require "util.hashes".md5;
 
 local log = require "util.logger".init("mod_saslauth");
 
@@ -50,7 +51,7 @@
 		if mechanism == "PLAIN" then
 			return func, password;
 		elseif mechanism == "DIGEST-MD5" then
-			return func, require "md5".sum(node..":"..host..":"..password);
+			return func, md5(node..":"..host..":"..password);
 		end
 	end
 	return func, nil;
--- a/util/dependencies.lua	Fri Nov 28 01:13:34 2008 +0500
+++ b/util/dependencies.lua	Fri Nov 28 01:16:26 2008 +0500
@@ -43,12 +43,4 @@
 end
 
 
-local md5 = softreq "md5";
-
-if not md5 then
-	missingdep("MD5", { ["luarocks"] = "luarocks install md5"; ["Source"] = "http://luaforge.net/frs/?group_id=155" });	
-	fatal = true;
-end
-
-
 if fatal then os.exit(1); end
--- a/util/hashes.lua	Fri Nov 28 01:13:34 2008 +0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-
-local softreq = function (...) local ok, lib =  pcall(require, ...); if ok then return lib; else return nil; end end
-local error = error;
-
-module "hashes"
-
-local md5 = softreq("md5");
-if md5 then
-	if md5.digest then
-		local md5_digest = md5.digest;
-		local sha1_digest = sha1.digest;
-		function _M.md5(input)
-			return md5_digest(input);
-		end
-		function _M.sha1(input)
-			return sha1_digest(input);
-		end
-	elseif md5.sumhexa then
-		local md5_sumhexa = md5.sumhexa;
-		function _M.md5(input)
-			return md5_sumhexa(input);
-		end
-	else
-		error("md5 library found, but unrecognised... no hash functions will be available", 0);
-	end
-else
-	error("No md5 library found. Install md5 using luarocks, for example", 0);
-end
-
-return _M;
--- a/util/sasl.lua	Fri Nov 28 01:13:34 2008 +0500
+++ b/util/sasl.lua	Fri Nov 28 01:16:26 2008 +0500
@@ -1,5 +1,5 @@
 
-local md5 = require "md5"
+local md5 = require "util.hashes".md5;
 local log = require "util.logger".init("sasl");
 local tostring = tostring;
 local st = require "util.stanza";
@@ -132,21 +132,21 @@
 			local A1 = Y..":"..response["nonce"]..":"..response["cnonce"]--:authzid
 			local A2 = "AUTHENTICATE:"..protocol.."/"..domain
 			
-			local HA1 = md5.sumhexa(A1)
-			local HA2 = md5.sumhexa(A2)
+			local HA1 = md5(A1, true)
+			local HA2 = md5(A2, true)
 			
 			local KD = HA1..":"..response["nonce"]..":"..response["nc"]..":"..response["cnonce"]..":"..response["qop"]..":"..HA2
-			local response_value = md5.sumhexa(KD)
+			local response_value = md5(KD, true)
 			
 			if response_value == response["response"] then
 				-- calculate rspauth
 				A2 = ":"..protocol.."/"..domain
 				
-				HA1 = md5.sumhexa(A1)
-				HA2 = md5.sumhexa(A2)
+				HA1 = md5(A1, true)
+				HA2 = md5(A2, true)
         
 				KD = HA1..":"..response["nonce"]..":"..response["nc"]..":"..response["cnonce"]..":"..response["qop"]..":"..HA2
-				local rspauth = md5.sumhexa(KD)
+				local rspauth = md5(KD, true)
 				self.authenticated = true
 				return "challenge", serialize({rspauth = rspauth})
 			else