Changeset

362:d8c3e94d765d

util.sasl.scram: Correctly verify that the server added its own nonce
author Kim Alvefur <zash@zash.se>
date Tue, 30 Sep 2014 11:59:52 +0200
parents 361:451dbad2a8e6
children 363:056ccefa6acf
files util/sasl/scram.lua
diffstat 1 files changed, 4 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/util/sasl/scram.lua	Tue Sep 23 22:15:13 2014 +0200
+++ b/util/sasl/scram.lua	Tue Sep 30 11:59:52 2014 +0200
@@ -43,8 +43,8 @@
 local function scram(stream, name)
 	local username = "n=" .. value_safe(stream.username);
 	local c_nonce = base64(crypto.rand.bytes(15));
-	local nonce = "r=" .. c_nonce;
-	local client_first_message_bare = username .. "," .. nonce;
+	local our_nonce = "r=" .. c_nonce;
+	local client_first_message_bare = username .. "," .. our_nonce;
 	local cbind_data = "";
 	local gs2_cbind_flag = "y";
 	if name == "SCRAM-SHA-1-PLUS" then
@@ -56,15 +56,14 @@
 	local cont, server_first_message = coroutine.yield(client_first_message);
 	if cont ~= "challenge" then return false end
 
-	local salt, iteration_count;
-	nonce, salt, iteration_count = server_first_message:match("(r=[^,]+),s=([^,]*),i=(%d+)");
+	local nonce, salt, iteration_count = server_first_message:match("(r=[^,]+),s=([^,]*),i=(%d+)");
 	local i = tonumber(iteration_count);
 	salt = unbase64(salt);
 	if not nonce or not salt or not i then
 		return false, "Could not parse server_first_message";
 	elseif nonce:find(c_nonce, 3, true) ~= 3 then
 		return false, "nonce sent by server does not match our nonce";
-	elseif nonce == c_nonce then
+	elseif nonce == our_nonce then
 		return false, "server did not append s-nonce to nonce";
 	end