Skip to content

Commit

Permalink
Extracted Models to separate package. Upgraded to netcoreapp2.2. (#103)
Browse files Browse the repository at this point in the history
* Moved Models and Public classes to Fido2NetLib.Models project

* Allow arguments to buildRelease.ps1

* Conditionally use nuget package when in release mode

* Added version information

* removed old dashboard

* Fixed broken package name

* Added buildscripts and bumped versions

* Changed to published nuget package

* Change foldername to Models

* Added Models to buildRelease script so that CI can test it

* Fixed some issues with moving the project

* Prefix Configuration and User with Fido2 to create less naming conflicts and confusion between domain models

* Bumped version

* Added run-all build script

* Bumped version dependency

* Released preview7

* Shuffled around props to reduce complexity and increase flexibility

Also fixed the documentation URL in the net46x warning
Suppressed warnings in sourced libs
Globalized supported targetframeworks as well as version variables etc.

* Fixed buildscripts

* Fixed buildWarnings/Errors

* Upgraded to netcoreapp2.2 and removed JWT from Demo
  • Loading branch information
abergs authored Jul 31, 2019
1 parent ee52d89 commit e723dda
Show file tree
Hide file tree
Showing 73 changed files with 790 additions and 696 deletions.
96 changes: 2 additions & 94 deletions Demo/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public MyController(IConfiguration config)
_mds.Initialize().Wait();
}
_origin = config["fido2:origin"];
_lib = new Fido2(new Configuration()
_lib = new Fido2(new Fido2Configuration()
{
ServerDomain = config["fido2:serverDomain"],
ServerName = "Fido2 test",
Expand All @@ -52,98 +52,6 @@ private string FormatException(Exception e)
return string.Format("{0}{1}", e.Message, e.InnerException != null ? " (" + e.InnerException.Message + ")" : "");
}

[HttpGet]
[Route("/dashboard-old/{username}")]
public ContentResult Index(string username)
{
// 1. Get user from DB
var user = DemoStorage.GetUser(username + "@example.com");

// 2. Get registered credentials from database
var existingCredentials = DemoStorage.GetCredentialsByUser(user);

var content = System.IO.File.ReadAllText("wwwroot/index.html");

var table = "";

foreach (var cred in existingCredentials)
{
var coseKey = PeterO.Cbor.CBORObject.DecodeFromBytes(cred.PublicKey);
var kty = coseKey[PeterO.Cbor.CBORObject.FromObject(COSE.KeyCommonParameter.KeyType)].AsInt32();
var desc = "";
var icon = "";
try
{
var entry = _mds.GetEntry(cred.AaGuid);
desc = entry.MetadataStatement.Description.ToString();
icon = entry.MetadataStatement.Icon.ToString();
}
catch { }

table +=
"<tr>" +
"<td class=\"format no-wrap\">" + cred.CredType + "</td>" +
"<td class=\"no-wrap\">" + cred.RegDate + "</td>" +
"<td class=\"no-wrap\">" + cred.SignatureCounter.ToString() + "</td>" +
"<td class=\"no-wrap\">" + cred.AaGuid.ToString() + "</td>" +
"<td class=\"no-wrap\">" + desc + "</td>" +
"<img src=" + icon + ">" +
"<td>";
switch (kty)
{
case (int) COSE.KeyType.OKP:
{
var X = coseKey[PeterO.Cbor.CBORObject.FromObject(COSE.KeyTypeParameter.X)].GetByteString();
table += "<table class=\"sub-table\">" +
"<tr>" +
"<td><pre>X: " + BitConverter.ToString(X).Replace("-", "") + "</pre></td>" +
"</tr>" +
"</table>";
break;
}
case (int) COSE.KeyType.EC2:
{
var X = coseKey[PeterO.Cbor.CBORObject.FromObject(COSE.KeyTypeParameter.X)].GetByteString();
var Y = coseKey[PeterO.Cbor.CBORObject.FromObject(COSE.KeyTypeParameter.Y)].GetByteString();
table += "<table class=\"sub-table\">" +
"<tr>" +
"<td><pre>X: " + BitConverter.ToString(X).Replace("-", "") + "</pre></td>" +
"</tr>" +
"<tr>" +
"<td><pre>Y: " + BitConverter.ToString(Y).Replace("-", "") + "</pre></td>" +
"</tr>" +
"</table>";
break;
}
case (int) COSE.KeyType.RSA:
{
var modulus = coseKey[PeterO.Cbor.CBORObject.FromObject(COSE.KeyTypeParameter.N)].GetByteString();
var exponent = coseKey[PeterO.Cbor.CBORObject.FromObject(COSE.KeyTypeParameter.E)].GetByteString();
table += "<table class=\"sub-table\">" +
"<tr>" +
"<td><pre>Modulus: " + BitConverter.ToString(modulus).Replace("-", "") + "</pre></td>" +
"</tr>" +
"<tr>" +
"<td><pre>Exponent: " + BitConverter.ToString(exponent).Replace("-", "") + "</pre></td>" +
"</tr>" +
"</table>";
break;
}
default:
{
throw new Fido2VerificationException(string.Format("Missing or unknown keytype {0}", kty.ToString()));
}
}
}

return new ContentResult
{
ContentType = "text/html",
StatusCode = (int)System.Net.HttpStatusCode.OK,
Content = string.Format(content, username, table)
};
}

[HttpPost]
[Route("/makeCredentialOptions")]
public JsonResult MakeCredentialOptions([FromForm] string username, [FromForm] string displayName, [FromForm] string attType, [FromForm] string authType, [FromForm] bool requireResidentKey, [FromForm] string userVerification)
Expand All @@ -157,7 +65,7 @@ public JsonResult MakeCredentialOptions([FromForm] string username, [FromForm] s
}

// 1. Get user from DB by username (in our example, auto create missing users)
var user = DemoStorage.GetOrAddUser(username, () => new User
var user = DemoStorage.GetOrAddUser(username, () => new Fido2User
{
DisplayName = displayName,
Name = username,
Expand Down
16 changes: 4 additions & 12 deletions Demo/Demo.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>$(SupportedNonMetaTargetFrameworks)</TargetFrameworks>
<UserSecretsId>39589262-6aa1-4bde-aaa9-403a7542cf63</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Fido2NetLib\**" />
<Content Remove="Fido2NetLib\**" />
<EmbeddedResource Remove="Fido2NetLib\**" />
<None Remove="Fido2NetLib\**" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Src\Fido2\Fido2.csproj" />

<PackageReference Include="Microsoft.AspNetCore.All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.2.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Src\Fido2NetLib.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\bulma\" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Demo/TestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public TestController(IConfiguration config)
if (false == _mds.IsInitialized())
_mds.Initialize().Wait();

_lib = new Fido2(new Fido2.Configuration()
_lib = new Fido2(new Fido2Configuration()
{
ServerDomain = config["fido2:serverDomain"],
ServerName = "Fido2 test",
Expand Down Expand Up @@ -67,7 +67,7 @@ public JsonResult MakeCredentialOptionsTest([FromBody] TEST_MakeCredentialParams
}

// 1. Get user from DB by username (in our example, auto create missing users)
var user = DemoStorage.GetOrAddUser(opts.Username, () => new User
var user = DemoStorage.GetOrAddUser(opts.Username, () => new Fido2User
{
DisplayName = opts.DisplayName,
Name = opts.Username,
Expand Down
34 changes: 34 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project>
<!-- Package Metadata -->
<PropertyGroup>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>preview8-dev</VersionSuffix>
<Description>FIDO2 .NET library (WebAuthn)</Description>
<RepositoryUrl>https://github.com/abergs/fido2-net-lib</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>fido2 webauthn</PackageTags>
<PackageReleaseNotes>Initial release</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/abergs/fido2-net-lib</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/abergs/fido2-net-lib/blob/master/LICENSE.txt</PackageLicenseUrl>
</PropertyGroup>
<!-- GLOBALLY USABLE VARIABLES -->
<PropertyGroup>
<!-- Establish a preset but make it an active choice for each project. -->
<SupportedNonMetaTargetFrameWorks>netcoreapp2.2</SupportedNonMetaTargetFrameWorks>
<!-- Can't have test project target .netstandard - only implementations not metaframeworks -->
<SupportedTargetFrameworks>netstandard2.0;$(SupportedNonMetaTargetFrameWorks)</SupportedTargetFrameworks>
</PropertyGroup>
<!-- Language + Compiler Settings-->
<PropertyGroup>
<!-- Pin down language version -->
<LangVersion>7.3</LangVersion>
<!-- Running with "latest" means time alone will make builds non-reproducable... aww hell na -->
</PropertyGroup>
<!--MISC-->
<PropertyGroup>
<!-- Avoid annoying build warnings when packing using the solution file -->
<IsPackable>false</IsPackable>
<!-- Avoid annoying build warnings when packing using the solution file -->
<IsTestProject>false</IsTestProject>
</PropertyGroup>
</Project>
6 changes: 4 additions & 2 deletions ExternalLibs/CBOR/PeterO/BigIntegerExtra.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
/*
Written by Peter O. in 2013.
Any copyright is dedicated to the Public Domain.
Expand All @@ -16,8 +17,9 @@ public sealed partial class BigInteger {
/// path='docs/doc[@name="P:PeterO.BigInteger.Zero"]/*'/>
[CLSCompliant(false)] [Obsolete(
"Use EInteger from PeterO.Numbers/com.upokecenter.numbers and the output of this class's ToString method.")]
public static BigInteger Zero {
get {
public static BigInteger Zero
{
get {
return ValueZeroValue;
}
}
Expand Down
6 changes: 4 additions & 2 deletions ExternalLibs/CBOR/PeterO/Cbor/CBORObjectExtra.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
/*
Written by Peter O. in 2013.
Any copyright is dedicated to the Public Domain.
Expand All @@ -17,8 +18,9 @@ public sealed partial class CBORObject {
/// <include file='../../docs.xml'
/// path='docs/doc[@name="M:CBORObject.AsUInt16"]/*'/>
[CLSCompliant(false)]
public ushort AsUInt16() {
int v = this.AsInt32();
public ushort AsUInt16()
{
int v = this.AsInt32();
if (v > UInt16.MaxValue || v < 0) {
throw new OverflowException("This object's value is out of range");
}
Expand Down
3 changes: 2 additions & 1 deletion ExternalLibs/Chaos.NaCL/Poly1305.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
using System;
using System.Collections.Generic;
using Chaos.NaCl.Internal;

Expand Down
4 changes: 2 additions & 2 deletions Scripts/buildRelease.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$scriptDir = Split-Path $myinvocation.mycommand.path -Parent
$root = Split-Path $scriptDir -Parent
$target = Join-Path $root "Src" | Join-Path -ChildPath "Fido2NetLib.csproj"
$target = Join-Path $root "fido2-net-lib.sln"
Write-Host "Building $target"
dotnet build -c Release $target
dotnet build -c Release $target $args
6 changes: 3 additions & 3 deletions Scripts/packRelease.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$scriptDir = Split-Path $myinvocation.mycommand.path -Parent
$root = Split-Path $scriptDir -Parent
$target = Join-Path $root "Src" | Join-Path -ChildPath "Fido2NetLib.csproj"
Write-Host "Packing $target"
dotnet pack -c Release $target
$target = Join-Path $root "fido2-net-lib.sln"
Write-Host "Building $target"
dotnet pack -c Release $target $args
37 changes: 24 additions & 13 deletions Scripts/publish.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
param([String]$nupkgPath="") #Must be the first statement in your script
param(
[Parameter(Mandatory=$true)]
[System.IO.FileInfo]
[String] $path) #Must be the first statement in your script

$scriptDir = Split-Path $myinvocation.mycommand.path -Parent
$root = Split-Path $scriptDir -Parent
$target = Join-Path $root "Src" | Join-Path -ChildPath "bin" | Join-Path -ChildPath "release"
# if ($nupkgPath -eq "") {
# $scriptDir = Split-Path $myinvocation.mycommand.path -Parent
# $root = Split-Path $scriptDir -Parent
# $target = Join-Path $root "Src" | Join-Path -ChildPath "bin" | Join-Path -ChildPath "release"

# Write-Error "No nupkg path supplied"
# Write-Host "nupkgs found in release folder $target\:"
# $files = Get-ChildItem $target -Filter *.nupkg
# Write-Host $files
# exit 1
# }

if ($nupkgPath -eq "") {
Write-Error "No nupkg path supplied"
Write-Host "nupkgs found in release folder $target\:"
$files = Get-ChildItem $target -Filter *.nupkg
Write-Host $files
exit 1
}
$path2 = $path;

Write-Host "Publishing $nupkgPath..."
$path = Resolve-Path $path
if($path2 -ne $path) {
Write-Host "Resolved $path2 -> $path"
}
Write-Host "Publishing $path..."
Start-Sleep 2
dotnet nuget push $nupkgPath --source https://api.nuget.org/v3/index.json
dotnet nuget push $path --source https://api.nuget.org/v3/index.json

Write-Host "Done $path..."
49 changes: 49 additions & 0 deletions Scripts/run-all.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
param([String]$VersionPrefix="1.0.0", [String]$VersionSuffix="") #Must be the first statement in your script

$scriptDir = Split-Path $myinvocation.mycommand.path -Parent
$root = Split-Path $scriptDir -Parent

## Prefix the suffix with a dash if set.
if($VersionSuffix) {
$VersionSuffixPath = "-" + $VersionSuffix
}

# Check for confirmation
Write-Host "This will call setVersion, pack and publish both projects to nuget."
Write-Host -background yellow -foreground black "Version: $VersionPrefix$VersionSuffixPath"
$confirmation = Read-Host "Are you Sure You Want To Proceed [y]"
if ($confirmation -ne 'y') {exit}

# proceed
& (join-path $scriptDir "setVersion.ps1") -VersionPrefix $VersionPrefix -VersionSuffix $VersionSuffix
& (join-path $scriptDir "buildRelease.ps1")
#& (join-path $scriptDir "packRelease.ps1")

if ($? -eq $false) {
write-host -background DarkBlue -foreground Red "<Error Exit>"
exit 1
}

$target1 = Join-Path $root "Src\Fido2\bin\Release\Fido2.$VersionPrefix$VersionSuffixPath.nupkg"
$target2 = Join-Path $root "Src\Fido2.Models\bin\Release\Fido2.Models.$VersionPrefix$VersionSuffixPath.nupkg"

if (
((Test-Path $target1) -eq $false) -Or ((Test-Path $target2) -eq $false)) {
write-host -background DarkBlue -foreground Red "Could not locate nupkg"
Write-Host "Path1 $target1"
Write-Host "Path2 $target2"

exit 1
}

Write-Host "Ready to publish $target1"
Write-Host "Ready to publish $target2"
Write-Host -background yellow -foreground black "Version: $VersionPrefix$VersionSuffixPath"

$confirmation = Read-Host "Are you Sure You Want To Proceed (y)"
if ($confirmation -ne 'y') {exit}
& (join-path $scriptDir "publish.ps1") -path $target2
& (join-path $scriptDir "publish.ps1") -path $target1


Write-Host "Done. Update to $VersionPrefix $VersionSuffix and published to nuget."
18 changes: 18 additions & 0 deletions Scripts/setVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
param([String]$VersionPrefix="1.0.0", [String]$VersionSuffix="") #Must be the first statement in your script

$scriptDir = Split-Path $myinvocation.mycommand.path -Parent
$root = Split-Path $scriptDir -Parent

$target1 = Join-Path $root "Directory.Build.props"

Write-Host "Changing $target1"
$filePathToTask = $target1
$xml = New-Object XML
$xml.Load($filePathToTask)
$element = $xml.SelectSingleNode("//VersionPrefix")
$element.InnerText = $VersionPrefix
$element = $xml.SelectSingleNode("//VersionSuffix")
$element.InnerText = $VersionSuffix
$xml.Save($filePathToTask)

Write-Host "Updated to version $VersionPrefix $VersionSuffix"
18 changes: 18 additions & 0 deletions Src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project>
<Import Project="..\Directory.Build.props"/>

<!-- SourceLink Support-->
<PropertyGroup>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-63127-02" PrivateAssets="All" />
</ItemGroup>

<!-- Projects inside "./src" should generate packages -->
<PropertyGroup>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
</Project>
Loading

0 comments on commit e723dda

Please sign in to comment.