From db3bd20f9309d6991b28e96b05279332d8369cfb Mon Sep 17 00:00:00 2001 From: Marcel Kloubert Date: Mon, 21 Aug 2017 19:53:02 +0200 Subject: [PATCH] added 'privateKeySourceFormat' and 'privateKeyTargetFormat' settings for SFTP --- CHANGELOG.md | 4 ++++ package-lock.json | 11 ++++++++++- package.json | 19 +++++++++++++++++-- src/plugins/sftp.ts | 32 +++++++++++++++++++++++++++----- 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 937fc5d..d9bd21f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log (vs-deploy) +## 9.32.0 (August 21st, 2017; SFTP private key format) + +* added `privateKeySourceFormat` and `privateKeyTargetFormat` settings for [SFTP](https://github.com/mkloubert/vs-deploy/wiki/target_sftp) targets, that can define the input and output format of a private key + ## 9.31.0 (August 21st, 2017; prompt target) * added `handleAs` property for entries in a [prompt target](https://github.com/mkloubert/vs-deploy/wiki/target_prompt), which can define in what data type to convert the user's input to diff --git a/package-lock.json b/package-lock.json index 9338df5..c204953 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "vs-deploy", - "version": "9.30.0", + "version": "9.31.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -140,6 +140,15 @@ "@types/node": "6.0.79" } }, + "@types/sshpk": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/@types/sshpk/-/sshpk-1.10.3.tgz", + "integrity": "sha1-JlstE/lSJeIKv/oXcZ/Kl1bI5Wo=", + "dev": true, + "requires": { + "@types/node": "6.0.79" + } + }, "@types/tmp": { "version": "0.0.32", "resolved": "https://registry.npmjs.org/@types/tmp/-/tmp-0.0.32.tgz", diff --git a/package.json b/package.json index 3f814a5..f95ac5f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vs-deploy", "displayName": "Deploy", "description": "Commands for deploying files of your workspace to a destination.", - "version": "9.31.0", + "version": "9.32.0", "publisher": "mkloubert", "engines": { "vscode": "^1.6.0" @@ -19854,7 +19854,12 @@ "handleAs": { "description": "The type to convert the user's input to.", "type": "string", - "enum": [ "", "list", "object", "string" ], + "enum": [ + "", + "list", + "object", + "string" + ], "default": "string" }, "isPassword": { @@ -24321,6 +24326,14 @@ "description": "The path to the private key file, if authentification should be done via SSH key.", "default": "./my-private-file.key" }, + "privateKeySourceFormat": { + "type": "string", + "description": "The source format of the private key." + }, + "privateKeyTargetFormat": { + "type": "string", + "description": "The custom target format of the private key." + }, "privateKeyPassphrase": { "type": "string", "description": "The passphrase for the key file, if needed." @@ -31981,6 +31994,7 @@ "@types/mocha": "^2.2.32", "@types/node": "^6.0.40", "@types/ssh2-sftp-client": "^1.0.5", + "@types/sshpk": "^1.10.3", "@types/tmp": "0.0.32", "@types/uuid": "^2.0.29", "mocha": "^2.3.3", @@ -32028,6 +32042,7 @@ "parse-listing": "^1.1.3", "pug": "^2.0.0-rc.1", "ssh2-sftp-client": "^1.0.5", + "sshpk": "^1.13.1", "tmp": "0.0.31", "typescript": "^2.3.2", "uglify-js": "^2.8.23", diff --git a/src/plugins/sftp.ts b/src/plugins/sftp.ts index a55de7a..ff1cda6 100644 --- a/src/plugins/sftp.ts +++ b/src/plugins/sftp.ts @@ -32,6 +32,7 @@ import * as i18 from '../i18'; import * as Moment from 'moment'; import * as Path from 'path'; const SFTP = require('ssh2-sftp-client'); +import * as sshpk from 'sshpk'; import * as TMP from 'tmp'; import * as vscode from 'vscode'; import * as Workflows from 'node-workflows'; @@ -62,6 +63,8 @@ interface DeployTargetSFTP extends deploy_contracts.TransformableDeployTarget, d closing?: SSHCommands; updateModesOfDirectories?: boolean; noCommandOutput?: boolean; + privateKeySourceFormat?: string; + privateKeyTargetFormat?: string; } interface FileToUpload { @@ -630,11 +633,30 @@ class SFtpPlugin extends deploy_objects.DeployPluginWithContextBase return; } - privateKey = data; - askForPasswordIfNeeded(false, - () => privateKeyPassphrase, - (pwdToSet) => privateKeyPassphrase = pwdToSet, - 'privateKeyPassphrase'); + try { + let privateKeySourceFormat = me.context.replaceWithValues(target.privateKeySourceFormat); + privateKeySourceFormat = privateKeySourceFormat.trim(); + + if ('' !== privateKeySourceFormat) { + let privateKeyTargetFormat = me.context.replaceWithValues(target.privateKeyTargetFormat); + privateKeyTargetFormat = privateKeyTargetFormat.trim(); + if ('' === privateKeyTargetFormat) { + privateKeyTargetFormat = 'ssh'; + } + + data = sshpk.parseKey(data, privateKeySourceFormat) + .toBuffer(privateKeyTargetFormat); + } + + privateKey = data; + askForPasswordIfNeeded(false, + () => privateKeyPassphrase, + (pwdToSet) => privateKeyPassphrase = pwdToSet, + 'privateKeyPassphrase'); + } + catch (e) { + completed(e); + } }); } }