1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 05:43:41 +00:00

[PM-3483] Remove migrateKeyForNeverLockIfNeeded Logic (#8953)

* Remove `migrateKeyForNeverLockIfNeeded` Logic

* Fix Test

* Remove `migrateAutoKeyIfNeeded`
This commit is contained in:
Justin Baur
2024-05-01 15:50:40 -04:00
committed by GitHub
parent b45c309f83
commit 4b42ff7171
10 changed files with 0 additions and 89 deletions

View File

@@ -737,7 +737,6 @@ export default class MainBackground {
this.cipherService, this.cipherService,
this.folderService, this.folderService,
this.collectionService, this.collectionService,
this.cryptoService,
this.platformUtilsService, this.platformUtilsService,
this.messagingService, this.messagingService,
this.searchService, this.searchService,

View File

@@ -12,10 +12,6 @@ import {
internalMasterPasswordServiceFactory, internalMasterPasswordServiceFactory,
MasterPasswordServiceInitOptions, MasterPasswordServiceInitOptions,
} from "../../auth/background/service-factories/master-password-service.factory"; } from "../../auth/background/service-factories/master-password-service.factory";
import {
CryptoServiceInitOptions,
cryptoServiceFactory,
} from "../../platform/background/service-factories/crypto-service.factory";
import { import {
CachedServices, CachedServices,
factory, factory,
@@ -70,7 +66,6 @@ export type VaultTimeoutServiceInitOptions = VaultTimeoutServiceFactoryOptions &
CipherServiceInitOptions & CipherServiceInitOptions &
FolderServiceInitOptions & FolderServiceInitOptions &
CollectionServiceInitOptions & CollectionServiceInitOptions &
CryptoServiceInitOptions &
PlatformUtilsServiceInitOptions & PlatformUtilsServiceInitOptions &
MessagingServiceInitOptions & MessagingServiceInitOptions &
SearchServiceInitOptions & SearchServiceInitOptions &
@@ -94,7 +89,6 @@ export function vaultTimeoutServiceFactory(
await cipherServiceFactory(cache, opts), await cipherServiceFactory(cache, opts),
await folderServiceFactory(cache, opts), await folderServiceFactory(cache, opts),
await collectionServiceFactory(cache, opts), await collectionServiceFactory(cache, opts),
await cryptoServiceFactory(cache, opts),
await platformUtilsServiceFactory(cache, opts), await platformUtilsServiceFactory(cache, opts),
await messagingServiceFactory(cache, opts), await messagingServiceFactory(cache, opts),
await searchServiceFactory(cache, opts), await searchServiceFactory(cache, opts),

View File

@@ -611,7 +611,6 @@ export class Main {
this.cipherService, this.cipherService,
this.folderService, this.folderService,
this.collectionService, this.collectionService,
this.cryptoService,
this.platformUtilsService, this.platformUtilsService,
this.messagingService, this.messagingService,
this.searchService, this.searchService,

View File

@@ -656,7 +656,6 @@ const safeProviders: SafeProvider[] = [
CipherServiceAbstraction, CipherServiceAbstraction,
FolderServiceAbstraction, FolderServiceAbstraction,
CollectionServiceAbstraction, CollectionServiceAbstraction,
CryptoServiceAbstraction,
PlatformUtilsServiceAbstraction, PlatformUtilsServiceAbstraction,
MessagingServiceAbstraction, MessagingServiceAbstraction,
SearchServiceAbstraction, SearchServiceAbstraction,

View File

@@ -296,10 +296,6 @@ export abstract class CryptoService {
kdfConfig: KdfConfig, kdfConfig: KdfConfig,
oldPinKey: EncString, oldPinKey: EncString,
): Promise<UserKey>; ): Promise<UserKey>;
/**
* Replaces old master auto keys with new user auto keys
*/
abstract migrateAutoKeyIfNeeded(userId?: string): Promise<void>;
/** /**
* @param keyMaterial The key material to derive the send key from * @param keyMaterial The key material to derive the send key from
* @returns A new send key * @returns A new send key

View File

@@ -82,10 +82,6 @@ export abstract class StateService<T extends Account = Account> {
* @deprecated For migration purposes only, use getUserKeyMasterKey instead * @deprecated For migration purposes only, use getUserKeyMasterKey instead
*/ */
getEncryptedCryptoSymmetricKey: (options?: StorageOptions) => Promise<string>; getEncryptedCryptoSymmetricKey: (options?: StorageOptions) => Promise<string>;
/**
* @deprecated For migration purposes only, use getUserKeyAuto instead
*/
getCryptoMasterKeyAuto: (options?: StorageOptions) => Promise<string>;
/** /**
* @deprecated For migration purposes only, use setUserKeyAuto instead * @deprecated For migration purposes only, use setUserKeyAuto instead
*/ */

View File

@@ -930,35 +930,6 @@ export class CryptoService implements CryptoServiceAbstraction {
} }
} }
async migrateAutoKeyIfNeeded(userId?: UserId) {
const oldAutoKey = await this.stateService.getCryptoMasterKeyAuto({ userId: userId });
if (!oldAutoKey) {
return;
}
// Decrypt
const masterKey = new SymmetricCryptoKey(Utils.fromB64ToArray(oldAutoKey)) as MasterKey;
if (await this.isLegacyUser(masterKey, userId)) {
// Legacy users don't have a user key, so no need to migrate.
// Instead, set the master key for additional isLegacyUser checks that will log the user out.
userId ??= await firstValueFrom(this.stateProvider.activeUserId$);
await this.masterPasswordService.setMasterKey(masterKey, userId);
return;
}
const encryptedUserKey = await this.stateService.getEncryptedCryptoSymmetricKey({
userId: userId,
});
const userKey = await this.decryptUserKeyWithMasterKey(
masterKey,
new EncString(encryptedUserKey),
userId,
);
// Migrate
await this.stateService.setUserKeyAutoUnlock(userKey.keyB64, { userId: userId });
await this.stateService.setCryptoMasterKeyAuto(null, { userId: userId });
// Set encrypted user key in case user immediately locks without syncing
await this.setMasterKeyEncryptedUserKey(encryptedUserKey);
}
async decryptAndMigrateOldPinKey( async decryptAndMigrateOldPinKey(
masterPasswordOnRestart: boolean, masterPasswordOnRestart: boolean,
pin: string, pin: string,

View File

@@ -268,23 +268,6 @@ export class StateService<
); );
} }
/**
* @deprecated Use UserKeyAuto instead
*/
async getCryptoMasterKeyAuto(options?: StorageOptions): Promise<string> {
options = this.reconcileOptions(
this.reconcileOptions(options, { keySuffix: "auto" }),
await this.defaultSecureStorageOptions(),
);
if (options?.userId == null) {
return null;
}
return await this.secureStorageService.get<string>(
`${options.userId}${partialKeys.autoKey}`,
options,
);
}
/** /**
* @deprecated Use UserKeyAuto instead * @deprecated Use UserKeyAuto instead
*/ */

