diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index cc973a8c82..3af124a99c 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -9,6 +9,7 @@ import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from "@bitw import { EncryptService } from "@bitwarden/common/abstractions/encrypt.service"; import { EventService as EventServiceAbstraction } from "@bitwarden/common/abstractions/event.service"; import { ExportService as ExportServiceAbstraction } from "@bitwarden/common/abstractions/export.service"; +import { Fido2Service as Fido2ServiceAbstraction } from "@bitwarden/common/abstractions/fido2/fido2.service.abstraction"; import { FileUploadService as FileUploadServiceAbstraction } from "@bitwarden/common/abstractions/fileUpload.service"; import { FolderApiServiceAbstraction } from "@bitwarden/common/abstractions/folder/folder-api.service.abstraction"; import { InternalFolderService as InternalFolderServiceAbstraction } from "@bitwarden/common/abstractions/folder/folder.service.abstraction"; @@ -56,6 +57,7 @@ import { EncryptServiceImplementation } from "@bitwarden/common/services/cryptog import { MultithreadEncryptServiceImplementation } from "@bitwarden/common/services/cryptography/multithread-encrypt.service.implementation"; import { EventService } from "@bitwarden/common/services/event.service"; import { ExportService } from "@bitwarden/common/services/export.service"; +import { Fido2Service } from "@bitwarden/common/services/fido2/fido2.service"; import { FileUploadService } from "@bitwarden/common/services/fileUpload.service"; import { FolderApiService } from "@bitwarden/common/services/folder/folder-api.service"; import { KeyConnectorService } from "@bitwarden/common/services/keyConnector.service"; @@ -165,6 +167,7 @@ export default class MainBackground { policyApiService: PolicyApiServiceAbstraction; userVerificationApiService: UserVerificationApiServiceAbstraction; syncNotifierService: SyncNotifierServiceAbstraction; + fido2Service: Fido2ServiceAbstraction; // Passed to the popup for Safari to workaround issues with theming, downloading, etc. backgroundWindow = window; @@ -461,6 +464,8 @@ export default class MainBackground { this.userVerificationApiService ); + this.fido2Service = new Fido2Service(); + const systemUtilsServiceReloadCallback = () => { const forceWindowReload = this.platformUtilsService.isSafari() || diff --git a/apps/browser/src/background/runtime.background.ts b/apps/browser/src/background/runtime.background.ts index 309edee28c..4e7387ca06 100644 --- a/apps/browser/src/background/runtime.background.ts +++ b/apps/browser/src/background/runtime.background.ts @@ -204,6 +204,13 @@ export default class RuntimeBackground { case "getClickedElementResponse": this.platformUtilsService.copyToClipboard(msg.identifier, { window: window }); break; + case "fido2RegisterCredentialRequest": + BrowserApi.tabSendMessageData( + sender.tab, + "fido2RegisterCredentialResponse", + await this.main.fido2Service.createCredential(msg.data) + ); + break; default: break; } diff --git a/apps/browser/src/content/webauthn/content-script.ts b/apps/browser/src/content/webauthn/content-script.ts index eafb3106d7..ce9ba8ab2e 100644 --- a/apps/browser/src/content/webauthn/content-script.ts +++ b/apps/browser/src/content/webauthn/content-script.ts @@ -12,6 +12,11 @@ const messenger = Messenger.createInExtensionContext(window, chrome.runtime.conn messenger.addHandler(async (message) => { if (message.type === MessageType.CredentialCreationRequest) { + chrome.runtime.sendMessage({ + command: "fido2RegisterCredentialRequest", + data: message.data, + }); + return { type: MessageType.CredentialCreationResponse, approved: true, diff --git a/apps/browser/src/content/webauthn/messaging/message.ts b/apps/browser/src/content/webauthn/messaging/message.ts index 9b0a8065fb..0fb6c88418 100644 --- a/apps/browser/src/content/webauthn/messaging/message.ts +++ b/apps/browser/src/content/webauthn/messaging/message.ts @@ -1,3 +1,5 @@ +import { CredentialRegistrationParams } from "@bitwarden/common/abstractions/fido2/fido2.service.abstraction"; + export enum MessageType { CredentialCreationRequest, CredentialCreationResponse, @@ -9,7 +11,7 @@ export enum MessageType { export type CredentialCreationRequest = { type: MessageType.CredentialCreationRequest; - rpId: string; + data: CredentialRegistrationParams; }; export type CredentialCreationResponse = { diff --git a/apps/browser/src/content/webauthn/page-script.ts b/apps/browser/src/content/webauthn/page-script.ts index b501b6abde..d01dacc4c7 100644 --- a/apps/browser/src/content/webauthn/page-script.ts +++ b/apps/browser/src/content/webauthn/page-script.ts @@ -14,7 +14,11 @@ const messenger = Messenger.createInPageContext(window); navigator.credentials.create = async (options?: CredentialCreationOptions): Promise => { await messenger.request({ type: MessageType.CredentialCreationRequest, - rpId: options.publicKey.rp.id, + data: { + rp: { + id: options.publicKey.rp.id, + }, + }, }); return await browserCredentials.create(options); diff --git a/libs/common/src/abstractions/fido2/fido2.service.abstraction.ts b/libs/common/src/abstractions/fido2/fido2.service.abstraction.ts new file mode 100644 index 0000000000..6e70a9e5de --- /dev/null +++ b/libs/common/src/abstractions/fido2/fido2.service.abstraction.ts @@ -0,0 +1,10 @@ +export interface CredentialRegistrationParams { + rp: { + id?: string; + }; +} + +export abstract class Fido2Service { + createCredential: (params: CredentialRegistrationParams) => unknown; + assertCredential: () => unknown; +} diff --git a/libs/common/src/services/fido2/fido2.service.ts b/libs/common/src/services/fido2/fido2.service.ts new file mode 100644 index 0000000000..97dfe25bac --- /dev/null +++ b/libs/common/src/services/fido2/fido2.service.ts @@ -0,0 +1,16 @@ +import { + CredentialRegistrationParams, + Fido2Service as Fido2ServiceAbstraction, +} from "../../abstractions/fido2/fido2.service.abstraction"; + +export class Fido2Service implements Fido2ServiceAbstraction { + createCredential(params: CredentialRegistrationParams): unknown { + // eslint-disable-next-line no-console + console.log("Fido2Service.registerCredential"); + return undefined; + } + + assertCredential(): unknown { + return undefined; + } +}