diff --git a/.editorConfig b/.editorConfig new file mode 100644 index 00000000..6ce0baa4 --- /dev/null +++ b/.editorConfig @@ -0,0 +1,6 @@ +# All files +[*] +indent_style = space + +[*.csproj] +indent_size = 4 \ No newline at end of file diff --git a/1Remote.sln b/1Remote.sln index cd938058..5ddd0ea5 100644 --- a/1Remote.sln +++ b/1Remote.sln @@ -7,6 +7,7 @@ Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "Installer", "Installer\Inst EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9CF15528-C588-43AA-9578-B9B669EF9667}" ProjectSection(SolutionItems) = preProject + .editorConfig = .editorConfig LICENSE = LICENSE readme.md = readme.md EndProjectSection diff --git a/Shawn.Utils b/Shawn.Utils index 2b50f434..8d9326a1 160000 --- a/Shawn.Utils +++ b/Shawn.Utils @@ -1 +1 @@ -Subproject commit 2b50f4344742cb9ab4ad2215a066581b0010e88f +Subproject commit 8d9326a12e70c3bad981e1e890104ba02ce7ccfa diff --git a/Ui/Model/Protocol/Base/ProtocolBaseWithAddressPortUserPwd.cs b/Ui/Model/Protocol/Base/ProtocolBaseWithAddressPortUserPwd.cs index f1cbff7e..21c1a239 100644 --- a/Ui/Model/Protocol/Base/ProtocolBaseWithAddressPortUserPwd.cs +++ b/Ui/Model/Protocol/Base/ProtocolBaseWithAddressPortUserPwd.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.Linq; using Shawn.Utils; namespace _1RM.Model.Protocol.Base @@ -60,6 +61,14 @@ namespace _1RM.Model.Protocol.Base set => SetAndNotifyIfChanged(ref _privateKey, value); } + /// + /// return true if private key is all ascii + /// + public bool IsPrivateKeyAllAscii() + { + return PrivateKey.All(c => c < 128); + } + protected override string GetSubTitle() { return string.IsNullOrEmpty(UserName) ? base.GetSubTitle() : $"{Address}:{Port} ({UserName})"; diff --git a/Ui/Model/ProtocolRunner/RunnerHelper.cs b/Ui/Model/ProtocolRunner/RunnerHelper.cs index 46d6142c..ed20e3fb 100644 --- a/Ui/Model/ProtocolRunner/RunnerHelper.cs +++ b/Ui/Model/ProtocolRunner/RunnerHelper.cs @@ -1,7 +1,10 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using _1RM.Model.Protocol; using _1RM.Model.Protocol.Base; using _1RM.Model.ProtocolRunner.Default; @@ -95,6 +98,28 @@ namespace _1RM.Model.ProtocolRunner { case SSH ssh when string.IsNullOrEmpty(ssh.PrivateKey) == false: case SFTP sftp when string.IsNullOrEmpty(sftp.PrivateKey) == false: + var pw = protocol as ProtocolBaseWithAddressPortUserPwd; + // if private key is not all ascii, copy it to temp file + if (pw?.IsPrivateKeyAllAscii() == false && File.Exists(pw.PrivateKey)) + { + var pk = Path.Combine(Path.GetTempPath(), new FileInfo(pw.PrivateKey).Name); + File.Copy(pw.PrivateKey, pk, true); + var autoDelTask = new Task(() => + { + Thread.Sleep(30 * 1000); + try + { + if (File.Exists(pk)) + File.Delete(pk); + } + catch + { + // ignored + } + }); + autoDelTask.Start(); + pw.PrivateKey = pk; + } exeArguments = runnerForSsh.ArgumentsForPrivateKey; break; } diff --git a/Ui/View/Host/ProtocolHosts/IntegrateHost.xaml.cs b/Ui/View/Host/ProtocolHosts/IntegrateHost.xaml.cs index e10753d5..34075569 100644 --- a/Ui/View/Host/ProtocolHosts/IntegrateHost.xaml.cs +++ b/Ui/View/Host/ProtocolHosts/IntegrateHost.xaml.cs @@ -380,8 +380,31 @@ namespace _1RM.View.Host.ProtocolHosts { // KITTY 需要根据 _sessionName 配置 cli 命令参数,所以在 start 时重新计算 cli 参数。 ExeArguments = kittyConnectable.GetExeArguments(_sessionName); - if (ProtocolServer is ProtocolBaseWithAddressPortUserPwd { UsePrivateKeyForConnect: true } pw) - kittyConnectable.ConfigKitty(_sessionName, kittyRunner, pw.PrivateKey); + if (ProtocolServer is ProtocolBaseWithAddressPortUserPwd { UsePrivateKeyForConnect: true } pw && string.IsNullOrEmpty(pw.PrivateKey) == false) + { + var pk = pw.PrivateKey; + // if private key is not all ascii, copy it to temp file + if (pw.IsPrivateKeyAllAscii() == false && File.Exists(pw.PrivateKey)) + { + pk = Path.Combine(Path.GetTempPath(), new FileInfo(pw.PrivateKey).Name); + File.Copy(pw.PrivateKey, pk, true); + var autoDelTask = new Task(() => + { + Thread.Sleep(30 * 1000); + try + { + if (File.Exists(pk)) + File.Delete(pk); + } + catch + { + // ignored + } + }); + autoDelTask.Start(); + } + kittyConnectable.ConfigKitty(_sessionName, kittyRunner, pk); + } else kittyConnectable.ConfigKitty(_sessionName, kittyRunner, ""); }