From 097917c657152871d6833b89a7ca253fc1775d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Tue, 18 May 2021 20:56:15 +0200 Subject: [PATCH] Add support for skipping authentication By setting `authMethods` to an empty array. Useful for peer-to-peer DBus when authentication is handled elsewhere. --- lib/handshake.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/handshake.js b/lib/handshake.js index 83304ae..830dec7 100644 --- a/lib/handshake.js +++ b/lib/handshake.js @@ -58,12 +58,15 @@ function hexlify (input) { module.exports = function auth (stream, opts, cb) { // filter used to make a copy so we don't accidently change opts data - let authMethods; - if (opts.authMethods) { - authMethods = opts.authMethods; - } else { + let authMethods = opts.authMethods; + if (opts.authMethods === undefined) { authMethods = constants.defaultAuthMethods; } + const skipAuthentication = authMethods.length === 0; + if (skipAuthentication) { + stream.once('readable', () => { cb(null, null); }); + return; + } stream.write('\0'); tryAuth(stream, authMethods.slice(), cb); };