Browse Source

Bug 2053: Support importing key files that are specified using home ~ prefix from OpenSSH config file

https://winscp.net/tracker/2053
(cherry picked from commit fe656b828c9720c304f236a1af3a8a039fc46305)

Source commit: 3ead5ac8367798c393a64bbefc8f69dc2c4af42d
Martin Prikryl 3 years ago
parent
commit
e31d69dc93
1 changed files with 9 additions and 1 deletions
  1. 9 1
      source/core/SessionData.cpp

+ 9 - 1
source/core/SessionData.cpp

@@ -1680,7 +1680,15 @@ void TSessionData::ImportFromOpenssh(TStrings * Lines)
         {
           // It's likely there would be forward slashes in OpenSSH config file and our load/save dialogs
           // (e.g. when converting keys) work suboptimally when working with forward slashes.
-          PublicKeyFile = GetNormalizedPath(Value);
+          UnicodeString Path = GetNormalizedPath(Value);
+          const UnicodeString HomePathPrefix = L"~";
+          if (StartsStr(HomePathPrefix, Path + L"\\"))
+          {
+            Path =
+              GetShellFolderPath(CSIDL_PROFILE) +
+              Path.SubString(HomePathPrefix.Length() + 1, Path.Length() - HomePathPrefix.Length());
+          }
+          PublicKeyFile = Path;
         }
         else if (SameText(Directive, L"KbdInteractiveAuthentication"))
         {