Skip to content

Commit

Permalink
Add temporary fix for issue #239 (flag "DF-GE")
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoofsKelvin committed Feb 11, 2021
1 parent 83d6cd0 commit 598ae06
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Socket } from 'net';
import { Client, ClientChannel, ConnectConfig, SFTPWrapper as SFTPWrapperReal } from 'ssh2';
import { SFTPStream } from 'ssh2-streams';
import * as vscode from 'vscode';
import { getConfig } from './config';
import { getConfig, getFlag } from './config';
import type { FileSystemConfig } from './fileSystemConfig';
import { censorConfig, Logging } from './logging';
import { toPromise } from './toPromise';
Expand Down Expand Up @@ -234,13 +234,21 @@ export async function createSSH(config: FileSystemConfig, sock?: NodeJS.Readable
reject(error);
});
try {
logging.info(`Creating SSH session over the opened socket`);
let debug = (_msg: string) => { };
const finalConfig: ConnectConfig = { ...config, sock, ...DEFAULT_CONFIG };
if (config.debug) {
const scope = Logging.scope(`ssh2(${config.name})`);
debug = (msg: string) => scope.debug(msg);
finalConfig.debug = (msg: string) => scope.debug(msg);
}
client.connect(Object.assign<ConnectConfig, ConnectConfig, ConnectConfig>(config, { sock, debug }, DEFAULT_CONFIG));
// 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?)
if (getFlag('DF-GE') === undefined && !finalConfig.algorithms?.kex) {
logging.info('Flag "DiffieHellman" specified, disabling DiffieHellman kex groupex algorithms');
let kex: string[] = require('ssh2-streams/lib/constants').ALGORITHMS.KEX;
kex = kex.filter(algo => !algo.includes('diffie-hellman-group-exchange'));
logging.debug(`\tResulting algorithms.kex: ${kex}`);
finalConfig.algorithms = { ...finalConfig.algorithms, kex };
}
client.connect(finalConfig);
} catch (e) {
reject(e);
}
Expand Down

0 comments on commit 598ae06

Please sign in to comment.