diff --git a/.github/workflows/dotnet-ubuntu.yml b/.github/workflows/dotnet-ubuntu.yml index 38e0a9e..b737062 100644 --- a/.github/workflows/dotnet-ubuntu.yml +++ b/.github/workflows/dotnet-ubuntu.yml @@ -18,7 +18,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 5.0.x + dotnet-version: 7.0.x - name: Restore dependencies run: dotnet restore - name: Build @@ -29,4 +29,4 @@ jobs: with: name: Sample-ubuntu path: | - SshNet.Keygen.Sample/bin/Debug/net5.0/* \ No newline at end of file + SshNet.Keygen.Sample/bin/Debug/net7.0/* diff --git a/.github/workflows/dotnet-windows.yml b/.github/workflows/dotnet-windows.yml index 1df4fc6..700a3ac 100644 --- a/.github/workflows/dotnet-windows.yml +++ b/.github/workflows/dotnet-windows.yml @@ -18,7 +18,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 5.0.x + dotnet-version: 7.0.x - name: Restore dependencies run: dotnet restore - name: Build @@ -29,5 +29,5 @@ jobs: with: name: sample-windows path: | - SshNet.Keygen.Sample/bin/Debug/net40/* - SshNet.Keygen.Sample/bin/Debug/net5.0/* \ No newline at end of file + SshNet.Keygen.Sample/bin/Debug/net462/* + SshNet.Keygen.Sample/bin/Debug/net7.0/* diff --git a/.github/workflows/nuget.yml b/.github/workflows/nuget.yml index e84ee9c..cf13677 100644 --- a/.github/workflows/nuget.yml +++ b/.github/workflows/nuget.yml @@ -16,7 +16,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 5.0.x + dotnet-version: 7.0.x - name: Restore dependencies run: dotnet restore - name: Build @@ -25,7 +25,7 @@ jobs: run: dotnet test --no-build --verbosity normal - name: publish on version change id: publish_nuget - uses: rohith/publish-nuget@v2 + uses: alirezanet/publish-nuget@v3.1.0 with: # Filepath of the project to be packaged, relative to root of repository PROJECT_FILE_PATH: SshNet.Keygen/SshNet.Keygen.csproj diff --git a/.gitmodules b/.gitmodules index 904bee4..249c12d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "Chaos.NaCl"] path = Chaos.NaCl url = https://github.com/CodesInChaos/Chaos.NaCl -[submodule "SSH.NET"] - path = SSH.NET - url = https://github.com/darinkes/SSH.NET-1.git diff --git a/README.md b/README.md index 1fa9393..3903eb4 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,9 @@ SshNet.Keygen ## Status WIP -Currently builds it's own fork of [SSH.NET](https://github.com/sshnet/SSH.NET) to be able to automatically test them. - -Needs this Branch: https://github.com/darinkes/SSH.NET-1/tree/agent_auth - ## .NET Frameworks -* .NET 4.0 +* .NET 4.6 * netstandard 2.0 ## Keys diff --git a/SSH.NET b/SSH.NET deleted file mode 160000 index f7fad26..0000000 --- a/SSH.NET +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f7fad2682e827d585a9c17d7011e6cf22130578e diff --git a/SshNet.Keygen.Sample/SshNet.Keygen.Sample.csproj b/SshNet.Keygen.Sample/SshNet.Keygen.Sample.csproj index 9d05cf6..481fb92 100644 --- a/SshNet.Keygen.Sample/SshNet.Keygen.Sample.csproj +++ b/SshNet.Keygen.Sample/SshNet.Keygen.Sample.csproj @@ -2,8 +2,8 @@ Exe - net40;net5.0 - net5.0 + net462;net7.0 + net7.0 9 @@ -11,4 +11,4 @@ - + \ No newline at end of file diff --git a/SshNet.Keygen.Tests/SshNet.Keygen.Tests.csproj b/SshNet.Keygen.Tests/SshNet.Keygen.Tests.csproj index a45b9d2..c3a0bc6 100644 --- a/SshNet.Keygen.Tests/SshNet.Keygen.Tests.csproj +++ b/SshNet.Keygen.Tests/SshNet.Keygen.Tests.csproj @@ -1,8 +1,8 @@ - net40;net5.0 - net5.0 + net462;net7.0 + net7.0 9 false @@ -21,4 +21,4 @@ - + \ No newline at end of file diff --git a/SshNet.Keygen.Tests/TestKey.cs b/SshNet.Keygen.Tests/TestKey.cs index 7db283a..81bfa44 100644 --- a/SshNet.Keygen.Tests/TestKey.cs +++ b/SshNet.Keygen.Tests/TestKey.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Reflection; using System.Security.Cryptography; using System.Text; @@ -32,8 +33,8 @@ public void TestExceptions() public void TestDefaultKey() { var key = SshKey.Generate(); - Assert.IsInstanceOf(((KeyHostAlgorithm)key.HostKey).Key); - Assert.AreEqual(2048, ((KeyHostAlgorithm)key.HostKey).Key.KeyLength); + Assert.IsInstanceOf(((KeyHostAlgorithm)key.HostKeyAlgorithms.First()).Key); + Assert.AreEqual(2048, ((KeyHostAlgorithm)key.HostKeyAlgorithms.First()).Key.KeyLength); } private static void KeyGenTest(SshKeyType keyType, int keyLength = 0) @@ -74,12 +75,12 @@ private static void KeyGenTest(SshKeyType keyType, int keyLength = 0) if (!string.IsNullOrEmpty(comment)) puttyKeyInfo.Comment = comment; - IPrivateKeyFile keyFile; + IPrivateKeySource keyFile; if (string.IsNullOrEmpty(path)) { keyFile = SshKey.Generate(keyInfo); if (keyLength != 0) - Assert.AreEqual(keyLength, ((KeyHostAlgorithm)keyFile.HostKey).Key.KeyLength); + Assert.AreEqual(keyLength, ((KeyHostAlgorithm)keyFile.HostKeyAlgorithms.First()).Key.KeyLength); } else { @@ -100,15 +101,15 @@ private static void KeyGenTest(SshKeyType keyType, int keyLength = 0) } } - Assert.IsInstanceOf(((KeyHostAlgorithm) keyFile.HostKey).Key); + Assert.IsInstanceOf(((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key); if (keyLength != 0) - Assert.AreEqual(keyLength, (((KeyHostAlgorithm) keyFile.HostKey).Key.KeyLength)); + Assert.AreEqual(keyLength, (((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key.KeyLength)); Assert.AreEqual( string.IsNullOrEmpty(comment) ? $"{Environment.UserName}@{Environment.MachineName}" : comment, - ((KeyHostAlgorithm) keyFile.HostKey).Key.Comment); + ((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key.Comment); } } } @@ -184,7 +185,7 @@ private void TestFormatKey(string keyname, int keyLength, string passphrase = var fpSha512Data = GetKey($"{keyname}.fingerprint.sha512"); var keyFile = new PrivateKeyFile(keydata.ToStream(), passphrase); - var key = ((KeyHostAlgorithm) keyFile.HostKey).Key; + var key = ((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key; Assert.IsInstanceOf(key); Assert.AreEqual(keyLength, key.KeyLength); diff --git a/SshNet.Keygen/Extensions/PrivateKeyFileExtension.cs b/SshNet.Keygen/Extensions/PrivateKeyFileExtension.cs index 580acad..038d2dc 100644 --- a/SshNet.Keygen/Extensions/PrivateKeyFileExtension.cs +++ b/SshNet.Keygen/Extensions/PrivateKeyFileExtension.cs @@ -1,4 +1,5 @@ -using Renci.SshNet; +using System.Linq; +using Renci.SshNet; using Renci.SshNet.Security; using SshNet.Keygen.SshKeyEncryption; @@ -8,51 +9,51 @@ public static class PrivateKeyFileExtension { #region Fingerprint - public static string Fingerprint(this IPrivateKeyFile keyFile) + public static string Fingerprint(this IPrivateKeySource keyFile) { return keyFile.Fingerprint(SshKeyGenerateInfo.DefaultHashAlgorithmName); } - public static string Fingerprint(this IPrivateKeyFile keyFile, SshKeyHashAlgorithmName hashAlgorithm) + public static string Fingerprint(this IPrivateKeySource keyFile, SshKeyHashAlgorithmName hashAlgorithm) { - return ((KeyHostAlgorithm) keyFile.HostKey).Key.Fingerprint(hashAlgorithm); + return ((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key.Fingerprint(hashAlgorithm); } #endregion #region Public - public static string ToPublic(this IPrivateKeyFile keyFile) + public static string ToPublic(this IPrivateKeySource keyFile) { - return ((KeyHostAlgorithm) keyFile.HostKey).Key.ToPublic(); + return ((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key.ToPublic(); } #endregion #region OpenSshFormat - public static string ToOpenSshFormat(this IPrivateKeyFile keyFile) + public static string ToOpenSshFormat(this IPrivateKeySource keyFile) { - return ((KeyHostAlgorithm) keyFile.HostKey).Key.ToOpenSshFormat(SshKeyGenerateInfo.DefaultSshKeyEncryption); + return ((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key.ToOpenSshFormat(SshKeyGenerateInfo.DefaultSshKeyEncryption); } - public static string ToOpenSshFormat(this IPrivateKeyFile keyFile, ISshKeyEncryption encryption) + public static string ToOpenSshFormat(this IPrivateKeySource keyFile, ISshKeyEncryption encryption) { - return ((KeyHostAlgorithm) keyFile.HostKey).Key.ToOpenSshFormat(encryption); + return ((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key.ToOpenSshFormat(encryption); } #endregion #region PuttyFormat - public static string ToPuttyFormat(this IPrivateKeyFile keyFile) + public static string ToPuttyFormat(this IPrivateKeySource keyFile) { - return ((KeyHostAlgorithm) keyFile.HostKey).Key.ToPuttyFormat(SshKeyGenerateInfo.DefaultSshKeyEncryption); + return ((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key.ToPuttyFormat(SshKeyGenerateInfo.DefaultSshKeyEncryption); } - public static string ToPuttyFormat(this IPrivateKeyFile keyFile, ISshKeyEncryption encryption) + public static string ToPuttyFormat(this IPrivateKeySource keyFile, ISshKeyEncryption encryption) { - return ((KeyHostAlgorithm) keyFile.HostKey).Key.ToPuttyFormat(encryption); + return ((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key.ToPuttyFormat(encryption); } #endregion diff --git a/SshNet.Keygen/PrivateGeneratedKey.cs b/SshNet.Keygen/PrivateGeneratedKey.cs index ae3f14d..70bc7d9 100644 --- a/SshNet.Keygen/PrivateGeneratedKey.cs +++ b/SshNet.Keygen/PrivateGeneratedKey.cs @@ -1,15 +1,21 @@ -using Renci.SshNet; +using System.Collections.Generic; +using Renci.SshNet; using Renci.SshNet.Security; namespace SshNet.Keygen { - public class PrivateGeneratedKey : IPrivateKeyFile + public class PrivateGeneratedKey : IPrivateKeySource { - public HostAlgorithm HostKey { get; } + private readonly List _hostAlgorithms = new(); + + public IReadOnlyCollection HostKeyAlgorithms => _hostAlgorithms; + + public Key Key { get; } public PrivateGeneratedKey(Key key) { - HostKey = new KeyHostAlgorithm(key.ToString(), key); + Key = key; + _hostAlgorithms.Add(new KeyHostAlgorithm(key.ToString(), key)); } } } \ No newline at end of file diff --git a/SshNet.Keygen/SshNet.Keygen.csproj b/SshNet.Keygen/SshNet.Keygen.csproj index 063d946..7ad61fc 100644 --- a/SshNet.Keygen/SshNet.Keygen.csproj +++ b/SshNet.Keygen/SshNet.Keygen.csproj @@ -1,17 +1,17 @@ - net40;netstandard2.0 + net462;netstandard2.0 netstandard2.0 9 enable SshNet.Keygen - 0.1.9-beta + 0.2.0-beta $(Version) ssh;scp;sftp SSH.NET Extension to generate and export Authentication Keys in OPENSSH-Format https://github.com/darinkes/SshNet.Keygen/releases/tag/$(PackageVersion) - Copyright (c) 2021 Stefan Rinkes - https://github.com/darinkes/SshNet.Keygen/blob/main/LICENSE + Copyright (c) 2021 - 2023 Stefan Rinkes + MIT https://github.com/darinkes/SshNet.Keygen/ false darinkes @@ -24,13 +24,10 @@ + - + - - - - \ No newline at end of file