Skip to content

Commit

Permalink
Rename 'extensions' to 'clientExtensionResults' for deserialization (#…
Browse files Browse the repository at this point in the history
…474)

* Rename 'extensions' to 'clientExtensionResults' for deserialization during registration.

* fix
  • Loading branch information
jonashendrickx authored Jan 4, 2024
1 parent d847702 commit 31a4f94
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 30 deletions.
10 changes: 9 additions & 1 deletion Src/Fido2.Models/AuthenticatorAssertionRawResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ public class AuthenticatorAssertionRawResponse
public PublicKeyCredentialType? Type { get; set; }

[JsonPropertyName("extensions")]
public AuthenticationExtensionsClientOutputs Extensions { get; set; }
[Obsolete("Use ClientExtensionResults instead")]
public AuthenticationExtensionsClientOutputs Extensions
{
get => ClientExtensionResults;
set => ClientExtensionResults = value;
}

[JsonPropertyName("clientExtensionResults")]
public AuthenticationExtensionsClientOutputs ClientExtensionResults { get; set; }

public sealed class AssertionResponse
{
Expand Down
6 changes: 3 additions & 3 deletions Src/Fido2/AuthenticatorAssertionResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public async Task<VerifyAssertionResult> VerifyAsync(
// https://www.w3.org/TR/webauthn/#sctn-appid-extension
// FIDO AppID Extension:
// If true, the AppID was used and thus, when verifying an assertion, the Relying Party MUST expect the rpIdHash to be the hash of the AppID, not the RP ID.
var rpid = Raw.Extensions?.AppID ?? false ? options.Extensions?.AppID : options.RpId;
var rpid = Raw.ClientExtensionResults?.AppID ?? false ? options.Extensions?.AppID : options.RpId;
byte[] hashedRpId = SHA256.HashData(Encoding.UTF8.GetBytes(rpid ?? string.Empty));
byte[] hash = SHA256.HashData(Raw.Response.ClientDataJson);

Expand Down Expand Up @@ -144,9 +144,9 @@ public async Task<VerifyAssertionResult> VerifyAsync(
// considering the client extension input values that were given in options.extensions and any specific policy of the Relying Party regarding unsolicited extensions,
// i.e., those that were not specified as part of options.extensions. In the general case, the meaning of "are as expected" is specific to the Relying Party and which extensions are in use.
byte[]? devicePublicKeyResult = null;
if (Raw.Extensions?.DevicePubKey is not null)
if (Raw.ClientExtensionResults?.DevicePubKey is not null)
{
devicePublicKeyResult = await DevicePublicKeyAuthenticationAsync(storedDevicePublicKeys, Raw.Extensions, AuthenticatorData, hash).ConfigureAwait(false);
devicePublicKeyResult = await DevicePublicKeyAuthenticationAsync(storedDevicePublicKeys, Raw.ClientExtensionResults, AuthenticatorData, hash).ConfigureAwait(false);
}

// Pretty sure these conditions are not able to be met due to the AuthenticatorData constructor implementation
Expand Down
50 changes: 25 additions & 25 deletions Test/AuthenticatorResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ public void TestAuthenticatorAssertionRawResponse()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
{
AppID = true,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -1264,13 +1264,13 @@ public void TestAuthenticatorAssertionRawResponse()
Assert.Equal(new byte[] { 0xf1, 0xd0 }, assertionResponse.Response.Signature);
Assert.Equal(clientDataJson, assertionResponse.Response.ClientDataJson);
Assert.Equal(new byte[] { 0xf1, 0xd0 }, assertionResponse.Response.UserHandle);
Assert.True(assertionResponse.Extensions.AppID);
Assert.Equal(new string[] { "foo", "bar" }, assertionResponse.Extensions.Extensions);
Assert.Equal("test", assertionResponse.Extensions.Example);
Assert.Equal((ulong)4, assertionResponse.Extensions.UserVerificationMethod[0][0]);
Assert.True(assertionResponse.Extensions.PRF.Enabled);
Assert.Equal(new byte[] { 0xf1, 0xd0 }, assertionResponse.Extensions.PRF.Results.First);
Assert.Equal(new byte[] { 0xf1, 0xd0 }, assertionResponse.Extensions.PRF.Results.Second);
Assert.True(assertionResponse.ClientExtensionResults.AppID);
Assert.Equal(new string[] { "foo", "bar" }, assertionResponse.ClientExtensionResults.Extensions);
Assert.Equal("test", assertionResponse.ClientExtensionResults.Example);
Assert.Equal((ulong)4, assertionResponse.ClientExtensionResults.UserVerificationMethod[0][0]);
Assert.True(assertionResponse.ClientExtensionResults.PRF.Enabled);
Assert.Equal(new byte[] { 0xf1, 0xd0 }, assertionResponse.ClientExtensionResults.PRF.Results.First);
Assert.Equal(new byte[] { 0xf1, 0xd0 }, assertionResponse.ClientExtensionResults.PRF.Results.Second);
}

[Fact]
Expand Down Expand Up @@ -1310,7 +1310,7 @@ public async Task TestAuthenticatorAssertionTypeNotPublicKey()
Type = PublicKeyCredentialType.Invalid,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -1378,7 +1378,7 @@ public async Task TestAuthenticatorAssertionIdMissing()
Response = assertion,
Type = PublicKeyCredentialType.PublicKey,
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -1447,7 +1447,7 @@ public async Task TestAuthenticatorAssertionRawIdMissing()
Response = assertion,
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs()
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -1516,7 +1516,7 @@ public async Task TestAuthenticatorAssertionUserHandleEmpty()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs()
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -1585,7 +1585,7 @@ public async Task TestAuthenticatorAssertionUserHandleNotOwnerOfPublicKey()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs()
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -1654,7 +1654,7 @@ public async Task TestAuthenticatorAssertionTypeNotWebAuthnGet()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -1725,7 +1725,7 @@ public async Task TestAuthenticatorAssertionAppId()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs()
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
{
AppID = true,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -1795,7 +1795,7 @@ public async Task TestAuthenticatorAssertionInvalidRpIdHash()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs()
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -1866,7 +1866,7 @@ public async Task TestAuthenticatorAssertionUPRequirementNotMet()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -1936,7 +1936,7 @@ public async Task TestAuthenticatorAssertionUVPolicyNotMet()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -2004,7 +2004,7 @@ public async Task TestAuthenticatorAssertionBEPolicyRequired()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs()
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -2073,7 +2073,7 @@ public async Task TestAuthenticatorAssertionBEPolicyDisallow()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -2142,7 +2142,7 @@ public async Task TestAuthenticatorAssertionBSPolicyRequired()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -2211,7 +2211,7 @@ public async Task TestAuthenticatorAssertionBSPolicyDisallow()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -2281,7 +2281,7 @@ public async Task TestAuthenticatorAssertionStoredPublicKeyMissing()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs()
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -2350,7 +2350,7 @@ public async Task TestAuthenticatorAssertionInvalidSignature()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs()
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down Expand Up @@ -2426,7 +2426,7 @@ public async Task TestAuthenticatorAssertionSignCountSignature()
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Extensions = new AuthenticationExtensionsClientOutputs()
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
{
AppID = false,
Extensions = new string[] { "foo", "bar" },
Expand Down
2 changes: 1 addition & 1 deletion Test/ExistingU2fRegistrationDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task TestFido2AssertionWithExistingU2fRegistrationWithAppId()
Id = keyHandleData,
RawId = keyHandleData,
Type = PublicKeyCredentialType.PublicKey,
Extensions = new AuthenticationExtensionsClientOutputs
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
{
AppID = true
},
Expand Down

0 comments on commit 31a4f94

Please sign in to comment.