Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions frontend/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ function bufferToBase64url(buf: ArrayBuffer): string {
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
}

// PRF salts arrive base64url-encoded; WebAuthn expects them as binary.
// Without the PRF extension the server cannot decrypt the IMAP password.
function prepareExtensions(
ext: Record<string, unknown> | undefined,
): AuthenticationExtensionsClientInputs | undefined {
const prf = ext?.prf as
| { evalByCredential?: Record<string, { first: string }> }
| undefined;
if (!prf?.evalByCredential) return undefined;
const byCred: Record<string, { first: ArrayBuffer }> = {};
for (const [credId, values] of Object.entries(prf.evalByCredential)) {
byCred[credId] = { first: base64urlToBuffer(values.first) };
}
return { prf: { evalByCredential: byCred } } as AuthenticationExtensionsClientInputs;
}

function preparePublicKeyOptions(
opts: PasskeyLoginBeginResponse["options"]["publicKey"],
): PublicKeyCredentialRequestOptions {
Expand All @@ -54,6 +70,7 @@ function preparePublicKeyOptions(
})),
userVerification:
(opts.userVerification as UserVerificationRequirement) ?? "required",
extensions: prepareExtensions(opts.extensions),
};
}

Expand Down
14 changes: 13 additions & 1 deletion frontend/src/components/settings/SecuritySettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ function bufferToBase64url(buf: ArrayBuffer): string {
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
}

// PRF salt arrives base64url-encoded; WebAuthn expects it as binary.
function prepareExtensions(
ext: Record<string, unknown> | undefined,
): AuthenticationExtensionsClientInputs | undefined {
const prf = ext?.prf as { eval?: { first: string } } | undefined;
if (!prf?.eval) return ext as AuthenticationExtensionsClientInputs | undefined;
return {
...ext,
prf: { eval: { first: base64urlToBuffer(prf.eval.first) } },
} as AuthenticationExtensionsClientInputs;
}

function prepareCreationOptions(
opts: PasskeyRegisterBeginResponse["options"]["publicKey"],
): PublicKeyCredentialCreationOptions {
Expand All @@ -82,7 +94,7 @@ function prepareCreationOptions(
})),
authenticatorSelection: opts.authenticatorSelection as AuthenticatorSelectionCriteria | undefined,
attestation: opts.attestation as AttestationConveyancePreference | undefined,
extensions: opts.extensions,
extensions: prepareExtensions(opts.extensions),
};
}

Expand Down