Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: passwordless-lib/fido2-net-lib
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4.0.0-beta.11
Choose a base ref
...
head repository: passwordless-lib/fido2-net-lib
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4.0.0-beta.12
Choose a head ref
  • 7 commits
  • 47 files changed
  • 2 contributors

Commits on Jan 16, 2024

  1. Tidy up tests (#494)

    * [Tests] Use collection expressions
    
    * [Tests] Use collection expressions (part 2)
    
    * [Tests] Apply formatting
    
    * Try to make dotnet format happy
    iamcarbon authored Jan 16, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2b60596 View commit details

Commits on Jan 26, 2024

  1. Review lifecycle of services registered in the DI container (#459)

    joegoldman2 authored Jan 26, 2024
    Copy the full SHA
    0a9886d View commit details

Commits on Feb 12, 2024

  1. Drop assertion-time attestation (#499)

    joegoldman2 authored Feb 12, 2024
    Copy the full SHA
    b597d18 View commit details

Commits on Feb 16, 2024

  1. Generate XML documentation file (#502)

    joegoldman2 authored Feb 16, 2024
    Copy the full SHA
    274e7a8 View commit details
  2. Tidying (#500)

    * Use primary constructors
    
    * Use collection expressions
    
    * Use primary constructors (part 2)
    
    * Move InternalsVisibleTo to csproj
    iamcarbon authored Feb 16, 2024
    Copy the full SHA
    57b8652 View commit details

Commits on Feb 28, 2024

  1. Update to .NET 8 (#503)

    * Update to .NET 8
    
    * Remove GuidHelper
    joegoldman2 authored Feb 28, 2024
    Copy the full SHA
    0f302e2 View commit details
  2. Rename Base64Converter.cs to Base64UrlConverter.cs (#506)

    joegoldman2 authored Feb 28, 2024
    Copy the full SHA
    9ad038b View commit details
Showing with 1,293 additions and 1,491 deletions.
  1. +8 −1 Directory.Build.props
  2. +2 −5 Src/Directory.Build.props
  3. +6 −11 Src/Fido2.AspNet/Fido2NetLibBuilderExtensions.cs
  4. +1 −1 Src/Fido2.BlazorWebAssembly/Fido2.BlazorWebAssembly.csproj
  5. +13 −24 Src/Fido2.Ctap2/Commands/AuthenticatorClientPinCommand.cs
  6. +0 −4 Src/Fido2.Models/AuthenticatorAssertionRawResponse.cs
  7. 0 Src/Fido2.Models/Converters/{Base64Converter.cs → Base64UrlConverter.cs}
  8. +21 −28 Src/Fido2.Models/CredentialCreateOptions.cs
  9. +4 −7 Src/Fido2.Models/Fido2Configuration.cs
  10. +1 −1 Src/Fido2.Models/Metadata/AuthenticatorStatus.cs
  11. +6 −10 Src/Fido2.Models/Objects/AuthenticationExtensionsDevicePublicKeyOutputs.cs
  12. +3 −7 Src/Fido2.Models/UndesiredMetadataStatusFido2VerificationException.cs
  13. +0 −3 Src/Fido2/Assembly.cs
  14. +6 −6 Src/Fido2/AttestationFormat/Packed.cs
  15. +7 −7 Src/Fido2/AttestationFormat/Tpm.cs
  16. +6 −45 Src/Fido2/AuthenticatorAssertionResponse.cs
  17. +4 −1 Src/Fido2/AuthenticatorAttestationResponse.cs
  18. +2 −7 Src/Fido2/Cbor/CborBoolean.cs
  19. +2 −9 Src/Fido2/Cbor/CborByteString.cs
  20. +2 −7 Src/Fido2/Cbor/CborInteger.cs
  21. +1 −1 Src/Fido2/Cbor/CborMap.cs
  22. +2 −7 Src/Fido2/Cbor/CborTextString.cs
  23. +0 −34 Src/Fido2/Extensions/GuidHelper.cs
  24. +12 −4 Src/Fido2/Fido2.cs
  25. +4 −0 Src/Fido2/Fido2.csproj
  26. +1 −0 Src/Fido2/IMetadataService.cs
  27. +3 −8 Src/Fido2/Internal/GetBLOBRequest.cs
  28. +3 −8 Src/Fido2/Metadata/Fido2MetadataServiceRepository.cs
  29. +9 −9 Src/Fido2/Metadata/FileSystemMetadataRepository.cs
  30. +4 −10 Src/Fido2/Metadata/MDSGetEndpointResponse.cs
  31. +6 −9 Src/Fido2/Objects/AttestedCredentialData.cs
  32. +18 −22 Src/Fido2/Objects/AuthenticatorData.cs
  33. +7 −7 Src/Fido2/Objects/AuthenticatorFlags.cs
  34. +3 −9 Src/Fido2/Objects/CredentialIdUserHandleParams.cs
  35. +3 −9 Src/Fido2/Objects/CredentialIdUserParams.cs
  36. +3 −3 Src/Fido2/Objects/DevicePublicKeyAuthenticatorOutput.cs
  37. +1 −1 Src/Fido2/Objects/Extensions.cs
  38. +1 −1 Test/Attestation/AndroidKey.cs
  39. +9 −9 Test/Attestation/Apple.cs
  40. +9 −9 Test/Attestation/FidoU2f.cs
  41. +1 −1 Test/Attestation/Packed.cs
  42. +854 −848 Test/Attestation/Tpm.cs
  43. +190 −190 Test/AuthenticatorResponse.cs
  44. +0 −47 Test/Extensions/DataHelper.cs
  45. +1 −1 Test/Extensions/SignatureHelper.cs
  46. +40 −41 Test/Fido2Tests.cs
  47. +14 −19 Test/MetadataServiceTests.cs
9 changes: 8 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
<Description>FIDO2 .NET library (WebAuthn)</Description>
<RepositoryUrl>https://github.com/passwordless-lib/fido2-net-lib</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<PackageTags>fido2 webauthn</PackageTags>
<PackageReleaseNotes>Initial release</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/passwordless-lib/fido2-net-lib</PackageProjectUrl>
@@ -15,9 +16,15 @@

<!-- Global Variables -->
<PropertyGroup>
<SupportedTargetFrameworks>net6.0</SupportedTargetFrameworks>
<SupportedTargetFrameworks>net8.0</SupportedTargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!--
Temporary disabling of CS1591 (Missing XML comment for publicly visible type or member) warning
Make sure to re-enable it when https://github.com/passwordless-lib/fido2-net-lib/issues/501 is resolved.
-->
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>

<!-- Language + Compiler Settings-->
7 changes: 2 additions & 5 deletions Src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -2,12 +2,9 @@
<Project>
<Import Project="..\Directory.Build.props"/>

<!-- SourceLink Support-->
<PropertyGroup Condition="$(IS_DOCKER) == ''">
<!-- Include PDB in the NuGet package -->
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
</PropertyGroup>
<ItemGroup Condition="$(IS_DOCKER) == ''">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

</Project>
17 changes: 6 additions & 11 deletions Src/Fido2.AspNet/Fido2NetLibBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ public static IFido2NetLibBuilder AddFido2(this IServiceCollection services, ICo

private static void AddServices(this IServiceCollection services)
{
services.AddTransient<IFido2, Fido2>();
services.AddScoped<IFido2, Fido2>();
services.AddSingleton<IMetadataService, NullMetadataService>(); //Default implementation if we choose not to enable MDS
services.TryAddSingleton<ISystemClock, SystemClock>();
}
@@ -42,14 +42,14 @@ public static IFido2NetLibBuilder AddFido2(this IServiceCollection services, Act

public static void AddCachedMetadataService(this IFido2NetLibBuilder builder, Action<IFido2MetadataServiceBuilder> configAction)
{
builder.AddMetadataService<DistributedCacheMetadataService>();
builder.Services.AddScoped<IMetadataService, DistributedCacheMetadataService>();

configAction(new Fido2NetLibBuilder(builder.Services));
}

public static IFido2MetadataServiceBuilder AddFileSystemMetadataRepository(this IFido2MetadataServiceBuilder builder, string directoryPath)
{
builder.Services.AddTransient<IMetadataRepository, FileSystemMetadataRepository>(r =>
builder.Services.AddScoped<IMetadataRepository, FileSystemMetadataRepository>(provider =>
{
return new FileSystemMetadataRepository(directoryPath);
});
@@ -62,7 +62,7 @@ public static IFido2MetadataServiceBuilder AddConformanceMetadataRepository(
HttpClient client = null,
string origin = "")
{
builder.Services.AddTransient<IMetadataRepository>(provider =>
builder.Services.AddScoped<IMetadataRepository>(provider =>
{
return new ConformanceMetadataRepository(client, origin);
});
@@ -80,15 +80,10 @@ public static IFido2MetadataServiceBuilder AddFidoMetadataRepository(this IFido2
if (clientBuilder != null)
clientBuilder(httpClientBuilder);

builder.Services.AddTransient<IMetadataRepository, Fido2MetadataServiceRepository>();
builder.Services.AddScoped<IMetadataRepository, Fido2MetadataServiceRepository>();

return builder;
}

private static void AddMetadataService<TService>(this IFido2NetLibBuilder builder) where TService : class, IMetadataService
{
builder.Services.AddScoped<IMetadataService, TService>();
}
}

public interface IFido2NetLibBuilder
@@ -104,7 +99,7 @@ public interface IFido2MetadataServiceBuilder
public class Fido2NetLibBuilder : IFido2NetLibBuilder, IFido2MetadataServiceBuilder
{
/// <summary>
/// Initializes a new instance of the <see cref="IdentityServerBuilder"/> class.
/// Initializes a new instance of the <see cref="Fido2NetLibBuilder"/> class.
/// </summary>
/// <param name="services">The services.</param>
/// <exception cref="System.ArgumentNullException">services</exception>
2 changes: 1 addition & 1 deletion Src/Fido2.BlazorWebAssembly/Fido2.BlazorWebAssembly.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>$(SupportedTargetFrameworks)</TargetFrameworks>
<RootNamespace>Fido2NetLib</RootNamespace>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Nullable>enable</Nullable>
37 changes: 13 additions & 24 deletions Src/Fido2.Ctap2/Commands/AuthenticatorClientPinCommand.cs
Original file line number Diff line number Diff line change
@@ -3,62 +3,51 @@

namespace Fido2NetLib.Ctap2;

public sealed class AuthenticatorClientPinCommand : CtapCommand
public sealed class AuthenticatorClientPinCommand(
uint pinProtocol,
AuthenticatorClientPinSubCommand subCommand,
CredentialPublicKey? keyAgreement = null,
byte[]? pinAuth = null,
byte[]? newPinEnc = null,
byte[]? pinHashEnc = null) : CtapCommand
{
public AuthenticatorClientPinCommand(
uint pinProtocol,
AuthenticatorClientPinSubCommand subCommand,
CredentialPublicKey? keyAgreement = null,
byte[]? pinAuth = null,
byte[]? newPinEnc = null,
byte[]? pinHashEnc = null)
{

PinProtocol = pinProtocol;
SubCommand = subCommand;
KeyAgreement = keyAgreement;
PinAuth = pinAuth;
NewPinEnc = newPinEnc;
PinHashEnc = pinHashEnc;
}

/// <summary>
/// Required PIN protocol version chosen by the client.
/// </summary>
[CborMember(0x01)]
public uint PinProtocol { get; }
public uint PinProtocol { get; } = pinProtocol;

/// <summary>
/// The authenticator Client PIN sub command currently being requested.
/// </summary>
[CborMember(0x02)]
public AuthenticatorClientPinSubCommand SubCommand { get; }
public AuthenticatorClientPinSubCommand SubCommand { get; } = subCommand;

/// <summary>
/// Public key of platformKeyAgreementKey.
/// The COSE_Key-encoded public key MUST contain the optional "alg" parameter and MUST NOT contain any other optional parameters.
/// The "alg" parameter MUST contain a COSEAlgorithmIdentifier value.
/// </summary>
[CborMember(0x03)]
public CredentialPublicKey? KeyAgreement { get; }
public CredentialPublicKey? KeyAgreement { get; } = keyAgreement;

/// <summary>
/// First 16 bytes of HMAC-SHA-256 of encrypted contents using sharedSecret.
/// </summary>
[CborMember(0x04)]
public byte[]? PinAuth { get; }
public byte[]? PinAuth { get; } = pinAuth;

/// <summary>
/// Encrypted new PIN using sharedSecret.
/// </summary>
[CborMember(0x05)]
public byte[]? NewPinEnc { get; }
public byte[]? NewPinEnc { get; } = newPinEnc;

/// <summary>
/// Encrypted first 16 bytes of SHA-256 of PIN using sharedSecret.
/// </summary>
[CborMember(0x06)]
public byte[]? PinHashEnc { get; }
public byte[]? PinHashEnc { get; } = pinHashEnc;

public override CtapCommandType Type => CtapCommandType.AuthenticatorClientPin;

4 changes: 0 additions & 4 deletions Src/Fido2.Models/AuthenticatorAssertionRawResponse.cs
Original file line number Diff line number Diff line change
@@ -54,9 +54,5 @@ public sealed class AssertionResponse
[JsonPropertyName("userHandle")]
[JsonConverter(typeof(Base64UrlConverter))]
public byte[]? UserHandle { get; set; }

[JsonPropertyName("attestationObject")]
[JsonConverter(typeof(Base64UrlConverter))]
public byte[]? AttestationObject { get; set; }
}
}
49 changes: 21 additions & 28 deletions Src/Fido2.Models/CredentialCreateOptions.cs
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ public sealed class CredentialCreateOptions : Fido2ResponseBase
/// This member is intended for use by Relying Parties that wish to limit the creation of multiple credentials for the same account on a single authenticator.The client is requested to return an error if the new credential would be created on an authenticator that also contains one of the credentials enumerated in this parameter.
/// </summary>
[JsonPropertyName("excludeCredentials")]
public IReadOnlyList<PublicKeyCredentialDescriptor> ExcludeCredentials { get; set; } = Array.Empty<PublicKeyCredentialDescriptor>();
public IReadOnlyList<PublicKeyCredentialDescriptor> ExcludeCredentials { get; set; } = [];

/// <summary>
/// This OPTIONAL member contains additional parameters requesting additional processing by the client and authenticator. For example, if transaction confirmation is sought from the user, then the prompt string might be included as an extension.
@@ -85,8 +85,8 @@ public static CredentialCreateOptions Create(
Rp = new PublicKeyCredentialRpEntity(config.ServerDomain, config.ServerName, config.ServerIcon),
Timeout = config.Timeout,
User = user,
PubKeyCredParams = new List<PubKeyCredParam>(10)
{
PubKeyCredParams =
[
// Add additional as appropriate
PubKeyCredParam.Ed25519,
PubKeyCredParam.ES256,
@@ -98,7 +98,7 @@ public static CredentialCreateOptions Create(
PubKeyCredParam.ES512,
PubKeyCredParam.RS512,
PubKeyCredParam.PS512,
},
],
AuthenticatorSelection = authenticatorSelection,
Attestation = attestationConveyancePreference,
ExcludeCredentials = excludeCredentials,
@@ -119,29 +119,25 @@ public static CredentialCreateOptions FromJson(string json)

#nullable enable

public sealed class PubKeyCredParam
/// <summary>
/// Constructs a PubKeyCredParam instance
/// </summary>
[method: JsonConstructor]
public sealed class PubKeyCredParam(
COSE.Algorithm alg,
PublicKeyCredentialType type = PublicKeyCredentialType.PublicKey)
{
/// <summary>
/// Constructs a PubKeyCredParam instance
/// </summary>
[JsonConstructor]
public PubKeyCredParam(COSE.Algorithm alg, PublicKeyCredentialType type = PublicKeyCredentialType.PublicKey)
{
Type = type;
Alg = alg;
}

/// <summary>
/// The type member specifies the type of credential to be created.
/// </summary>
[JsonPropertyName("type")]
public PublicKeyCredentialType Type { get; }
public PublicKeyCredentialType Type { get; } = type;

/// <summary>
/// The alg member specifies the cryptographic signature algorithm with which the newly generated credential will be used, and thus also the type of asymmetric key pair to be generated, e.g., RSA or Elliptic Curve.
/// </summary>
[JsonPropertyName("alg")]
public COSE.Algorithm Alg { get; }
public COSE.Algorithm Alg { get; } = alg;

public static readonly PubKeyCredParam ES256 = new(COSE.Algorithm.ES256); // External authenticators support the ES256 algorithm
public static readonly PubKeyCredParam ES384 = new(COSE.Algorithm.ES384);
@@ -158,31 +154,28 @@ public PubKeyCredParam(COSE.Algorithm alg, PublicKeyCredentialType type = Public
/// <summary>
/// PublicKeyCredentialRpEntity
/// </summary>
public sealed class PublicKeyCredentialRpEntity
public sealed class PublicKeyCredentialRpEntity(
string id,
string name,
string? icon = null)
{
public PublicKeyCredentialRpEntity(string id, string name, string? icon = null)
{
Name = name;
Id = id;
Icon = icon;
}

/// <summary>
/// A unique identifier for the Relying Party entity, which sets the RP ID.
/// </summary>
[JsonPropertyName("id")]
public string Id { get; set; }
public string Id { get; set; } = id;

/// <summary>
/// A human-readable name for the entity. Its function depends on what the PublicKeyCredentialEntity represents:
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; }
public string Name { get; set; } = name;

[JsonPropertyName("icon")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Icon { get; set; }
public string? Icon { get; set; } = icon;
}

#nullable disable

/// <summary>
11 changes: 4 additions & 7 deletions Src/Fido2.Models/Fido2Configuration.cs
Original file line number Diff line number Diff line change
@@ -52,10 +52,7 @@ public IReadOnlySet<string> Origins
{
get
{
if (_origins == null)
{
_origins = new HashSet<string>(0);
}
_origins ??= new HashSet<string>(0);

return _origins;
}
@@ -91,14 +88,14 @@ public IReadOnlySet<string> FullyQualifiedOrigins
/// <summary>
/// List of metadata statuses for an authenticator that should cause attestations to be rejected.
/// </summary>
public AuthenticatorStatus[] UndesiredAuthenticatorMetadataStatuses { get; set; } = new AuthenticatorStatus[]
{
public AuthenticatorStatus[] UndesiredAuthenticatorMetadataStatuses { get; set; } =
[
AuthenticatorStatus.ATTESTATION_KEY_COMPROMISE,
AuthenticatorStatus.USER_VERIFICATION_BYPASS,
AuthenticatorStatus.USER_KEY_REMOTE_COMPROMISE,
AuthenticatorStatus.USER_KEY_PHYSICAL_COMPROMISE,
AuthenticatorStatus.REVOKED
};
];

/// <summary>
/// Whether or not to accept a backup eligible credential
2 changes: 1 addition & 1 deletion Src/Fido2.Models/Metadata/AuthenticatorStatus.cs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ namespace Fido2NetLib;
/// <remarks>
/// <see href="https://fidoalliance.org/specs/fido-v2.0-rd-20180702/fido-metadata-service-v2.0-rd-20180702.html#authenticatorstatus-enum"/>
/// </remarks>
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter<AuthenticatorStatus>))]
public enum AuthenticatorStatus
{
/// <summary>
Original file line number Diff line number Diff line change
@@ -4,20 +4,16 @@ namespace Fido2NetLib.Objects;

using System.Text.Json.Serialization;

public sealed class AuthenticationExtensionsDevicePublicKeyOutputs
[method: JsonConstructor]
public sealed class AuthenticationExtensionsDevicePublicKeyOutputs(
byte[] authenticatorOutput,
byte[] signature)
{
[JsonConstructor]
public AuthenticationExtensionsDevicePublicKeyOutputs(byte[] authenticatorOutput, byte[] signature)
{
AuthenticatorOutput = authenticatorOutput;
Signature = signature;
}

[JsonConverter(typeof(Base64UrlConverter))]
[JsonPropertyName("authenticatorOutput")]
public byte[] AuthenticatorOutput { get; }
public byte[] AuthenticatorOutput { get; } = authenticatorOutput;

[JsonConverter(typeof(Base64UrlConverter))]
[JsonPropertyName("signature")]
public byte[] Signature { get; }
public byte[] Signature { get; } = signature;
}
Original file line number Diff line number Diff line change
@@ -3,15 +3,11 @@
/// <summary>
/// Exception thrown when a new attestation comes from an authenticator with a current reported security issue.
/// </summary>
public class UndesiredMetadataStatusFido2VerificationException : Fido2VerificationException
public class UndesiredMetadataStatusFido2VerificationException(StatusReport statusReport)
: Fido2VerificationException($"Authenticator found with undesirable status. Was {statusReport.Status}")
{
public UndesiredMetadataStatusFido2VerificationException(StatusReport statusReport) : base($"Authenticator found with undesirable status. Was {statusReport.Status}")
{
StatusReport = statusReport;
}

/// <summary>
/// Status report from the authenticator that caused the attestation to be rejected.
/// </summary>
public StatusReport StatusReport { get; }
public StatusReport StatusReport { get; } = statusReport;
}
3 changes: 0 additions & 3 deletions Src/Fido2/Assembly.cs

This file was deleted.

Loading