feat: let kitty support a ppk with non-ascii path. close #719

pull/758/head
Shawn 4 months ago
parent 727f99eec3
commit a288e59120

@ -0,0 +1,6 @@
# All files
[*]
indent_style = space
[*.csproj]
indent_size = 4

@ -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

@ -1 +1 @@
Subproject commit 2b50f4344742cb9ab4ad2215a066581b0010e88f
Subproject commit 8d9326a12e70c3bad981e1e890104ba02ce7ccfa

@ -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);
}
/// <summary>
/// return true if private key is all ascii
/// </summary>
public bool IsPrivateKeyAllAscii()
{
return PrivateKey.All(c => c < 128);
}
protected override string GetSubTitle()
{
return string.IsNullOrEmpty(UserName) ? base.GetSubTitle() : $"{Address}:{Port} ({UserName})";

@ -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;
}

@ -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, "");
}

Loading…
Cancel
Save