From 6cc70c7ae538715cd1bb84d2ee51f243220e9952 Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Sun, 19 Nov 2017 17:28:51 +0100 Subject: Added a friendly error message if the SSH key fails to parse/load. This fixes #2856 --- Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs | 37 +++++++++++++++---------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'Duplicati/Library/Backend/SSHv2') diff --git a/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs b/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs index 1131c521f..415fcd6fe 100644 --- a/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs +++ b/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs @@ -327,28 +327,35 @@ namespace Duplicati.Library.Backend public static Renci.SshNet.PrivateKeyFile ValidateKeyFile(string filename, string password) { - if (filename.StartsWith(KEYFILE_URI, StringComparison.OrdinalIgnoreCase)) + try { - using (var ms = new System.IO.MemoryStream()) - using (var sr = new System.IO.StreamWriter(ms)) + if (filename.StartsWith(KEYFILE_URI, StringComparison.OrdinalIgnoreCase)) + { + using (var ms = new System.IO.MemoryStream()) + using (var sr = new System.IO.StreamWriter(ms)) + { + sr.Write(Duplicati.Library.Utility.Uri.UrlDecode(filename.Substring(KEYFILE_URI.Length))); + sr.Flush(); + + ms.Position = 0; + + if (String.IsNullOrEmpty(password)) + return new Renci.SshNet.PrivateKeyFile(ms); + else + return new Renci.SshNet.PrivateKeyFile(ms, password); + } + } + else { - sr.Write(Duplicati.Library.Utility.Uri.UrlDecode(filename.Substring(KEYFILE_URI.Length))); - sr.Flush(); - - ms.Position = 0; - if (String.IsNullOrEmpty(password)) - return new Renci.SshNet.PrivateKeyFile(ms); + return new Renci.SshNet.PrivateKeyFile(filename); else - return new Renci.SshNet.PrivateKeyFile(ms, password); + return new Renci.SshNet.PrivateKeyFile(filename, password); } } - else + catch (Exception ex) { - if (String.IsNullOrEmpty(password)) - return new Renci.SshNet.PrivateKeyFile(filename); - else - return new Renci.SshNet.PrivateKeyFile(filename, password); + throw new UserInformationException(string.Format("Failed to parse the keyfile, check the key format and passphrase. Error message was {0}", ex.Message), ex); } } -- cgit v1.2.3