Skip to content

Commit e8c1b41

Browse files
Regenhardtabergs
andauthored
Change Id to be received as string instead of decoded (#586)
RawId is decoded to the raw byte value, while Id is the same value in base64url-encoded form. Co-authored-by: Anders Åberg <[email protected]>
1 parent b54892b commit e8c1b41

File tree

10 files changed

+57
-52
lines changed

10 files changed

+57
-52
lines changed

BlazorWasmDemo/Server/Controllers/UserController.cs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ namespace Fido2NetLib;
99

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

1618
[JsonConverter(typeof(Base64UrlConverter))]
1719
[JsonPropertyName("rawId"), Required]

Src/Fido2/AuthenticatorAssertionResponse.cs

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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)