diff options
author | Kenneth Skovhede <kenneth@hexad.dk> | 2017-11-19 19:28:51 +0300 |
---|---|---|
committer | Kenneth Skovhede <kenneth@hexad.dk> | 2017-11-19 19:28:51 +0300 |
commit | 6cc70c7ae538715cd1bb84d2ee51f243220e9952 (patch) | |
tree | 95282067983c18ace73eddf7da7a3fdae3e51d3f /Duplicati/Library/Backend/SSHv2 | |
parent | c8865b6c3086d471830becd3312dde29db3bd8bb (diff) |
Added a friendly error message if the SSH key fails to parse/load.
This fixes #2856
Diffstat (limited to 'Duplicati/Library/Backend/SSHv2')
-rw-r--r-- | Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs | 37 |
1 files changed, 22 insertions, 15 deletions
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);
}
}
|