Skip to content

Commit c496c25

Browse files
authored
chore(NODE-4266): improve error message for SCRAM-SHA-1 in FIPS mode (#3258)
No tests because the Node.js driver CI doesn’t have a FIPS setup. MONGOSH-1232 will add integration tests for this message.
1 parent c9d3816 commit c496c25

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/cmap/auth/scram.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,17 @@ function passwordDigest(username: string, password: string) {
261261
throw new MongoInvalidArgumentError('Password cannot be empty');
262262
}
263263

264-
const md5 = crypto.createHash('md5');
264+
let md5: crypto.Hash;
265+
try {
266+
md5 = crypto.createHash('md5');
267+
} catch (err) {
268+
if (crypto.getFips()) {
269+
// This error is (slightly) more helpful than what comes from OpenSSL directly, e.g.
270+
// 'Error: error:060800C8:digital envelope routines:EVP_DigestInit_ex:disabled for FIPS'
271+
throw new Error('Auth mechanism SCRAM-SHA-1 is not supported in FIPS mode');
272+
}
273+
throw err;
274+
}
265275
md5.update(`${username}:mongo:${password}`, 'utf8');
266276
return md5.digest('hex');
267277
}

0 commit comments

Comments
 (0)