Skip to content

Commit 61e2694

Browse files
committed
Change Id to be received as string instead of decoded
RawId is decoded to the raw byte value, while Id is the same value in base64url-encoded form.
1 parent b7f1735 commit 61e2694

8 files changed

+29
-29
lines changed

BlazorWasmDemo/Server/Controllers/UserController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public async Task<string> MakeAssertionAsync([FromBody] AuthenticatorAssertionRa
265265
_pendingAssertions.Remove(key);
266266

267267
// 2. Get registered credential from database
268-
var creds = _demoStorage.GetCredentialById(clientResponse.Id) ?? throw new Exception("Unknown credentials");
268+
var creds = _demoStorage.GetCredentialById(clientResponse.RawId) ?? throw new Exception("Unknown credentials");
269269

270270
// 3. Make the assertion
271271
var res = await _fido2.MakeAssertionAsync(new MakeAssertionParams

Demo/Controller.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public async Task<JsonResult> MakeAssertion([FromBody] AuthenticatorAssertionRaw
194194
var options = AssertionOptions.FromJson(jsonOptions);
195195

196196
// 2. Get registered credential from database
197-
var creds = DemoStorage.GetCredentialById(clientResponse.Id) ?? throw new Exception("Unknown credentials");
197+
var creds = DemoStorage.GetCredentialById(clientResponse.RawId) ?? throw new Exception("Unknown credentials");
198198

199199
// 3. Get credential counter from database
200200
var storedCounter = creds.SignCount;

Demo/TestController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public async Task<JsonResult> MakeAssertionTestAsync([FromBody] AuthenticatorAss
181181
var options = AssertionOptions.FromJson(jsonOptions);
182182

183183
// 2. Get registered credential from database
184-
var creds = _demoStorage.GetCredentialById(clientResponse.Id);
184+
var creds = _demoStorage.GetCredentialById(clientResponse.RawId);
185185

186186
// 3. Get credential counter from database
187187
var storedCounter = creds.SignCount;

Src/Fido2.Models/AuthenticatorAssertionRawResponse.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ namespace Fido2NetLib;
1212
/// </summary>
1313
public class AuthenticatorAssertionRawResponse
1414
{
15-
[JsonConverter(typeof(Base64UrlConverter))]
1615
[JsonPropertyName("id"), Required]
17-
public byte[] Id { get; init; }
16+
public string Id { get; init; }
1817

1918
// might be wrong to base64url encode this...
2019
[JsonConverter(typeof(Base64UrlConverter))]

Src/Fido2/AuthenticatorAssertionResponse.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public async Task<VerifyAssertionResult> VerifyAsync(
7777
if (options.AllowCredentials != null && options.AllowCredentials.Any())
7878
{
7979
// might need to transform x.Id and raw.id as described in https://www.w3.org/TR/webauthn/#publickeycredential
80-
if (!options.AllowCredentials.Any(x => x.Id.SequenceEqual(Raw.Id)))
80+
if (!options.AllowCredentials.Any(x => x.Id.SequenceEqual(Raw.RawId)))
8181
throw new Fido2VerificationException(Fido2ErrorCode.InvalidAssertionResponse, Fido2ErrorMessages.CredentialIdNotInAllowedCredentials);
8282
}
8383

@@ -87,7 +87,7 @@ public async Task<VerifyAssertionResult> VerifyAsync(
8787
if (UserHandle.Length is 0)
8888
throw new Fido2VerificationException(Fido2ErrorMessages.UserHandleIsEmpty);
8989

90-
if (await isUserHandleOwnerOfCredId(new IsUserHandleOwnerOfCredentialIdParams(Raw.Id, UserHandle), cancellationToken) is false)
90+
if (await isUserHandleOwnerOfCredId(new IsUserHandleOwnerOfCredentialIdParams(Raw.RawId, UserHandle), cancellationToken) is false)
9191
{
9292
throw new Fido2VerificationException(Fido2ErrorCode.InvalidAssertionResponse, Fido2ErrorMessages.UserHandleNotOwnerOfPublicKey);
9393
}
@@ -177,7 +177,7 @@ public async Task<VerifyAssertionResult> VerifyAsync(
177177

178178
return new VerifyAssertionResult
179179
{
180-
CredentialId = Raw.Id,
180+
CredentialId = Raw.RawId,
181181
SignCount = authData.SignCount,
182182
IsBackedUp = authData.IsBackedUp
183183

Tests/Fido2.Tests/AuthenticatorResponse.cs

+18-18
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ public void TestAuthenticatorAssertionRawResponse()
12751275
{
12761276
Response = assertion,
12771277
Type = PublicKeyCredentialType.PublicKey,
1278-
Id = [0xf1, 0xd0],
1278+
Id = "8dA",
12791279
RawId = [0xf1, 0xd0],
12801280
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
12811281
{
@@ -1301,7 +1301,7 @@ public void TestAuthenticatorAssertionRawResponse()
13011301
}
13021302
};
13031303
Assert.Equal(PublicKeyCredentialType.PublicKey, assertionResponse.Type);
1304-
Assert.Equal([0xf1, 0xd0], assertionResponse.Id);
1304+
Assert.Equal("8dA", assertionResponse.Id);
13051305
Assert.Equal([0xf1, 0xd0], assertionResponse.RawId);
13061306
Assert.Equal([0xf1, 0xd0], assertionResponse.Response.AuthenticatorData);
13071307
Assert.Equal([0xf1, 0xd0], assertionResponse.Response.Signature);
@@ -1352,7 +1352,7 @@ public async Task TestAuthenticatorAssertionTypeNotPublicKey()
13521352
{
13531353
Response = assertion,
13541354
Type = PublicKeyCredentialType.Invalid,
1355-
Id = [0xf1, 0xd0],
1355+
Id = "8dA",
13561356
RawId = [0xf1, 0xd0],
13571357
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
13581358
{
@@ -1504,7 +1504,7 @@ public async Task TestAuthenticatorAssertionRawIdMissing()
15041504
{
15051505
Response = assertion,
15061506
Type = PublicKeyCredentialType.PublicKey,
1507-
Id = [0xf1, 0xd0],
1507+
Id = "8dA",
15081508
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
15091509
{
15101510
AppID = false,
@@ -1579,7 +1579,7 @@ public async Task TestAuthenticatorAssertionUserHandleEmpty()
15791579
{
15801580
Response = assertion,
15811581
Type = PublicKeyCredentialType.PublicKey,
1582-
Id = [0xf1, 0xd0],
1582+
Id = "8dA",
15831583
RawId = [0xf1, 0xd0],
15841584
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
15851585
{
@@ -1655,7 +1655,7 @@ public async Task TestAuthenticatorAssertionUserHandleNotOwnerOfPublicKey()
16551655
{
16561656
Response = assertion,
16571657
Type = PublicKeyCredentialType.PublicKey,
1658-
Id = [0xf1, 0xd0],
1658+
Id = "8dA",
16591659
RawId = [0xf1, 0xd0],
16601660
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
16611661
{
@@ -1731,7 +1731,7 @@ public async Task TestAuthenticatorAssertionTypeNotWebAuthnGet()
17311731
{
17321732
Response = assertion,
17331733
Type = PublicKeyCredentialType.PublicKey,
1734-
Id = [0xf1, 0xd0],
1734+
Id = "8dA",
17351735
RawId = [0xf1, 0xd0],
17361736
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
17371737
{
@@ -1809,7 +1809,7 @@ public async Task TestAuthenticatorAssertionAppId()
18091809
{
18101810
Response = assertion,
18111811
Type = PublicKeyCredentialType.PublicKey,
1812-
Id = [0xf1, 0xd0],
1812+
Id = "8dA",
18131813
RawId = [0xf1, 0xd0],
18141814
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
18151815
{
@@ -1886,7 +1886,7 @@ public async Task TestAuthenticatorAssertionInvalidRpIdHash()
18861886
{
18871887
Response = assertion,
18881888
Type = PublicKeyCredentialType.PublicKey,
1889-
Id = [0xf1, 0xd0],
1889+
Id = "8dA",
18901890
RawId = [0xf1, 0xd0],
18911891
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
18921892
{
@@ -1964,7 +1964,7 @@ public async Task TestAuthenticatorAssertionUPRequirementNotMet()
19641964
{
19651965
Response = assertion,
19661966
Type = PublicKeyCredentialType.PublicKey,
1967-
Id = [0xf1, 0xd0],
1967+
Id = "8dA",
19681968
RawId = [0xf1, 0xd0],
19691969
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
19701970
{
@@ -2041,7 +2041,7 @@ public async Task TestAuthenticatorAssertionUVPolicyNotMet()
20412041
{
20422042
Response = assertion,
20432043
Type = PublicKeyCredentialType.PublicKey,
2044-
Id = [0xf1, 0xd0],
2044+
Id = "8dA",
20452045
RawId = [0xf1, 0xd0],
20462046
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
20472047
{
@@ -2116,7 +2116,7 @@ public async Task TestAuthenticatorAssertionBEPolicyRequired()
21162116
{
21172117
Response = assertion,
21182118
Type = PublicKeyCredentialType.PublicKey,
2119-
Id = [0xf1, 0xd0],
2119+
Id = "8dA",
21202120
RawId = [0xf1, 0xd0],
21212121
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
21222122
{
@@ -2192,7 +2192,7 @@ public async Task TestAuthenticatorAssertionBEPolicyDisallow()
21922192
{
21932193
Response = assertion,
21942194
Type = PublicKeyCredentialType.PublicKey,
2195-
Id = [0xf1, 0xd0],
2195+
Id = "8dA",
21962196
RawId = [0xf1, 0xd0],
21972197
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
21982198
{
@@ -2268,7 +2268,7 @@ public async Task TestAuthenticatorAssertionBSPolicyRequired()
22682268
{
22692269
Response = assertion,
22702270
Type = PublicKeyCredentialType.PublicKey,
2271-
Id = [0xf1, 0xd0],
2271+
Id = "8dA",
22722272
RawId = [0xf1, 0xd0],
22732273
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
22742274
{
@@ -2344,7 +2344,7 @@ public async Task TestAuthenticatorAssertionBSPolicyDisallow()
23442344
{
23452345
Response = assertion,
23462346
Type = PublicKeyCredentialType.PublicKey,
2347-
Id = [0xf1, 0xd0],
2347+
Id = "8dA",
23482348
RawId = [0xf1, 0xd0],
23492349
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
23502350
{
@@ -2421,7 +2421,7 @@ public async Task TestAuthenticatorAssertionStoredPublicKeyMissing()
24212421
{
24222422
Response = assertion,
24232423
Type = PublicKeyCredentialType.PublicKey,
2424-
Id = [0xf1, 0xd0],
2424+
Id = "8dA",
24252425
RawId = [0xf1, 0xd0],
24262426
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
24272427
{
@@ -2497,7 +2497,7 @@ public async Task TestAuthenticatorAssertionInvalidSignature()
24972497
{
24982498
Response = assertion,
24992499
Type = PublicKeyCredentialType.PublicKey,
2500-
Id = [0xf1, 0xd0],
2500+
Id = "8dA",
25012501
RawId = [0xf1, 0xd0],
25022502
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
25032503
{
@@ -2580,7 +2580,7 @@ public async Task TestAuthenticatorAssertionSignCountSignature()
25802580
{
25812581
Response = assertion,
25822582
Type = PublicKeyCredentialType.PublicKey,
2583-
Id = [0xf1, 0xd0],
2583+
Id = "8dA",
25842584
RawId = [0xf1, 0xd0],
25852585
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
25862586
{

Tests/Fido2.Tests/ExistingU2fRegistrationDataTests.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public async Task TestFido2AssertionWithExistingU2fRegistrationWithAppId()
1414
{
1515
// u2f registration with appId
1616
var appId = "https://localhost:44336";
17-
var keyHandleData = Base64Url.DecodeFromChars("2uzGTqu9XGoDQpRBhkv3qDYWzEEZrDjOHT94fHe3J9VXl6KpaY6jL1C4gCAVSBCWZejOn-EYSyXfiG7RDQqgKw");
17+
var keyHandleB64Data = "2uzGTqu9XGoDQpRBhkv3qDYWzEEZrDjOHT94fHe3J9VXl6KpaY6jL1C4gCAVSBCWZejOn-EYSyXfiG7RDQqgKw";
18+
var keyHandleData = Base64Url.DecodeFromChars(keyHandleB64Data);
1819
var publicKeyData = Base64Url.DecodeFromChars("BEKJkJiDzo8wlrYbAHmyz5a5vShbkStO58ZO7F-hy4fvBp6TowCZoV2dNGcxIN1yT18799bb_WuP0Yq_DSv5a-U");
1920

2021
//key as cbor
@@ -36,7 +37,7 @@ public async Task TestFido2AssertionWithExistingU2fRegistrationWithAppId()
3637

3738
var authResponse = new AuthenticatorAssertionRawResponse
3839
{
39-
Id = keyHandleData,
40+
Id = keyHandleB64Data,
4041
RawId = keyHandleData,
4142
Type = PublicKeyCredentialType.PublicKey,
4243
ClientExtensionResults = new AuthenticationExtensionsClientOutputs

Tests/Fido2.Tests/Fido2Tests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ internal static async Task<VerifyAssertionResult> MakeAssertionResponseAsync(
987987
{
988988
Response = assertion,
989989
Type = PublicKeyCredentialType.PublicKey,
990-
Id = [0xf1, 0xd0],
990+
Id = "8dA",
991991
RawId = [0xf1, 0xd0],
992992
};
993993
IsUserHandleOwnerOfCredentialIdAsync callback = (args, cancellationToken) =>

0 commit comments

Comments
 (0)