mod_auth_internal_hashed: Coverting salted password to stored_key and server_key.

Tue, 08 Jun 2010 15:02:53 +0200

author
Tobias Markmann <tm@ayena.de>
date
Tue, 08 Jun 2010 15:02:53 +0200
changeset 3208
4b660bf61048
parent 3207
b350d9753804
child 3209
cbceb398c1e4

mod_auth_internal_hashed: Coverting salted password to stored_key and server_key.

plugins/mod_auth_internal_hashed.lua file | annotate | diff | comparison | revisions
--- a/plugins/mod_auth_internal_hashed.lua	Tue Jun 08 14:54:47 2010 +0200
+++ b/plugins/mod_auth_internal_hashed.lua	Tue Jun 08 15:02:53 2010 +0200
@@ -22,6 +22,10 @@
 local nodeprep = require "util.encodings".stringprep.nodeprep;
 local hosts = hosts;
 
+-- TODO: remove these two lines in near future
+local hmac_sha1 = require "util.hmac".sha1;
+local sha1 = require "util.hashes".sha1;
+
 local prosody = _G.prosody;
 
 local is_cyrus = usermanager.is_cyrus;
@@ -53,9 +57,20 @@
 			return nil, "Auth failed. Stored salt and iteration count information is not complete.";
 		end
 		
-		if credentials.saltedPasswordSHA1
+		local valid, stored_key, server_key
 		
-		local valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, credentials.salt, credentials.iteration_count);
+		if credentials.hexpass then
+			-- convert hexpass to stored_key and server_key
+			-- TODO: remove this in near future
+			valid = true;
+			local salted_password = credentials.hexpass:gsub("..", function(x) return string.char(tonumber(x, 16)); end);
+			
+			stored_key = sha1(hmac_sha1(salted_password, "Client Key"))
+			server_key = hmac_sha1(salted_password, "Server Key");
+		else
+			valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, credentials.salt, credentials.iteration_count);
+		end
+		
 		local stored_key_hex = stored_key:gsub(".", function (c) return ("%02x"):format(c:byte()); end);
 		local server_key_hex = server_key:gsub(".", function (c) return ("%02x"):format(c:byte()); end);
 		

mercurial