From b9ce772ffa51991a28527ff3a09bb4178b8e43f1 Mon Sep 17 00:00:00 2001 From: Kelvin Schoofs Date: Fri, 3 Dec 2021 15:35:45 +0100 Subject: [PATCH] (Test) Add authHandler --- src/connect.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/connect.ts b/src/connect.ts index 1546073..e114f6d 100644 --- a/src/connect.ts +++ b/src/connect.ts @@ -261,6 +261,18 @@ export async function createSSH(config: FileSystemConfig, sock?: NodeJS.Readable const scope = Logging.scope(`ssh2(${config.name})`); finalConfig.debug = (msg: string) => scope.debug(msg); } + // TODO: Temporary for #331 (and possibly problems with `publickey` going before `agent`) + const authsAllowed: string[] = []; + if (finalConfig.password) authsAllowed.push('password'); + if (finalConfig.agent) authsAllowed.push('agent'); + if (finalConfig.privateKey) authsAllowed.push('publickey'); + authsAllowed.push('keyboard-interactive'); + authsAllowed.push('none'); + if (finalConfig.privateKey && finalConfig.localHostname && finalConfig.localUsername) authsAllowed.push('hostbased'); + finalConfig.authHandler = (methodsLeft, partialSuccess) => { + logging.debug`authHandler(${methodsLeft}, ${partialSuccess}) => ${authsAllowed[0] || false}`; + return authsAllowed.shift() || false; + }; // Unless the flag 'DF-GE' is specified, disable DiffieHellman groupex algorithms (issue #239) // Note: If the config already specifies a custom `algorithms.key`, ignore it (trust the user?) const [flagV, flagR] = getFlagBoolean('DF-GE', false, config.flags);