Skip to content

Commit

Permalink
[PM-4882] Passkeys: funnel rp name or id to the cipher name on save (#…
Browse files Browse the repository at this point in the history
…7969)

* funnel rp name or id to the cipher name on save

* remove comment

* add rp name and id to addCipher function

---------

Co-authored-by: Merissa Weinstein <merissaweinstein@merissas-mbp-2.lan>
  • Loading branch information
merissaacosta and Merissa Weinstein authored Mar 6, 2024
1 parent 51f482d commit 5dcc035
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type BrowserFido2Message = { sessionId: string } & (
userName: string;
userVerification: boolean;
fallbackSupported: boolean;
rpId: string;
}
| {
type: "ConfirmNewCredentialResponse";
Expand Down Expand Up @@ -242,6 +243,7 @@ export class BrowserFido2UserInterfaceSession implements Fido2UserInterfaceSessi
credentialName,
userName,
userVerification,
rpId,
}: NewCredentialParams): Promise<{ cipherId: string; userVerified: boolean }> {
const data: BrowserFido2Message = {
type: "ConfirmNewCredentialRequest",
Expand All @@ -250,6 +252,7 @@ export class BrowserFido2UserInterfaceSession implements Fido2UserInterfaceSessi
userName,
userVerification,
fallbackSupported: this.fallbackSupported,
rpId,
};

await this.send(data);
Expand Down
14 changes: 7 additions & 7 deletions apps/browser/src/vault/popup/components/fido2/fido2.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { SearchService } from "@bitwarden/common/abstractions/search.service";
import { SettingsService } from "@bitwarden/common/abstractions/settings.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { SecureNoteType, CipherType } from "@bitwarden/common/vault/enums";
import { CipherRepromptType } from "@bitwarden/common/vault/enums/cipher-reprompt-type";
Expand Down Expand Up @@ -245,7 +244,8 @@ export class Fido2Component implements OnInit, OnDestroy {
protected async saveNewLogin() {
const data = this.message$.value;
if (data?.type === "ConfirmNewCredentialRequest") {
await this.createNewCipher();
const name = data.credentialName || data.rpId;
await this.createNewCipher(name);

// We are bypassing user verification pending implementation of PIN and biometric support.
this.send({
Expand Down Expand Up @@ -296,7 +296,7 @@ export class Fido2Component implements OnInit, OnDestroy {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(["/add-cipher"], {
queryParams: {
name: Utils.getHostname(this.url),
name: data.credentialName || data.rpId,
uri: this.url,
uilocation: "popout",
senderTabId: this.senderTabId,
Expand Down Expand Up @@ -344,9 +344,9 @@ export class Fido2Component implements OnInit, OnDestroy {
this.destroy$.complete();
}

private buildCipher() {
private buildCipher(name: string) {
this.cipher = new CipherView();
this.cipher.name = Utils.getHostname(this.url);
this.cipher.name = name;
this.cipher.type = CipherType.Login;
this.cipher.login = new LoginView();
this.cipher.login.uris = [new LoginUriView()];
Expand All @@ -358,8 +358,8 @@ export class Fido2Component implements OnInit, OnDestroy {
this.cipher.reprompt = CipherRepromptType.None;
}

private async createNewCipher() {
this.buildCipher();
private async createNewCipher(name: string) {
this.buildCipher(name);
const cipher = await this.cipherService.encrypt(this.cipher);
try {
await this.cipherService.createWithServer(cipher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export interface NewCredentialParams {
* Whether or not the user must be verified before completing the operation.
*/
userVerification: boolean;
/**
* The relying party ID is usually the URL
*/
rpId: string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ describe("FidoAuthenticatorService", () => {
credentialName: params.rpEntity.name,
userName: params.userEntity.displayName,
userVerification,
rpId: params.rpEntity.id,
} as NewCredentialParams);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
credentialName: params.rpEntity.name,
userName: params.userEntity.displayName,
userVerification: params.requireUserVerification,
rpId: params.rpEntity.id,
});
const cipherId = response.cipherId;
userVerified = response.userVerified;
Expand Down

0 comments on commit 5dcc035

Please sign in to comment.