From 28079dfbac6457b948e9b853ff1f1acf793816c7 Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Wed, 12 Mar 2025 15:21:48 +0100 Subject: [PATCH] Registration on change password --- .../app/auth/settings/change-password.component.ts | 6 +++++- libs/angular/src/services/jslib-services.module.ts | 14 ++++++++++++++ .../src/auth/opaque/default-opaque-api.service.ts | 8 ++++---- libs/common/src/auth/opaque/opaque-api.service.ts | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/apps/web/src/app/auth/settings/change-password.component.ts b/apps/web/src/app/auth/settings/change-password.component.ts index eb98f7fde07..8d04f1d07bc 100644 --- a/apps/web/src/app/auth/settings/change-password.component.ts +++ b/apps/web/src/app/auth/settings/change-password.component.ts @@ -12,6 +12,7 @@ import { AccountService } from "@bitwarden/common/auth/abstractions/account.serv import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction"; import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction"; import { PasswordRequest } from "@bitwarden/common/auth/models/request/password.request"; +import { OpaqueService } from "@bitwarden/common/auth/opaque/opaque.service"; import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; @@ -59,6 +60,7 @@ export class ChangePasswordComponent masterPasswordService: InternalMasterPasswordServiceAbstraction, accountService: AccountService, toastService: ToastService, + private opaqueService: OpaqueService, ) { super( i18nService, @@ -213,6 +215,7 @@ export class ChangePasswordComponent try { if (this.rotateUserKey) { + throw new Error("Userkey rotation not supported"); this.formPromise = this.apiService.postPassword(request).then(async () => { // we need to save this for local masterkey verification during rotation await this.masterPasswordService.setMasterKeyHash(newLocalKeyHash, userId as UserId); @@ -223,6 +226,7 @@ export class ChangePasswordComponent this.formPromise = this.apiService.postPassword(request); } + await this.opaqueService.Register(this.masterPassword, newUserKey[0]); await this.formPromise; this.toastService.showToast({ @@ -230,7 +234,7 @@ export class ChangePasswordComponent title: this.i18nService.t("masterPasswordChanged"), message: this.i18nService.t("logBackIn"), }); - this.messagingService.send("logout"); + //this.messagingService.send("logout"); } catch { this.toastService.showToast({ variant: "error", diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index 93e29846e69..14a59b2741a 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -104,6 +104,10 @@ import { UserVerificationService as UserVerificationServiceAbstraction } from "@ import { WebAuthnLoginApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/webauthn/webauthn-login-api.service.abstraction"; import { WebAuthnLoginPrfKeyServiceAbstraction } from "@bitwarden/common/auth/abstractions/webauthn/webauthn-login-prf-key.service.abstraction"; import { WebAuthnLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/webauthn/webauthn-login.service.abstraction"; +import { DefaultOpaqueApiService } from "@bitwarden/common/auth/opaque/default-opaque-api.service"; +import { DefaultOpaqueService } from "@bitwarden/common/auth/opaque/default-opaque.service"; +import { OpaqueApiService } from "@bitwarden/common/auth/opaque/opaque-api.service"; +import { OpaqueService } from "@bitwarden/common/auth/opaque/opaque.service"; import { AccountApiServiceImplementation } from "@bitwarden/common/auth/services/account-api.service"; import { AccountServiceImplementation } from "@bitwarden/common/auth/services/account.service"; import { AnonymousHubService } from "@bitwarden/common/auth/services/anonymous-hub.service"; @@ -1475,6 +1479,16 @@ const safeProviders: SafeProvider[] = [ ToastService, ], }), + safeProvider({ + provide: OpaqueApiService, + useClass: DefaultOpaqueApiService, + deps: [ApiServiceAbstraction, EnvironmentService], + }), + safeProvider({ + provide: OpaqueService, + useClass: DefaultOpaqueService, + deps: [OpaqueApiService, SdkService], + }), ]; @NgModule({ diff --git a/libs/common/src/auth/opaque/default-opaque-api.service.ts b/libs/common/src/auth/opaque/default-opaque-api.service.ts index 3485021d3e7..6355beaa3e6 100644 --- a/libs/common/src/auth/opaque/default-opaque-api.service.ts +++ b/libs/common/src/auth/opaque/default-opaque-api.service.ts @@ -21,9 +21,9 @@ export class DefaultOpaqueApiService implements OpaqueApiService { const env = await firstValueFrom(this.environmentService.environment$); const response = await this.apiService.send( "POST", - `/opaque/registration-start`, + `/opaque/start-registration`, request, - false, + true, true, env.getApiUrl(), ); @@ -37,9 +37,9 @@ export class DefaultOpaqueApiService implements OpaqueApiService { const env = await firstValueFrom(this.environmentService.environment$); const response = await this.apiService.send( "POST", - `/opaque/${credentialId}registration-start`, + `/opaque/finish-registration`, request, - false, + true, true, env.getApiUrl(), ); diff --git a/libs/common/src/auth/opaque/opaque-api.service.ts b/libs/common/src/auth/opaque/opaque-api.service.ts index 35dce77fc4d..c6c2aaf0ca5 100644 --- a/libs/common/src/auth/opaque/opaque-api.service.ts +++ b/libs/common/src/auth/opaque/opaque-api.service.ts @@ -1,4 +1,4 @@ -import { OpaqueSessionId as OpaqueSessionId } from "../../types/guid"; +import { OpaqueSessionId } from "../../types/guid"; import { RegistrationFinishRequest } from "./models/registration-finish.request"; import { RegistrationFinishResponse } from "./models/registration-finish.response";