Skip to content

Commit bb187c7

Browse files
committed
PR feedback
1 parent 65e6a37 commit bb187c7

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/Identity/Core/src/DefaultPasskeyHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private async Task<PasskeyAttestationResult> PerformAttestationCoreAsync(
117117
}
118118

119119
// 8. Verify that the value of clientData.challenge equals the base64url encoding of pkOptions.challenge.
120-
if (!clientData.Challenge.Equals(originalOptions.Challenge))
120+
if (!clientData.Challenge.FixedTimeEquals(originalOptions.Challenge))
121121
{
122122
throw PasskeyException.InvalidChallenge();
123123
}
@@ -162,7 +162,7 @@ private async Task<PasskeyAttestationResult> PerformAttestationCoreAsync(
162162

163163
// 14. Verify that the rpIdHash in authenticatorData is the SHA-256 hash of the RP ID expected by the Relying Party.
164164
var rpIdHash = SHA256.HashData(Encoding.UTF8.GetBytes(originalOptions.Rp.Id ?? string.Empty));
165-
if (!authenticatorData.RpIdHash.Span.SequenceEqual(rpIdHash.AsSpan()))
165+
if (!CryptographicOperations.FixedTimeEquals(authenticatorData.RpIdHash.Span, rpIdHash.AsSpan()))
166166
{
167167
throw PasskeyException.InvalidRelyingPartyIDHash();
168168
}
@@ -373,7 +373,7 @@ private async Task<PasskeyAssertionResult<TUser>> PerformAssertionCoreAsync(
373373
}
374374

375375
// 11. Verify that the value of C.challenge equals the base64url encoding of originalOptions.challenge.
376-
if (!clientData.Challenge.Equals(originalOptions.Challenge))
376+
if (!clientData.Challenge.FixedTimeEquals(originalOptions.Challenge))
377377
{
378378
throw PasskeyException.InvalidChallenge();
379379
}
@@ -403,7 +403,7 @@ private async Task<PasskeyAssertionResult<TUser>> PerformAssertionCoreAsync(
403403

404404
// 15. Verify that the rpIdHash in authData is the SHA-256 hash of the RP ID expected by the Relying Party.
405405
var rpIdHash = SHA256.HashData(Encoding.UTF8.GetBytes(originalOptions.RpId ?? string.Empty));
406-
if (!authenticatorData.RpIdHash.Span.SequenceEqual(rpIdHash.AsSpan()))
406+
if (!CryptographicOperations.FixedTimeEquals(authenticatorData.RpIdHash.Span, rpIdHash.AsSpan()))
407407
{
408408
throw PasskeyException.InvalidRelyingPartyIDHash();
409409
}

src/Identity/Core/src/Passkeys/BufferSource.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Linq;
5+
using System.Security.Cryptography;
56
using System.Text;
67
using System.Text.Json.Serialization;
78

@@ -77,6 +78,15 @@ public bool Equals(BufferSource? other)
7778
return other is not null && _bytes.Span.SequenceEqual(other._bytes.Span);
7879
}
7980

81+
/// <summary>
82+
/// Performs a fixed-time value-based equality comparison with another <see cref="BufferSource"/> instance
83+
/// using <see cref="CryptographicOperations.FixedTimeEquals"/>.
84+
/// </summary>
85+
public bool FixedTimeEquals(BufferSource? other)
86+
{
87+
return other is not null && CryptographicOperations.FixedTimeEquals(_bytes.Span, other._bytes.Span);
88+
}
89+
8090
/// <inheritdoc/>
8191
public override bool Equals(object? obj)
8292
=> obj is BufferSource other && Equals(other);

src/Identity/Core/src/SignInManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ private void ThrowIfNoPasskeyHandler()
522522
}
523523

524524
/// <summary>
525-
/// Attempts to sign in the user with a passkey, as an asynchronous operation.
525+
/// Attempts to sign in the user with a passkey.
526526
/// </summary>
527527
/// <param name="credentialJson">The credentials obtained by JSON-serializing the result of the <c>navigator.credentials.get()</c> JavaScript function.</param>
528528
/// <param name="options">The original passkey request options provided to the browser.</param>

0 commit comments

Comments
 (0)