From bcb87caa89f5841272955fb4b320f75d632856f7 Mon Sep 17 00:00:00 2001 From: Sebastiaan Deckers Date: Wed, 8 May 2019 02:11:55 +0800 Subject: [PATCH] fix(authentication): fix auth issue with BSON promoteBuffers: true --- lib/auth/scram.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/auth/scram.js b/lib/auth/scram.js index 234e0f5f0..ac8853eb3 100644 --- a/lib/auth/scram.js +++ b/lib/auth/scram.js @@ -177,7 +177,8 @@ class ScramSHA extends AuthProvider { return callback(tmpError, null); } - const dict = parsePayload(r.payload.value()); + const payload = Buffer.isBuffer(r.payload) ? new Binary(r.payload) : r.payload; + const dict = parsePayload(payload.value()); const iterations = parseInt(dict.i, 10); const salt = dict.s; const rnonce = dict.r; @@ -198,7 +199,7 @@ class ScramSHA extends AuthProvider { const clientKey = HMAC(cryptoMethod, saltedPassword, 'Client Key'); const storedKey = H(cryptoMethod, clientKey); - const authMessage = [firstBare, r.payload.value().toString('base64'), withoutProof].join(','); + const authMessage = [firstBare, payload.value().toString('base64'), withoutProof].join(','); const clientSignature = HMAC(cryptoMethod, storedKey, authMessage); const clientProof = `p=${xor(clientKey, clientSignature)}`;