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 92d23e6 commit 65c27c7
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 32 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,10 +18,10 @@ 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
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
run: dotnet test --no-build --verbosity normal
4 changes: 2 additions & 2 deletions .github/workflows/dotnet-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ 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
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
run: dotnet test --no-build --verbosity normal
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "SSH.NET"]
path = SSH.NET
url = https://github.com/darinkes/SSH.NET-1.git
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ SshNet.PuttyKeyFile
## 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
Expand All @@ -39,4 +35,4 @@ var key = new PuttyKeyFile("my-key.ppk");
using var client = new SshClient("ssh.foo.com", "root", key);
client.Connect();
Console.WriteLine(client.RunCommand("hostname").Result);
```
```
1 change: 0 additions & 1 deletion SSH.NET
Submodule SSH.NET deleted from f7fad2
6 changes: 3 additions & 3 deletions SshNet.PuttyKeyFile.Sample/SshNet.PuttyKeyFile.Sample.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>
<OutputType>exe</OutputType>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
Expand All @@ -18,4 +18,4 @@
<ItemGroup>
<ProjectReference Include="..\SshNet.PuttyKeyFile\SshNet.PuttyKeyFile.csproj" />
</ItemGroup>
</Project>
</Project>
7 changes: 4 additions & 3 deletions SshNet.PuttyKeyFile.Tests/PuttyKeyFileTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
using Renci.SshNet.Security;
Expand All @@ -21,9 +22,9 @@ public void Setup()

var keyFile = new PuttyKeyFile(keyStream, pass);

Assert.IsInstanceOf<TKey>(((KeyHostAlgorithm) keyFile.HostKey).Key);
Assert.AreEqual(keyLength, ((KeyHostAlgorithm) keyFile.HostKey).Key.KeyLength);
Assert.AreEqual(comment, ((KeyHostAlgorithm) keyFile.HostKey).Key.Comment);
Assert.IsInstanceOf<TKey>(((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key);
Assert.AreEqual(keyLength, ((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key.KeyLength);
Assert.AreEqual(comment, ((KeyHostAlgorithm) keyFile.HostKeyAlgorithms.First()).Key.Comment);
}

[Test]
Expand Down
6 changes: 3 additions & 3 deletions SshNet.PuttyKeyFile.Tests/SshNet.PuttyKeyFile.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>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand All @@ -21,4 +21,4 @@
<ItemGroup>
<ProjectReference Include="..\SshNet.PuttyKeyFile\SshNet.PuttyKeyFile.csproj" />
</ItemGroup>
</Project>
</Project>
12 changes: 9 additions & 3 deletions SshNet.PuttyKeyFile/PuttyKeyFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace SshNet.PuttyKeyFile
{
public class PuttyKeyFile : IPrivateKeyFile
public class PuttyKeyFile : IPrivateKeySource
{
private static readonly Regex PuttyPrivateKeyRegex = new(
@"^PuTTY-User-Key-File-(?<fileVersion>[0-9]+): *(?<keyType>[^\r\n]+)(\r|\n)+" +
Expand All @@ -27,7 +27,11 @@ public class PuttyKeyFile : IPrivateKeyFile
@"Private-(?<macOrHash>(MAC|Hash)): *(?<hashData>[a-zA-Z0-9/+=]+)",
RegexOptions.Compiled | RegexOptions.Multiline);

public HostAlgorithm HostKey { get; private set; } = null!;
private readonly List<HostAlgorithm> _hostAlgorithms = new();

public IReadOnlyCollection<HostAlgorithm> HostKeyAlgorithms => _hostAlgorithms;

public Key Key { get; private set; }

public PuttyKeyFile(Stream privateKey)

Check warning on line 36 in SshNet.PuttyKeyFile/PuttyKeyFile.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Key' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 36 in SshNet.PuttyKeyFile/PuttyKeyFile.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Key' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 36 in SshNet.PuttyKeyFile/PuttyKeyFile.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Key' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 36 in SshNet.PuttyKeyFile/PuttyKeyFile.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Key' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 36 in SshNet.PuttyKeyFile/PuttyKeyFile.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Key' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 36 in SshNet.PuttyKeyFile/PuttyKeyFile.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Key' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
{
Expand Down Expand Up @@ -183,7 +187,9 @@ private void Open(Stream privateKey, string? passPhrase)
}

parsedKey.Comment = comment;
HostKey = new KeyHostAlgorithm(parsedKey.ToString(), parsedKey);

Key = parsedKey;
_hostAlgorithms.Add(new KeyHostAlgorithm(parsedKey.ToString(), parsedKey));
}

private static byte[] GetCipherKey(string? passphrase, int length)
Expand Down
9 changes: 3 additions & 6 deletions SshNet.PuttyKeyFile/SshNet.PuttyKeyFile.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<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>
</PropertyGroup>

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

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

0 comments on commit 65c27c7

Please sign in to comment.