Heimdall-backed members enrol WebAuthn passkeys on the Linked accounts page (ticket from a fresh ordinary Heimdall sign-in, 48 h cooling-off, cap 5, FixedWindowBudget on ceremonies) and unlink with a strong passkey: the assertion is verified at Bifrost, then inside the completion that holds the bearer Bifrost calls Heimdall's POST /v1/apps/bifrost/step-up and the unlink with the returned token. The Google step-up closes once a strong passkey exists. Migration AddPasskeyCredentials is additive. Tests use a software authenticator and a fake Heimdall step-up route modeled on the contract. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
48 lines
1.8 KiB
C#
48 lines
1.8 KiB
C#
using Bifrost.Web.Configuration;
|
|
using Fido2NetLib;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Bifrost.Web.Features.Passkeys;
|
|
|
|
/// <summary>
|
|
/// The relying party every passkey ceremony runs as. RP ID and origin come from <see cref="BifrostHostOptions"/> and from
|
|
/// nothing the browser sends: the public base URL must be https and its host must be the expected host, otherwise passkeys
|
|
/// are unavailable (the page offers none and every ceremony endpoint refuses). A passkey is bound to the RP ID by the
|
|
/// authenticator, so a wrong or http origin would enrol keys that cannot be used or can be phished.
|
|
/// </summary>
|
|
public sealed class PasskeyRelyingParty
|
|
{
|
|
public const string Name = "Bifrost";
|
|
|
|
public PasskeyRelyingParty(IOptions<BifrostHostOptions> hostOptions, ILogger<PasskeyRelyingParty> logger)
|
|
{
|
|
var host = hostOptions.Value;
|
|
if (!Uri.TryCreate(host.PublicBaseUrl, UriKind.Absolute, out var url)
|
|
|| url.Scheme != Uri.UriSchemeHttps
|
|
|| string.IsNullOrWhiteSpace(host.ExpectedHost)
|
|
|| !string.Equals(url.Host, host.ExpectedHost, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
logger.LogWarning("Passkeys are unavailable: Host:PublicBaseUrl must be https and its host must equal Host:ExpectedHost.");
|
|
return;
|
|
}
|
|
|
|
Origin = url.GetLeftPart(UriPartial.Authority);
|
|
RpId = url.Host.ToLowerInvariant();
|
|
Fido2 = new Fido2(new Fido2Configuration
|
|
{
|
|
RPID = RpId,
|
|
RPName = Name,
|
|
Origins = new HashSet<string>([Origin], StringComparer.Ordinal),
|
|
ChallengeSize = 32,
|
|
Timeout = 120_000
|
|
});
|
|
}
|
|
|
|
public bool IsAvailable => Fido2 is not null;
|
|
|
|
public string? Origin { get; }
|
|
|
|
public string? RpId { get; }
|
|
|
|
public IFido2? Fido2 { get; }
|
|
}
|