Skip to content

Commit df48720

Browse files
committed
Reverted RsaSha256 workaround as per SSH.NET v2023 upgrade (sshnet/SSH.NET#825 (comment))
1 parent ff68f67 commit df48720

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

src/VsLinuxDebugger/Core/Security/RsaSha256DigitalSignature.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace VsLinuxDebugger.Core.Security
88
{
9+
/*
910
/// <summary>
1011
/// Based on https://github.com/sshnet/SSH.NET/blob/1d5d58e17c68a2f319c51e7f938ce6e964498bcc/src/Renci.SshNet/Security/Cryptography/RsaDigitalSignature.cs#L12
1112
///
@@ -62,4 +63,5 @@ protected override byte[] Hash(byte[] input)
6263
return _hash.ComputeHash(input);
6364
}
6465
}
66+
*/
6567
}

src/VsLinuxDebugger/Core/Security/RsaSha256Util.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Reflection;
34
using System.Security.Cryptography;
45
using Renci.SshNet;
@@ -14,6 +15,7 @@ namespace VsLinuxDebugger.Core.Security
1415
/// </summary>
1516
public static class RsaSha256Util
1617
{
18+
/*
1719
/// <summary>RSA SHA2 256.</summary>
1820
public const string RSA_SHA2_256 = "rsa-sha2-256";
1921
@@ -26,12 +28,14 @@ public static class RsaSha256Util
2628
/// <exception cref="ArgumentNullException">Argument Null Exception.</exception>
2729
public static void ConvertToKeyWithSha256Signature(PrivateKeyFile keyFile)
2830
{
29-
var oldKeyHostAlgorithm = keyFile.HostKey as KeyHostAlgorithm;
31+
//// var oldKeyHostAlgorithm = keyFile.HostKey as KeyHostAlgorithm;
32+
var oldKeyHostAlgorithm = keyFile.HostKeyAlgorithms.First();
3033
if (oldKeyHostAlgorithm == null)
3134
{
3235
throw new ArgumentNullException(nameof(oldKeyHostAlgorithm));
3336
}
3437
38+
//// var x = new KeyHostAlgorithm("name", key: null, digitalSignature: new RsaDigitalSignature(null));
3539
var oldRsaKey = oldKeyHostAlgorithm.Key as RsaKey;
3640
if (oldRsaKey == null)
3741
{
@@ -59,5 +63,6 @@ private static void UpdatePrivateKeyFile(PrivateKeyFile keyFile, RsaWithSha256Si
5963
var keyField = typeof(PrivateKeyFile).GetField("_key", BindingFlags.NonPublic | BindingFlags.Instance);
6064
keyField.SetValue(keyFile, key);
6165
}
66+
*/
6267
}
6368
}

src/VsLinuxDebugger/Core/Security/RsaWithSha256SignatureKey.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace VsLinuxDebugger.Core.Security
66
{
7+
/*
78
/// <summary>RSA With SHA256 Signature Key.</summary>
89
public class RsaWithSha256SignatureKey : RsaKey
910
{
@@ -28,4 +29,5 @@ public override string ToString()
2829
return RsaSha256Util.RSA_SHA2_256;
2930
}
3031
}
32+
*/
3133
}

src/VsLinuxDebugger/Core/SshTool.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
using System.IO;
55
using System.Text.RegularExpressions;
66
using System.Threading.Tasks;
7+
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
78
using Renci.SshNet;
89
using Renci.SshNet.Common;
10+
using Renci.SshNet.Security;
911
using SharpCompress.Common;
1012
using SharpCompress.Writers;
1113
using VsLinuxDebugger.Core.Security;
@@ -157,7 +159,7 @@ public async Task CleanFolderAsync(string path)
157159
public async Task<bool> ConnectAsync()
158160
{
159161
PrivateKeyFile keyFile = null;
160-
ConnectionInfo conn = null;
162+
ConnectionInfo connInfo = null;
161163
try
162164
{
163165
if (_info.PrivateKeyEnabled)
@@ -169,12 +171,13 @@ public async Task<bool> ConnectAsync()
169171
else
170172
keyFile = new PrivateKeyFile(_info.PrivateKeyPath, _info.PrivateKeyPassword);
171173

174+
/**
172175
// adds rsa-sha2-256
173176
RsaSha256Util.ConvertToKeyWithSha256Signature(keyFile);
174177
var authenticationMethodRsa = new PrivateKeyAuthenticationMethod(_info.UserName, keyFile);
175-
conn = new ConnectionInfo(_info.Host, _info.Port, _info.UserName, authenticationMethodRsa);
176-
RsaSha256Util.SetupConnection(conn);
177-
178+
connInfo = new ConnectionInfo(_info.Host, _info.Port, _info.UserName, authenticationMethodRsa);
179+
RsaSha256Util.SetupConnection(connInfo);
180+
*/
178181
}
179182
}
180183
catch (Exception ex)
@@ -187,10 +190,9 @@ public async Task<bool> ConnectAsync()
187190
try
188191
{
189192
Logger.Output($"SSH connecting...");
190-
if (_info.PrivateKeyEnabled && File.Exists(_info.PrivateKeyPath))
191-
_ssh = new SshClient(conn);
192-
else
193-
_ssh = new SshClient(_info.Host, _info.Port, _info.UserName, _info.UserPass);
193+
_ssh = (_info.PrivateKeyEnabled && File.Exists(_info.PrivateKeyPath))
194+
? new SshClient(_info.Host, _info.Port, _info.UserName, keyFile)
195+
: new SshClient(_info.Host, _info.Port, _info.UserName, _info.UserPass);
194196

195197
await Task.Run(() => _ssh.Connect());
196198
}
@@ -202,20 +204,18 @@ public async Task<bool> ConnectAsync()
202204

203205
try
204206
{
205-
if (_info.PrivateKeyEnabled && File.Exists(_info.PrivateKeyPath))
206-
_sftp = new SftpClient(conn);
207-
else
208-
_sftp = new SftpClient(_info.Host, _info.Port, _info.UserName, _info.UserPass);
207+
_sftp = (_info.PrivateKeyEnabled && File.Exists(_info.PrivateKeyPath))
208+
? new SftpClient(connInfo)
209+
: new SftpClient(_info.Host, _info.Port, _info.UserName, _info.UserPass);
209210

210211
_sftp.Connect();
211212

212213
}
213214
catch (Exception)
214215
{
215-
if (_info.PrivateKeyEnabled && File.Exists(_info.PrivateKeyPath))
216-
_scp = new ScpClient(conn);
217-
else
218-
_scp = new ScpClient(_info.Host, _info.Port, _info.UserName, _info.UserPass);
216+
_scp = (_info.PrivateKeyEnabled && File.Exists(_info.PrivateKeyPath))
217+
? new ScpClient(connInfo)
218+
: new ScpClient(_info.Host, _info.Port, _info.UserName, _info.UserPass);
219219

220220
_scp.Connect();
221221
}

src/VsLinuxDebugger/VsLinuxDebugger.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
<Version>0.30.1</Version>
105105
</PackageReference>
106106
<PackageReference Include="SSH.NET">
107-
<Version>2020.0.2</Version>
107+
<Version>2023.0.1</Version>
108108
</PackageReference>
109109
<PackageReference Include="System.Text.Json">
110110
<Version>6.0.2</Version>

0 commit comments

Comments
 (0)