View File

@@ -9,7 +9,6 @@ import { AuthService } from "../../auth/abstractions/auth.service";
import { AuthenticationStatus } from "../../auth/enums/authentication-status"; import { AuthenticationStatus } from "../../auth/enums/authentication-status";
import { FakeMasterPasswordService } from "../../auth/services/master-password/fake-master-password.service"; import { FakeMasterPasswordService } from "../../auth/services/master-password/fake-master-password.service";
import { VaultTimeoutAction } from "../../enums/vault-timeout-action.enum"; import { VaultTimeoutAction } from "../../enums/vault-timeout-action.enum";
import { CryptoService } from "../../platform/abstractions/crypto.service";
import { MessagingService } from "../../platform/abstractions/messaging.service"; import { MessagingService } from "../../platform/abstractions/messaging.service";
import { PlatformUtilsService } from "../../platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "../../platform/abstractions/platform-utils.service";
import { StateService } from "../../platform/abstractions/state.service"; import { StateService } from "../../platform/abstractions/state.service";
@@ -28,7 +27,6 @@ describe("VaultTimeoutService", () => {
let cipherService: MockProxy<CipherService>; let cipherService: MockProxy<CipherService>;
let folderService: MockProxy<FolderService>; let folderService: MockProxy<FolderService>;
let collectionService: MockProxy<CollectionService>; let collectionService: MockProxy<CollectionService>;
let cryptoService: MockProxy<CryptoService>;
let platformUtilsService: MockProxy<PlatformUtilsService>; let platformUtilsService: MockProxy<PlatformUtilsService>;
let messagingService: MockProxy<MessagingService>; let messagingService: MockProxy<MessagingService>;
let searchService: MockProxy<SearchService>; let searchService: MockProxy<SearchService>;
@@ -52,7 +50,6 @@ describe("VaultTimeoutService", () => {
cipherService = mock(); cipherService = mock();
folderService = mock(); folderService = mock();
collectionService = mock(); collectionService = mock();
cryptoService = mock();
platformUtilsService = mock(); platformUtilsService = mock();
messagingService = mock(); messagingService = mock();
searchService = mock(); searchService = mock();
@@ -76,7 +73,6 @@ describe("VaultTimeoutService", () => {
cipherService, cipherService,
folderService, folderService,
collectionService, collectionService,
cryptoService,
platformUtilsService, platformUtilsService,
messagingService, messagingService,
searchService, searchService,

View File

@@ -7,9 +7,7 @@ import { AccountService } from "../../auth/abstractions/account.service";
import { AuthService } from "../../auth/abstractions/auth.service"; import { AuthService } from "../../auth/abstractions/auth.service";
import { InternalMasterPasswordServiceAbstraction } from "../../auth/abstractions/master-password.service.abstraction"; import { InternalMasterPasswordServiceAbstraction } from "../../auth/abstractions/master-password.service.abstraction";
import { AuthenticationStatus } from "../../auth/enums/authentication-status"; import { AuthenticationStatus } from "../../auth/enums/authentication-status";
import { ClientType } from "../../enums";
import { VaultTimeoutAction } from "../../enums/vault-timeout-action.enum"; import { VaultTimeoutAction } from "../../enums/vault-timeout-action.enum";
import { CryptoService } from "../../platform/abstractions/crypto.service";
import { MessagingService } from "../../platform/abstractions/messaging.service"; import { MessagingService } from "../../platform/abstractions/messaging.service";
import { PlatformUtilsService } from "../../platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "../../platform/abstractions/platform-utils.service";
import { StateService } from "../../platform/abstractions/state.service"; import { StateService } from "../../platform/abstractions/state.service";
@@ -28,7 +26,6 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction {
private cipherService: CipherService, private cipherService: CipherService,
private folderService: FolderService, private folderService: FolderService,
private collectionService: CollectionService, private collectionService: CollectionService,
private cryptoService: CryptoService,
protected platformUtilsService: PlatformUtilsService, protected platformUtilsService: PlatformUtilsService,
private messagingService: MessagingService, private messagingService: MessagingService,
private searchService: SearchService, private searchService: SearchService,
@@ -44,8 +41,6 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction {
if (this.inited) { if (this.inited) {
return; return;
} }
// TODO: Remove after 2023.10 release (https://bitwarden.atlassian.net/browse/PM-3483)
await this.migrateKeyForNeverLockIfNeeded();
this.inited = true; this.inited = true;
if (checkOnInterval) { if (checkOnInterval) {
@@ -175,21 +170,4 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction {
? await this.logOut(userId) ? await this.logOut(userId)
: await this.lock(userId); : await this.lock(userId);
} }
private async migrateKeyForNeverLockIfNeeded(): Promise<void> {
// Web can't set vault timeout to never
if (this.platformUtilsService.getClientType() == ClientType.Web) {
return;
}
const accounts = await firstValueFrom(this.stateService.accounts$);
for (const userId in accounts) {
if (userId != null) {
await this.cryptoService.migrateAutoKeyIfNeeded(userId);
// Legacy users should be logged out since we're not on the web vault and can't migrate.
if (await this.cryptoService.isLegacyUser(null, userId)) {
await this.logOut(userId);
}
}
}
}
} }