mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix: Fix issue with key based credentials not being read correctly (#6824)
This commit is contained in:
@@ -10,6 +10,8 @@ import type {
|
||||
} from 'n8n-workflow';
|
||||
import { BINARY_ENCODING, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { formatPrivateKey } from '@utils/utilities';
|
||||
|
||||
import { rm, writeFile } from 'fs/promises';
|
||||
|
||||
import { file as tmpFile } from 'tmp-promise';
|
||||
@@ -47,14 +49,6 @@ 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',
|
||||
@@ -304,15 +298,11 @@ export class Ssh implements INodeType {
|
||||
password: credentials.password as string,
|
||||
});
|
||||
} else {
|
||||
const { path } = await tmpFile({ prefix: 'n8n-ssh-' });
|
||||
temporaryFiles.push(path);
|
||||
await writeFile(path, sanitizePrivateKey(credentials.privateKey as string));
|
||||
|
||||
const options: Config = {
|
||||
host: credentials.host as string,
|
||||
username: credentials.username as string,
|
||||
port: credentials.port as number,
|
||||
privateKey: path,
|
||||
privateKey: formatPrivateKey(credentials.privateKey as string),
|
||||
};
|
||||
|
||||
if (credentials.passphrase) {
|
||||
@@ -364,16 +354,11 @@ export class Ssh implements INodeType {
|
||||
});
|
||||
} else if (authentication === 'privateKey') {
|
||||
const credentials = await this.getCredentials('sshPrivateKey');
|
||||
|
||||
const { path } = await tmpFile({ prefix: 'n8n-ssh-' });
|
||||
temporaryFiles.push(path);
|
||||
await writeFile(path, sanitizePrivateKey(credentials.privateKey as string));
|
||||
|
||||
const options: Config = {
|
||||
host: credentials.host as string,
|
||||
username: credentials.username as string,
|
||||
port: credentials.port as number,
|
||||
privateKey: path,
|
||||
privateKey: formatPrivateKey(credentials.privateKey as string),
|
||||
};
|
||||
|
||||
if (credentials.passphrase) {
|
||||
|
||||
Reference in New Issue
Block a user