Skip to content

Commit

Permalink
Use SSH.NET 2023 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
darinkes committed Nov 29, 2023
1 parent 96a0773 commit a5776ad
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 54 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dotnet-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,4 +29,4 @@ jobs:
with:
name: Sample-ubuntu
path: |
SshNet.Keygen.Sample/bin/Debug/net5.0/*
SshNet.Keygen.Sample/bin/Debug/net7.0/*
6 changes: 3 additions & 3 deletions .github/workflows/dotnet-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,5 +29,5 @@ jobs:
with:
name: sample-windows
path: |
SshNet.Keygen.Sample/bin/Debug/net40/*
SshNet.Keygen.Sample/bin/Debug/net5.0/*
SshNet.Keygen.Sample/bin/Debug/net462/*
SshNet.Keygen.Sample/bin/Debug/net7.0/*
4 changes: 2 additions & 2 deletions .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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
Expand Down Expand Up @@ -206,4 +206,4 @@ var publicKey = keyFile.ToPublic();

Console.WriteLine("Private Key: {0}", privateKey);
Console.WriteLine("Public Key: {0}", publicKey);
```
```
1 change: 0 additions & 1 deletion SSH.NET
Submodule SSH.NET deleted from f7fad2
6 changes: 3 additions & 3 deletions SshNet.Keygen.Sample/SshNet.Keygen.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net40;net5.0</TargetFrameworks>
<TargetFramework Condition="'$(OS)' != 'Windows_NT'">net5.0</TargetFramework>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net462;net7.0</TargetFrameworks>
<TargetFramework Condition="'$(OS)' != 'Windows_NT'">net7.0</TargetFramework>
<LangVersion>9</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\SshNet.Keygen\SshNet.Keygen.csproj" />
</ItemGroup>

</Project>
</Project>
6 changes: 3 additions & 3 deletions SshNet.Keygen.Tests/SshNet.Keygen.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net40;net5.0</TargetFrameworks>
<TargetFramework Condition="'$(OS)' != 'Windows_NT'">net5.0</TargetFramework>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net462;net7.0</TargetFrameworks>
<TargetFramework Condition="'$(OS)' != 'Windows_NT'">net7.0</TargetFramework>
<LangVersion>9</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -21,4 +21,4 @@
<EmbeddedResource Include="TestKeys\*" />
</ItemGroup>

</Project>
</Project>
17 changes: 9 additions & 8 deletions SshNet.Keygen.Tests/TestKey.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -32,8 +33,8 @@ public void TestExceptions()
public void TestDefaultKey()
{
var key = SshKey.Generate();
Assert.IsInstanceOf<RsaKey>(((KeyHostAlgorithm)key.HostKey).Key);
Assert.AreEqual(2048, ((KeyHostAlgorithm)key.HostKey).Key.KeyLength);
Assert.IsInstanceOf<RsaKey>(((KeyHostAlgorithm)key.HostKeyAlgorithms.First()).Key);
Assert.AreEqual(2048, ((KeyHostAlgorithm)key.HostKeyAlgorithms.First()).Key.KeyLength);
}

private static void KeyGenTest<TKey>(SshKeyType keyType, int keyLength = 0)
Expand Down Expand Up @@ -74,12 +75,12 @@ private static void KeyGenTest<TKey>(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
{
Expand All @@ -100,15 +101,15 @@ private static void KeyGenTest<TKey>(SshKeyType keyType, int keyLength = 0)
}
}

Assert.IsInstanceOf<TKey>(((KeyHostAlgorithm) keyFile.HostKey).Key);
Assert.IsInstanceOf<TKey>(((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);
}
}
}
Expand Down Expand Up @@ -184,7 +185,7 @@ private void TestFormatKey<T>(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<T>(key);
Assert.AreEqual(keyLength, key.KeyLength);
Expand Down
29 changes: 15 additions & 14 deletions SshNet.Keygen/Extensions/PrivateKeyFileExtension.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Renci.SshNet;
using System.Linq;
using Renci.SshNet;
using Renci.SshNet.Security;
using SshNet.Keygen.SshKeyEncryption;

Expand All @@ -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
Expand Down
14 changes: 10 additions & 4 deletions SshNet.Keygen/PrivateGeneratedKey.cs
Original file line number Diff line number Diff line change
@@ -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<HostAlgorithm> _hostAlgorithms = new();

public IReadOnlyCollection<HostAlgorithm> 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));
}
}
}
15 changes: 6 additions & 9 deletions SshNet.Keygen/SshNet.Keygen.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net40;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net462;netstandard2.0</TargetFrameworks>
<TargetFramework Condition="'$(OS)' != 'Windows_NT'">netstandard2.0</TargetFramework>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
<PackageId>SshNet.Keygen</PackageId>
<Version>0.1.9-beta</Version>
<Version>0.2.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 Stefan Rinkes</Copyright>
<PackageLicenseUrl>https://github.com/darinkes/SshNet.Keygen/blob/main/LICENSE</PackageLicenseUrl>
<Copyright>Copyright (c) 2021 - 2023 Stefan Rinkes</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/darinkes/SshNet.Keygen/</PackageProjectUrl>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Authors>darinkes</Authors>
Expand All @@ -24,13 +24,10 @@
</Compile>

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

<ItemGroup Condition=" '$(TargetFramework)' != 'net40' ">
<ItemGroup Condition=" '$(TargetFramework)' != 'net462' ">
<PackageReference Include="System.Security.Cryptography.Cng" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SSH.NET\src\Renci.SshNet\Renci.SshNet.csproj" />
</ItemGroup>
</Project>

0 comments on commit a5776ad

Please sign in to comment.