Skip to content

Commit

Permalink
Use dynamic RP ID (#2746)
Browse files Browse the repository at this point in the history
* Use dynamic RP ID

* CR review changes
  • Loading branch information
lmuntaner authored Dec 13, 2024
1 parent 860baae commit 411ed8a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/frontend/src/utils/multiWebAuthnIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
* then we know which one the user is actually using
* - It doesn't support creating credentials; use `WebAuthnIdentity` for that
*/
import { DOMAIN_COMPATIBILITY } from "$src/featureFlags";
import { PublicKey, Signature, SignIdentity } from "@dfinity/agent";
import { DER_COSE_OID, unwrapDER, WebAuthnIdentity } from "@dfinity/identity";
import { isNullish } from "@dfinity/utils";
import borc from "borc";
import { CredentialData } from "./credential-devices";
import { findWebAuthnRpId, relatedDomains } from "./findWebAuthnRpId";
import { bufferEqual } from "./iiConnection";
import { supportsWebauthRoR } from "./userAgent";

/**
* A SignIdentity that uses `navigator.credentials`. See https://webauthn.guide/ for
Expand Down Expand Up @@ -64,6 +67,16 @@ export class MultiWebAuthnIdentity extends SignIdentity {
return this._actualIdentity.sign(blob);
}

const rpId =
DOMAIN_COMPATIBILITY.isEnabled() &&
supportsWebauthRoR(window.navigator.userAgent)
? findWebAuthnRpId(
window.location.origin,
this.credentialData,
relatedDomains()
)
: undefined;

const result = (await navigator.credentials.get({
publicKey: {
allowCredentials: this.credentialData.map((cd) => ({
Expand All @@ -72,6 +85,7 @@ export class MultiWebAuthnIdentity extends SignIdentity {
})),
challenge: blob,
userVerification: "discouraged",
rpId,
},
})) as PublicKeyCredential;

Expand Down

0 comments on commit 411ed8a

Please sign in to comment.