diff --git a/angular/src/components/remove-password.component.ts b/angular/src/components/remove-password.component.ts index 91c35312..56132cbd 100644 --- a/angular/src/components/remove-password.component.ts +++ b/angular/src/components/remove-password.component.ts @@ -8,11 +8,8 @@ import { ApiService } from 'jslib-common/abstractions/api.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { KeyConnectorService } from 'jslib-common/abstractions/keyConnector.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; +import { StateService } from 'jslib-common/abstractions/state.service'; import { SyncService } from 'jslib-common/abstractions/sync.service'; -import { UserService } from 'jslib-common/abstractions/user.service'; - -import { ConstantsService } from 'jslib-common/services/constants.service'; import { Organization } from 'jslib-common/models/domain/organization'; @@ -27,14 +24,14 @@ export class RemovePasswordComponent implements OnInit { organization: Organization; email: string; - constructor(private router: Router, private userService: UserService, + constructor(private router: Router, private stateService: StateService, private apiService: ApiService, private syncService: SyncService, private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, - private keyConnectorService: KeyConnectorService, private storageService: StorageService) { } + private keyConnectorService: KeyConnectorService) { } async ngOnInit() { this.organization = await this.keyConnectorService.getManagingOrganization(); - this.email = await this.userService.getEmail(); + this.email = await this.stateService.getEmail(); await this.syncService.fullSync(false); this.loading = false; } diff --git a/common/src/abstractions/state.service.ts b/common/src/abstractions/state.service.ts index 6880fec8..2f213e84 100644 --- a/common/src/abstractions/state.service.ts +++ b/common/src/abstractions/state.service.ts @@ -46,6 +46,7 @@ export abstract class StateService { getCanAccessPremium: (options?: StorageOptions) => Promise; getClearClipboard: (options?: StorageOptions) => Promise; getCollapsedGroupings: (options?: StorageOptions) => Promise>; + getConvertAccountToKeyConnector: (options?: StorageOptions) => Promise; getCryptoMasterKey: (options?: StorageOptions) => Promise; getCryptoMasterKeyB64: (options: StorageOptions) => Promise; getDecodedToken: (options?: StorageOptions) => Promise; @@ -135,6 +136,7 @@ export abstract class StateService { getTheme: (options?: StorageOptions) => Promise; getTwoFactorToken: (options?: StorageOptions) => Promise; getUserId: (options?: StorageOptions) => Promise; + getUsesKeyConnector: (options?: StorageOptions) => Promise; getVaultTimeout: (options?: StorageOptions) => Promise; getVaultTimeoutAction: (options?: StorageOptions) => Promise; getWindow: () => Promise>; @@ -152,6 +154,7 @@ export abstract class StateService { setBiometricUnlock: (value: boolean, options?: StorageOptions) => Promise; setClearClipboard: (value: number, options?: StorageOptions) => Promise; setCollapsedGroupings: (value: Set, options?: StorageOptions) => Promise; + setConvertAccountToKeyConnector: (value: boolean, options?: StorageOptions) => Promise; setCryptoMasterKey: (value: SymmetricCryptoKey, options?: StorageOptions) => Promise; setCryptoMasterKeyB64: (value: string, options: StorageOptions) => Promise; setDecodedToken: (value: any, options?: StorageOptions) => Promise; @@ -238,6 +241,7 @@ export abstract class StateService { setSsoState: (value: string, options?: StorageOptions) => Promise; setTheme: (value: string, options?: StorageOptions) => Promise; setTwoFactorToken: (value: string, options?: StorageOptions) => Promise; + setUsesKeyConnector: (vaule: boolean, options?: StorageOptions) => Promise; setVaultTimeout: (value: number, options?: StorageOptions) => Promise; setVaultTimeoutAction: (value: string, options?: StorageOptions) => Promise; setWindow: (value: Map) => Promise; diff --git a/common/src/models/domain/account.ts b/common/src/models/domain/account.ts index 4cd755de..d1b58ebc 100644 --- a/common/src/models/domain/account.ts +++ b/common/src/models/domain/account.ts @@ -130,6 +130,8 @@ export class Account { enableBiometric: boolean; enableBiometrics: boolean; noAutoPromptBiometricsText: string; + convertAccountToKeyConnector: boolean; + usesKeyConnector: boolean; private hasPremiumPersonally: boolean; constructor(userId: string, userEmail: string, diff --git a/common/src/services/keyConnector.service.ts b/common/src/services/keyConnector.service.ts index 68aac9a2..085b87c7 100644 --- a/common/src/services/keyConnector.service.ts +++ b/common/src/services/keyConnector.service.ts @@ -3,9 +3,9 @@ import { CryptoService } from '../abstractions/crypto.service'; import { EnvironmentService } from '../abstractions/environment.service'; import { KeyConnectorService as KeyConnectorServiceAbstraction } from '../abstractions/keyConnector.service'; import { LogService } from '../abstractions/log.service'; -import { StorageService } from '../abstractions/storage.service'; +import { OrganizationService } from '../abstractions/organization.service'; +import { StateService } from '../abstractions/state.service'; import { TokenService } from '../abstractions/token.service'; -import { UserService } from '../abstractions/user.service'; import { OrganizationUserType } from '../enums/organizationUserType'; @@ -15,26 +15,18 @@ import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey'; import { KeyConnectorUserKeyRequest } from '../models/request/keyConnectorUserKeyRequest'; -const Keys = { - usesKeyConnector: 'usesKeyConnector', - convertAccountToKeyConnector: 'convertAccountToKeyConnector', -}; - export class KeyConnectorService implements KeyConnectorServiceAbstraction { - private usesKeyConnector?: boolean = null; - - constructor(private storageService: StorageService, private userService: UserService, - private cryptoService: CryptoService, private apiService: ApiService, - private environmentService: EnvironmentService, private tokenService: TokenService, - private logService: LogService) { } + constructor(private stateService: StateService, private cryptoService: CryptoService, + private apiService: ApiService, private environmentService: EnvironmentService, + private tokenService: TokenService, private logService: LogService, + private organizationService: OrganizationService) { } setUsesKeyConnector(usesKeyConnector: boolean) { - this.usesKeyConnector = usesKeyConnector; - return this.storageService.save(Keys.usesKeyConnector, usesKeyConnector); + return this.stateService.setUsesKeyConnector(usesKeyConnector); } async getUsesKeyConnector(): Promise { - return this.usesKeyConnector ??= await this.storageService.get(Keys.usesKeyConnector); + return await this.stateService.getUsesKeyConnector(); } async userNeedsMigration() { @@ -80,7 +72,7 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { } async getManagingOrganization() { - const orgs = await this.userService.getAllOrganizations(); + const orgs = await this.organizationService.getAll(); return orgs.find(o => o.usesKeyConnector && o.type !== OrganizationUserType.Admin && @@ -89,15 +81,15 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { } async setConvertAccountRequired(status: boolean) { - await this.storageService.save(Keys.convertAccountToKeyConnector, status); + await this.stateService.setConvertAccountToKeyConnector(status); } async getConvertAccountRequired(): Promise { - return await this.storageService.get(Keys.convertAccountToKeyConnector); + return await this.stateService.getConvertAccountToKeyConnector(); } async removeConvertAccountRequired() { - await this.storageService.remove(Keys.convertAccountToKeyConnector); + await this.stateService.setConvertAccountToKeyConnector(null); } async clear() { diff --git a/common/src/services/state.service.ts b/common/src/services/state.service.ts index 28986c00..c4985d79 100644 --- a/common/src/services/state.service.ts +++ b/common/src/services/state.service.ts @@ -517,6 +517,14 @@ export class StateService implements StateServiceAbstraction { return (await this.getGlobals(this.reconcileOptions(options, this.defaultInMemoryOptions))).organizationInvitation; } + async getConvertAccountToKeyConnector(options?: StorageOptions): Promise { + return (await this.getAccount(this.reconcileOptions(options, this.defaultOnDiskOptions)))?.convertAccountToKeyConnector; + }; + + async getUsesKeyConnector(options?: StorageOptions): Promise { + return (await this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions)))?.usesKeyConnector; + }; + async setAccessToken(value: string, options?: StorageOptions): Promise { const account = await this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions)); account.accessToken = value; @@ -1154,6 +1162,18 @@ export class StateService implements StateServiceAbstraction { await this.saveGlobals(globals, this.reconcileOptions(options, this.defaultInMemoryOptions)); } + async setConvertAccountToKeyConnector(value: boolean, options?: StorageOptions): Promise { + const account = await this.getAccount(this.reconcileOptions(options, this.defaultOnDiskOptions)); + account.convertAccountToKeyConnector = value; + await this.saveAccount(account, this.reconcileOptions(options, this.defaultOnDiskOptions)); + } + + async setUsesKeyConnector(value: boolean, options?: StorageOptions): Promise { + const account = await this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions)); + account.usesKeyConnector = value; + await this.saveAccount(account, this.reconcileOptions(options, this.defaultInMemoryOptions)); + } + async setActiveUser(userId: string): Promise { if (!this.state.accounts[userId]) { return; diff --git a/common/src/services/sync.service.ts b/common/src/services/sync.service.ts index b0d6e36d..18015ccc 100644 --- a/common/src/services/sync.service.ts +++ b/common/src/services/sync.service.ts @@ -13,11 +13,6 @@ import { SendService } from '../abstractions/send.service'; import { SettingsService } from '../abstractions/settings.service'; import { StateService } from '../abstractions/state.service'; import { SyncService as SyncServiceAbstraction } from '../abstractions/sync.service'; -<<<<<<< HEAD -======= -import { TokenService } from '../abstractions/token.service'; -import { UserService } from '../abstractions/user.service'; ->>>>>>> master import { CipherData } from '../models/data/cipherData'; import { CollectionData } from '../models/data/collectionData'; @@ -48,14 +43,9 @@ export class SyncService implements SyncServiceAbstraction { private cryptoService: CryptoService, private collectionService: CollectionService, private messagingService: MessagingService, private policyService: PolicyService, private sendService: SendService, private logService: LogService, -<<<<<<< HEAD - private logoutCallback: (expired: boolean) => Promise, private stateService: StateService, - private organizationService: OrganizationService, private providerService: ProviderService) { -======= - private tokenService: TokenService, private keyConnectorService: KeyConnectorService, - private logoutCallback: (expired: boolean) => Promise) { ->>>>>>> master - } + private keyConnectorService: KeyConnectorService, private stateService: StateService, + private organizationService: OrganizationService, private providerService: ProviderService, + private logoutCallback: (expired: boolean) => Promise) { } async getLastSync(): Promise { if (await this.stateService.getUserId() == null) { @@ -298,16 +288,10 @@ export class SyncService implements SyncServiceAbstraction { await this.cryptoService.setEncPrivateKey(response.privateKey); await this.cryptoService.setProviderKeys(response.providers); await this.cryptoService.setOrgKeys(response.organizations, response.providerOrganizations); -<<<<<<< HEAD await this.stateService.setSecurityStamp(response.securityStamp); await this.stateService.setEmailVerified(response.emailVerified); await this.stateService.setForcePasswordReset(response.forcePasswordReset); -======= - await this.userService.setSecurityStamp(response.securityStamp); - await this.userService.setEmailVerified(response.emailVerified); - await this.userService.setForcePasswordReset(response.forcePasswordReset); await this.keyConnectorService.setUsesKeyConnector(response.usesKeyConnector); ->>>>>>> master const organizations: { [id: string]: OrganizationData; } = {}; response.organizations.forEach(o => { diff --git a/common/src/services/vaultTimeout.service.ts b/common/src/services/vaultTimeout.service.ts index fd7d1b4e..9e12bec3 100644 --- a/common/src/services/vaultTimeout.service.ts +++ b/common/src/services/vaultTimeout.service.ts @@ -19,18 +19,11 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction { constructor(private cipherService: CipherService, private folderService: FolderService, private collectionService: CollectionService, private cryptoService: CryptoService, -<<<<<<< HEAD protected platformUtilsService: PlatformUtilsService, private messagingService: MessagingService, private searchService: SearchService, private tokenService: TokenService, - private policyService: PolicyService, private stateService: StateService, - private lockedCallback: () => Promise = null, private loggedOutCallback: (userId?: string) => Promise = null) { -======= - protected platformUtilsService: PlatformUtilsService, private storageService: StorageService, - private messagingService: MessagingService, private searchService: SearchService, - private userService: UserService, private tokenService: TokenService, private policyService: PolicyService, - private keyConnectorService: KeyConnectorService, - private lockedCallback: () => Promise = null, private loggedOutCallback: () => Promise = null) { ->>>>>>> master + private policyService: PolicyService, private keyConnectorService: KeyConnectorService, + private stateService: StateService, private lockedCallback: () => Promise = null, + private loggedOutCallback: (userId?: string) => Promise = null) { } init(checkOnInterval: boolean) { @@ -103,7 +96,15 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction { return; } -<<<<<<< HEAD + if (await this.keyConnectorService.getUsesKeyConnector()) { + const pinSet = await this.isPinLockSet(); + const pinLock = (pinSet[0] && await this.stateService.getDecryptedPinProtected() != null) || pinSet[1]; + + if (!pinLock && !await this.isBiometricLockSet()) { + await this.logOut(); + } + } + if (userId == null || userId === await this.stateService.getUserId()) { this.searchService.clearIndex(); } @@ -119,29 +120,6 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction { await this.stateService.setBiometricLocked(true, { userId: userId }); this.messagingService.send('locked', { userId: userId }); -======= - if (await this.keyConnectorService.getUsesKeyConnector()) { - const pinSet = await this.isPinLockSet(); - const pinLock = (pinSet[0] && this.pinProtectedKey != null) || pinSet[1]; - - if (!pinLock && !await this.isBiometricLockSet()) { - await this.logOut(); - } - } - - this.biometricLocked = true; - this.everBeenUnlocked = true; - await this.cryptoService.clearKey(false); - await this.cryptoService.clearOrgKeys(true); - await this.cryptoService.clearKeyPair(true); - await this.cryptoService.clearEncKey(true); - - this.folderService.clearCache(); - this.cipherService.clearCache(); - this.collectionService.clearCache(); - this.searchService.clearIndex(); - this.messagingService.send('locked'); ->>>>>>> master if (this.lockedCallback != null) { await this.lockedCallback(); } diff --git a/node/src/cli/commands/login.command.ts b/node/src/cli/commands/login.command.ts index df3ca05e..0bb744fd 100644 --- a/node/src/cli/commands/login.command.ts +++ b/node/src/cli/commands/login.command.ts @@ -49,14 +49,9 @@ export class LoginCommand { protected i18nService: I18nService, protected environmentService: EnvironmentService, protected passwordGenerationService: PasswordGenerationService, protected cryptoFunctionService: CryptoFunctionService, protected platformUtilsService: PlatformUtilsService, -<<<<<<< HEAD protected stateService: StateService, protected cryptoService: CryptoService, - protected policyService: PolicyService, clientId: string, private syncService: SyncService) { -======= - protected userService: UserService, protected cryptoService: CryptoService, protected policyService: PolicyService, clientId: string, private syncService: SyncService, protected keyConnectorService: KeyConnectorService) { ->>>>>>> master this.clientId = clientId; }