Skip to content

Commit

Permalink
Merge pull request #20 from HenrikWM/f-nuget
Browse files Browse the repository at this point in the history
NuGet-publishing
  • Loading branch information
HenrikWM committed Nov 20, 2020
2 parents 6b89235 + 2e71033 commit 3b9e16f
Show file tree
Hide file tree
Showing 39 changed files with 238 additions and 113 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
- name: Build and Test
run: ./Build.ps1
shell: pwsh
- name: Artifacts
uses: actions/upload-artifact@v2
with:
name: artifacts
path: artifacts/**/*
30 changes: 0 additions & 30 deletions .github/workflows/dotnet-core.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Release

on:
push:
tags:
- "*.*.*"
jobs:
build:
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Build and Test
run: ./Build.ps1
shell: pwsh
- name: Push to NuGet
env:
NUGET_URL: https://api.nuget.org/v3/index.json
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: ./Push.ps1
shell: pwsh
- name: Artifacts
uses: actions/upload-artifact@v2
with:
name: artifacts
path: artifacts/**/*
15 changes: 13 additions & 2 deletions AnonymousTokens.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,31 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Server-side", "Server-side"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4DDE2573-8947-4348-95B4-688102A8294D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnonymousTokensShared", "src\AnonymousTokensShared\AnonymousTokensShared.csproj", "{D98EB88A-9922-4AA5-8C97-6206C7196CD5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnonymousTokens", "src\AnonymousTokens\AnonymousTokens.csproj", "{D98EB88A-9922-4AA5-8C97-6206C7196CD5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server.TokenGeneration.Api", "samples\ClientServer\Server\Server.TokenGeneration.Api\Server.TokenGeneration.Api.csproj", "{E691A98B-3EBC-4AE7-8858-67601E805909}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server.TokenVerification.Api", "samples\ClientServer\Server\Server.TokenVerification.Api\Server.TokenVerification.Api.csproj", "{A4143A14-789E-4AD0-BAD9-BF5B32E24EC7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{4FB09123-E5E6-4367-BEDD-FF3D9906A2BA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnonymousTokensShared.UnitTests", "test\AnonymousTokensShared.UnitTests\AnonymousTokensShared.UnitTests.csproj", "{E24CF8EE-6D9B-49AC-92A5-EB1F81FDAAA2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnonymousTokens.UnitTests", "test\AnonymousTokens.UnitTests\AnonymousTokens.UnitTests.csproj", "{E24CF8EE-6D9B-49AC-92A5-EB1F81FDAAA2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{645EAD64-C3E7-41AA-B7E4-E423DFFCEEDF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ClientServer", "ClientServer", "{017DB04E-CA83-4400-90FD-4CA10428EC51}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2969E75A-CD07-49C8-8740-9273B0C807C6}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.github\workflows\CI.yml = .github\workflows\CI.yml
.github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml
.github\dependabot.yml = .github\dependabot.yml
Directory.Build.props = Directory.Build.props
readme.md = readme.md
.github\workflows\Release.yml = .github\workflows\Release.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
35 changes: 35 additions & 0 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Taken from psake https://github.com/psake/psake

<#
.SYNOPSIS
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
to see if an error occcured. If an error is detected then an exception is thrown.
This function allows you to run command-line programs without having to
explicitly check the $lastexitcode variable.
.EXAMPLE
exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
#>
function Exec
{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
)
& $cmd
if ($lastexitcode -ne 0) {
throw ("Exec: " + $errorMessage)
}
}

$artifacts = ".\artifacts"

if(Test-Path $artifacts) { Remove-Item $artifacts -Force -Recurse }

exec { & dotnet clean -c Release }

exec { & dotnet build -c Release }

exec { & dotnet test -c Release -r $artifacts --no-build -l trx --verbosity=normal }

exec { & dotnet pack .\src\AnonymousTokens\AnonymousTokens.csproj -c Release -o $artifacts --no-build }
7 changes: 7 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<NoWarn>$(NoWarn);CS1701;CS1702;CS1591;CS1570</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Henrik W. Moe
Copyright (c) 2020 Henrik Walker Moe, Tjerand Silde, Martin Strand

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
6 changes: 6 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
14 changes: 14 additions & 0 deletions Push.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$scriptName = $MyInvocation.MyCommand.Name
$artifacts = "./artifacts"

