Skip to content

Commit 826d448

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 826d448

10 files changed

+57
-52
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

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ namespace Fido2NetLib;
1212
/// </summary>
1313
public class AuthenticatorAssertionRawResponse
1414
{
15-
[JsonConverter(typeof(Base64UrlConverter))]
15+
/// <summary>
16+
/// A string containing the credential's identifier. Base64UrlEncoding of <seealso cref="RawId"/>.
17+
/// </summary>
1618
[JsonPropertyName("id"), Required]
17-
public byte[] Id { get; init; }
19+
public string Id { get; init; }
1820

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

Src/Fido2.Models/AuthenticatorAttestationRawResponse.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ namespace Fido2NetLib;
77

88
public sealed class AuthenticatorAttestationRawResponse
99
{
10-
[JsonConverter(typeof(Base64UrlConverter))]
10+
/// <summary>
11+
/// A string containing the credential's identifier. Base64UrlEncoding of <seealso cref="RawId"/>.
12+
/// </summary>
1113
[JsonPropertyName("id"), Required]
12-
public byte[] Id { get; init; }
14+
public string Id { get; init; }
1315

1416
[JsonConverter(typeof(Base64UrlConverter))]
1517
[JsonPropertyName("rawId"), Required]

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/Attestation/Apple.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public async Task TestApplePublicKeyMismatch()
224224
var attestationResponse = new AuthenticatorAttestationRawResponse
225225
{
226226
Type = PublicKeyCredentialType.PublicKey,
227-
Id = [0xf1, 0xd0],
227+
Id = "8dA",
228228
RawId = [0xf1, 0xd0],
229229
Response = new AuthenticatorAttestationRawResponse.AttestationResponse
230230
{

0 commit comments

Comments
 (0)