diff --git a/bitwarden_license/bit-web/src/app/secrets-manager/models/view/service-account.view.ts b/bitwarden_license/bit-web/src/app/secrets-manager/models/view/service-account.view.ts index 3df383ef96c..c28f607d7c0 100644 --- a/bitwarden_license/bit-web/src/app/secrets-manager/models/view/service-account.view.ts +++ b/bitwarden_license/bit-web/src/app/secrets-manager/models/view/service-account.view.ts @@ -6,6 +6,7 @@ export class ServiceAccountView { name: string; creationDate: string; revisionDate: string; + decryptionError: boolean = false; } export class ServiceAccountSecretsDetailsView extends ServiceAccountView { diff --git a/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-account.service.ts b/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-account.service.ts index 2706bf99f3b..23e47ddb4b5 100644 --- a/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-account.service.ts +++ b/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-account.service.ts @@ -7,8 +7,12 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service"; -import { EncString } from "@bitwarden/common/key-management/crypto/models/enc-string"; +import { + DECRYPT_ERROR, + EncString, +} from "@bitwarden/common/key-management/crypto/models/enc-string"; import { ListResponse } from "@bitwarden/common/models/response/list.response"; +import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; import { OrganizationId } from "@bitwarden/common/types/guid"; import { KeyService } from "@bitwarden/key-management"; @@ -38,6 +42,7 @@ export class ServiceAccountService { private apiService: ApiService, private encryptService: EncryptService, private accountService: AccountService, + private logService: LogService, ) {} private getOrganizationKey$(organizationId: string) { @@ -167,12 +172,18 @@ export class ServiceAccountService { serviceAccountView.organizationId = serviceAccountResponse.organizationId; serviceAccountView.creationDate = serviceAccountResponse.creationDate; serviceAccountView.revisionDate = serviceAccountResponse.revisionDate; - serviceAccountView.name = serviceAccountResponse.name - ? await this.encryptService.decryptString( - new EncString(serviceAccountResponse.name), - organizationKey, - ) - : null; + + if (serviceAccountResponse.name) { + const name = await this.decryptField( + new EncString(serviceAccountResponse.name), + organizationKey, + ); + serviceAccountView.name = name.value; + serviceAccountView.decryptionError = name.error; + } else { + serviceAccountView.name = null; + } + return serviceAccountView; } @@ -186,9 +197,15 @@ export class ServiceAccountService { view.creationDate = response.creationDate; view.revisionDate = response.revisionDate; view.accessToSecrets = response.accessToSecrets; - view.name = response.name - ? await this.encryptService.decryptString(new EncString(response.name), organizationKey) - : null; + + if (response.name) { + const name = await this.decryptField(new EncString(response.name), organizationKey); + view.name = name.value; + view.decryptionError = name.error; + } else { + view.name = null; + } + return view; } @@ -203,4 +220,17 @@ export class ServiceAccountService { }), ); } + + private async decryptField( + encString: EncString, + organizationKey: SymmetricCryptoKey, + ): Promise<{ value: string; error: boolean }> { + try { + const decrypted = await this.encryptService.decryptString(encString, organizationKey); + return { value: decrypted, error: false }; + } catch (error) { + this.logService.error("Error decrypting service account field", error); + return { value: DECRYPT_ERROR, error: true }; + } + } } diff --git a/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-accounts-list.component.html b/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-accounts-list.component.html index 65f951ce857..11e32520ccc 100644 --- a/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-accounts-list.component.html +++ b/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-accounts-list.component.html @@ -58,9 +58,31 @@