Skip to content

Commit 71291eb

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. passwordless-lib#513
1 parent 9ad038b commit 71291eb

8 files changed

+29
-29
lines changed

BlazorWasmDemo/Server/Controllers/UserController.cs

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

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

273273
// 3. Make the assertion
274274
var res = await _fido2.MakeAssertionAsync(

Demo/Controller.cs

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

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

197197
// 3. Get credential counter from database
198198
var storedCounter = creds.SignCount;

Demo/TestController.cs

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

156156
// 2. Get registered credential from database
157-
var creds = _demoStorage.GetCredentialById(clientResponse.Id);
157+
var creds = _demoStorage.GetCredentialById(clientResponse.RawId);
158158

159159
// 3. Get credential counter from database
160160
var storedCounter = creds.SignCount;

Src/Fido2.Models/AuthenticatorAssertionRawResponse.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ namespace Fido2NetLib;
1111
/// </summary>
1212
public class AuthenticatorAssertionRawResponse
1313
{
14-
[JsonConverter(typeof(Base64UrlConverter))]
1514
[JsonPropertyName("id")]
16-
public byte[] Id { get; set; }
15+
public string Id { get; set; }
1716

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

Src/Fido2/AuthenticatorAssertionResponse.cs

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

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

91-
if (await isUserHandleOwnerOfCredId(new IsUserHandleOwnerOfCredentialIdParams(Raw.Id, UserHandle), cancellationToken) is false)
91+
if (await isUserHandleOwnerOfCredId(new IsUserHandleOwnerOfCredentialIdParams(Raw.RawId, UserHandle), cancellationToken) is false)
9292
{
9393
throw new Fido2VerificationException(Fido2ErrorCode.InvalidAssertionResponse, Fido2ErrorMessages.UserHandleNotOwnerOfPublicKey);
9494
}
@@ -177,7 +177,7 @@ public async Task<VerifyAssertionResult> VerifyAsync(
177177
return new VerifyAssertionResult
178178
{
179179
Status = "ok",
180-
CredentialId = Raw.Id,
180+
CredentialId = Raw.RawId,
181181
SignCount = authData.SignCount,
182182
IsBackedUp = authData.IsBackedUp,
183183
DevicePublicKey = devicePublicKeyResult,

Test/AuthenticatorResponse.cs

+18-18
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ public void TestAuthenticatorAssertionRawResponse()
12321232
{
12331233
Response = assertion,
12341234
Type = PublicKeyCredentialType.PublicKey,
1235-
Id = [0xf1, 0xd0],
1235+
Id = "8dA",
12361236
RawId = [0xf1, 0xd0],
12371237
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
12381238
{
@@ -1258,7 +1258,7 @@ public void TestAuthenticatorAssertionRawResponse()
12581258
}
12591259
};
12601260
Assert.Equal(PublicKeyCredentialType.PublicKey, assertionResponse.Type);
1261-
Assert.Equal([0xf1, 0xd0], assertionResponse.Id);
1261+
Assert.Equal("8dA", assertionResponse.Id);
12621262
Assert.Equal([0xf1, 0xd0], assertionResponse.RawId);
12631263
Assert.Equal([0xf1, 0xd0], assertionResponse.Response.AuthenticatorData);
12641264
Assert.Equal([0xf1, 0xd0], assertionResponse.Response.Signature);
@@ -1308,7 +1308,7 @@ public async Task TestAuthenticatorAssertionTypeNotPublicKey()
13081308
{
13091309
Response = assertion,
13101310
Type = PublicKeyCredentialType.Invalid,
1311-
Id = [0xf1, 0xd0],
1311+
Id = "8dA",
13121312
RawId = [0xf1, 0xd0],
13131313
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
13141314
{
@@ -1446,7 +1446,7 @@ public async Task TestAuthenticatorAssertionRawIdMissing()
14461446
{
14471447
Response = assertion,
14481448
Type = PublicKeyCredentialType.PublicKey,
1449-
Id = [0xf1, 0xd0],
1449+
Id = "8dA",
14501450
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
14511451
{
14521452
AppID = false,
@@ -1514,7 +1514,7 @@ public async Task TestAuthenticatorAssertionUserHandleEmpty()
15141514
{
15151515
Response = assertion,
15161516
Type = PublicKeyCredentialType.PublicKey,
1517-
Id = [0xf1, 0xd0],
1517+
Id = "8dA",
15181518
RawId = [0xf1, 0xd0],
15191519
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
15201520
{
@@ -1583,7 +1583,7 @@ public async Task TestAuthenticatorAssertionUserHandleNotOwnerOfPublicKey()
15831583
{
15841584
Response = assertion,
15851585
Type = PublicKeyCredentialType.PublicKey,
1586-
Id = [0xf1, 0xd0],
1586+
Id = "8dA",
15871587
RawId = [0xf1, 0xd0],
15881588
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
15891589
{
@@ -1652,7 +1652,7 @@ public async Task TestAuthenticatorAssertionTypeNotWebAuthnGet()
16521652
{
16531653
Response = assertion,
16541654
Type = PublicKeyCredentialType.PublicKey,
1655-
Id = [0xf1, 0xd0],
1655+
Id = "8dA",
16561656
RawId = [0xf1, 0xd0],
16571657
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
16581658
{
@@ -1723,7 +1723,7 @@ public async Task TestAuthenticatorAssertionAppId()
17231723
{
17241724
Response = assertion,
17251725
Type = PublicKeyCredentialType.PublicKey,
1726-
Id = [0xf1, 0xd0],
1726+
Id = "8dA",
17271727
RawId = [0xf1, 0xd0],
17281728
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
17291729
{
@@ -1793,7 +1793,7 @@ public async Task TestAuthenticatorAssertionInvalidRpIdHash()
17931793
{
17941794
Response = assertion,
17951795
Type = PublicKeyCredentialType.PublicKey,
1796-
Id = [0xf1, 0xd0],
1796+
Id = "8dA",
17971797
RawId = [0xf1, 0xd0],
17981798
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
17991799
{
@@ -1864,7 +1864,7 @@ public async Task TestAuthenticatorAssertionUPRequirementNotMet()
18641864
{
18651865
Response = assertion,
18661866
Type = PublicKeyCredentialType.PublicKey,
1867-
Id = [0xf1, 0xd0],
1867+
Id = "8dA",
18681868
RawId = [0xf1, 0xd0],
18691869
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
18701870
{
@@ -1934,7 +1934,7 @@ public async Task TestAuthenticatorAssertionUVPolicyNotMet()
19341934
{
19351935
Response = assertion,
19361936
Type = PublicKeyCredentialType.PublicKey,
1937-
Id = [0xf1, 0xd0],
1937+
Id = "8dA",
19381938
RawId = [0xf1, 0xd0],
19391939
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
19401940
{
@@ -2002,7 +2002,7 @@ public async Task TestAuthenticatorAssertionBEPolicyRequired()
20022002
{
20032003
Response = assertion,
20042004
Type = PublicKeyCredentialType.PublicKey,
2005-
Id = [0xf1, 0xd0],
2005+
Id = "8dA",
20062006
RawId = [0xf1, 0xd0],
20072007
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
20082008
{
@@ -2071,7 +2071,7 @@ public async Task TestAuthenticatorAssertionBEPolicyDisallow()
20712071
{
20722072
Response = assertion,
20732073
Type = PublicKeyCredentialType.PublicKey,
2074-
Id = [0xf1, 0xd0],
2074+
Id = "8dA",
20752075
RawId = [0xf1, 0xd0],
20762076
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
20772077
{
@@ -2140,7 +2140,7 @@ public async Task TestAuthenticatorAssertionBSPolicyRequired()
21402140
{
21412141
Response = assertion,
21422142
Type = PublicKeyCredentialType.PublicKey,
2143-
Id = [0xf1, 0xd0],
2143+
Id = "8dA",
21442144
RawId = [0xf1, 0xd0],
21452145
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
21462146
{
@@ -2209,7 +2209,7 @@ public async Task TestAuthenticatorAssertionBSPolicyDisallow()
22092209
{
22102210
Response = assertion,
22112211
Type = PublicKeyCredentialType.PublicKey,
2212-
Id = [0xf1, 0xd0],
2212+
Id = "8dA",
22132213
RawId = [0xf1, 0xd0],
22142214
ClientExtensionResults = new AuthenticationExtensionsClientOutputs
22152215
{
@@ -2279,7 +2279,7 @@ public async Task TestAuthenticatorAssertionStoredPublicKeyMissing()
22792279
{
22802280
Response = assertion,
22812281
Type = PublicKeyCredentialType.PublicKey,
2282-
Id = [0xf1, 0xd0],
2282+
Id = "8dA",
22832283
RawId = [0xf1, 0xd0],
22842284
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
22852285
{
@@ -2348,7 +2348,7 @@ public async Task TestAuthenticatorAssertionInvalidSignature()
23482348
{
23492349
Response = assertion,
23502350
Type = PublicKeyCredentialType.PublicKey,
2351-
Id = [0xf1, 0xd0],
2351+
Id = "8dA",
23522352
RawId = [0xf1, 0xd0],
23532353
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
23542354
{
@@ -2424,7 +2424,7 @@ public async Task TestAuthenticatorAssertionSignCountSignature()
24242424
{
24252425
Response = assertion,
24262426
Type = PublicKeyCredentialType.PublicKey,
2427-
Id = [0xf1, 0xd0],
2427+
Id = "8dA",
24282428
RawId = [0xf1, 0xd0],
24292429
ClientExtensionResults = new AuthenticationExtensionsClientOutputs()
24302430
{

Test/ExistingU2fRegistrationDataTests.cs

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

1920
//key as cbor
@@ -35,7 +36,7 @@ public async Task TestFido2AssertionWithExistingU2fRegistrationWithAppId()
3536

3637
var authResponse = new AuthenticatorAssertionRawResponse
3738
{
38-
Id = keyHandleData,
39+
Id = keyHandleB64Data,
3940
RawId = keyHandleData,
4041
Type = PublicKeyCredentialType.PublicKey,
4142
ClientExtensionResults = new AuthenticationExtensionsClientOutputs

Test/Fido2Tests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ internal static async Task<VerifyAssertionResult> MakeAssertionResponseAsync(
921921
{
922922
Response = assertion,
923923
Type = PublicKeyCredentialType.PublicKey,
924-
Id = [0xf1, 0xd0],
924+
Id = "8dA",
925925
RawId = [0xf1, 0xd0],
926926
};
927927
IsUserHandleOwnerOfCredentialIdAsync callback = (args, cancellationToken) =>

0 commit comments

Comments
 (0)