Skip to content

Commit

Permalink
Update SSH.NET
Browse files Browse the repository at this point in the history
  • Loading branch information
darinkes committed Mar 9, 2024
1 parent d8002c4 commit 87e8f4b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 98 deletions.
68 changes: 0 additions & 68 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ SshNet.Keygen
[![NuGet](https://img.shields.io/nuget/v/SshNet.Keygen.svg?style=flat)](https://www.nuget.org/packages/SshNet.Keygen)
![Nuget](https://img.shields.io/nuget/dt/SshNet.Keygen)

![CodeQL](https://github.com/darinkes/SshNet.Keygen/workflows/CodeQL/badge.svg)
![.NET-Ubuntu](https://github.com/darinkes/SshNet.Keygen/workflows/.NET-Ubuntu/badge.svg)
![.NET-Windows](https://github.com/darinkes/SshNet.Keygen/workflows/.NET-Windows/badge.svg)
![NuGet](https://github.com/darinkes/SshNet.Keygen/workflows/NuGet/badge.svg)
Expand Down
2 changes: 1 addition & 1 deletion SshNet.Keygen.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static void Main(string[] args)
Console.WriteLine("Add this to your .ssh/authorized_keys of the SSH Server: {0}", publicKey);
Console.ReadLine();

using var client = new SshClient("ssh.foo.com", "root", key);
using var client = new SshClient("localhost", Environment.GetEnvironmentVariable("USER") ?? Environment.GetEnvironmentVariable("USERNAME"), key);
client.Connect();
Console.WriteLine(client.RunCommand("hostname").Result);
}
Expand Down
6 changes: 3 additions & 3 deletions SshNet.Keygen.Tests/SshNet.Keygen.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
</ItemGroup>

<ItemGroup>
Expand Down
35 changes: 18 additions & 17 deletions SshNet.Keygen.Tests/TestKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Security.Cryptography;
using System.Text;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using Renci.SshNet;
using Renci.SshNet.Security;
using SshNet.Keygen.Extensions;
Expand Down Expand Up @@ -33,8 +34,8 @@ public void TestExceptions()
public void TestDefaultKey()
{
var key = SshKey.Generate();
Assert.IsInstanceOf<RsaKey>(((KeyHostAlgorithm)key.HostKeyAlgorithms.First()).Key);
Assert.AreEqual(2048, ((KeyHostAlgorithm)key.HostKeyAlgorithms.First()).Key.KeyLength);
ClassicAssert.IsInstanceOf<RsaKey>(((KeyHostAlgorithm)key.HostKeyAlgorithms.First()).Key);
ClassicAssert.AreEqual(2048, ((KeyHostAlgorithm)key.HostKeyAlgorithms.First()).Key.KeyLength);
}

private static void KeyGenTest<TKey>(SshKeyType keyType, int keyLength = 0)
Expand Down Expand Up @@ -80,13 +81,13 @@ private static void KeyGenTest<TKey>(SshKeyType keyType, int keyLength = 0)
{
keyFile = SshKey.Generate(keyInfo);
if (keyLength != 0)
Assert.AreEqual(keyLength, ((KeyHostAlgorithm)keyFile.HostKeyAlgorithms.First()).Key.KeyLength);
ClassicAssert.AreEqual(keyLength, ((KeyHostAlgorithm)keyFile.HostKeyAlgorithms.First()).Key.KeyLength);
}
else
{
_ = SshKey.Generate(path, FileMode.Create, keyInfo);
keyFile = new PrivateKeyFile(path, password);
Assert.IsTrue(File.Exists(path));
ClassicAssert.IsTrue(File.Exists(path));

switch (sshKeyEncryption.CipherName)
{
Expand All @@ -96,16 +97,16 @@ private static void KeyGenTest<TKey>(SshKeyType keyType, int keyLength = 0)
default:
File.Delete($"{path}.ppk");
_ = SshKey.Generate($"{path}.ppk", FileMode.Create, puttyKeyInfo);
Assert.IsTrue(File.Exists($"{path}.ppk"));
ClassicAssert.IsTrue(File.Exists($"{path}.ppk"));
break;
}
}

Assert.IsInstanceOf<TKey>(((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key);
ClassicAssert.IsInstanceOf<TKey>(((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key);
if (keyLength != 0)
Assert.AreEqual(keyLength, (((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key.KeyLength));
ClassicAssert.AreEqual(keyLength, (((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key.KeyLength));

Assert.AreEqual(
ClassicAssert.AreEqual(
string.IsNullOrEmpty(comment)
? $"{Environment.UserName}@{Environment.MachineName}"
: comment,
Expand Down Expand Up @@ -187,15 +188,15 @@ private void TestFormatKey<T>(string keyname, int keyLength, string passphrase =

var key = ((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key;

Assert.IsInstanceOf<T>(key);
Assert.AreEqual(keyLength, key.KeyLength);
Assert.AreEqual(pubkeydata.Trim(), keyFile.ToPublic().Trim());
Assert.AreEqual(fpSha256Data.Trim(), keyFile.Fingerprint().Trim());
Assert.AreEqual(fpMd5Data.Trim(), keyFile.Fingerprint(SshKeyHashAlgorithmName.MD5).Trim());
Assert.AreEqual(fpSha1Data.Trim(), keyFile.Fingerprint(SshKeyHashAlgorithmName.SHA1).Trim());
Assert.AreEqual(fpSha256Data.Trim(), keyFile.Fingerprint(SshKeyHashAlgorithmName.SHA256).Trim());
Assert.AreEqual(fpSha384Data.Trim(), keyFile.Fingerprint(SshKeyHashAlgorithmName.SHA384).Trim());
Assert.AreEqual(fpSha512Data.Trim(), keyFile.Fingerprint(SshKeyHashAlgorithmName.SHA512).Trim());
ClassicAssert.IsInstanceOf<T>(key);
ClassicAssert.AreEqual(keyLength, key.KeyLength);
ClassicAssert.AreEqual(pubkeydata.Trim(), keyFile.ToPublic().Trim());
ClassicAssert.AreEqual(fpSha256Data.Trim(), keyFile.Fingerprint().Trim());
ClassicAssert.AreEqual(fpMd5Data.Trim(), keyFile.Fingerprint(SshKeyHashAlgorithmName.MD5).Trim());
ClassicAssert.AreEqual(fpSha1Data.Trim(), keyFile.Fingerprint(SshKeyHashAlgorithmName.SHA1).Trim());
ClassicAssert.AreEqual(fpSha256Data.Trim(), keyFile.Fingerprint(SshKeyHashAlgorithmName.SHA256).Trim());
ClassicAssert.AreEqual(fpSha384Data.Trim(), keyFile.Fingerprint(SshKeyHashAlgorithmName.SHA384).Trim());
ClassicAssert.AreEqual(fpSha512Data.Trim(), keyFile.Fingerprint(SshKeyHashAlgorithmName.SHA512).Trim());

// We cannot test the result of the PrivateKey Export, since Random CheckInts are random...
// So just check the key can be reimport again.
Expand Down
4 changes: 2 additions & 2 deletions SshNet.Keygen/SshKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public static PrivateGeneratedKey Generate(SshKeyGenerateInfo info)
using var rngCsp = new RNGCryptoServiceProvider();
var seed = new byte[Ed25519.PrivateKeySeedSizeInBytes];
rngCsp.GetBytes(seed);
Ed25519.KeyPairFromSeed(out var edPubKey, out var edKey, seed);
key = new ED25519Key(edPubKey, edKey.Reverse());
Ed25519.KeyPairFromSeed(out _, out var edKey, seed);
key = new ED25519Key(edKey.Reverse());
break;
}
case SshKeyType.RSA:
Expand Down
6 changes: 3 additions & 3 deletions SshNet.Keygen/SshKeyEncryption/SshKeyEncryptionAes256.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public byte[] Encrypt(byte[] data)
switch(_mode)
{
case Aes256Mode.CBC:
cipher = new AesCipher(key, new CbcCipherMode(iv), new PKCS7Padding());
cipher = new AesCipher(key, iv, AesCipherMode.CBC);
break;
default:
_mode = Aes256Mode.CTR;
cipher = new AesCipher(key, new CtrCipherMode(iv), new PKCS7Padding());
cipher = new AesCipher(key, iv, AesCipherMode.CTR);
break;
}

Expand Down Expand Up @@ -113,7 +113,7 @@ public byte[] PuttyEncrypt(byte[] data)
throw new NotSupportedException($"Unsupported AES Mode: {_mode}");
default:
_mode = Aes256Mode.CBC;
cipher = new AesCipher(cipherKey, new CbcCipherMode(new byte[cipherKey.Length]), new PKCS7Padding());
cipher = new AesCipher(cipherKey, new byte[cipherKey.Length], AesCipherMode.CBC);
break;
}
return cipher.Encrypt(data);
Expand Down
6 changes: 3 additions & 3 deletions SshNet.Keygen/SshNet.Keygen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
<PackageId>SshNet.Keygen</PackageId>
<Version>0.2.0-beta</Version>
<Version>2024.0.0-beta</Version>
<PackageVersion>$(Version)</PackageVersion>
<PackageTags>ssh;scp;sftp</PackageTags>
<Description>SSH.NET Extension to generate and export Authentication Keys in OPENSSH-Format</Description>
<PackageReleaseNotes>https://github.com/darinkes/SshNet.Keygen/releases/tag/$(PackageVersion)</PackageReleaseNotes>
<Copyright>Copyright (c) 2021 - 2023 Stefan Rinkes</Copyright>
<Copyright>Copyright (c) 2021 - 2024 Stefan Rinkes</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/darinkes/SshNet.Keygen/</PackageProjectUrl>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
Expand All @@ -24,7 +24,7 @@
</Compile>

<PackageReference Include="SshNet.Security.Cryptography" Version="[1.3.0]" />
<PackageReference Include="SSH.NET" Version="2023.0.0" />
<PackageReference Include="SSH.NET" Version="2024.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'net462' ">
Expand Down

0 comments on commit 87e8f4b

Please sign in to comment.