From a2d94199895b0c179e6136568a0a7f03df377dcf Mon Sep 17 00:00:00 2001 From: NI Date: Sat, 14 Nov 2020 23:00:35 +0800 Subject: [PATCH] Allow Fingerprint to be defined in SSH Preset. Once defined, Sshwifty will use the fingerprint value to verify the public key fingerprint of the connecting SSH host --- README.md | 6 ++++++ sshwifty.conf.example.json | 3 ++- ui/commands/presets.js | 23 +++++++++++++++++++++-- ui/commands/ssh.js | 6 ++++-- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 32b0101..9cf7d8e 100644 --- a/README.md +++ b/README.md @@ -253,6 +253,12 @@ Here is all the options of a configuration file: // Data for predefined Authentication field. Valid values is what // displayed on the page (Password, Private Key, None) "Authentication": "Password", + + // Data for server public key fingerprint. You can acquire the value of + // the fingerprint by manually connect to a new SSH host with Sshwifty, + // the fingerprint will be displayed on the Fingerprint comformation + // page. + "Fingerprint": "SHA256:bgO...." } }, { diff --git a/sshwifty.conf.example.json b/sshwifty.conf.example.json index 815418f..c304932 100644 --- a/sshwifty.conf.example.json +++ b/sshwifty.conf.example.json @@ -37,7 +37,8 @@ "User": "root", "Encoding": "utf-8", "Private Key": "-----BEGIN RSA PRIV...\nMIIE...\n-----END RSA PRI...\n", - "Authentication": "Private Key" + "Authentication": "Private Key", + "Fingerprint": "SHA256:bgO...." } }, { diff --git a/ui/commands/presets.js b/ui/commands/presets.js index 9a66751..c95d2aa 100644 --- a/ui/commands/presets.js +++ b/ui/commands/presets.js @@ -25,7 +25,7 @@ const presetItem = { title: "", type: "", host: "", - meta: {} + meta: {}, }; /** @@ -153,6 +153,25 @@ export class Preset { return this.preset.meta[name]; } + /** + * Return the given meta of current preset, and if failed, return the given + * default value + * + * @param {string} name name of the meta data + * @param {string} defaultValue default value to be returned when the meta was + * not found + * + * @returns {string} + * + */ + metaDefault(name, defaultValue) { + try { + return this.meta(name); + } catch (e) { + return defaultValue; + } + } + /** * Insert new meta item * @@ -182,7 +201,7 @@ export function emptyPreset() { title: "Default", type: "Default", host: "", - meta: {} + meta: {}, }); } diff --git a/ui/commands/ssh.js b/ui/commands/ssh.js index 21395d6..d566a49 100644 --- a/ui/commands/ssh.js +++ b/ui/commands/ssh.js @@ -732,7 +732,9 @@ class Wizard { authentication: r.authentication, host: r.host, charset: r.encoding, - fingerprint: "", + fingerprint: self.preset + ? self.preset.metaDefault("Fingerprint", "") + : "", }, self.session ); @@ -855,7 +857,7 @@ class Wizard { default: throw new Exception( - "Prompt is not support by auth method: " + config.auth + 'Auth method "' + config.auth + '" was unsupported' ); }