diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-09-20 15:07:40 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-09-20 15:07:40 +0200 |
| commit | 2a619ceba75a4c16b25de12d59a87eac795a4468 (patch) | |
| tree | 1d63a35217011fa761b703633b3f91fd839ec71e /wrappers/csharp | |
| parent | 7e309b67de74fe5bd5a1c70c1880c2a381c4f78b (diff) | |
Remove: unused wrappers
Diffstat (limited to 'wrappers/csharp')
| -rw-r--r-- | wrappers/csharp/.gitignore | 4 | ||||
| -rw-r--r-- | wrappers/csharp/Discovery.cs | 157 | ||||
| -rw-r--r-- | wrappers/csharp/EduVpnCommon.csproj | 73 | ||||
| -rw-r--r-- | wrappers/csharp/EduVpnCommon.props | 7 | ||||
| -rw-r--r-- | wrappers/csharp/EduVpnCommon.sln | 22 | ||||
| -rw-r--r-- | wrappers/csharp/EduVpnCommonTests/EduVpnCommonTests.csproj | 19 | ||||
| -rw-r--r-- | wrappers/csharp/EduVpnCommonTests/VerifyTests.cs | 82 | ||||
| -rw-r--r-- | wrappers/csharp/Makefile | 19 | ||||
| -rw-r--r-- | wrappers/csharp/README.md | 43 |
9 files changed, 0 insertions, 426 deletions
diff --git a/wrappers/csharp/.gitignore b/wrappers/csharp/.gitignore deleted file mode 100644 index 115bb34..0000000 --- a/wrappers/csharp/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -bin/ -obj/ -/packages/ -.vs/ diff --git a/wrappers/csharp/Discovery.cs b/wrappers/csharp/Discovery.cs deleted file mode 100644 index 21c979f..0000000 --- a/wrappers/csharp/Discovery.cs +++ /dev/null @@ -1,157 +0,0 @@ -using System; -using System.Diagnostics; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Text; - -// Make InsecureTestingSetExtraKey visible to tests -[assembly: InternalsVisibleTo("EduVpnCommonTests")] - -namespace EduVpnCommon -{ - public static class Discovery - { - /// <summary> - /// Verifies the signature on the JSON server_list.json/organization_list.json file. - /// If the function returns, the signature is valid for the given file type. - /// </summary> - /// <param name="signatureFileContent">.minisig signature file contents.</param> - /// <param name="signedJson">Signed .json file contents.</param> - /// <param name="expectedFileName">The file type to be verified, one of <c>"server_list.json"</c> or <c>"organization_list.json"</c>.</param> - /// <param name="minSignTime">Minimum time for signature. Should be set to at least the time of the previous signature.</param> - /// <exception cref="ArgumentException">If <c>expectedFileName</c> is not one of the allowed values.</exception> - /// <exception cref="VerifyException">If signature verification fails.</exception> - public static void Verify( - ArraySegment<byte> signatureFileContent, // Span<byte> would be nicer, but is not available in .NET Standard 2.0 - ArraySegment<byte> signedJson, - string expectedFileName, - DateTimeOffset minSignTime) - { - VerifyReturnCode result; - { - using var signatureHandle = GoSliceHandle.FromArray(signatureFileContent); - using var jsonHandle = GoSliceHandle.FromArray(signedJson); - using var expectedFileHandle = GoSliceHandle.FromString(expectedFileName); - - result = Verify(signatureHandle.Slice, jsonHandle.Slice, expectedFileHandle.Slice, - (ulong) minSignTime.ToUnixTimeSeconds()); - } - - switch (result) - { - case VerifyReturnCode.Ok: - return; - case VerifyReturnCode.ErrUnknownExpectedFileName: - throw new ArgumentException("unknown expected file name", nameof(expectedFileName)); - case VerifyReturnCode.ErrInvalidSignature: - throw new InvalidSignatureException(); - case VerifyReturnCode.ErrInvalidSignatureUnknownKey: - throw new InvalidSignatureUnknownKeyException(); - case VerifyReturnCode.ErrTooOld: - throw new SignatureTooOldException(); - default: - throw new UnknownVerifyException((sbyte) result); - } - } - - /// <summary>Use for testing only, see Go documentation.</summary> - internal static void InsecureTestingSetExtraKey(string keyString) - { - using var keyHandle = GoSliceHandle.FromString(keyString); - InsecureTestingSetExtraKey(keyHandle.Slice); - } - - const string LibName = "eduvpn_common"; - - [DllImport(LibName)] - static extern VerifyReturnCode Verify(GoSlice signatureFileContent, GoSlice signedJson, GoSlice expectedFileName, ulong minSignTime); - - [DllImport(LibName)] static extern void InsecureTestingSetExtraKey(GoSlice keyStr); - - /// <summary> - /// Safe auto-disposing Go slice handle. - /// Non-copying alternative to `Marshal.AllocHGlobal` etc. - /// </summary> - class GoSliceHandle : IDisposable - { - GCHandle gcHandle_; - readonly GoSlice slice_; - - public GoSlice Slice => gcHandle_.IsAllocated - ? slice_ - : throw new InvalidOperationException("Handle was disposed"); - - GoSliceHandle(Array array, int offset, int count) - { - Debug.Assert(offset <= array.Length && /*prevent overflow:*/ count <= array.Length && offset <= array.Length - count); - gcHandle_ = GCHandle.Alloc(array, GCHandleType.Pinned); - var elemSize = Marshal.SizeOf(array.GetType().GetElementType()!); - slice_ = new GoSlice(gcHandle_.AddrOfPinnedObject() + offset * elemSize, count * elemSize); - } - - public static GoSliceHandle FromArray<T>(ArraySegment<T> segment) where T : struct => - new GoSliceHandle(segment.Array!, segment.Offset, segment.Count); - - /// <summary>From string as UTF-8.</summary> - public static GoSliceHandle FromString(string str) => - FromArray(new ArraySegment<byte>(Encoding.UTF8.GetBytes(str))); - - public void Dispose() => gcHandle_.Free(); - } - - // C-compatible structure - readonly struct GoSlice - { - readonly IntPtr data_; - readonly long len_, cap_; - - public GoSlice(IntPtr data, long len, long cap) - { - data_ = data; - len_ = len; - cap_ = cap; - } - - public GoSlice(IntPtr data, long len) : this(data, len, len) { } - } - } - - /// <summary>Verification failed, do not trust the file.</summary> - public abstract class VerifyException : Exception - { - protected VerifyException(string message) : base(message) { } - } - - /// <summary>Signature is invalid (for the expected file type).</summary> - public sealed class InvalidSignatureException : VerifyException - { - public InvalidSignatureException() : base("invalid signature") { } - } - - /// <summary>Signature was created with an unknown key and has not been verified.</summary> - public sealed class InvalidSignatureUnknownKeyException : VerifyException - { - public InvalidSignatureUnknownKeyException() : base("invalid signature (unknown key)") { } - } - - /// <summary>Signature timestamp smaller than specified minimum signing time (rollback).</summary> - public sealed class SignatureTooOldException : VerifyException - { - public SignatureTooOldException() : base("replay of previous signature (rollback)") { } - } - - /// <summary>Other unknown error.</summary> - public sealed class UnknownVerifyException : VerifyException - { - public UnknownVerifyException(sbyte code) : base($"unknown verify error ({code})") => Debug.Assert(code != 0); - } - - enum VerifyReturnCode : sbyte - { - Ok, - ErrUnknownExpectedFileName, - ErrInvalidSignature, - ErrInvalidSignatureUnknownKey, - ErrTooOld - } -} diff --git a/wrappers/csharp/EduVpnCommon.csproj b/wrappers/csharp/EduVpnCommon.csproj deleted file mode 100644 index 587601c..0000000 --- a/wrappers/csharp/EduVpnCommon.csproj +++ /dev/null @@ -1,73 +0,0 @@ -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <TargetFramework>netstandard2.0</TargetFramework> - <LangVersion>8</LangVersion> - <Nullable>enable</Nullable> - <PackageId>EduVpn.Common</PackageId> - <PackageVersion>0.1.0</PackageVersion> - <Authors /> - <Description>Common EduVpn logic</Description> - <Product>EduVpn</Product> - </PropertyGroup> - - <ItemGroup> - <Compile Remove="EduVpnCommonTests/**" /> - <EmbeddedResource Remove="EduVpnCommonTests/**" /> - <None Remove="EduVpnCommonTests/**" /> - </ItemGroup> - - <!-- Include EXPORTS_LIB_PATH, LIB_NAME definitions --> - <ImportGroup Label="PropertySheets"> - <Import Project="EduVpnCommon.props" /> - </ImportGroup> - - <Target Name="Build library for current OS" BeforeTargets="PrepareForBuild" - Condition="!(Exists('$(EXPORTS_LIB_PATH)/windows/amd64/$(LIB_NAME).dll') - Or Exists('$(EXPORTS_LIB_PATH)/windows/386/$(LIB_NAME).dll') - Or Exists('$(EXPORTS_LIB_PATH)/windows/arm/$(LIB_NAME).dll') - Or Exists('$(EXPORTS_LIB_PATH)/windows/arm64/$(LIB_NAME).dll') - Or Exists('$(EXPORTS_LIB_PATH)/linux/amd64/lib$(LIB_NAME).so') - Or Exists('$(EXPORTS_LIB_PATH)/linux/arm/lib$(LIB_NAME).so') - Or Exists('$(EXPORTS_LIB_PATH)/linux/arm64/lib$(LIB_NAME).so'))"> - <Message Text="!! Shared $(LIB_NAME) library not found, you should build that one first" Importance="high" /> - </Target> - - <ItemGroup> - <!-- - See https://docs.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks#architecture-specific-folders - and https://docs.microsoft.com/en-us/dotnet/core/rid-catalog - --> - - <None Condition="Exists('$(EXPORTS_LIB_PATH)/windows/amd64/$(LIB_NAME).dll')" - Include="$(EXPORTS_LIB_PATH)/windows/amd64/$(LIB_NAME).dll" Pack="true" PackagePath="runtimes/win-x64/native/"> - <CopyToOutputDirectory>Always</CopyToOutputDirectory> - </None> - <None Condition="Exists('$(EXPORTS_LIB_PATH)/windows/386/$(LIB_NAME).dll')" - Include="$(EXPORTS_LIB_PATH)/windows/386/$(LIB_NAME).dll" Pack="true" PackagePath="runtimes/win-x86/native/"> - <CopyToOutputDirectory>Always</CopyToOutputDirectory> - </None> - <None Condition="Exists('$(EXPORTS_LIB_PATH)/windows/arm/$(LIB_NAME).dll')" - Include="$(EXPORTS_LIB_PATH)/windows/arm/$(LIB_NAME).dll" Pack="true" PackagePath="runtimes/win-arm/native/"> - <CopyToOutputDirectory>Always</CopyToOutputDirectory> - </None> - <None Condition="Exists('$(EXPORTS_LIB_PATH)/windows/arm64/$(LIB_NAME).dll')" - Include="$(EXPORTS_LIB_PATH)/windows/arm64/$(LIB_NAME).dll" Pack="true" PackagePath="runtimes/win-arm64/native/"> - <CopyToOutputDirectory>Always</CopyToOutputDirectory> - </None> - - <None Condition="Exists('$(EXPORTS_LIB_PATH)/linux/amd64/lib$(LIB_NAME).so')" - Include="$(EXPORTS_LIB_PATH)/linux/amd64/lib$(LIB_NAME).so" Pack="true" PackagePath="runtimes/linux-x64/native/"> - <CopyToOutputDirectory>Always</CopyToOutputDirectory> - </None> - <None Condition="Exists('$(EXPORTS_LIB_PATH)/linux/arm/lib$(LIB_NAME).so')" - Include="$(EXPORTS_LIB_PATH)/linux/arm/lib$(LIB_NAME).so" Pack="true" PackagePath="runtimes/linux-arm/native/"> - <CopyToOutputDirectory>Always</CopyToOutputDirectory> - </None> - <None Condition="Exists('$(EXPORTS_LIB_PATH)/linux/arm64/lib$(LIB_NAME).so')" - Include="$(EXPORTS_LIB_PATH)/linux/arm64/lib$(LIB_NAME).so" Pack="true" PackagePath="runtimes/linux-arm64/native/"> - <CopyToOutputDirectory>Always</CopyToOutputDirectory> - </None> - </ItemGroup> - -</Project> diff --git a/wrappers/csharp/EduVpnCommon.props b/wrappers/csharp/EduVpnCommon.props deleted file mode 100644 index 97c2289..0000000 --- a/wrappers/csharp/EduVpnCommon.props +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> - <EXPORTS_LIB_PATH Condition="'$(EXPORTS_LIB_PATH)' == ''">$(SolutionDir)../../exports/lib</EXPORTS_LIB_PATH> - <LIB_NAME Condition="'$(LIB_NAME)' == ''">eduvpn_common</LIB_NAME> - </PropertyGroup> -</Project> diff --git a/wrappers/csharp/EduVpnCommon.sln b/wrappers/csharp/EduVpnCommon.sln deleted file mode 100644 index 0d59e2f..0000000 --- a/wrappers/csharp/EduVpnCommon.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EduVpnCommon", "EduVpnCommon.csproj", "{D95F43A0-EF74-41FD-A526-8987151ABB30}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EduVpnCommonTests", "EduVpnCommonTests/EduVpnCommonTests.csproj", "{B7A75F1A-C83F-4FAB-AD16-E9DB7EF58EBC}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D95F43A0-EF74-41FD-A526-8987151ABB30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D95F43A0-EF74-41FD-A526-8987151ABB30}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D95F43A0-EF74-41FD-A526-8987151ABB30}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D95F43A0-EF74-41FD-A526-8987151ABB30}.Release|Any CPU.Build.0 = Release|Any CPU - {B7A75F1A-C83F-4FAB-AD16-E9DB7EF58EBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B7A75F1A-C83F-4FAB-AD16-E9DB7EF58EBC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B7A75F1A-C83F-4FAB-AD16-E9DB7EF58EBC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B7A75F1A-C83F-4FAB-AD16-E9DB7EF58EBC}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal diff --git a/wrappers/csharp/EduVpnCommonTests/EduVpnCommonTests.csproj b/wrappers/csharp/EduVpnCommonTests/EduVpnCommonTests.csproj deleted file mode 100644 index 9a44848..0000000 --- a/wrappers/csharp/EduVpnCommonTests/EduVpnCommonTests.csproj +++ /dev/null @@ -1,19 +0,0 @@ -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <TargetFramework>net5.0</TargetFramework> - <IsPackable>false</IsPackable> - </PropertyGroup> - - <ItemGroup> - <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> - <PackageReference Include="NUnit" Version="3.13.1" /> - <PackageReference Include="NUnit3TestAdapter" Version="3.17.0" /> - <PackageReference Include="coverlet.collector" Version="3.0.2" /> - </ItemGroup> - - <ItemGroup> - <ProjectReference Include="../EduVpnCommon.csproj" /> - </ItemGroup> - -</Project> diff --git a/wrappers/csharp/EduVpnCommonTests/VerifyTests.cs b/wrappers/csharp/EduVpnCommonTests/VerifyTests.cs deleted file mode 100644 index fba2161..0000000 --- a/wrappers/csharp/EduVpnCommonTests/VerifyTests.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using EduVpnCommon; -using NUnit.Framework; - -namespace EduVpnCommonTests -{ - [TestFixture(TestOf = typeof(Discovery)), Parallelizable] - public class VerifyTests - { - // Relative to e.g. EduVpnCommonTests/bin/Debug/net5.0 - readonly string testDataDir_ = $"{TestContext.CurrentContext.TestDirectory}/../../../../../../src/test_data"; - - [OneTimeSetUp] - public void OneTimeSetUp() => - Discovery.InsecureTestingSetExtraKey(File.ReadLines($"{testDataDir_}/public.key").Last()); - - [Test] - [TestCase("server_list.json.minisig", "server_list.json", "server_list.json")] - [TestCase("organization_list.json.minisig", "organization_list.json", "organization_list.json")] - public void TestValid(string sigFile, string jsonFile, string expectedFileName) => - Discovery.Verify( - File.ReadAllBytes($"{testDataDir_}/{sigFile}"), - File.ReadAllBytes($"{testDataDir_}/{jsonFile}"), - expectedFileName, - DateTimeOffset.FromUnixTimeSeconds(10)); - - [Test] - [TestCase("server_list.json.minisig", "server_list.json", "server_list.json")] - public void TestValidSegment(string sigFile, string jsonFile, string expectedFileName) - { - var bytes = new byte[] { 1, 2, 3 }.Concat(File.ReadAllBytes($"{testDataDir_}/{jsonFile}")) - .Concat(new byte[] { 1, 2, 3 }).ToArray(); - Discovery.Verify( - File.ReadAllBytes($"{testDataDir_}/{sigFile}"), - new(bytes, 3, bytes.Length - 3 - 3), - expectedFileName, - DateTimeOffset.UnixEpoch); - } - - [Test] - [TestCase("random.txt", "server_list.json", "server_list.json")] - public void TestInvalidSignature(string sigFile, string jsonFile, string expectedFileName) => - Assert.Throws<InvalidSignatureException>( - () => Discovery.Verify( - File.ReadAllBytes($"{testDataDir_}/{sigFile}"), - File.ReadAllBytes($"{testDataDir_}/{jsonFile}"), - expectedFileName, - DateTimeOffset.UnixEpoch)); - - [Test] - [TestCase("server_list.json.wrong_key.minisig", "server_list.json", "server_list.json")] - public void TestWrongKey(string sigFile, string jsonFile, string expectedFileName) => - Assert.Throws<InvalidSignatureUnknownKeyException>( - () => Discovery.Verify( - File.ReadAllBytes($"{testDataDir_}/{sigFile}"), - File.ReadAllBytes($"{testDataDir_}/{jsonFile}"), - expectedFileName, - DateTimeOffset.UnixEpoch)); - - [Test] - [TestCase("server_list.json.minisig", "server_list.json", "server_list.json")] - public void TestOldSignature(string sigFile, string jsonFile, string expectedFileName) => - Assert.Throws<SignatureTooOldException>( - () => Discovery.Verify( - File.ReadAllBytes($"{testDataDir_}/{sigFile}"), - File.ReadAllBytes($"{testDataDir_}/{jsonFile}"), - expectedFileName, - DateTimeOffset.FromUnixTimeSeconds(11))); - - [Test] - [TestCase("other_list.json.minisig", "other_list.json", "other_list.json")] - public void TestUnknownExpectedFile(string sigFile, string jsonFile, string expectedFileName) => - Assert.Throws<ArgumentException>( - () => Discovery.Verify( - File.ReadAllBytes($"{testDataDir_}/{sigFile}"), - File.ReadAllBytes($"{testDataDir_}/{jsonFile}"), - expectedFileName, - DateTimeOffset.UnixEpoch)); - } -} diff --git a/wrappers/csharp/Makefile b/wrappers/csharp/Makefile deleted file mode 100644 index 187ddbd..0000000 --- a/wrappers/csharp/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -.PHONY: build pack test clean - -EXPORTS_PATH ?= ../../exports -include $(EXPORTS_PATH)/common.mk - -# Export, see EduVpnCommon.props -export EXPORTS_LIB_PATH - -build: - dotnet publish EduVpnCommon.csproj --configuration Release - -pack: - dotnet pack EduVpnCommon.csproj --configuration Release - -test: .try-build-lib - dotnet test - -clean: - rm -rf bin/ obj/ EduVpnCommonTests/bin/ EduVpnCommonTests/obj/ diff --git a/wrappers/csharp/README.md b/wrappers/csharp/README.md deleted file mode 100644 index 1ff1123..0000000 --- a/wrappers/csharp/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# C# wrapper - -## Requirements - -You will need to install the [.NET SDK](https://dotnet.microsoft.com/download), which includes the `dotnet` tool. The -wrapper targets .NET Standard 2.0, which means that at least .NET Core 2.0 is required (.NET 5+ is also fine). For the -tests, .NET 5 is required. (Or change `<TargetFramework>` in EduVpnCommonTests.csproj to e.g. `net6.0` to use newer -versions.) - -## Build & test - -First build the shared Go library. Next: - -Build `EduVpnCommon` (Release): - -```shell -make -``` - -Build as nupkg, including shared Go library for all platforms built in `exports/lib/`: - -```shell -make pack -``` - -If you do not build this as part of the full repository, specify `EXPORTS_PATH="path/to/exports-folder"` -when calling make. This folder must contain `common.mk` and the `lib/` folder with built libraries. - -The wrapper targets .NET Standard 2.0, which means that it can be referenced by projects using either .NET Framework -4.6.1+, .NET Core 2.0+, or .NET 5+. - -Currently, directly referencing the project may not work (with `System.BadImageFormatException`) if you have multiple -dynamic libraries compiled in the `exports/lib/` folder. If you instead add the `.nupkg`, e.g. with one of the -methods [here](https://stackoverflow.com/q/43400069) or [here](https://stackoverflow.com/q/10240029), it automatically -copies the correct library. - -This also means that tests may fail if you have multiple dynamic libraries compiled! - -Test: - -```shell -make test -``` |
