mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
* PM-5268 - Add DEVICE_TRUST_DISK to state definitions * PM-5268 - DeviceTrustCryptoService - Get most of state provider refactor done - WIP - commented out stuff for now. * PM-5268 - DeviceTrustCryptoServiceStateProviderMigrator - WIP - got first draft of migrator in place and working on tests. Rollback tests are failing for some reason TBD. * PM-5268 - more WIP on device trust crypto service migrator tests * PM-5268 - DeviceTrustCryptoServiceStateProviderMigrator - Refactor based on call with platform * PM-5268 - DeviceTrustCryptoServiceStateProviderMigrator - tests passing * PM-5268 - Update DeviceTrustCryptoService to convert over to state providers + update all service instantiations / dependencies to ensure state provider is passed in or injected. * PM-5268 - Register new migration * PM-5268 - Temporarily remove device trust crypto service from migrator to ease merge conflicts as there are 6 more migrators before I can apply mine in main. * PM-5268 - Update migration numbers of DeviceTrustCryptoServiceStateProviderMigrator based on latest migrations from main. * PM-5268 - (1) Export new KeyDefinitions from DeviceTrustCryptoService for use in test suite (2) Update DeviceTrustCryptoService test file to use state provider. * PM-5268 - Fix DeviceTrustCryptoServiceStateProviderMigrator tests to use proper versions * PM-5268 - Actually fix all instances of DeviceTrustCryptoServiceStateProviderMigrator test failures * PM-5268 - Clean up state service, account, and login strategy of all migrated references * PM-5268 - Account - finish cleaning up device key * PM-5268 - StateService - clean up last reference to device key * PM-5268 - Remove even more device key refs. *facepalm* * PM-5268 - Finish resolving merge conflicts by incrementing migration version from 22 to 23 * PM-5268 - bump migration versions * PM-5268 - DeviceTrustCryptoService - Implement secure storage functionality for getDeviceKey and setDeviceKey (to achieve feature parity with the ElectronStateService implementation prior to the state provider migration). Tests to follow shortly. * PM-5268 - DeviceTrustCryptoService tests - getDeviceKey now tested with all new secure storage scenarios. SetDeviceKey tests to follow. * PM-5268 - DeviceTrustCryptoService tests - test all setDeviceKey scenarios with state provider & secure storage * PM-5268 - Update DeviceTrustCryptoService deps to actually use secure storage svc on platforms that support it. * PM-5268 - Bump migration version due to merge conflicts. * PM-5268 - Bump migration version * PM-5268 - tweak jsdocs to be single line per PR feedback * PM-5268 - DeviceTrustCryptoSvc - improve debuggability. * PM-5268 - Remove state service as a dependency on the device trust crypto service (woo!) * PM-5268 - Update migration test json to correctly reflect reality. * PM-5268 - DeviceTrustCryptoSvc - getDeviceKey - add throw error for active user id missing. * PM-5268 - Fix tests * PM-5268 - WIP start on adding user id to every method on device trust crypto service. * PM-5268 - Update lock comp dependencies across clients * PM-5268 - Update login via auth request deps across clients to add acct service. * PM-5268 - UserKeyRotationSvc - add acct service to get active acct id for call to rotateDevicesTrust and then update tests. * PM-5268 - WIP on trying to fix device trust crypto svc tests. * PM-5268 - More WIP device trust crypto svc tests passing * PM-5268 - Device Trust crypto service - get all tests passing * PM-5268 - DeviceTrustCryptoService.getDeviceKey - fix secure storage b64 to symmetric crypto key conversion * PM-5268 - Add more tests and update test names * PM-5268 - rename state to indicate it was disk local * PM-5268 - DeviceTrustCryptoService - save symmetric key in JSON format * PM-5268 - Fix lock comp tests by adding acct service dep * PM-5268 - Update set device key tests to pass * PM-5268 - Bump migration versions again * PM-5268 - Fix user key rotation svc tests * PM-5268 - Update web jest config to allow use of common spec in user-key-rotation-svc tests * PM-5268 - Bump migration version * PM-5268 - Per PR feedback, save off user id * PM-5268 - bump migration version * PM-5268 - Per PR feedback, remove unnecessary await. * PM-5268 - Bump migration verson
181 lines
9.7 KiB
TypeScript
181 lines
9.7 KiB
TypeScript
// eslint-disable-next-line import/no-restricted-paths -- Needed to print log messages
|
|
import { LogService } from "../platform/abstractions/log.service";
|
|
// eslint-disable-next-line import/no-restricted-paths -- Needed to interface with storage locations
|
|
import { AbstractStorageService } from "../platform/abstractions/storage.service";
|
|
|
|
import { MigrationBuilder } from "./migration-builder";
|
|
import { EverHadUserKeyMigrator } from "./migrations/10-move-ever-had-user-key-to-state-providers";
|
|
import { OrganizationKeyMigrator } from "./migrations/11-move-org-keys-to-state-providers";
|
|
import { MoveEnvironmentStateToProviders } from "./migrations/12-move-environment-state-to-providers";
|
|
import { ProviderKeyMigrator } from "./migrations/13-move-provider-keys-to-state-providers";
|
|
import { MoveBiometricClientKeyHalfToStateProviders } from "./migrations/14-move-biometric-client-key-half-state-to-providers";
|
|
import { FolderMigrator } from "./migrations/15-move-folder-state-to-state-provider";
|
|
import { LastSyncMigrator } from "./migrations/16-move-last-sync-to-state-provider";
|
|
import { EnablePasskeysMigrator } from "./migrations/17-move-enable-passkeys-to-state-providers";
|
|
import { AutofillSettingsKeyMigrator } from "./migrations/18-move-autofill-settings-to-state-providers";
|
|
import { RequirePasswordOnStartMigrator } from "./migrations/19-migrate-require-password-on-start";
|
|
import { PrivateKeyMigrator } from "./migrations/20-move-private-key-to-state-providers";
|
|
import { CollectionMigrator } from "./migrations/21-move-collections-state-to-state-provider";
|
|
import { CollapsedGroupingsMigrator } from "./migrations/22-move-collapsed-groupings-to-state-provider";
|
|
import { MoveBiometricPromptsToStateProviders } from "./migrations/23-move-biometric-prompts-to-state-providers";
|
|
import { SmOnboardingTasksMigrator } from "./migrations/24-move-sm-onboarding-key-to-state-providers";
|
|
import { ClearClipboardDelayMigrator } from "./migrations/25-move-clear-clipboard-to-autofill-settings-state-provider";
|
|
import { RevertLastSyncMigrator } from "./migrations/26-revert-move-last-sync-to-state-provider";
|
|
import { BadgeSettingsMigrator } from "./migrations/27-move-badge-settings-to-state-providers";
|
|
import { MoveBiometricUnlockToStateProviders } from "./migrations/28-move-biometric-unlock-to-state-providers";
|
|
import { UserNotificationSettingsKeyMigrator } from "./migrations/29-move-user-notification-settings-to-state-provider";
|
|
import { PolicyMigrator } from "./migrations/30-move-policy-state-to-state-provider";
|
|
import { EnableContextMenuMigrator } from "./migrations/31-move-enable-context-menu-to-autofill-settings-state-provider";
|
|
import { PreferredLanguageMigrator } from "./migrations/32-move-preferred-language";
|
|
import { AppIdMigrator } from "./migrations/33-move-app-id-to-state-providers";
|
|
import { DomainSettingsMigrator } from "./migrations/34-move-domain-settings-to-state-providers";
|
|
import { MoveThemeToStateProviderMigrator } from "./migrations/35-move-theme-to-state-providers";
|
|
import { VaultSettingsKeyMigrator } from "./migrations/36-move-show-card-and-identity-to-state-provider";
|
|
import { AvatarColorMigrator } from "./migrations/37-move-avatar-color-to-state-providers";
|
|
import { TokenServiceStateProviderMigrator } from "./migrations/38-migrate-token-svc-to-state-provider";
|
|
import { MoveBillingAccountProfileMigrator } from "./migrations/39-move-billing-account-profile-to-state-providers";
|
|
import { RemoveEverBeenUnlockedMigrator } from "./migrations/4-remove-ever-been-unlocked";
|
|
import { OrganizationMigrator } from "./migrations/40-move-organization-state-to-state-provider";
|
|
import { EventCollectionMigrator } from "./migrations/41-move-event-collection-to-state-provider";
|
|
import { EnableFaviconMigrator } from "./migrations/42-move-enable-favicon-to-domain-settings-state-provider";
|
|
import { AutoConfirmFingerPrintsMigrator } from "./migrations/43-move-auto-confirm-finger-prints-to-state-provider";
|
|
import { UserDecryptionOptionsMigrator } from "./migrations/44-move-user-decryption-options-to-state-provider";
|
|
import { MergeEnvironmentState } from "./migrations/45-merge-environment-state";
|
|
import { DeleteBiometricPromptCancelledData } from "./migrations/46-delete-orphaned-biometric-prompt-data";
|
|
import { MoveDesktopSettingsMigrator } from "./migrations/47-move-desktop-settings";
|
|
import { MoveDdgToStateProviderMigrator } from "./migrations/48-move-ddg-to-state-provider";
|
|
import { AccountServerConfigMigrator } from "./migrations/49-move-account-server-configs";
|
|
import { AddKeyTypeToOrgKeysMigrator } from "./migrations/5-add-key-type-to-org-keys";
|
|
import { KeyConnectorMigrator } from "./migrations/50-move-key-connector-to-state-provider";
|
|
import { RememberedEmailMigrator } from "./migrations/51-move-remembered-email-to-state-providers";
|
|
import { DeleteInstalledVersion } from "./migrations/52-delete-installed-version";
|
|
import { DeviceTrustCryptoServiceStateProviderMigrator } from "./migrations/53-migrate-device-trust-crypto-svc-to-state-providers";
|
|
import { RemoveLegacyEtmKeyMigrator } from "./migrations/6-remove-legacy-etm-key";
|
|
import { MoveBiometricAutoPromptToAccount } from "./migrations/7-move-biometric-auto-prompt-to-account";
|
|
import { MoveStateVersionMigrator } from "./migrations/8-move-state-version";
|
|
import { MoveBrowserSettingsToGlobal } from "./migrations/9-move-browser-settings-to-global";
|
|
import { MinVersionMigrator } from "./migrations/min-version";
|
|
|
|
export const MIN_VERSION = 3;
|
|
export const CURRENT_VERSION = 53;
|
|
export type MinVersion = typeof MIN_VERSION;
|
|
|
|
export function createMigrationBuilder() {
|
|
return MigrationBuilder.create()
|
|
.with(MinVersionMigrator)
|
|
.with(RemoveEverBeenUnlockedMigrator, 3, 4)
|
|
.with(AddKeyTypeToOrgKeysMigrator, 4, 5)
|
|
.with(RemoveLegacyEtmKeyMigrator, 5, 6)
|
|
.with(MoveBiometricAutoPromptToAccount, 6, 7)
|
|
.with(MoveStateVersionMigrator, 7, 8)
|
|
.with(MoveBrowserSettingsToGlobal, 8, 9)
|
|
.with(EverHadUserKeyMigrator, 9, 10)
|
|
.with(OrganizationKeyMigrator, 10, 11)
|
|
.with(MoveEnvironmentStateToProviders, 11, 12)
|
|
.with(ProviderKeyMigrator, 12, 13)
|
|
.with(MoveBiometricClientKeyHalfToStateProviders, 13, 14)
|
|
.with(FolderMigrator, 14, 15)
|
|
.with(LastSyncMigrator, 15, 16)
|
|
.with(EnablePasskeysMigrator, 16, 17)
|
|
.with(AutofillSettingsKeyMigrator, 17, 18)
|
|
.with(RequirePasswordOnStartMigrator, 18, 19)
|
|
.with(PrivateKeyMigrator, 19, 20)
|
|
.with(CollectionMigrator, 20, 21)
|
|
.with(CollapsedGroupingsMigrator, 21, 22)
|
|
.with(MoveBiometricPromptsToStateProviders, 22, 23)
|
|
.with(SmOnboardingTasksMigrator, 23, 24)
|
|
.with(ClearClipboardDelayMigrator, 24, 25)
|
|
.with(RevertLastSyncMigrator, 25, 26)
|
|
.with(BadgeSettingsMigrator, 26, 27)
|
|
.with(MoveBiometricUnlockToStateProviders, 27, 28)
|
|
.with(UserNotificationSettingsKeyMigrator, 28, 29)
|
|
.with(PolicyMigrator, 29, 30)
|
|
.with(EnableContextMenuMigrator, 30, 31)
|
|
.with(PreferredLanguageMigrator, 31, 32)
|
|
.with(AppIdMigrator, 32, 33)
|
|
.with(DomainSettingsMigrator, 33, 34)
|
|
.with(MoveThemeToStateProviderMigrator, 34, 35)
|
|
.with(VaultSettingsKeyMigrator, 35, 36)
|
|
.with(AvatarColorMigrator, 36, 37)
|
|
.with(TokenServiceStateProviderMigrator, 37, 38)
|
|
.with(MoveBillingAccountProfileMigrator, 38, 39)
|
|
.with(OrganizationMigrator, 39, 40)
|
|
.with(EventCollectionMigrator, 40, 41)
|
|
.with(EnableFaviconMigrator, 41, 42)
|
|
.with(AutoConfirmFingerPrintsMigrator, 42, 43)
|
|
.with(UserDecryptionOptionsMigrator, 43, 44)
|
|
.with(MergeEnvironmentState, 44, 45)
|
|
.with(DeleteBiometricPromptCancelledData, 45, 46)
|
|
.with(MoveDesktopSettingsMigrator, 46, 47)
|
|
.with(MoveDdgToStateProviderMigrator, 47, 48)
|
|
.with(AccountServerConfigMigrator, 48, 49)
|
|
.with(KeyConnectorMigrator, 49, 50)
|
|
.with(RememberedEmailMigrator, 50, 51)
|
|
.with(DeleteInstalledVersion, 51, 52)
|
|
.with(DeviceTrustCryptoServiceStateProviderMigrator, 52, CURRENT_VERSION);
|
|
}
|
|
|
|
export async function currentVersion(
|
|
storageService: AbstractStorageService,
|
|
logService: LogService,
|
|
) {
|
|
let state = await storageService.get<number>("stateVersion");
|
|
if (state == null) {
|
|
// Pre v8
|
|
state = (await storageService.get<{ stateVersion: number }>("global"))?.stateVersion;
|
|
}
|
|
if (state == null) {
|
|
logService.info("No state version found, assuming empty state.");
|
|
return -1;
|
|
}
|
|
logService.info(`State version: ${state}`);
|
|
return state;
|
|
}
|
|
|
|
/**
|
|
* Waits for migrations to have a chance to run and will resolve the promise once they are.
|
|
*
|
|
* @param storageService Disk storage where the `stateVersion` will or is already saved in.
|
|
* @param logService Log service
|
|
*/
|
|
export async function waitForMigrations(
|
|
storageService: AbstractStorageService,
|
|
logService: LogService,
|
|
) {
|
|
const isReady = async () => {
|
|
const version = await currentVersion(storageService, logService);
|
|
// The saved version is what we consider the latest
|
|
// migrations should be complete, the state version
|
|
// shouldn't become larger than `CURRENT_VERSION` in
|
|
// any normal usage of the application but it is common
|
|
// enough in dev scenarios where we want to consider that
|
|
// ready as well and return true in that scenario.
|
|
return version >= CURRENT_VERSION;
|
|
};
|
|
|
|
const wait = async (time: number) => {
|
|
// Wait exponentially
|
|
const nextTime = time * 2;
|
|
if (nextTime > 8192) {
|
|
// Don't wait longer than ~8 seconds in a single wait,
|
|
// if the migrations still haven't happened. They aren't
|
|
// likely to.
|
|
return;
|
|
}
|
|
return new Promise<void>((resolve) => {
|
|
setTimeout(async () => {
|
|
if (!(await isReady())) {
|
|
logService.info(`Waiting for migrations to finish, waiting for ${nextTime}ms`);
|
|
await wait(nextTime);
|
|
}
|
|
resolve();
|
|
}, time);
|
|
});
|
|
};
|
|
|
|
if (!(await isReady())) {
|
|
// Wait for 2ms to start with
|
|
await wait(2);
|
|
}
|
|
}
|