mirror of
https://github.com/bitwarden/browser
synced 2026-02-11 22:13:32 +00:00
Use PlatformUtilsService Directly
This commit is contained in:
@@ -589,7 +589,7 @@ export default class MainBackground {
|
||||
this.tokenService = new TokenService(
|
||||
this.singleUserStateProvider,
|
||||
this.globalStateProvider,
|
||||
this.platformUtilsService.supportsSecureStorage(),
|
||||
this.platformUtilsService,
|
||||
this.secureStorageService,
|
||||
this.keyGenerationService,
|
||||
this.encryptService,
|
||||
|
||||
@@ -374,7 +374,7 @@ export class ServiceContainer {
|
||||
this.tokenService = new TokenService(
|
||||
this.singleUserStateProvider,
|
||||
this.globalStateProvider,
|
||||
this.platformUtilsService.supportsSecureStorage(),
|
||||
this.platformUtilsService,
|
||||
this.secureStorageService,
|
||||
this.keyGenerationService,
|
||||
this.encryptService,
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
OBSERVABLE_MEMORY_STORAGE,
|
||||
OBSERVABLE_DISK_STORAGE,
|
||||
WINDOW,
|
||||
SUPPORTS_SECURE_STORAGE,
|
||||
SYSTEM_THEME_OBSERVABLE,
|
||||
SafeInjectionToken,
|
||||
DEFAULT_VAULT_TIMEOUT,
|
||||
@@ -107,10 +106,7 @@ import { flagEnabled } from "../../platform/flags";
|
||||
import { DesktopSettingsService } from "../../platform/services/desktop-settings.service";
|
||||
import { ElectronKeyService } from "../../platform/services/electron-key.service";
|
||||
import { ElectronLogRendererService } from "../../platform/services/electron-log.renderer.service";
|
||||
import {
|
||||
ELECTRON_SUPPORTS_SECURE_STORAGE,
|
||||
ElectronPlatformUtilsService,
|
||||
} from "../../platform/services/electron-platform-utils.service";
|
||||
import { ElectronPlatformUtilsService } from "../../platform/services/electron-platform-utils.service";
|
||||
import { ElectronRendererMessageSender } from "../../platform/services/electron-renderer-message.sender";
|
||||
import { ElectronRendererSecureStorageService } from "../../platform/services/electron-renderer-secure-storage.service";
|
||||
import { ElectronRendererStorageService } from "../../platform/services/electron-renderer-storage.service";
|
||||
@@ -169,13 +165,6 @@ const safeProviders: SafeProvider[] = [
|
||||
useClass: ElectronPlatformUtilsService,
|
||||
deps: [I18nServiceAbstraction, MessagingServiceAbstraction],
|
||||
}),
|
||||
safeProvider({
|
||||
// We manually override the value of SUPPORTS_SECURE_STORAGE here to avoid
|
||||
// the TokenService having to inject the PlatformUtilsService which introduces a
|
||||
// circular dependency on Desktop only.
|
||||
provide: SUPPORTS_SECURE_STORAGE,
|
||||
useValue: ELECTRON_SUPPORTS_SECURE_STORAGE,
|
||||
}),
|
||||
safeProvider({
|
||||
provide: DEFAULT_VAULT_TIMEOUT,
|
||||
useValue: VaultTimeoutStringType.OnRestart,
|
||||
|
||||
@@ -10,8 +10,6 @@ import {
|
||||
|
||||
import { ClipboardWriteMessage } from "../types/clipboard";
|
||||
|
||||
export const ELECTRON_SUPPORTS_SECURE_STORAGE = true;
|
||||
|
||||
export class ElectronPlatformUtilsService implements PlatformUtilsService {
|
||||
constructor(
|
||||
protected i18nService: I18nService,
|
||||
@@ -134,7 +132,7 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService {
|
||||
}
|
||||
|
||||
supportsSecureStorage(): boolean {
|
||||
return ELECTRON_SUPPORTS_SECURE_STORAGE;
|
||||
return true;
|
||||
}
|
||||
|
||||
getAutofillKeyboardShortcut(): Promise<string> {
|
||||
|
||||
@@ -45,7 +45,6 @@ export const LOGOUT_CALLBACK = new SafeInjectionToken<
|
||||
export const LOCKED_CALLBACK = new SafeInjectionToken<(userId?: string) => Promise<void>>(
|
||||
"LOCKED_CALLBACK",
|
||||
);
|
||||
export const SUPPORTS_SECURE_STORAGE = new SafeInjectionToken<boolean>("SUPPORTS_SECURE_STORAGE");
|
||||
export const LOCALES_DIRECTORY = new SafeInjectionToken<string>("LOCALES_DIRECTORY");
|
||||
export const SYSTEM_LANGUAGE = new SafeInjectionToken<string>("SYSTEM_LANGUAGE");
|
||||
export const LOG_MAC_FAILURES = new SafeInjectionToken<boolean>("LOG_MAC_FAILURES");
|
||||
|
||||
@@ -319,7 +319,6 @@ import {
|
||||
SafeInjectionToken,
|
||||
SECURE_STORAGE,
|
||||
STATE_FACTORY,
|
||||
SUPPORTS_SECURE_STORAGE,
|
||||
SYSTEM_LANGUAGE,
|
||||
SYSTEM_THEME_OBSERVABLE,
|
||||
WINDOW,
|
||||
@@ -345,12 +344,6 @@ const safeProviders: SafeProvider[] = [
|
||||
useFactory: (i18nService: I18nServiceAbstraction) => i18nService.translationLocale,
|
||||
deps: [I18nServiceAbstraction],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: SUPPORTS_SECURE_STORAGE,
|
||||
useFactory: (platformUtilsService: PlatformUtilsServiceAbstraction) =>
|
||||
platformUtilsService.supportsSecureStorage(),
|
||||
deps: [PlatformUtilsServiceAbstraction],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: LOCALES_DIRECTORY,
|
||||
useValue: "./locales",
|
||||
@@ -589,7 +582,7 @@ const safeProviders: SafeProvider[] = [
|
||||
deps: [
|
||||
SingleUserStateProvider,
|
||||
GlobalStateProvider,
|
||||
SUPPORTS_SECURE_STORAGE,
|
||||
PlatformUtilsServiceAbstraction,
|
||||
SECURE_STORAGE,
|
||||
KeyGenerationServiceAbstraction,
|
||||
EncryptService,
|
||||
|
||||
@@ -8,6 +8,7 @@ import { VaultTimeoutAction } from "../../enums/vault-timeout-action.enum";
|
||||
import { EncryptService } from "../../platform/abstractions/encrypt.service";
|
||||
import { KeyGenerationService } from "../../platform/abstractions/key-generation.service";
|
||||
import { LogService } from "../../platform/abstractions/log.service";
|
||||
import { PlatformUtilsService } from "../../platform/abstractions/platform-utils.service";
|
||||
import { AbstractStorageService } from "../../platform/abstractions/storage.service";
|
||||
import { StorageLocation } from "../../platform/enums";
|
||||
import { StorageOptions } from "../../platform/models/domain/storage-options";
|
||||
@@ -3011,10 +3012,13 @@ describe("TokenService", () => {
|
||||
|
||||
// Helpers
|
||||
function createTokenService(supportsSecureStorage: boolean) {
|
||||
const platformUtilsService = mock<PlatformUtilsService>();
|
||||
platformUtilsService.supportsSecureStorage.mockReturnValue(supportsSecureStorage);
|
||||
|
||||
return new TokenService(
|
||||
singleUserStateProvider,
|
||||
globalStateProvider,
|
||||
supportsSecureStorage,
|
||||
platformUtilsService,
|
||||
secureStorageService,
|
||||
keyGenerationService,
|
||||
encryptService,
|
||||
|
||||
@@ -9,6 +9,7 @@ import { VaultTimeoutAction } from "../../enums/vault-timeout-action.enum";
|
||||
import { EncryptService } from "../../platform/abstractions/encrypt.service";
|
||||
import { KeyGenerationService } from "../../platform/abstractions/key-generation.service";
|
||||
import { LogService } from "../../platform/abstractions/log.service";
|
||||
import { PlatformUtilsService } from "../../platform/abstractions/platform-utils.service";
|
||||
import { AbstractStorageService } from "../../platform/abstractions/storage.service";
|
||||
import { StorageLocation } from "../../platform/enums";
|
||||
import { Utils } from "../../platform/misc/utils";
|
||||
@@ -131,7 +132,7 @@ export class TokenService implements TokenServiceAbstraction {
|
||||
// this service into the AccountService, we will make a circular dependency
|
||||
private singleUserStateProvider: SingleUserStateProvider,
|
||||
private globalStateProvider: GlobalStateProvider,
|
||||
private readonly platformSupportsSecureStorage: boolean,
|
||||
private readonly platforUtilsService: PlatformUtilsService,
|
||||
private secureStorageService: AbstractStorageService,
|
||||
private keyGenerationService: KeyGenerationService,
|
||||
private encryptService: EncryptService,
|
||||
@@ -262,7 +263,7 @@ export class TokenService implements TokenServiceAbstraction {
|
||||
}
|
||||
|
||||
private async getOrCreateAccessTokenKey(userId: UserId): Promise<AccessTokenKey> {
|
||||
if (!this.platformSupportsSecureStorage) {
|
||||
if (!this.platforUtilsService.supportsSecureStorage()) {
|
||||
throw new Error("Platform does not support secure storage. Cannot obtain access token key.");
|
||||
}
|
||||
|
||||
@@ -417,7 +418,7 @@ export class TokenService implements TokenServiceAbstraction {
|
||||
// we can't determine storage location w/out vaultTimeoutAction and vaultTimeout
|
||||
// but we can simply clear all locations to avoid the need to require those parameters.
|
||||
|
||||
if (this.platformSupportsSecureStorage) {
|
||||
if (this.platforUtilsService.supportsSecureStorage()) {
|
||||
// Always clear the access token key when clearing the access token
|
||||
// The next set of the access token will create a new access token key
|
||||
await this.clearAccessTokenKey(userId);
|
||||
@@ -450,7 +451,7 @@ export class TokenService implements TokenServiceAbstraction {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.platformSupportsSecureStorage) {
|
||||
if (this.platforUtilsService.supportsSecureStorage()) {
|
||||
let accessTokenKey: AccessTokenKey;
|
||||
try {
|
||||
accessTokenKey = await this.getAccessTokenKey(userId);
|
||||
@@ -627,7 +628,7 @@ export class TokenService implements TokenServiceAbstraction {
|
||||
return refreshTokenDisk;
|
||||
}
|
||||
|
||||
if (this.platformSupportsSecureStorage) {
|
||||
if (this.platforUtilsService.supportsSecureStorage()) {
|
||||
try {
|
||||
const refreshTokenSecureStorage = await this.getStringFromSecureStorage(
|
||||
userId,
|
||||
@@ -663,7 +664,7 @@ export class TokenService implements TokenServiceAbstraction {
|
||||
// we can't determine storage location w/out vaultTimeoutAction and vaultTimeout
|
||||
// but we can simply clear all locations to avoid the need to require those parameters
|
||||
|
||||
if (this.platformSupportsSecureStorage) {
|
||||
if (this.platforUtilsService.supportsSecureStorage()) {
|
||||
await this.secureStorageService.remove(
|
||||
`${userId}${this.refreshTokenSecureStorageKey}`,
|
||||
this.getSecureStorageOptions(userId),
|
||||
@@ -1086,7 +1087,7 @@ export class TokenService implements TokenServiceAbstraction {
|
||||
) {
|
||||
return TokenStorageLocation.Memory;
|
||||
} else {
|
||||
if (useSecureStorage && this.platformSupportsSecureStorage) {
|
||||
if (useSecureStorage && this.platforUtilsService.supportsSecureStorage()) {
|
||||
return TokenStorageLocation.SecureStorage;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user