Browse Source

Merge pull request #250 from kmlucy/master

Add support for host checking
pull/259/head
Cian Butler 5 years ago
committed by GitHub
parent
commit
27ea8734e0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      index.js
  2. 1
      src/server/cli/options.ts
  3. 1
      src/server/cli/parseArgs.ts
  4. 3
      src/server/command/index.ts
  5. 7
      src/server/command/ssh.ts
  6. 1
      src/server/interfaces.ts

6
index.js

@ -73,6 +73,12 @@ if (require.main === module) {
type: 'boolean', type: 'boolean',
default: process.env.FORCESSH || false default: process.env.FORCESSH || false
}, },
knownhosts: {
demand: false,
description: 'path to known hosts file',
type: 'string',
default: process.env.KNOWNHOSTS || '/dev/null',
},
base: { base: {
demand: false, demand: false,
alias: 'b', alias: 'b',

1
src/server/cli/options.ts

@ -5,6 +5,7 @@ export interface Options {
sshauth: string; sshauth: string;
sshkey?: string; sshkey?: string;
sshpass?: string; sshpass?: string;
knownhosts: string;
sslkey?: string; sslkey?: string;
sslcert?: string; sslcert?: string;
base: string; base: string;

1
src/server/cli/parseArgs.ts

@ -13,6 +13,7 @@ export function unWrapArgs(
port: args.sshport, port: args.sshport,
pass: args.sshpass, pass: args.sshpass,
key: args.sshkey, key: args.sshkey,
knownhosts: args.knownhosts,
}, },
server: { server: {
base: args.base, base: args.base,

3
src/server/command/index.ts

@ -24,7 +24,7 @@ export default (
conn: { remoteAddress }, conn: { remoteAddress },
}, },
}: Socket, }: Socket,
{ user, host, port, auth, pass, key }: SSH, { user, host, port, auth, pass, key, knownhosts }: SSH,
command: string, command: string,
forcessh: boolean forcessh: boolean
): { args: string[]; user: boolean } => ({ ): { args: string[]; user: boolean } => ({
@ -37,6 +37,7 @@ export default (
pass: pass || '', pass: pass || '',
command, command,
auth, auth,
knownhosts,
}), }),
key key
), ),

7
src/server/command/ssh.ts

@ -3,10 +3,11 @@ import parseCommand from './parse';
import logger from '../utils/logger'; import logger from '../utils/logger';
export default function sshOptions( export default function sshOptions(
{ pass, path, command, host, port, auth }: { [s: string]: string }, { pass, path, command, host, port, auth, knownhosts }: { [s: string]: string },
key?: string key?: string
): string[] { ): string[] {
const cmd = parseCommand(command, path); const cmd = parseCommand(command, path);
const hostChecking = (knownhosts !== '/dev/null') ? 'yes' : 'no'
const sshRemoteOptsBase = [ const sshRemoteOptsBase = [
'ssh', 'ssh',
host, host,
@ -16,9 +17,9 @@ export default function sshOptions(
'-o', '-o',
`PreferredAuthentications=${auth}`, `PreferredAuthentications=${auth}`,
'-o', '-o',
'UserKnownHostsFile=/dev/null', `UserKnownHostsFile=${knownhosts}`,
'-o', '-o',
'StrictHostKeyChecking=no', `StrictHostKeyChecking=${hostChecking}`,
]; ];
logger.info(`Authentication Type: ${auth}`); logger.info(`Authentication Type: ${auth}`);
if (!isUndefined(key)) { if (!isUndefined(key)) {

1
src/server/interfaces.ts

@ -3,6 +3,7 @@ export interface SSH {
host: string; host: string;
auth: string; auth: string;
port: number; port: number;
knownhosts: string;
pass?: string; pass?: string;
key?: string; key?: string;
} }

Loading…
Cancel
Save