Skip to content

Commit

Permalink
fix(SSH Node): Private key field as password and credential test (#6298)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency committed May 23, 2023
1 parent bbe6d4c commit d5c7e6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class SshPrivateKey implements ICredentialType {
type: 'string',
typeOptions: {
rows: 4,
password: true,
},
default: '',
},
Expand Down
13 changes: 11 additions & 2 deletions packages/nodes-base/nodes/Ssh/Ssh.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ async function resolveHomeDir(
return path;
}

function sanitizePrivateKey(privateKey: string) {
const [openSshKey, bodySshKey, endSshKey] = privateKey
.split('-----')
.filter((item) => item !== '');

return `-----${openSshKey}-----\n${bodySshKey.replace(/ /g, '\n')}\n-----${endSshKey}-----`;
}

export class Ssh implements INodeType {
description: INodeTypeDescription = {
displayName: 'SSH',
Expand Down Expand Up @@ -76,6 +84,7 @@ export class Ssh implements INodeType {
{
name: 'sshPrivateKey',
required: true,
testedBy: 'sshConnectionTest',
displayOptions: {
show: {
authentication: ['privateKey'],
Expand Down Expand Up @@ -297,7 +306,7 @@ export class Ssh implements INodeType {
} else {
const { path } = await tmpFile({ prefix: 'n8n-ssh-' });
temporaryFiles.push(path);
await writeFile(path, credentials.privateKey as string);
await writeFile(path, sanitizePrivateKey(credentials.privateKey as string));

const options: Config = {
host: credentials.host as string,
Expand Down Expand Up @@ -358,7 +367,7 @@ export class Ssh implements INodeType {

const { path } = await tmpFile({ prefix: 'n8n-ssh-' });
temporaryFiles.push(path);
await writeFile(path, credentials.privateKey as string);
await writeFile(path, sanitizePrivateKey(credentials.privateKey as string));

const options: Config = {
host: credentials.host as string,
Expand Down

0 comments on commit d5c7e6f

Please sign in to comment.