if ([string]::IsNullOrEmpty($Env:NUGET_API_KEY)) {
Write-Host "${scriptName}: NUGET_API_KEY is empty or not set. Skipped pushing package(s)."
} else {
Get-ChildItem $artifacts -Filter "*.nupkg" | ForEach-Object {
Write-Host "$($scriptName): Pushing $($_.Name)"
dotnet nuget push $_ --source $Env:NUGET_URL --api-key $Env:NUGET_API_KEY
if ($lastexitcode -ne 0) {
throw ("Exec: " + $errorMessage)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\AnonymousTokensShared\AnonymousTokensShared.csproj" />
<ProjectReference Include="..\..\..\..\src\AnonymousTokens\AnonymousTokens.csproj" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions samples/ClientServer/Client/Client.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

using AnonymousTokensConsole.ApiClients.TokenGeneration;

using AnonymousTokensShared.Protocol;
using AnonymousTokensShared.Services.InMemory;
using AnonymousTokens.Protocol;
using AnonymousTokens.Services.InMemory;

using Client.Console.ApiClients.TokenVerification;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using AnonymousTokensShared.Protocol;
using AnonymousTokensShared.Services.InMemory;
using AnonymousTokens.Protocol;
using AnonymousTokens.Services.InMemory;

using Microsoft.AspNetCore.Mvc;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\AnonymousTokensShared\AnonymousTokensShared.csproj" />
<ProjectReference Include="..\..\..\..\src\AnonymousTokens\AnonymousTokens.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AnonymousTokensShared.Protocol;
using AnonymousTokensShared.Services;
using AnonymousTokensShared.Services.InMemory;
using AnonymousTokens.Protocol;
using AnonymousTokens.Services;
using AnonymousTokens.Services.InMemory;

using Microsoft.AspNetCore.Mvc;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\AnonymousTokensShared\AnonymousTokensShared.csproj" />
<ProjectReference Include="..\..\..\..\src\AnonymousTokens\AnonymousTokens.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

using AnonymousTokensShared.Services;
using AnonymousTokensShared.Services.InMemory;
using AnonymousTokens.Services;
using AnonymousTokens.Services.InMemory;

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand Down
43 changes: 43 additions & 0 deletions src/AnonymousTokens/AnonymousTokens.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Authors>Henrik Walker Moe, Tjerand Silde, Martin Strand</Authors>
<Description>Anonymous tokens implementation in .NET based on Privacy Pass</Description>
<Copyright>Copyright Henrik Walker Moe, Tjerand Silde, Martin Strand</Copyright>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<Features>strict</Features>
<PackageTags>privacy-pass;anonymous-tokens</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<MinVerTagPrefix>v</MinVerTagPrefix>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
<Version>0.1.0</Version>
<RepositoryUrl>https://github.com/HenrikWM/anonymous-tokens</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>

<ItemGroup>
<None Remove="Services\InMemory\private-key.pem" />
<None Remove="Services\InMemory\public-key.pem" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Services\InMemory\private-key.pem" />
<EmbeddedResource Include="Services\InMemory\public-key.pem" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.8" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Math.EC;

using System.Security.Cryptography;

using ECCurve = Org.BouncyCastle.Math.EC.ECCurve;
using ECPoint = Org.BouncyCastle.Math.EC.ECPoint;

namespace AnonymousTokensShared
namespace AnonymousTokens
{
public static class ECCurveHash
{
Expand All @@ -16,7 +16,7 @@ public static class ECCurveHash
/// <param name="curve">The elliptic curve in Weierstrass form</param>
/// <param name="t">The seed</param>
/// <returns>A random point T uniquely determined by seed t, otherwise null</returns>
public static ECPoint HashToWeierstrassCurve(ECCurve curve, byte[] t)
public static ECPoint? HashToWeierstrassCurve(ECCurve curve, byte[] t)
{
ECFieldElement x, ax, x3, y, y2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Org.BouncyCastle.Math.EC;
using Org.BouncyCastle.Security;

namespace AnonymousTokensShared
namespace AnonymousTokens
{
public static class ECCurveRandomNumberGenerator
{
Expand Down
23 changes: 23 additions & 0 deletions src/AnonymousTokens/ECPointVerifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Org.BouncyCastle.Math.EC;

namespace AnonymousTokens
{
public static class ECPointVerifier
{
/// <summary>
/// Verifies that a point is valid, on the correct curve and in the corect subgroup.
/// </summary>
/// <param name="point">Elliptic curve point that we want to verify</param>
/// <param name="curve">Elliptic curce that we want to verify against</param>
/// <returns>True if the point is valid and otherwise false</returns>
public static bool PointIsValid(ECPoint point, ECCurve curve)
{
if (point == null || !curve.Equals(point.Curve) || point.Multiply(curve.Cofactor).Equals(curve.Infinity))
{
return false;
}

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using ECPoint = Org.BouncyCastle.Math.EC.ECPoint;

namespace AnonymousTokensShared.Protocol
namespace AnonymousTokens.Protocol
{
public static class CPChallengeGenerator
{
Expand Down

0 comments on commit 3b9e16f

Please sign in to comment.