From f37fb88ddfd02d73f76bcad844794fbefffc2e29 Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Mon, 19 May 2025 12:31:05 +0200 Subject: [PATCH] Add comments and add backward compatibilty for sync --- .../src/models/response/profile.response.ts | 11 +++++++++-- .../src/platform/sync/default-sync.service.ts | 19 ++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/libs/common/src/models/response/profile.response.ts b/libs/common/src/models/response/profile.response.ts index 8344f1f30e0..c9355ebab6a 100644 --- a/libs/common/src/models/response/profile.response.ts +++ b/libs/common/src/models/response/profile.response.ts @@ -19,8 +19,10 @@ export class ProfileResponse extends BaseResponse { key: string; avatarColor: string; creationDate: string; + // Cleanup: Can be removed after moving to accountKeys privateKey: string; - accountKeys: PrivateAccountKeysResponseModel; + // Cleanup: This should be non-optional after the server has been released for a while https://bitwarden.atlassian.net/browse/PM-21768 + accountKeys: PrivateAccountKeysResponseModel | null; securityStamp: string; forcePasswordReset: boolean; usesKeyConnector: boolean; @@ -40,7 +42,12 @@ export class ProfileResponse extends BaseResponse { this.culture = this.getResponseProperty("Culture"); this.twoFactorEnabled = this.getResponseProperty("TwoFactorEnabled"); this.key = this.getResponseProperty("Key"); - this.accountKeys = new PrivateAccountKeysResponseModel(this.getResponseProperty("AccountKeys")); + // Cleanup: This should be non-optional after the server has been released for a while https://bitwarden.atlassian.net/browse/PM-21768 + if (this.getResponseProperty("AccountKeys") != null) { + this.accountKeys = new PrivateAccountKeysResponseModel( + this.getResponseProperty("AccountKeys"), + ); + } this.avatarColor = this.getResponseProperty("AvatarColor"); this.creationDate = this.getResponseProperty("CreationDate"); this.privateKey = this.getResponseProperty("PrivateKey"); diff --git a/libs/common/src/platform/sync/default-sync.service.ts b/libs/common/src/platform/sync/default-sync.service.ts index cf7a7c6f4e5..676d5bb7eb4 100644 --- a/libs/common/src/platform/sync/default-sync.service.ts +++ b/libs/common/src/platform/sync/default-sync.service.ts @@ -195,15 +195,20 @@ export class DefaultSyncService extends CoreSyncService { /// Key management initialization await this.keyService.setMasterKeyEncryptedUserKey(response.key, response.id); - await this.keyService.setPrivateKey( - response.accountKeys.AsymmetricEncryptionKeys.wrappedPrivateKey.encryptedString!, - response.id, - ); - if (response.accountKeys.SigningKeys !== null) { - await this.keyService.setUserSigningKey( - response.accountKeys.SigningKeys.wrappedSigningKey, + // Cleanup: Only the first branch should be kept after the server always returns accountKeys https://bitwarden.atlassian.net/browse/PM-21768 + if (response.accountKeys != null) { + await this.keyService.setPrivateKey( + response.accountKeys.AsymmetricEncryptionKeys.wrappedPrivateKey.encryptedString!, response.id, ); + if (response.accountKeys.SigningKeys !== null) { + await this.keyService.setUserSigningKey( + response.accountKeys.SigningKeys.wrappedSigningKey, + response.id, + ); + } + } else { + await this.keyService.setPrivateKey(response.privateKey, response.id); } await this.keyService.setProviderKeys(response.providers, response.id); await this.keyService.setOrgKeys(