mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 14:23:32 +00:00
PM-6787 - Rename DeviceTrustCryptoService to DeviceTrustService (#8819)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { DeviceTrustCryptoService } from "@bitwarden/common/auth/services/device-trust-crypto.service.implementation";
|
import { DeviceTrustService } from "@bitwarden/common/auth/services/device-trust.service.implementation";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DevicesApiServiceInitOptions,
|
DevicesApiServiceInitOptions,
|
||||||
@@ -52,9 +52,9 @@ import {
|
|||||||
userDecryptionOptionsServiceFactory,
|
userDecryptionOptionsServiceFactory,
|
||||||
} from "./user-decryption-options-service.factory";
|
} from "./user-decryption-options-service.factory";
|
||||||
|
|
||||||
type DeviceTrustCryptoServiceFactoryOptions = FactoryOptions;
|
type DeviceTrustServiceFactoryOptions = FactoryOptions;
|
||||||
|
|
||||||
export type DeviceTrustCryptoServiceInitOptions = DeviceTrustCryptoServiceFactoryOptions &
|
export type DeviceTrustServiceInitOptions = DeviceTrustServiceFactoryOptions &
|
||||||
KeyGenerationServiceInitOptions &
|
KeyGenerationServiceInitOptions &
|
||||||
CryptoFunctionServiceInitOptions &
|
CryptoFunctionServiceInitOptions &
|
||||||
CryptoServiceInitOptions &
|
CryptoServiceInitOptions &
|
||||||
@@ -67,16 +67,16 @@ export type DeviceTrustCryptoServiceInitOptions = DeviceTrustCryptoServiceFactor
|
|||||||
SecureStorageServiceInitOptions &
|
SecureStorageServiceInitOptions &
|
||||||
UserDecryptionOptionsServiceInitOptions;
|
UserDecryptionOptionsServiceInitOptions;
|
||||||
|
|
||||||
export function deviceTrustCryptoServiceFactory(
|
export function deviceTrustServiceFactory(
|
||||||
cache: { deviceTrustCryptoService?: DeviceTrustCryptoServiceAbstraction } & CachedServices,
|
cache: { deviceTrustService?: DeviceTrustServiceAbstraction } & CachedServices,
|
||||||
opts: DeviceTrustCryptoServiceInitOptions,
|
opts: DeviceTrustServiceInitOptions,
|
||||||
): Promise<DeviceTrustCryptoServiceAbstraction> {
|
): Promise<DeviceTrustServiceAbstraction> {
|
||||||
return factory(
|
return factory(
|
||||||
cache,
|
cache,
|
||||||
"deviceTrustCryptoService",
|
"deviceTrustService",
|
||||||
opts,
|
opts,
|
||||||
async () =>
|
async () =>
|
||||||
new DeviceTrustCryptoService(
|
new DeviceTrustService(
|
||||||
await keyGenerationServiceFactory(cache, opts),
|
await keyGenerationServiceFactory(cache, opts),
|
||||||
await cryptoFunctionServiceFactory(cache, opts),
|
await cryptoFunctionServiceFactory(cache, opts),
|
||||||
await cryptoServiceFactory(cache, opts),
|
await cryptoServiceFactory(cache, opts),
|
||||||
@@ -65,9 +65,9 @@ import {
|
|||||||
AuthRequestServiceInitOptions,
|
AuthRequestServiceInitOptions,
|
||||||
} from "./auth-request-service.factory";
|
} from "./auth-request-service.factory";
|
||||||
import {
|
import {
|
||||||
deviceTrustCryptoServiceFactory,
|
deviceTrustServiceFactory,
|
||||||
DeviceTrustCryptoServiceInitOptions,
|
DeviceTrustServiceInitOptions,
|
||||||
} from "./device-trust-crypto-service.factory";
|
} from "./device-trust-service.factory";
|
||||||
import {
|
import {
|
||||||
keyConnectorServiceFactory,
|
keyConnectorServiceFactory,
|
||||||
KeyConnectorServiceInitOptions,
|
KeyConnectorServiceInitOptions,
|
||||||
@@ -102,7 +102,7 @@ export type LoginStrategyServiceInitOptions = LoginStrategyServiceFactoryOptions
|
|||||||
EncryptServiceInitOptions &
|
EncryptServiceInitOptions &
|
||||||
PolicyServiceInitOptions &
|
PolicyServiceInitOptions &
|
||||||
PasswordStrengthServiceInitOptions &
|
PasswordStrengthServiceInitOptions &
|
||||||
DeviceTrustCryptoServiceInitOptions &
|
DeviceTrustServiceInitOptions &
|
||||||
AuthRequestServiceInitOptions &
|
AuthRequestServiceInitOptions &
|
||||||
UserDecryptionOptionsServiceInitOptions &
|
UserDecryptionOptionsServiceInitOptions &
|
||||||
GlobalStateProviderInitOptions &
|
GlobalStateProviderInitOptions &
|
||||||
@@ -135,7 +135,7 @@ export function loginStrategyServiceFactory(
|
|||||||
await encryptServiceFactory(cache, opts),
|
await encryptServiceFactory(cache, opts),
|
||||||
await passwordStrengthServiceFactory(cache, opts),
|
await passwordStrengthServiceFactory(cache, opts),
|
||||||
await policyServiceFactory(cache, opts),
|
await policyServiceFactory(cache, opts),
|
||||||
await deviceTrustCryptoServiceFactory(cache, opts),
|
await deviceTrustServiceFactory(cache, opts),
|
||||||
await authRequestServiceFactory(cache, opts),
|
await authRequestServiceFactory(cache, opts),
|
||||||
await internalUserDecryptionOptionServiceFactory(cache, opts),
|
await internalUserDecryptionOptionServiceFactory(cache, opts),
|
||||||
await globalStateProviderFactory(cache, opts),
|
await globalStateProviderFactory(cache, opts),
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abs
|
|||||||
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
||||||
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
||||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||||
@@ -60,7 +60,7 @@ export class LockComponent extends BaseLockComponent {
|
|||||||
passwordStrengthService: PasswordStrengthServiceAbstraction,
|
passwordStrengthService: PasswordStrengthServiceAbstraction,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
dialogService: DialogService,
|
dialogService: DialogService,
|
||||||
deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction,
|
deviceTrustService: DeviceTrustServiceAbstraction,
|
||||||
userVerificationService: UserVerificationService,
|
userVerificationService: UserVerificationService,
|
||||||
pinCryptoService: PinCryptoServiceAbstraction,
|
pinCryptoService: PinCryptoServiceAbstraction,
|
||||||
private routerService: BrowserRouterService,
|
private routerService: BrowserRouterService,
|
||||||
@@ -85,7 +85,7 @@ export class LockComponent extends BaseLockComponent {
|
|||||||
policyService,
|
policyService,
|
||||||
passwordStrengthService,
|
passwordStrengthService,
|
||||||
dialogService,
|
dialogService,
|
||||||
deviceTrustCryptoService,
|
deviceTrustService,
|
||||||
userVerificationService,
|
userVerificationService,
|
||||||
pinCryptoService,
|
pinCryptoService,
|
||||||
biometricStateService,
|
biometricStateService,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { AnonymousHubService } from "@bitwarden/common/auth/abstractions/anonymous-hub.service";
|
import { AnonymousHubService } from "@bitwarden/common/auth/abstractions/anonymous-hub.service";
|
||||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
||||||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
@@ -47,7 +47,7 @@ export class LoginViaAuthRequestComponent extends BaseLoginWithDeviceComponent {
|
|||||||
stateService: StateService,
|
stateService: StateService,
|
||||||
loginEmailService: LoginEmailServiceAbstraction,
|
loginEmailService: LoginEmailServiceAbstraction,
|
||||||
syncService: SyncService,
|
syncService: SyncService,
|
||||||
deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction,
|
deviceTrustService: DeviceTrustServiceAbstraction,
|
||||||
authRequestService: AuthRequestServiceAbstraction,
|
authRequestService: AuthRequestServiceAbstraction,
|
||||||
loginStrategyService: LoginStrategyServiceAbstraction,
|
loginStrategyService: LoginStrategyServiceAbstraction,
|
||||||
accountService: AccountService,
|
accountService: AccountService,
|
||||||
@@ -69,7 +69,7 @@ export class LoginViaAuthRequestComponent extends BaseLoginWithDeviceComponent {
|
|||||||
validationService,
|
validationService,
|
||||||
stateService,
|
stateService,
|
||||||
loginEmailService,
|
loginEmailService,
|
||||||
deviceTrustCryptoService,
|
deviceTrustService,
|
||||||
authRequestService,
|
authRequestService,
|
||||||
loginStrategyService,
|
loginStrategyService,
|
||||||
accountService,
|
accountService,
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import { ProviderService } from "@bitwarden/common/admin-console/services/provid
|
|||||||
import { AccountService as AccountServiceAbstraction } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService as AccountServiceAbstraction } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { AuthService as AuthServiceAbstraction } from "@bitwarden/common/auth/abstractions/auth.service";
|
import { AuthService as AuthServiceAbstraction } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||||
import { AvatarService as AvatarServiceAbstraction } from "@bitwarden/common/auth/abstractions/avatar.service";
|
import { AvatarService as AvatarServiceAbstraction } from "@bitwarden/common/auth/abstractions/avatar.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { DevicesServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices/devices.service.abstraction";
|
import { DevicesServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices/devices.service.abstraction";
|
||||||
import { DevicesApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices-api.service.abstraction";
|
import { DevicesApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices-api.service.abstraction";
|
||||||
import { KeyConnectorService as KeyConnectorServiceAbstraction } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
import { KeyConnectorService as KeyConnectorServiceAbstraction } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
||||||
@@ -45,7 +45,7 @@ import { ForceSetPasswordReason } from "@bitwarden/common/auth/models/domain/for
|
|||||||
import { AccountServiceImplementation } from "@bitwarden/common/auth/services/account.service";
|
import { AccountServiceImplementation } from "@bitwarden/common/auth/services/account.service";
|
||||||
import { AuthService } from "@bitwarden/common/auth/services/auth.service";
|
import { AuthService } from "@bitwarden/common/auth/services/auth.service";
|
||||||
import { AvatarService } from "@bitwarden/common/auth/services/avatar.service";
|
import { AvatarService } from "@bitwarden/common/auth/services/avatar.service";
|
||||||
import { DeviceTrustCryptoService } from "@bitwarden/common/auth/services/device-trust-crypto.service.implementation";
|
import { DeviceTrustService } from "@bitwarden/common/auth/services/device-trust.service.implementation";
|
||||||
import { DevicesServiceImplementation } from "@bitwarden/common/auth/services/devices/devices.service.implementation";
|
import { DevicesServiceImplementation } from "@bitwarden/common/auth/services/devices/devices.service.implementation";
|
||||||
import { DevicesApiServiceImplementation } from "@bitwarden/common/auth/services/devices-api.service.implementation";
|
import { DevicesApiServiceImplementation } from "@bitwarden/common/auth/services/devices-api.service.implementation";
|
||||||
import { KeyConnectorService } from "@bitwarden/common/auth/services/key-connector.service";
|
import { KeyConnectorService } from "@bitwarden/common/auth/services/key-connector.service";
|
||||||
@@ -318,7 +318,7 @@ export default class MainBackground {
|
|||||||
configApiService: ConfigApiServiceAbstraction;
|
configApiService: ConfigApiServiceAbstraction;
|
||||||
devicesApiService: DevicesApiServiceAbstraction;
|
devicesApiService: DevicesApiServiceAbstraction;
|
||||||
devicesService: DevicesServiceAbstraction;
|
devicesService: DevicesServiceAbstraction;
|
||||||
deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction;
|
deviceTrustService: DeviceTrustServiceAbstraction;
|
||||||
authRequestService: AuthRequestServiceAbstraction;
|
authRequestService: AuthRequestServiceAbstraction;
|
||||||
accountService: AccountServiceAbstraction;
|
accountService: AccountServiceAbstraction;
|
||||||
globalStateProvider: GlobalStateProvider;
|
globalStateProvider: GlobalStateProvider;
|
||||||
@@ -612,7 +612,7 @@ export default class MainBackground {
|
|||||||
this.userDecryptionOptionsService = new UserDecryptionOptionsService(this.stateProvider);
|
this.userDecryptionOptionsService = new UserDecryptionOptionsService(this.stateProvider);
|
||||||
|
|
||||||
this.devicesApiService = new DevicesApiServiceImplementation(this.apiService);
|
this.devicesApiService = new DevicesApiServiceImplementation(this.apiService);
|
||||||
this.deviceTrustCryptoService = new DeviceTrustCryptoService(
|
this.deviceTrustService = new DeviceTrustService(
|
||||||
this.keyGenerationService,
|
this.keyGenerationService,
|
||||||
this.cryptoFunctionService,
|
this.cryptoFunctionService,
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
@@ -670,7 +670,7 @@ export default class MainBackground {
|
|||||||
this.encryptService,
|
this.encryptService,
|
||||||
this.passwordStrengthService,
|
this.passwordStrengthService,
|
||||||
this.policyService,
|
this.policyService,
|
||||||
this.deviceTrustCryptoService,
|
this.deviceTrustService,
|
||||||
this.authRequestService,
|
this.authRequestService,
|
||||||
this.userDecryptionOptionsService,
|
this.userDecryptionOptionsService,
|
||||||
this.globalStateProvider,
|
this.globalStateProvider,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import { OrganizationService } from "@bitwarden/common/admin-console/abstraction
|
|||||||
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||||
import { AccountService as AccountServiceAbstraction } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService as AccountServiceAbstraction } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { AuthService as AuthServiceAbstraction } from "@bitwarden/common/auth/abstractions/auth.service";
|
import { AuthService as AuthServiceAbstraction } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { DevicesServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices/devices.service.abstraction";
|
import { DevicesServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices/devices.service.abstraction";
|
||||||
import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
||||||
import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction";
|
import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction";
|
||||||
@@ -250,8 +250,8 @@ const safeProviders: SafeProvider[] = [
|
|||||||
deps: [],
|
deps: [],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
provide: DeviceTrustCryptoServiceAbstraction,
|
provide: DeviceTrustServiceAbstraction,
|
||||||
useFactory: getBgService<DeviceTrustCryptoServiceAbstraction>("deviceTrustCryptoService"),
|
useFactory: getBgService<DeviceTrustServiceAbstraction>("deviceTrustService"),
|
||||||
deps: [],
|
deps: [],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
|
|||||||
@@ -28,13 +28,13 @@ import { ProviderApiService } from "@bitwarden/common/admin-console/services/pro
|
|||||||
import { ProviderService } from "@bitwarden/common/admin-console/services/provider.service";
|
import { ProviderService } from "@bitwarden/common/admin-console/services/provider.service";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { AvatarService as AvatarServiceAbstraction } from "@bitwarden/common/auth/abstractions/avatar.service";
|
import { AvatarService as AvatarServiceAbstraction } from "@bitwarden/common/auth/abstractions/avatar.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { DevicesApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices-api.service.abstraction";
|
import { DevicesApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices-api.service.abstraction";
|
||||||
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
||||||
import { AccountServiceImplementation } from "@bitwarden/common/auth/services/account.service";
|
import { AccountServiceImplementation } from "@bitwarden/common/auth/services/account.service";
|
||||||
import { AuthService } from "@bitwarden/common/auth/services/auth.service";
|
import { AuthService } from "@bitwarden/common/auth/services/auth.service";
|
||||||
import { AvatarService } from "@bitwarden/common/auth/services/avatar.service";
|
import { AvatarService } from "@bitwarden/common/auth/services/avatar.service";
|
||||||
import { DeviceTrustCryptoService } from "@bitwarden/common/auth/services/device-trust-crypto.service.implementation";
|
import { DeviceTrustService } from "@bitwarden/common/auth/services/device-trust.service.implementation";
|
||||||
import { DevicesApiServiceImplementation } from "@bitwarden/common/auth/services/devices-api.service.implementation";
|
import { DevicesApiServiceImplementation } from "@bitwarden/common/auth/services/devices-api.service.implementation";
|
||||||
import { KeyConnectorService } from "@bitwarden/common/auth/services/key-connector.service";
|
import { KeyConnectorService } from "@bitwarden/common/auth/services/key-connector.service";
|
||||||
import { MasterPasswordService } from "@bitwarden/common/auth/services/master-password/master-password.service";
|
import { MasterPasswordService } from "@bitwarden/common/auth/services/master-password/master-password.service";
|
||||||
@@ -217,7 +217,7 @@ export class Main {
|
|||||||
syncNotifierService: SyncNotifierService;
|
syncNotifierService: SyncNotifierService;
|
||||||
sendApiService: SendApiService;
|
sendApiService: SendApiService;
|
||||||
devicesApiService: DevicesApiServiceAbstraction;
|
devicesApiService: DevicesApiServiceAbstraction;
|
||||||
deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction;
|
deviceTrustService: DeviceTrustServiceAbstraction;
|
||||||
authRequestService: AuthRequestService;
|
authRequestService: AuthRequestService;
|
||||||
configApiService: ConfigApiServiceAbstraction;
|
configApiService: ConfigApiServiceAbstraction;
|
||||||
configService: ConfigService;
|
configService: ConfigService;
|
||||||
@@ -460,7 +460,7 @@ export class Main {
|
|||||||
this.userDecryptionOptionsService = new UserDecryptionOptionsService(this.stateProvider);
|
this.userDecryptionOptionsService = new UserDecryptionOptionsService(this.stateProvider);
|
||||||
|
|
||||||
this.devicesApiService = new DevicesApiServiceImplementation(this.apiService);
|
this.devicesApiService = new DevicesApiServiceImplementation(this.apiService);
|
||||||
this.deviceTrustCryptoService = new DeviceTrustCryptoService(
|
this.deviceTrustService = new DeviceTrustService(
|
||||||
this.keyGenerationService,
|
this.keyGenerationService,
|
||||||
this.cryptoFunctionService,
|
this.cryptoFunctionService,
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
@@ -505,7 +505,7 @@ export class Main {
|
|||||||
this.encryptService,
|
this.encryptService,
|
||||||
this.passwordStrengthService,
|
this.passwordStrengthService,
|
||||||
this.policyService,
|
this.policyService,
|
||||||
this.deviceTrustCryptoService,
|
this.deviceTrustService,
|
||||||
this.authRequestService,
|
this.authRequestService,
|
||||||
this.userDecryptionOptionsService,
|
this.userDecryptionOptionsService,
|
||||||
this.globalStateProvider,
|
this.globalStateProvider,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { VaultTimeoutService } from "@bitwarden/common/abstractions/vault-timeou
|
|||||||
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
||||||
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
||||||
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
||||||
import { FakeMasterPasswordService } from "@bitwarden/common/auth/services/master-password/fake-master-password.service";
|
import { FakeMasterPasswordService } from "@bitwarden/common/auth/services/master-password/fake-master-password.service";
|
||||||
@@ -145,8 +145,8 @@ describe("LockComponent", () => {
|
|||||||
useValue: mock<DialogService>(),
|
useValue: mock<DialogService>(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: DeviceTrustCryptoServiceAbstraction,
|
provide: DeviceTrustServiceAbstraction,
|
||||||
useValue: mock<DeviceTrustCryptoServiceAbstraction>(),
|
useValue: mock<DeviceTrustServiceAbstraction>(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: UserVerificationService,
|
provide: UserVerificationService,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { VaultTimeoutService } from "@bitwarden/common/abstractions/vault-timeou
|
|||||||
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
||||||
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
||||||
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
||||||
import { DeviceType } from "@bitwarden/common/enums";
|
import { DeviceType } from "@bitwarden/common/enums";
|
||||||
@@ -58,7 +58,7 @@ export class LockComponent extends BaseLockComponent {
|
|||||||
passwordStrengthService: PasswordStrengthServiceAbstraction,
|
passwordStrengthService: PasswordStrengthServiceAbstraction,
|
||||||
logService: LogService,
|
logService: LogService,
|
||||||
dialogService: DialogService,
|
dialogService: DialogService,
|
||||||
deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction,
|
deviceTrustService: DeviceTrustServiceAbstraction,
|
||||||
userVerificationService: UserVerificationService,
|
userVerificationService: UserVerificationService,
|
||||||
pinCryptoService: PinCryptoServiceAbstraction,
|
pinCryptoService: PinCryptoServiceAbstraction,
|
||||||
biometricStateService: BiometricStateService,
|
biometricStateService: BiometricStateService,
|
||||||
@@ -82,7 +82,7 @@ export class LockComponent extends BaseLockComponent {
|
|||||||
policyService,
|
policyService,
|
||||||
passwordStrengthService,
|
passwordStrengthService,
|
||||||
dialogService,
|
dialogService,
|
||||||
deviceTrustCryptoService,
|
deviceTrustService,
|
||||||
userVerificationService,
|
userVerificationService,
|
||||||
pinCryptoService,
|
pinCryptoService,
|
||||||
biometricStateService,
|
biometricStateService,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { AnonymousHubService } from "@bitwarden/common/auth/abstractions/anonymous-hub.service";
|
import { AnonymousHubService } from "@bitwarden/common/auth/abstractions/anonymous-hub.service";
|
||||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
||||||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
@@ -55,7 +55,7 @@ export class LoginViaAuthRequestComponent extends BaseLoginWithDeviceComponent {
|
|||||||
syncService: SyncService,
|
syncService: SyncService,
|
||||||
stateService: StateService,
|
stateService: StateService,
|
||||||
loginEmailService: LoginEmailServiceAbstraction,
|
loginEmailService: LoginEmailServiceAbstraction,
|
||||||
deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction,
|
deviceTrustService: DeviceTrustServiceAbstraction,
|
||||||
authRequestService: AuthRequestServiceAbstraction,
|
authRequestService: AuthRequestServiceAbstraction,
|
||||||
loginStrategyService: LoginStrategyServiceAbstraction,
|
loginStrategyService: LoginStrategyServiceAbstraction,
|
||||||
accountService: AccountService,
|
accountService: AccountService,
|
||||||
@@ -77,7 +77,7 @@ export class LoginViaAuthRequestComponent extends BaseLoginWithDeviceComponent {
|
|||||||
validationService,
|
validationService,
|
||||||
stateService,
|
stateService,
|
||||||
loginEmailService,
|
loginEmailService,
|
||||||
deviceTrustCryptoService,
|
deviceTrustService,
|
||||||
authRequestService,
|
authRequestService,
|
||||||
loginStrategyService,
|
loginStrategyService,
|
||||||
accountService,
|
accountService,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { mock, MockProxy } from "jest-mock-extended";
|
import { mock, MockProxy } from "jest-mock-extended";
|
||||||
import { BehaviorSubject } from "rxjs";
|
import { BehaviorSubject } from "rxjs";
|
||||||
|
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { FakeMasterPasswordService } from "@bitwarden/common/auth/services/master-password/fake-master-password.service";
|
import { FakeMasterPasswordService } from "@bitwarden/common/auth/services/master-password/fake-master-password.service";
|
||||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
@@ -42,7 +42,7 @@ describe("KeyRotationService", () => {
|
|||||||
let mockSendService: MockProxy<SendService>;
|
let mockSendService: MockProxy<SendService>;
|
||||||
let mockEmergencyAccessService: MockProxy<EmergencyAccessService>;
|
let mockEmergencyAccessService: MockProxy<EmergencyAccessService>;
|
||||||
let mockResetPasswordService: MockProxy<OrganizationUserResetPasswordService>;
|
let mockResetPasswordService: MockProxy<OrganizationUserResetPasswordService>;
|
||||||
let mockDeviceTrustCryptoService: MockProxy<DeviceTrustCryptoServiceAbstraction>;
|
let mockDeviceTrustService: MockProxy<DeviceTrustServiceAbstraction>;
|
||||||
let mockCryptoService: MockProxy<CryptoService>;
|
let mockCryptoService: MockProxy<CryptoService>;
|
||||||
let mockEncryptService: MockProxy<EncryptService>;
|
let mockEncryptService: MockProxy<EncryptService>;
|
||||||
let mockStateService: MockProxy<StateService>;
|
let mockStateService: MockProxy<StateService>;
|
||||||
@@ -60,7 +60,7 @@ describe("KeyRotationService", () => {
|
|||||||
mockSendService = mock<SendService>();
|
mockSendService = mock<SendService>();
|
||||||
mockEmergencyAccessService = mock<EmergencyAccessService>();
|
mockEmergencyAccessService = mock<EmergencyAccessService>();
|
||||||
mockResetPasswordService = mock<OrganizationUserResetPasswordService>();
|
mockResetPasswordService = mock<OrganizationUserResetPasswordService>();
|
||||||
mockDeviceTrustCryptoService = mock<DeviceTrustCryptoServiceAbstraction>();
|
mockDeviceTrustService = mock<DeviceTrustServiceAbstraction>();
|
||||||
mockCryptoService = mock<CryptoService>();
|
mockCryptoService = mock<CryptoService>();
|
||||||
mockEncryptService = mock<EncryptService>();
|
mockEncryptService = mock<EncryptService>();
|
||||||
mockStateService = mock<StateService>();
|
mockStateService = mock<StateService>();
|
||||||
@@ -74,7 +74,7 @@ describe("KeyRotationService", () => {
|
|||||||
mockSendService,
|
mockSendService,
|
||||||
mockEmergencyAccessService,
|
mockEmergencyAccessService,
|
||||||
mockResetPasswordService,
|
mockResetPasswordService,
|
||||||
mockDeviceTrustCryptoService,
|
mockDeviceTrustService,
|
||||||
mockCryptoService,
|
mockCryptoService,
|
||||||
mockEncryptService,
|
mockEncryptService,
|
||||||
mockStateService,
|
mockStateService,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Injectable } from "@angular/core";
|
|||||||
import { firstValueFrom } from "rxjs";
|
import { firstValueFrom } from "rxjs";
|
||||||
|
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
||||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||||
@@ -33,7 +33,7 @@ export class UserKeyRotationService {
|
|||||||
private sendService: SendService,
|
private sendService: SendService,
|
||||||
private emergencyAccessService: EmergencyAccessService,
|
private emergencyAccessService: EmergencyAccessService,
|
||||||
private resetPasswordService: OrganizationUserResetPasswordService,
|
private resetPasswordService: OrganizationUserResetPasswordService,
|
||||||
private deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction,
|
private deviceTrustService: DeviceTrustServiceAbstraction,
|
||||||
private cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
private encryptService: EncryptService,
|
private encryptService: EncryptService,
|
||||||
private stateService: StateService,
|
private stateService: StateService,
|
||||||
@@ -96,7 +96,7 @@ export class UserKeyRotationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
||||||
await this.deviceTrustCryptoService.rotateDevicesTrust(
|
await this.deviceTrustService.rotateDevicesTrust(
|
||||||
activeAccount.id,
|
activeAccount.id,
|
||||||
newUserKey,
|
newUserKey,
|
||||||
masterPasswordHash,
|
masterPasswordHash,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|||||||
import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction";
|
import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction";
|
||||||
import { OrganizationUserService } from "@bitwarden/common/admin-console/abstractions/organization-user/organization-user.service";
|
import { OrganizationUserService } from "@bitwarden/common/admin-console/abstractions/organization-user/organization-user.service";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { DevicesServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices/devices.service.abstraction";
|
import { DevicesServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices/devices.service.abstraction";
|
||||||
import { PasswordResetEnrollmentServiceAbstraction } from "@bitwarden/common/auth/abstractions/password-reset-enrollment.service.abstraction";
|
import { PasswordResetEnrollmentServiceAbstraction } from "@bitwarden/common/auth/abstractions/password-reset-enrollment.service.abstraction";
|
||||||
import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction";
|
import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction";
|
||||||
@@ -93,7 +93,7 @@ export class BaseLoginDecryptionOptionsComponent implements OnInit, OnDestroy {
|
|||||||
protected apiService: ApiService,
|
protected apiService: ApiService,
|
||||||
protected i18nService: I18nService,
|
protected i18nService: I18nService,
|
||||||
protected validationService: ValidationService,
|
protected validationService: ValidationService,
|
||||||
protected deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction,
|
protected deviceTrustService: DeviceTrustServiceAbstraction,
|
||||||
protected platformUtilsService: PlatformUtilsService,
|
protected platformUtilsService: PlatformUtilsService,
|
||||||
protected userDecryptionOptionsService: UserDecryptionOptionsServiceAbstraction,
|
protected userDecryptionOptionsService: UserDecryptionOptionsServiceAbstraction,
|
||||||
protected passwordResetEnrollmentService: PasswordResetEnrollmentServiceAbstraction,
|
protected passwordResetEnrollmentService: PasswordResetEnrollmentServiceAbstraction,
|
||||||
@@ -156,7 +156,7 @@ export class BaseLoginDecryptionOptionsComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async setRememberDeviceDefaultValue() {
|
private async setRememberDeviceDefaultValue() {
|
||||||
const rememberDeviceFromState = await this.deviceTrustCryptoService.getShouldTrustDevice(
|
const rememberDeviceFromState = await this.deviceTrustService.getShouldTrustDevice(
|
||||||
this.activeAccountId,
|
this.activeAccountId,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -169,9 +169,7 @@ export class BaseLoginDecryptionOptionsComponent implements OnInit, OnDestroy {
|
|||||||
this.rememberDevice.valueChanges
|
this.rememberDevice.valueChanges
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap((value) =>
|
switchMap((value) =>
|
||||||
defer(() =>
|
defer(() => this.deviceTrustService.setShouldTrustDevice(this.activeAccountId, value)),
|
||||||
this.deviceTrustCryptoService.setShouldTrustDevice(this.activeAccountId, value),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
takeUntil(this.destroy$),
|
takeUntil(this.destroy$),
|
||||||
)
|
)
|
||||||
@@ -288,7 +286,7 @@ export class BaseLoginDecryptionOptionsComponent implements OnInit, OnDestroy {
|
|||||||
await this.passwordResetEnrollmentService.enroll(this.data.organizationId);
|
await this.passwordResetEnrollmentService.enroll(this.data.organizationId);
|
||||||
|
|
||||||
if (this.rememberDeviceForm.value.rememberDevice) {
|
if (this.rememberDeviceForm.value.rememberDevice) {
|
||||||
await this.deviceTrustCryptoService.trustDevice(this.activeAccountId);
|
await this.deviceTrustService.trustDevice(this.activeAccountId);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.validationService.showError(error);
|
this.validationService.showError(error);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abs
|
|||||||
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||||
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
|
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
||||||
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
||||||
import { ForceSetPasswordReason } from "@bitwarden/common/auth/models/domain/force-set-password-reason";
|
import { ForceSetPasswordReason } from "@bitwarden/common/auth/models/domain/force-set-password-reason";
|
||||||
@@ -74,7 +74,7 @@ export class LockComponent implements OnInit, OnDestroy {
|
|||||||
protected policyService: InternalPolicyService,
|
protected policyService: InternalPolicyService,
|
||||||
protected passwordStrengthService: PasswordStrengthServiceAbstraction,
|
protected passwordStrengthService: PasswordStrengthServiceAbstraction,
|
||||||
protected dialogService: DialogService,
|
protected dialogService: DialogService,
|
||||||
protected deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction,
|
protected deviceTrustService: DeviceTrustServiceAbstraction,
|
||||||
protected userVerificationService: UserVerificationService,
|
protected userVerificationService: UserVerificationService,
|
||||||
protected pinCryptoService: PinCryptoServiceAbstraction,
|
protected pinCryptoService: PinCryptoServiceAbstraction,
|
||||||
protected biometricStateService: BiometricStateService,
|
protected biometricStateService: BiometricStateService,
|
||||||
@@ -277,7 +277,7 @@ export class LockComponent implements OnInit, OnDestroy {
|
|||||||
// Now that we have a decrypted user key in memory, we can check if we
|
// Now that we have a decrypted user key in memory, we can check if we
|
||||||
// need to establish trust on the current device
|
// need to establish trust on the current device
|
||||||
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
||||||
await this.deviceTrustCryptoService.trustDeviceIfRequired(activeAccount.id);
|
await this.deviceTrustService.trustDeviceIfRequired(activeAccount.id);
|
||||||
|
|
||||||
await this.doContinue(evaluatePasswordAfterUnlock);
|
await this.doContinue(evaluatePasswordAfterUnlock);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { AnonymousHubService } from "@bitwarden/common/auth/abstractions/anonymous-hub.service";
|
import { AnonymousHubService } from "@bitwarden/common/auth/abstractions/anonymous-hub.service";
|
||||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { AuthRequestType } from "@bitwarden/common/auth/enums/auth-request-type";
|
import { AuthRequestType } from "@bitwarden/common/auth/enums/auth-request-type";
|
||||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||||
import { AdminAuthRequestStorable } from "@bitwarden/common/auth/models/domain/admin-auth-req-storable";
|
import { AdminAuthRequestStorable } from "@bitwarden/common/auth/models/domain/admin-auth-req-storable";
|
||||||
@@ -86,7 +86,7 @@ export class LoginViaAuthRequestComponent
|
|||||||
private validationService: ValidationService,
|
private validationService: ValidationService,
|
||||||
private stateService: StateService,
|
private stateService: StateService,
|
||||||
private loginEmailService: LoginEmailServiceAbstraction,
|
private loginEmailService: LoginEmailServiceAbstraction,
|
||||||
private deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction,
|
private deviceTrustService: DeviceTrustServiceAbstraction,
|
||||||
private authRequestService: AuthRequestServiceAbstraction,
|
private authRequestService: AuthRequestServiceAbstraction,
|
||||||
private loginStrategyService: LoginStrategyServiceAbstraction,
|
private loginStrategyService: LoginStrategyServiceAbstraction,
|
||||||
private accountService: AccountService,
|
private accountService: AccountService,
|
||||||
@@ -402,7 +402,7 @@ export class LoginViaAuthRequestComponent
|
|||||||
// Now that we have a decrypted user key in memory, we can check if we
|
// Now that we have a decrypted user key in memory, we can check if we
|
||||||
// need to establish trust on the current device
|
// need to establish trust on the current device
|
||||||
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
||||||
await this.deviceTrustCryptoService.trustDeviceIfRequired(activeAccount.id);
|
await this.deviceTrustService.trustDeviceIfRequired(activeAccount.id);
|
||||||
|
|
||||||
// TODO: don't forget to use auto enrollment service everywhere we trust device
|
// TODO: don't forget to use auto enrollment service everywhere we trust device
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
import { firstValueFrom } from "rxjs";
|
import { firstValueFrom } from "rxjs";
|
||||||
|
|
||||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
||||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||||
import { ClientType } from "@bitwarden/common/enums";
|
import { ClientType } from "@bitwarden/common/enums";
|
||||||
@@ -30,7 +30,7 @@ export function lockGuard(): CanActivateFn {
|
|||||||
) => {
|
) => {
|
||||||
const authService = inject(AuthService);
|
const authService = inject(AuthService);
|
||||||
const cryptoService = inject(CryptoService);
|
const cryptoService = inject(CryptoService);
|
||||||
const deviceTrustCryptoService = inject(DeviceTrustCryptoServiceAbstraction);
|
const deviceTrustService = inject(DeviceTrustServiceAbstraction);
|
||||||
const platformUtilService = inject(PlatformUtilsService);
|
const platformUtilService = inject(PlatformUtilsService);
|
||||||
const messagingService = inject(MessagingService);
|
const messagingService = inject(MessagingService);
|
||||||
const router = inject(Router);
|
const router = inject(Router);
|
||||||
@@ -53,7 +53,7 @@ export function lockGuard(): CanActivateFn {
|
|||||||
|
|
||||||
// User is authN and in locked state.
|
// User is authN and in locked state.
|
||||||
|
|
||||||
const tdeEnabled = await firstValueFrom(deviceTrustCryptoService.supportsDeviceTrust$);
|
const tdeEnabled = await firstValueFrom(deviceTrustService.supportsDeviceTrust$);
|
||||||
|
|
||||||
// Create special exception which allows users to go from the login-initiated page to the lock page for the approve w/ MP flow
|
// Create special exception which allows users to go from the login-initiated page to the lock page for the approve w/ MP flow
|
||||||
// The MP check is necessary to prevent direct manual navigation from other locked state pages for users who don't have a MP
|
// The MP check is necessary to prevent direct manual navigation from other locked state pages for users who don't have a MP
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { CanActivateFn, Router } from "@angular/router";
|
|||||||
import { firstValueFrom } from "rxjs";
|
import { firstValueFrom } from "rxjs";
|
||||||
|
|
||||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ export function redirectGuard(overrides: Partial<RedirectRoutes> = {}): CanActiv
|
|||||||
return async (route) => {
|
return async (route) => {
|
||||||
const authService = inject(AuthService);
|
const authService = inject(AuthService);
|
||||||
const cryptoService = inject(CryptoService);
|
const cryptoService = inject(CryptoService);
|
||||||
const deviceTrustCryptoService = inject(DeviceTrustCryptoServiceAbstraction);
|
const deviceTrustService = inject(DeviceTrustServiceAbstraction);
|
||||||
const router = inject(Router);
|
const router = inject(Router);
|
||||||
|
|
||||||
const authStatus = await authService.getAuthStatus();
|
const authStatus = await authService.getAuthStatus();
|
||||||
@@ -46,7 +46,7 @@ export function redirectGuard(overrides: Partial<RedirectRoutes> = {}): CanActiv
|
|||||||
|
|
||||||
// If locked, TDE is enabled, and the user hasn't decrypted yet, then redirect to the
|
// If locked, TDE is enabled, and the user hasn't decrypted yet, then redirect to the
|
||||||
// login decryption options component.
|
// login decryption options component.
|
||||||
const tdeEnabled = await firstValueFrom(deviceTrustCryptoService.supportsDeviceTrust$);
|
const tdeEnabled = await firstValueFrom(deviceTrustService.supportsDeviceTrust$);
|
||||||
const everHadUserKey = await firstValueFrom(cryptoService.everHadUserKey$);
|
const everHadUserKey = await firstValueFrom(cryptoService.everHadUserKey$);
|
||||||
if (authStatus === AuthenticationStatus.Locked && tdeEnabled && !everHadUserKey) {
|
if (authStatus === AuthenticationStatus.Locked && tdeEnabled && !everHadUserKey) {
|
||||||
return router.createUrlTree([routes.notDecrypted], { queryParams: route.queryParams });
|
return router.createUrlTree([routes.notDecrypted], { queryParams: route.queryParams });
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
import { firstValueFrom } from "rxjs";
|
import { firstValueFrom } from "rxjs";
|
||||||
|
|
||||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
|
||||||
@@ -22,11 +22,11 @@ export function tdeDecryptionRequiredGuard(): CanActivateFn {
|
|||||||
return async (_: ActivatedRouteSnapshot, state: RouterStateSnapshot) => {
|
return async (_: ActivatedRouteSnapshot, state: RouterStateSnapshot) => {
|
||||||
const authService = inject(AuthService);
|
const authService = inject(AuthService);
|
||||||
const cryptoService = inject(CryptoService);
|
const cryptoService = inject(CryptoService);
|
||||||
const deviceTrustCryptoService = inject(DeviceTrustCryptoServiceAbstraction);
|
const deviceTrustService = inject(DeviceTrustServiceAbstraction);
|
||||||
const router = inject(Router);
|
const router = inject(Router);
|
||||||
|
|
||||||
const authStatus = await authService.getAuthStatus();
|
const authStatus = await authService.getAuthStatus();
|
||||||
const tdeEnabled = await firstValueFrom(deviceTrustCryptoService.supportsDeviceTrust$);
|
const tdeEnabled = await firstValueFrom(deviceTrustService.supportsDeviceTrust$);
|
||||||
const everHadUserKey = await firstValueFrom(cryptoService.everHadUserKey$);
|
const everHadUserKey = await firstValueFrom(cryptoService.everHadUserKey$);
|
||||||
if (authStatus !== AuthenticationStatus.Locked || !tdeEnabled || everHadUserKey) {
|
if (authStatus !== AuthenticationStatus.Locked || !tdeEnabled || everHadUserKey) {
|
||||||
return router.createUrlTree(["/"]);
|
return router.createUrlTree(["/"]);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ import {
|
|||||||
import { AnonymousHubService as AnonymousHubServiceAbstraction } from "@bitwarden/common/auth/abstractions/anonymous-hub.service";
|
import { AnonymousHubService as AnonymousHubServiceAbstraction } from "@bitwarden/common/auth/abstractions/anonymous-hub.service";
|
||||||
import { AuthService as AuthServiceAbstraction } from "@bitwarden/common/auth/abstractions/auth.service";
|
import { AuthService as AuthServiceAbstraction } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||||
import { AvatarService as AvatarServiceAbstraction } from "@bitwarden/common/auth/abstractions/avatar.service";
|
import { AvatarService as AvatarServiceAbstraction } from "@bitwarden/common/auth/abstractions/avatar.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { DevicesServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices/devices.service.abstraction";
|
import { DevicesServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices/devices.service.abstraction";
|
||||||
import { DevicesApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices-api.service.abstraction";
|
import { DevicesApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices-api.service.abstraction";
|
||||||
import { KeyConnectorService as KeyConnectorServiceAbstraction } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
import { KeyConnectorService as KeyConnectorServiceAbstraction } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
||||||
@@ -82,7 +82,7 @@ import { AccountServiceImplementation } from "@bitwarden/common/auth/services/ac
|
|||||||
import { AnonymousHubService } from "@bitwarden/common/auth/services/anonymous-hub.service";
|
import { AnonymousHubService } from "@bitwarden/common/auth/services/anonymous-hub.service";
|
||||||
import { AuthService } from "@bitwarden/common/auth/services/auth.service";
|
import { AuthService } from "@bitwarden/common/auth/services/auth.service";
|
||||||
import { AvatarService } from "@bitwarden/common/auth/services/avatar.service";
|
import { AvatarService } from "@bitwarden/common/auth/services/avatar.service";
|
||||||
import { DeviceTrustCryptoService } from "@bitwarden/common/auth/services/device-trust-crypto.service.implementation";
|
import { DeviceTrustService } from "@bitwarden/common/auth/services/device-trust.service.implementation";
|
||||||
import { DevicesServiceImplementation } from "@bitwarden/common/auth/services/devices/devices.service.implementation";
|
import { DevicesServiceImplementation } from "@bitwarden/common/auth/services/devices/devices.service.implementation";
|
||||||
import { DevicesApiServiceImplementation } from "@bitwarden/common/auth/services/devices-api.service.implementation";
|
import { DevicesApiServiceImplementation } from "@bitwarden/common/auth/services/devices-api.service.implementation";
|
||||||
import { KeyConnectorService } from "@bitwarden/common/auth/services/key-connector.service";
|
import { KeyConnectorService } from "@bitwarden/common/auth/services/key-connector.service";
|
||||||
@@ -385,7 +385,7 @@ const safeProviders: SafeProvider[] = [
|
|||||||
EncryptService,
|
EncryptService,
|
||||||
PasswordStrengthServiceAbstraction,
|
PasswordStrengthServiceAbstraction,
|
||||||
PolicyServiceAbstraction,
|
PolicyServiceAbstraction,
|
||||||
DeviceTrustCryptoServiceAbstraction,
|
DeviceTrustServiceAbstraction,
|
||||||
AuthRequestServiceAbstraction,
|
AuthRequestServiceAbstraction,
|
||||||
InternalUserDecryptionOptionsServiceAbstraction,
|
InternalUserDecryptionOptionsServiceAbstraction,
|
||||||
GlobalStateProvider,
|
GlobalStateProvider,
|
||||||
@@ -949,8 +949,8 @@ const safeProviders: SafeProvider[] = [
|
|||||||
deps: [DevicesApiServiceAbstraction],
|
deps: [DevicesApiServiceAbstraction],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
provide: DeviceTrustCryptoServiceAbstraction,
|
provide: DeviceTrustServiceAbstraction,
|
||||||
useClass: DeviceTrustCryptoService,
|
useClass: DeviceTrustService,
|
||||||
deps: [
|
deps: [
|
||||||
KeyGenerationServiceAbstraction,
|
KeyGenerationServiceAbstraction,
|
||||||
CryptoFunctionServiceAbstraction,
|
CryptoFunctionServiceAbstraction,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { mock, MockProxy } from "jest-mock-extended";
|
import { mock, MockProxy } from "jest-mock-extended";
|
||||||
|
|
||||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
||||||
import { TwoFactorService } from "@bitwarden/common/auth/abstractions/two-factor.service";
|
import { TwoFactorService } from "@bitwarden/common/auth/abstractions/two-factor.service";
|
||||||
import { IdentityTokenResponse } from "@bitwarden/common/auth/models/response/identity-token.response";
|
import { IdentityTokenResponse } from "@bitwarden/common/auth/models/response/identity-token.response";
|
||||||
@@ -42,7 +42,7 @@ describe("AuthRequestLoginStrategy", () => {
|
|||||||
let stateService: MockProxy<StateService>;
|
let stateService: MockProxy<StateService>;
|
||||||
let twoFactorService: MockProxy<TwoFactorService>;
|
let twoFactorService: MockProxy<TwoFactorService>;
|
||||||
let userDecryptionOptions: MockProxy<InternalUserDecryptionOptionsServiceAbstraction>;
|
let userDecryptionOptions: MockProxy<InternalUserDecryptionOptionsServiceAbstraction>;
|
||||||
let deviceTrustCryptoService: MockProxy<DeviceTrustCryptoServiceAbstraction>;
|
let deviceTrustService: MockProxy<DeviceTrustServiceAbstraction>;
|
||||||
let billingAccountProfileStateService: MockProxy<BillingAccountProfileStateService>;
|
let billingAccountProfileStateService: MockProxy<BillingAccountProfileStateService>;
|
||||||
|
|
||||||
const mockUserId = Utils.newGuid() as UserId;
|
const mockUserId = Utils.newGuid() as UserId;
|
||||||
@@ -75,7 +75,7 @@ describe("AuthRequestLoginStrategy", () => {
|
|||||||
stateService = mock<StateService>();
|
stateService = mock<StateService>();
|
||||||
twoFactorService = mock<TwoFactorService>();
|
twoFactorService = mock<TwoFactorService>();
|
||||||
userDecryptionOptions = mock<InternalUserDecryptionOptionsServiceAbstraction>();
|
userDecryptionOptions = mock<InternalUserDecryptionOptionsServiceAbstraction>();
|
||||||
deviceTrustCryptoService = mock<DeviceTrustCryptoServiceAbstraction>();
|
deviceTrustService = mock<DeviceTrustServiceAbstraction>();
|
||||||
billingAccountProfileStateService = mock<BillingAccountProfileStateService>();
|
billingAccountProfileStateService = mock<BillingAccountProfileStateService>();
|
||||||
|
|
||||||
accountService = mockAccountServiceWith(mockUserId);
|
accountService = mockAccountServiceWith(mockUserId);
|
||||||
@@ -99,7 +99,7 @@ describe("AuthRequestLoginStrategy", () => {
|
|||||||
stateService,
|
stateService,
|
||||||
twoFactorService,
|
twoFactorService,
|
||||||
userDecryptionOptions,
|
userDecryptionOptions,
|
||||||
deviceTrustCryptoService,
|
deviceTrustService,
|
||||||
billingAccountProfileStateService,
|
billingAccountProfileStateService,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ describe("AuthRequestLoginStrategy", () => {
|
|||||||
);
|
);
|
||||||
expect(cryptoService.setMasterKeyEncryptedUserKey).toHaveBeenCalledWith(tokenResponse.key);
|
expect(cryptoService.setMasterKeyEncryptedUserKey).toHaveBeenCalledWith(tokenResponse.key);
|
||||||
expect(cryptoService.setUserKey).toHaveBeenCalledWith(userKey);
|
expect(cryptoService.setUserKey).toHaveBeenCalledWith(userKey);
|
||||||
expect(deviceTrustCryptoService.trustDeviceIfRequired).toHaveBeenCalled();
|
expect(deviceTrustService.trustDeviceIfRequired).toHaveBeenCalled();
|
||||||
expect(cryptoService.setPrivateKey).toHaveBeenCalledWith(tokenResponse.privateKey);
|
expect(cryptoService.setPrivateKey).toHaveBeenCalledWith(tokenResponse.privateKey);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -160,6 +160,6 @@ describe("AuthRequestLoginStrategy", () => {
|
|||||||
expect(cryptoService.setPrivateKey).toHaveBeenCalledWith(tokenResponse.privateKey);
|
expect(cryptoService.setPrivateKey).toHaveBeenCalledWith(tokenResponse.privateKey);
|
||||||
|
|
||||||
// trustDeviceIfRequired should be called
|
// trustDeviceIfRequired should be called
|
||||||
expect(deviceTrustCryptoService.trustDeviceIfRequired).not.toHaveBeenCalled();
|
expect(deviceTrustService.trustDeviceIfRequired).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { Jsonify } from "type-fest";
|
|||||||
|
|
||||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
|
||||||
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
||||||
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
||||||
import { TwoFactorService } from "@bitwarden/common/auth/abstractions/two-factor.service";
|
import { TwoFactorService } from "@bitwarden/common/auth/abstractions/two-factor.service";
|
||||||
@@ -18,6 +17,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
|
|||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
||||||
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/src/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { UserId } from "@bitwarden/common/types/guid";
|
import { UserId } from "@bitwarden/common/types/guid";
|
||||||
|
|
||||||
import { InternalUserDecryptionOptionsServiceAbstraction } from "../abstractions/user-decryption-options.service.abstraction";
|
import { InternalUserDecryptionOptionsServiceAbstraction } from "../abstractions/user-decryption-options.service.abstraction";
|
||||||
@@ -61,7 +61,7 @@ export class AuthRequestLoginStrategy extends LoginStrategy {
|
|||||||
stateService: StateService,
|
stateService: StateService,
|
||||||
twoFactorService: TwoFactorService,
|
twoFactorService: TwoFactorService,
|
||||||
userDecryptionOptionsService: InternalUserDecryptionOptionsServiceAbstraction,
|
userDecryptionOptionsService: InternalUserDecryptionOptionsServiceAbstraction,
|
||||||
private deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction,
|
private deviceTrustService: DeviceTrustServiceAbstraction,
|
||||||
billingAccountProfileStateService: BillingAccountProfileStateService,
|
billingAccountProfileStateService: BillingAccountProfileStateService,
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
@@ -147,7 +147,7 @@ export class AuthRequestLoginStrategy extends LoginStrategy {
|
|||||||
await this.trySetUserKeyWithMasterKey();
|
await this.trySetUserKeyWithMasterKey();
|
||||||
|
|
||||||
// Establish trust if required after setting user key
|
// Establish trust if required after setting user key
|
||||||
await this.deviceTrustCryptoService.trustDeviceIfRequired(userId);
|
await this.deviceTrustService.trustDeviceIfRequired(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { mock, MockProxy } from "jest-mock-extended";
|
import { mock, MockProxy } from "jest-mock-extended";
|
||||||
|
|
||||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
||||||
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
||||||
import { TwoFactorService } from "@bitwarden/common/auth/abstractions/two-factor.service";
|
import { TwoFactorService } from "@bitwarden/common/auth/abstractions/two-factor.service";
|
||||||
@@ -50,7 +50,7 @@ describe("SsoLoginStrategy", () => {
|
|||||||
let twoFactorService: MockProxy<TwoFactorService>;
|
let twoFactorService: MockProxy<TwoFactorService>;
|
||||||
let userDecryptionOptionsService: MockProxy<InternalUserDecryptionOptionsServiceAbstraction>;
|
let userDecryptionOptionsService: MockProxy<InternalUserDecryptionOptionsServiceAbstraction>;
|
||||||
let keyConnectorService: MockProxy<KeyConnectorService>;
|
let keyConnectorService: MockProxy<KeyConnectorService>;
|
||||||
let deviceTrustCryptoService: MockProxy<DeviceTrustCryptoServiceAbstraction>;
|
let deviceTrustService: MockProxy<DeviceTrustServiceAbstraction>;
|
||||||
let authRequestService: MockProxy<AuthRequestServiceAbstraction>;
|
let authRequestService: MockProxy<AuthRequestServiceAbstraction>;
|
||||||
let i18nService: MockProxy<I18nService>;
|
let i18nService: MockProxy<I18nService>;
|
||||||
let billingAccountProfileStateService: MockProxy<BillingAccountProfileStateService>;
|
let billingAccountProfileStateService: MockProxy<BillingAccountProfileStateService>;
|
||||||
@@ -82,7 +82,7 @@ describe("SsoLoginStrategy", () => {
|
|||||||
twoFactorService = mock<TwoFactorService>();
|
twoFactorService = mock<TwoFactorService>();
|
||||||
userDecryptionOptionsService = mock<InternalUserDecryptionOptionsServiceAbstraction>();
|
userDecryptionOptionsService = mock<InternalUserDecryptionOptionsServiceAbstraction>();
|
||||||
keyConnectorService = mock<KeyConnectorService>();
|
keyConnectorService = mock<KeyConnectorService>();
|
||||||
deviceTrustCryptoService = mock<DeviceTrustCryptoServiceAbstraction>();
|
deviceTrustService = mock<DeviceTrustServiceAbstraction>();
|
||||||
authRequestService = mock<AuthRequestServiceAbstraction>();
|
authRequestService = mock<AuthRequestServiceAbstraction>();
|
||||||
i18nService = mock<I18nService>();
|
i18nService = mock<I18nService>();
|
||||||
billingAccountProfileStateService = mock<BillingAccountProfileStateService>();
|
billingAccountProfileStateService = mock<BillingAccountProfileStateService>();
|
||||||
@@ -106,7 +106,7 @@ describe("SsoLoginStrategy", () => {
|
|||||||
twoFactorService,
|
twoFactorService,
|
||||||
userDecryptionOptionsService,
|
userDecryptionOptionsService,
|
||||||
keyConnectorService,
|
keyConnectorService,
|
||||||
deviceTrustCryptoService,
|
deviceTrustService,
|
||||||
authRequestService,
|
authRequestService,
|
||||||
i18nService,
|
i18nService,
|
||||||
billingAccountProfileStateService,
|
billingAccountProfileStateService,
|
||||||
@@ -209,8 +209,8 @@ describe("SsoLoginStrategy", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
apiService.postIdentityToken.mockResolvedValue(idTokenResponse);
|
apiService.postIdentityToken.mockResolvedValue(idTokenResponse);
|
||||||
deviceTrustCryptoService.getDeviceKey.mockResolvedValue(mockDeviceKey);
|
deviceTrustService.getDeviceKey.mockResolvedValue(mockDeviceKey);
|
||||||
deviceTrustCryptoService.decryptUserKeyWithDeviceKey.mockResolvedValue(mockUserKey);
|
deviceTrustService.decryptUserKeyWithDeviceKey.mockResolvedValue(mockUserKey);
|
||||||
|
|
||||||
const cryptoSvcSetUserKeySpy = jest.spyOn(cryptoService, "setUserKey");
|
const cryptoSvcSetUserKeySpy = jest.spyOn(cryptoService, "setUserKey");
|
||||||
|
|
||||||
@@ -218,8 +218,8 @@ describe("SsoLoginStrategy", () => {
|
|||||||
await ssoLoginStrategy.logIn(credentials);
|
await ssoLoginStrategy.logIn(credentials);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(deviceTrustCryptoService.getDeviceKey).toHaveBeenCalledTimes(1);
|
expect(deviceTrustService.getDeviceKey).toHaveBeenCalledTimes(1);
|
||||||
expect(deviceTrustCryptoService.decryptUserKeyWithDeviceKey).toHaveBeenCalledTimes(1);
|
expect(deviceTrustService.decryptUserKeyWithDeviceKey).toHaveBeenCalledTimes(1);
|
||||||
expect(cryptoSvcSetUserKeySpy).toHaveBeenCalledTimes(1);
|
expect(cryptoSvcSetUserKeySpy).toHaveBeenCalledTimes(1);
|
||||||
expect(cryptoSvcSetUserKeySpy).toHaveBeenCalledWith(mockUserKey);
|
expect(cryptoSvcSetUserKeySpy).toHaveBeenCalledWith(mockUserKey);
|
||||||
});
|
});
|
||||||
@@ -232,8 +232,8 @@ describe("SsoLoginStrategy", () => {
|
|||||||
);
|
);
|
||||||
apiService.postIdentityToken.mockResolvedValue(idTokenResponse);
|
apiService.postIdentityToken.mockResolvedValue(idTokenResponse);
|
||||||
// Set deviceKey to be null
|
// Set deviceKey to be null
|
||||||
deviceTrustCryptoService.getDeviceKey.mockResolvedValue(null);
|
deviceTrustService.getDeviceKey.mockResolvedValue(null);
|
||||||
deviceTrustCryptoService.decryptUserKeyWithDeviceKey.mockResolvedValue(mockUserKey);
|
deviceTrustService.decryptUserKeyWithDeviceKey.mockResolvedValue(mockUserKey);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await ssoLoginStrategy.logIn(credentials);
|
await ssoLoginStrategy.logIn(credentials);
|
||||||
@@ -254,7 +254,7 @@ describe("SsoLoginStrategy", () => {
|
|||||||
// Arrange
|
// Arrange
|
||||||
const idTokenResponse = mockIdTokenResponseWithModifiedTrustedDeviceOption(valueName, null);
|
const idTokenResponse = mockIdTokenResponseWithModifiedTrustedDeviceOption(valueName, null);
|
||||||
apiService.postIdentityToken.mockResolvedValue(idTokenResponse);
|
apiService.postIdentityToken.mockResolvedValue(idTokenResponse);
|
||||||
deviceTrustCryptoService.getDeviceKey.mockResolvedValue(mockDeviceKey);
|
deviceTrustService.getDeviceKey.mockResolvedValue(mockDeviceKey);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await ssoLoginStrategy.logIn(credentials);
|
await ssoLoginStrategy.logIn(credentials);
|
||||||
@@ -271,9 +271,9 @@ describe("SsoLoginStrategy", () => {
|
|||||||
userDecryptionOptsServerResponseWithTdeOption,
|
userDecryptionOptsServerResponseWithTdeOption,
|
||||||
);
|
);
|
||||||
apiService.postIdentityToken.mockResolvedValue(idTokenResponse);
|
apiService.postIdentityToken.mockResolvedValue(idTokenResponse);
|
||||||
deviceTrustCryptoService.getDeviceKey.mockResolvedValue(mockDeviceKey);
|
deviceTrustService.getDeviceKey.mockResolvedValue(mockDeviceKey);
|
||||||
// Set userKey to be null
|
// Set userKey to be null
|
||||||
deviceTrustCryptoService.decryptUserKeyWithDeviceKey.mockResolvedValue(null);
|
deviceTrustService.decryptUserKeyWithDeviceKey.mockResolvedValue(null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await ssoLoginStrategy.logIn(credentials);
|
await ssoLoginStrategy.logIn(credentials);
|
||||||
@@ -321,7 +321,7 @@ describe("SsoLoginStrategy", () => {
|
|||||||
await ssoLoginStrategy.logIn(credentials);
|
await ssoLoginStrategy.logIn(credentials);
|
||||||
|
|
||||||
expect(authRequestService.setKeysAfterDecryptingSharedMasterKeyAndHash).toHaveBeenCalled();
|
expect(authRequestService.setKeysAfterDecryptingSharedMasterKeyAndHash).toHaveBeenCalled();
|
||||||
expect(deviceTrustCryptoService.decryptUserKeyWithDeviceKey).not.toHaveBeenCalled();
|
expect(deviceTrustService.decryptUserKeyWithDeviceKey).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets the user key from approved admin request if exists", async () => {
|
it("sets the user key from approved admin request if exists", async () => {
|
||||||
@@ -338,7 +338,7 @@ describe("SsoLoginStrategy", () => {
|
|||||||
await ssoLoginStrategy.logIn(credentials);
|
await ssoLoginStrategy.logIn(credentials);
|
||||||
|
|
||||||
expect(authRequestService.setUserKeyAfterDecryptingSharedUserKey).toHaveBeenCalled();
|
expect(authRequestService.setUserKeyAfterDecryptingSharedUserKey).toHaveBeenCalled();
|
||||||
expect(deviceTrustCryptoService.decryptUserKeyWithDeviceKey).not.toHaveBeenCalled();
|
expect(deviceTrustService.decryptUserKeyWithDeviceKey).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("attempts to establish a trusted device if successful", async () => {
|
it("attempts to establish a trusted device if successful", async () => {
|
||||||
@@ -355,7 +355,7 @@ describe("SsoLoginStrategy", () => {
|
|||||||
await ssoLoginStrategy.logIn(credentials);
|
await ssoLoginStrategy.logIn(credentials);
|
||||||
|
|
||||||
expect(authRequestService.setUserKeyAfterDecryptingSharedUserKey).toHaveBeenCalled();
|
expect(authRequestService.setUserKeyAfterDecryptingSharedUserKey).toHaveBeenCalled();
|
||||||
expect(deviceTrustCryptoService.trustDeviceIfRequired).toHaveBeenCalled();
|
expect(deviceTrustService.trustDeviceIfRequired).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("clears the admin auth request if server returns a 404, meaning it was deleted", async () => {
|
it("clears the admin auth request if server returns a 404, meaning it was deleted", async () => {
|
||||||
@@ -369,7 +369,7 @@ describe("SsoLoginStrategy", () => {
|
|||||||
authRequestService.setKeysAfterDecryptingSharedMasterKeyAndHash,
|
authRequestService.setKeysAfterDecryptingSharedMasterKeyAndHash,
|
||||||
).not.toHaveBeenCalled();
|
).not.toHaveBeenCalled();
|
||||||
expect(authRequestService.setUserKeyAfterDecryptingSharedUserKey).not.toHaveBeenCalled();
|
expect(authRequestService.setUserKeyAfterDecryptingSharedUserKey).not.toHaveBeenCalled();
|
||||||
expect(deviceTrustCryptoService.trustDeviceIfRequired).not.toHaveBeenCalled();
|
expect(deviceTrustService.trustDeviceIfRequired).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("attempts to login with a trusted device if admin auth request isn't successful", async () => {
|
it("attempts to login with a trusted device if admin auth request isn't successful", async () => {
|
||||||
@@ -382,11 +382,11 @@ describe("SsoLoginStrategy", () => {
|
|||||||
};
|
};
|
||||||
apiService.getAuthRequest.mockResolvedValue(adminAuthResponse as AuthRequestResponse);
|
apiService.getAuthRequest.mockResolvedValue(adminAuthResponse as AuthRequestResponse);
|
||||||
cryptoService.hasUserKey.mockResolvedValue(false);
|
cryptoService.hasUserKey.mockResolvedValue(false);
|
||||||
deviceTrustCryptoService.getDeviceKey.mockResolvedValue("DEVICE_KEY" as any);
|
deviceTrustService.getDeviceKey.mockResolvedValue("DEVICE_KEY" as any);
|
||||||
|
|
||||||
await ssoLoginStrategy.logIn(credentials);
|
await ssoLoginStrategy.logIn(credentials);
|
||||||
|
|
||||||
expect(deviceTrustCryptoService.decryptUserKeyWithDeviceKey).toHaveBeenCalled();
|
expect(deviceTrustService.decryptUserKeyWithDeviceKey).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { Jsonify } from "type-fest";
|
|||||||
|
|
||||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
|
||||||
import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
||||||
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
||||||
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
||||||
@@ -22,6 +21,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
|
|||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
||||||
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/src/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { UserId } from "@bitwarden/common/types/guid";
|
import { UserId } from "@bitwarden/common/types/guid";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -94,7 +94,7 @@ export class SsoLoginStrategy extends LoginStrategy {
|
|||||||
twoFactorService: TwoFactorService,
|
twoFactorService: TwoFactorService,
|
||||||
userDecryptionOptionsService: InternalUserDecryptionOptionsServiceAbstraction,
|
userDecryptionOptionsService: InternalUserDecryptionOptionsServiceAbstraction,
|
||||||
private keyConnectorService: KeyConnectorService,
|
private keyConnectorService: KeyConnectorService,
|
||||||
private deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction,
|
private deviceTrustService: DeviceTrustServiceAbstraction,
|
||||||
private authRequestService: AuthRequestServiceAbstraction,
|
private authRequestService: AuthRequestServiceAbstraction,
|
||||||
private i18nService: I18nService,
|
private i18nService: I18nService,
|
||||||
billingAccountProfileStateService: BillingAccountProfileStateService,
|
billingAccountProfileStateService: BillingAccountProfileStateService,
|
||||||
@@ -298,7 +298,7 @@ export class SsoLoginStrategy extends LoginStrategy {
|
|||||||
if (await this.cryptoService.hasUserKey()) {
|
if (await this.cryptoService.hasUserKey()) {
|
||||||
// Now that we have a decrypted user key in memory, we can check if we
|
// Now that we have a decrypted user key in memory, we can check if we
|
||||||
// need to establish trust on the current device
|
// need to establish trust on the current device
|
||||||
await this.deviceTrustCryptoService.trustDeviceIfRequired(userId);
|
await this.deviceTrustService.trustDeviceIfRequired(userId);
|
||||||
|
|
||||||
// if we successfully decrypted the user key, we can delete the admin auth request out of state
|
// if we successfully decrypted the user key, we can delete the admin auth request out of state
|
||||||
// TODO: eventually we post and clean up DB as well once consumed on client
|
// TODO: eventually we post and clean up DB as well once consumed on client
|
||||||
@@ -314,7 +314,7 @@ export class SsoLoginStrategy extends LoginStrategy {
|
|||||||
|
|
||||||
const userId = (await this.stateService.getUserId()) as UserId;
|
const userId = (await this.stateService.getUserId()) as UserId;
|
||||||
|
|
||||||
const deviceKey = await this.deviceTrustCryptoService.getDeviceKey(userId);
|
const deviceKey = await this.deviceTrustService.getDeviceKey(userId);
|
||||||
const encDevicePrivateKey = trustedDeviceOption?.encryptedPrivateKey;
|
const encDevicePrivateKey = trustedDeviceOption?.encryptedPrivateKey;
|
||||||
const encUserKey = trustedDeviceOption?.encryptedUserKey;
|
const encUserKey = trustedDeviceOption?.encryptedUserKey;
|
||||||
|
|
||||||
@@ -322,7 +322,7 @@ export class SsoLoginStrategy extends LoginStrategy {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const userKey = await this.deviceTrustCryptoService.decryptUserKeyWithDeviceKey(
|
const userKey = await this.deviceTrustService.decryptUserKeyWithDeviceKey(
|
||||||
userId,
|
userId,
|
||||||
encDevicePrivateKey,
|
encDevicePrivateKey,
|
||||||
encUserKey,
|
encUserKey,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { MockProxy, mock } from "jest-mock-extended";
|
|||||||
|
|
||||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||||
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
||||||
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
||||||
import { TwoFactorService } from "@bitwarden/common/auth/abstractions/two-factor.service";
|
import { TwoFactorService } from "@bitwarden/common/auth/abstractions/two-factor.service";
|
||||||
@@ -62,7 +62,7 @@ describe("LoginStrategyService", () => {
|
|||||||
let encryptService: MockProxy<EncryptService>;
|
let encryptService: MockProxy<EncryptService>;
|
||||||
let passwordStrengthService: MockProxy<PasswordStrengthServiceAbstraction>;
|
let passwordStrengthService: MockProxy<PasswordStrengthServiceAbstraction>;
|
||||||
let policyService: MockProxy<PolicyService>;
|
let policyService: MockProxy<PolicyService>;
|
||||||
let deviceTrustCryptoService: MockProxy<DeviceTrustCryptoServiceAbstraction>;
|
let deviceTrustService: MockProxy<DeviceTrustServiceAbstraction>;
|
||||||
let authRequestService: MockProxy<AuthRequestServiceAbstraction>;
|
let authRequestService: MockProxy<AuthRequestServiceAbstraction>;
|
||||||
let userDecryptionOptionsService: MockProxy<InternalUserDecryptionOptionsServiceAbstraction>;
|
let userDecryptionOptionsService: MockProxy<InternalUserDecryptionOptionsServiceAbstraction>;
|
||||||
let billingAccountProfileStateService: MockProxy<BillingAccountProfileStateService>;
|
let billingAccountProfileStateService: MockProxy<BillingAccountProfileStateService>;
|
||||||
@@ -90,7 +90,7 @@ describe("LoginStrategyService", () => {
|
|||||||
encryptService = mock<EncryptService>();
|
encryptService = mock<EncryptService>();
|
||||||
passwordStrengthService = mock<PasswordStrengthServiceAbstraction>();
|
passwordStrengthService = mock<PasswordStrengthServiceAbstraction>();
|
||||||
policyService = mock<PolicyService>();
|
policyService = mock<PolicyService>();
|
||||||
deviceTrustCryptoService = mock<DeviceTrustCryptoServiceAbstraction>();
|
deviceTrustService = mock<DeviceTrustServiceAbstraction>();
|
||||||
authRequestService = mock<AuthRequestServiceAbstraction>();
|
authRequestService = mock<AuthRequestServiceAbstraction>();
|
||||||
userDecryptionOptionsService = mock<UserDecryptionOptionsService>();
|
userDecryptionOptionsService = mock<UserDecryptionOptionsService>();
|
||||||
billingAccountProfileStateService = mock<BillingAccountProfileStateService>();
|
billingAccountProfileStateService = mock<BillingAccountProfileStateService>();
|
||||||
@@ -114,7 +114,7 @@ describe("LoginStrategyService", () => {
|
|||||||
encryptService,
|
encryptService,
|
||||||
passwordStrengthService,
|
passwordStrengthService,
|
||||||
policyService,
|
policyService,
|
||||||
deviceTrustCryptoService,
|
deviceTrustService,
|
||||||
authRequestService,
|
authRequestService,
|
||||||
userDecryptionOptionsService,
|
userDecryptionOptionsService,
|
||||||
stateProvider,
|
stateProvider,
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import {
|
|||||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||||
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
|
|
||||||
import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
||||||
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
||||||
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
||||||
@@ -36,6 +35,7 @@ import { StateService } from "@bitwarden/common/platform/abstractions/state.serv
|
|||||||
import { KdfType } from "@bitwarden/common/platform/enums";
|
import { KdfType } from "@bitwarden/common/platform/enums";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { GlobalState, GlobalStateProvider } from "@bitwarden/common/platform/state";
|
import { GlobalState, GlobalStateProvider } from "@bitwarden/common/platform/state";
|
||||||
|
import { DeviceTrustServiceAbstraction } from "@bitwarden/common/src/auth/abstractions/device-trust.service.abstraction";
|
||||||
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
|
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
|
||||||
import { MasterKey } from "@bitwarden/common/types/key";
|
import { MasterKey } from "@bitwarden/common/types/key";
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
|
|||||||
protected encryptService: EncryptService,
|
protected encryptService: EncryptService,
|
||||||
protected passwordStrengthService: PasswordStrengthServiceAbstraction,
|
protected passwordStrengthService: PasswordStrengthServiceAbstraction,
|
||||||
protected policyService: PolicyService,
|
protected policyService: PolicyService,
|
||||||
protected deviceTrustCryptoService: DeviceTrustCryptoServiceAbstraction,
|
protected deviceTrustService: DeviceTrustServiceAbstraction,
|
||||||
protected authRequestService: AuthRequestServiceAbstraction,
|
protected authRequestService: AuthRequestServiceAbstraction,
|
||||||
protected userDecryptionOptionsService: InternalUserDecryptionOptionsServiceAbstraction,
|
protected userDecryptionOptionsService: InternalUserDecryptionOptionsServiceAbstraction,
|
||||||
protected stateProvider: GlobalStateProvider,
|
protected stateProvider: GlobalStateProvider,
|
||||||
@@ -371,7 +371,7 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
|
|||||||
this.twoFactorService,
|
this.twoFactorService,
|
||||||
this.userDecryptionOptionsService,
|
this.userDecryptionOptionsService,
|
||||||
this.keyConnectorService,
|
this.keyConnectorService,
|
||||||
this.deviceTrustCryptoService,
|
this.deviceTrustService,
|
||||||
this.authRequestService,
|
this.authRequestService,
|
||||||
this.i18nService,
|
this.i18nService,
|
||||||
this.billingAccountProfileStateService,
|
this.billingAccountProfileStateService,
|
||||||
@@ -410,7 +410,7 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
|
|||||||
this.stateService,
|
this.stateService,
|
||||||
this.twoFactorService,
|
this.twoFactorService,
|
||||||
this.userDecryptionOptionsService,
|
this.userDecryptionOptionsService,
|
||||||
this.deviceTrustCryptoService,
|
this.deviceTrustService,
|
||||||
this.billingAccountProfileStateService,
|
this.billingAccountProfileStateService,
|
||||||
);
|
);
|
||||||
case AuthenticationType.WebAuthn:
|
case AuthenticationType.WebAuthn:
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ import { Observable } from "rxjs";
|
|||||||
import { EncString } from "../../platform/models/domain/enc-string";
|
import { EncString } from "../../platform/models/domain/enc-string";
|
||||||
import { UserId } from "../../types/guid";
|
import { UserId } from "../../types/guid";
|
||||||
import { DeviceKey, UserKey } from "../../types/key";
|
import { DeviceKey, UserKey } from "../../types/key";
|
||||||
import { DeviceResponse } from "../abstractions/devices/responses/device.response";
|
|
||||||
|
|
||||||
export abstract class DeviceTrustCryptoServiceAbstraction {
|
import { DeviceResponse } from "./devices/responses/device.response";
|
||||||
|
|
||||||
|
export abstract class DeviceTrustServiceAbstraction {
|
||||||
supportsDeviceTrust$: Observable<boolean>;
|
supportsDeviceTrust$: Observable<boolean>;
|
||||||
/**
|
/**
|
||||||
* @description Retrieves the users choice to trust the device which can only happen after decryption
|
* @description Retrieves the users choice to trust the device which can only happen after decryption
|
||||||
@@ -17,7 +17,7 @@ import { SymmetricCryptoKey } from "../../platform/models/domain/symmetric-crypt
|
|||||||
import { DEVICE_TRUST_DISK_LOCAL, StateProvider, UserKeyDefinition } from "../../platform/state";
|
import { DEVICE_TRUST_DISK_LOCAL, StateProvider, UserKeyDefinition } from "../../platform/state";
|
||||||
import { UserId } from "../../types/guid";
|
import { UserId } from "../../types/guid";
|
||||||
import { UserKey, DeviceKey } from "../../types/key";
|
import { UserKey, DeviceKey } from "../../types/key";
|
||||||
import { DeviceTrustCryptoServiceAbstraction } from "../abstractions/device-trust-crypto.service.abstraction";
|
import { DeviceTrustServiceAbstraction } from "../abstractions/device-trust.service.abstraction";
|
||||||
import { DeviceResponse } from "../abstractions/devices/responses/device.response";
|
import { DeviceResponse } from "../abstractions/devices/responses/device.response";
|
||||||
import { DevicesApiServiceAbstraction } from "../abstractions/devices-api.service.abstraction";
|
import { DevicesApiServiceAbstraction } from "../abstractions/devices-api.service.abstraction";
|
||||||
import { SecretVerificationRequest } from "../models/request/secret-verification.request";
|
import { SecretVerificationRequest } from "../models/request/secret-verification.request";
|
||||||
@@ -42,7 +42,7 @@ export const SHOULD_TRUST_DEVICE = new UserKeyDefinition<boolean>(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export class DeviceTrustCryptoService implements DeviceTrustCryptoServiceAbstraction {
|
export class DeviceTrustService implements DeviceTrustServiceAbstraction {
|
||||||
private readonly platformSupportsSecureStorage =
|
private readonly platformSupportsSecureStorage =
|
||||||
this.platformUtilsService.supportsSecureStorage();
|
this.platformUtilsService.supportsSecureStorage();
|
||||||
private readonly deviceKeySecureStorageKey: string = "_deviceKey";
|
private readonly deviceKeySecureStorageKey: string = "_deviceKey";
|
||||||
@@ -33,11 +33,11 @@ import { ProtectedDeviceResponse } from "../models/response/protected-device.res
|
|||||||
import {
|
import {
|
||||||
SHOULD_TRUST_DEVICE,
|
SHOULD_TRUST_DEVICE,
|
||||||
DEVICE_KEY,
|
DEVICE_KEY,
|
||||||
DeviceTrustCryptoService,
|
DeviceTrustService,
|
||||||
} from "./device-trust-crypto.service.implementation";
|
} from "./device-trust.service.implementation";
|
||||||
|
|
||||||
describe("deviceTrustCryptoService", () => {
|
describe("deviceTrustService", () => {
|
||||||
let deviceTrustCryptoService: DeviceTrustCryptoService;
|
let deviceTrustService: DeviceTrustService;
|
||||||
|
|
||||||
const keyGenerationService = mock<KeyGenerationService>();
|
const keyGenerationService = mock<KeyGenerationService>();
|
||||||
const cryptoFunctionService = mock<CryptoFunctionService>();
|
const cryptoFunctionService = mock<CryptoFunctionService>();
|
||||||
@@ -70,11 +70,11 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
const supportsSecureStorage = false; // default to false; tests will override as needed
|
const supportsSecureStorage = false; // default to false; tests will override as needed
|
||||||
// By default all the tests will have a mocked active user in state provider.
|
// By default all the tests will have a mocked active user in state provider.
|
||||||
deviceTrustCryptoService = createDeviceTrustCryptoService(mockUserId, supportsSecureStorage);
|
deviceTrustService = createDeviceTrustService(mockUserId, supportsSecureStorage);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("instantiates", () => {
|
it("instantiates", () => {
|
||||||
expect(deviceTrustCryptoService).not.toBeFalsy();
|
expect(deviceTrustService).not.toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("User Trust Device Choice For Decryption", () => {
|
describe("User Trust Device Choice For Decryption", () => {
|
||||||
@@ -84,7 +84,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
|
|
||||||
await stateProvider.setUserState(SHOULD_TRUST_DEVICE, newValue, mockUserId);
|
await stateProvider.setUserState(SHOULD_TRUST_DEVICE, newValue, mockUserId);
|
||||||
|
|
||||||
const result = await deviceTrustCryptoService.getShouldTrustDevice(mockUserId);
|
const result = await deviceTrustService.getShouldTrustDevice(mockUserId);
|
||||||
|
|
||||||
expect(result).toEqual(newValue);
|
expect(result).toEqual(newValue);
|
||||||
});
|
});
|
||||||
@@ -95,9 +95,9 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
await stateProvider.setUserState(SHOULD_TRUST_DEVICE, false, mockUserId);
|
await stateProvider.setUserState(SHOULD_TRUST_DEVICE, false, mockUserId);
|
||||||
|
|
||||||
const newValue = true;
|
const newValue = true;
|
||||||
await deviceTrustCryptoService.setShouldTrustDevice(mockUserId, newValue);
|
await deviceTrustService.setShouldTrustDevice(mockUserId, newValue);
|
||||||
|
|
||||||
const result = await deviceTrustCryptoService.getShouldTrustDevice(mockUserId);
|
const result = await deviceTrustService.getShouldTrustDevice(mockUserId);
|
||||||
expect(result).toEqual(newValue);
|
expect(result).toEqual(newValue);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -105,25 +105,25 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
|
|
||||||
describe("trustDeviceIfRequired", () => {
|
describe("trustDeviceIfRequired", () => {
|
||||||
it("should trust device and reset when getShouldTrustDevice returns true", async () => {
|
it("should trust device and reset when getShouldTrustDevice returns true", async () => {
|
||||||
jest.spyOn(deviceTrustCryptoService, "getShouldTrustDevice").mockResolvedValue(true);
|
jest.spyOn(deviceTrustService, "getShouldTrustDevice").mockResolvedValue(true);
|
||||||
jest.spyOn(deviceTrustCryptoService, "trustDevice").mockResolvedValue({} as DeviceResponse);
|
jest.spyOn(deviceTrustService, "trustDevice").mockResolvedValue({} as DeviceResponse);
|
||||||
jest.spyOn(deviceTrustCryptoService, "setShouldTrustDevice").mockResolvedValue();
|
jest.spyOn(deviceTrustService, "setShouldTrustDevice").mockResolvedValue();
|
||||||
|
|
||||||
await deviceTrustCryptoService.trustDeviceIfRequired(mockUserId);
|
await deviceTrustService.trustDeviceIfRequired(mockUserId);
|
||||||
|
|
||||||
expect(deviceTrustCryptoService.getShouldTrustDevice).toHaveBeenCalledTimes(1);
|
expect(deviceTrustService.getShouldTrustDevice).toHaveBeenCalledTimes(1);
|
||||||
expect(deviceTrustCryptoService.trustDevice).toHaveBeenCalledTimes(1);
|
expect(deviceTrustService.trustDevice).toHaveBeenCalledTimes(1);
|
||||||
expect(deviceTrustCryptoService.setShouldTrustDevice).toHaveBeenCalledWith(mockUserId, false);
|
expect(deviceTrustService.setShouldTrustDevice).toHaveBeenCalledWith(mockUserId, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not trust device nor reset when getShouldTrustDevice returns false", async () => {
|
it("should not trust device nor reset when getShouldTrustDevice returns false", async () => {
|
||||||
const getShouldTrustDeviceSpy = jest
|
const getShouldTrustDeviceSpy = jest
|
||||||
.spyOn(deviceTrustCryptoService, "getShouldTrustDevice")
|
.spyOn(deviceTrustService, "getShouldTrustDevice")
|
||||||
.mockResolvedValue(false);
|
.mockResolvedValue(false);
|
||||||
const trustDeviceSpy = jest.spyOn(deviceTrustCryptoService, "trustDevice");
|
const trustDeviceSpy = jest.spyOn(deviceTrustService, "trustDevice");
|
||||||
const setShouldTrustDeviceSpy = jest.spyOn(deviceTrustCryptoService, "setShouldTrustDevice");
|
const setShouldTrustDeviceSpy = jest.spyOn(deviceTrustService, "setShouldTrustDevice");
|
||||||
|
|
||||||
await deviceTrustCryptoService.trustDeviceIfRequired(mockUserId);
|
await deviceTrustService.trustDeviceIfRequired(mockUserId);
|
||||||
|
|
||||||
expect(getShouldTrustDeviceSpy).toHaveBeenCalledTimes(1);
|
expect(getShouldTrustDeviceSpy).toHaveBeenCalledTimes(1);
|
||||||
expect(trustDeviceSpy).not.toHaveBeenCalled();
|
expect(trustDeviceSpy).not.toHaveBeenCalled();
|
||||||
@@ -151,7 +151,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
it("returns null when there is not an existing device key", async () => {
|
it("returns null when there is not an existing device key", async () => {
|
||||||
await stateProvider.setUserState(DEVICE_KEY, null, mockUserId);
|
await stateProvider.setUserState(DEVICE_KEY, null, mockUserId);
|
||||||
|
|
||||||
const deviceKey = await deviceTrustCryptoService.getDeviceKey(mockUserId);
|
const deviceKey = await deviceTrustService.getDeviceKey(mockUserId);
|
||||||
|
|
||||||
expect(deviceKey).toBeNull();
|
expect(deviceKey).toBeNull();
|
||||||
expect(secureStorageService.get).not.toHaveBeenCalled();
|
expect(secureStorageService.get).not.toHaveBeenCalled();
|
||||||
@@ -160,7 +160,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
it("returns the device key when there is an existing device key", async () => {
|
it("returns the device key when there is an existing device key", async () => {
|
||||||
await stateProvider.setUserState(DEVICE_KEY, existingDeviceKey, mockUserId);
|
await stateProvider.setUserState(DEVICE_KEY, existingDeviceKey, mockUserId);
|
||||||
|
|
||||||
const deviceKey = await deviceTrustCryptoService.getDeviceKey(mockUserId);
|
const deviceKey = await deviceTrustService.getDeviceKey(mockUserId);
|
||||||
|
|
||||||
expect(deviceKey).not.toBeNull();
|
expect(deviceKey).not.toBeNull();
|
||||||
expect(deviceKey).toBeInstanceOf(SymmetricCryptoKey);
|
expect(deviceKey).toBeInstanceOf(SymmetricCryptoKey);
|
||||||
@@ -172,17 +172,14 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
describe("Secure Storage supported", () => {
|
describe("Secure Storage supported", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const supportsSecureStorage = true;
|
const supportsSecureStorage = true;
|
||||||
deviceTrustCryptoService = createDeviceTrustCryptoService(
|
deviceTrustService = createDeviceTrustService(mockUserId, supportsSecureStorage);
|
||||||
mockUserId,
|
|
||||||
supportsSecureStorage,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns null when there is not an existing device key for the passed in user id", async () => {
|
it("returns null when there is not an existing device key for the passed in user id", async () => {
|
||||||
secureStorageService.get.mockResolvedValue(null);
|
secureStorageService.get.mockResolvedValue(null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const deviceKey = await deviceTrustCryptoService.getDeviceKey(mockUserId);
|
const deviceKey = await deviceTrustService.getDeviceKey(mockUserId);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(deviceKey).toBeNull();
|
expect(deviceKey).toBeNull();
|
||||||
@@ -193,7 +190,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
secureStorageService.get.mockResolvedValue(existingDeviceKeyB64);
|
secureStorageService.get.mockResolvedValue(existingDeviceKeyB64);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const deviceKey = await deviceTrustCryptoService.getDeviceKey(mockUserId);
|
const deviceKey = await deviceTrustService.getDeviceKey(mockUserId);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(deviceKey).not.toBeNull();
|
expect(deviceKey).not.toBeNull();
|
||||||
@@ -203,7 +200,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("throws an error when no user id is passed in", async () => {
|
it("throws an error when no user id is passed in", async () => {
|
||||||
await expect(deviceTrustCryptoService.getDeviceKey(null)).rejects.toThrow(
|
await expect(deviceTrustService.getDeviceKey(null)).rejects.toThrow(
|
||||||
"UserId is required. Cannot get device key.",
|
"UserId is required. Cannot get device key.",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -220,7 +217,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
|
|
||||||
// TypeScript will allow calling private methods if the object is of type 'any'
|
// TypeScript will allow calling private methods if the object is of type 'any'
|
||||||
// This is a hacky workaround, but it allows for cleaner tests
|
// This is a hacky workaround, but it allows for cleaner tests
|
||||||
await (deviceTrustCryptoService as any).setDeviceKey(mockUserId, newDeviceKey);
|
await (deviceTrustService as any).setDeviceKey(mockUserId, newDeviceKey);
|
||||||
|
|
||||||
expect(stateProvider.mock.setUserState).toHaveBeenLastCalledWith(
|
expect(stateProvider.mock.setUserState).toHaveBeenLastCalledWith(
|
||||||
DEVICE_KEY,
|
DEVICE_KEY,
|
||||||
@@ -232,10 +229,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
describe("Secure Storage supported", () => {
|
describe("Secure Storage supported", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const supportsSecureStorage = true;
|
const supportsSecureStorage = true;
|
||||||
deviceTrustCryptoService = createDeviceTrustCryptoService(
|
deviceTrustService = createDeviceTrustService(mockUserId, supportsSecureStorage);
|
||||||
mockUserId,
|
|
||||||
supportsSecureStorage,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("successfully sets the device key in secure storage", async () => {
|
it("successfully sets the device key in secure storage", async () => {
|
||||||
@@ -251,7 +245,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
// Act
|
// Act
|
||||||
// TypeScript will allow calling private methods if the object is of type 'any'
|
// TypeScript will allow calling private methods if the object is of type 'any'
|
||||||
// This is a hacky workaround, but it allows for cleaner tests
|
// This is a hacky workaround, but it allows for cleaner tests
|
||||||
await (deviceTrustCryptoService as any).setDeviceKey(mockUserId, newDeviceKey);
|
await (deviceTrustService as any).setDeviceKey(mockUserId, newDeviceKey);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(stateProvider.mock.setUserState).not.toHaveBeenCalledTimes(2);
|
expect(stateProvider.mock.setUserState).not.toHaveBeenCalledTimes(2);
|
||||||
@@ -268,9 +262,9 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
new Uint8Array(deviceKeyBytesLength) as CsprngArray,
|
new Uint8Array(deviceKeyBytesLength) as CsprngArray,
|
||||||
) as DeviceKey;
|
) as DeviceKey;
|
||||||
|
|
||||||
await expect(
|
await expect((deviceTrustService as any).setDeviceKey(null, newDeviceKey)).rejects.toThrow(
|
||||||
(deviceTrustCryptoService as any).setDeviceKey(null, newDeviceKey),
|
"UserId is required. Cannot set device key.",
|
||||||
).rejects.toThrow("UserId is required. Cannot set device key.");
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -285,7 +279,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
|
|
||||||
// TypeScript will allow calling private methods if the object is of type 'any'
|
// TypeScript will allow calling private methods if the object is of type 'any'
|
||||||
// This is a hacky workaround, but it allows for cleaner tests
|
// This is a hacky workaround, but it allows for cleaner tests
|
||||||
const deviceKey = await (deviceTrustCryptoService as any).makeDeviceKey();
|
const deviceKey = await (deviceTrustService as any).makeDeviceKey();
|
||||||
|
|
||||||
expect(keyGenSvcGenerateKeySpy).toHaveBeenCalledTimes(1);
|
expect(keyGenSvcGenerateKeySpy).toHaveBeenCalledTimes(1);
|
||||||
expect(keyGenSvcGenerateKeySpy).toHaveBeenCalledWith(deviceKeyBytesLength * 8);
|
expect(keyGenSvcGenerateKeySpy).toHaveBeenCalledWith(deviceKeyBytesLength * 8);
|
||||||
@@ -362,7 +356,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
|
|
||||||
// TypeScript will allow calling private methods if the object is of type 'any'
|
// TypeScript will allow calling private methods if the object is of type 'any'
|
||||||
makeDeviceKeySpy = jest
|
makeDeviceKeySpy = jest
|
||||||
.spyOn(deviceTrustCryptoService as any, "makeDeviceKey")
|
.spyOn(deviceTrustService as any, "makeDeviceKey")
|
||||||
.mockResolvedValue(mockDeviceKey);
|
.mockResolvedValue(mockDeviceKey);
|
||||||
|
|
||||||
rsaGenerateKeyPairSpy = jest
|
rsaGenerateKeyPairSpy = jest
|
||||||
@@ -398,7 +392,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("calls the required methods with the correct arguments and returns a DeviceResponse", async () => {
|
it("calls the required methods with the correct arguments and returns a DeviceResponse", async () => {
|
||||||
const response = await deviceTrustCryptoService.trustDevice(mockUserId);
|
const response = await deviceTrustService.trustDevice(mockUserId);
|
||||||
|
|
||||||
expect(makeDeviceKeySpy).toHaveBeenCalledTimes(1);
|
expect(makeDeviceKeySpy).toHaveBeenCalledTimes(1);
|
||||||
expect(rsaGenerateKeyPairSpy).toHaveBeenCalledTimes(1);
|
expect(rsaGenerateKeyPairSpy).toHaveBeenCalledTimes(1);
|
||||||
@@ -429,7 +423,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
// setup the spy to return null
|
// setup the spy to return null
|
||||||
cryptoSvcGetUserKeySpy.mockResolvedValue(null);
|
cryptoSvcGetUserKeySpy.mockResolvedValue(null);
|
||||||
// check if the expected error is thrown
|
// check if the expected error is thrown
|
||||||
await expect(deviceTrustCryptoService.trustDevice(mockUserId)).rejects.toThrow(
|
await expect(deviceTrustService.trustDevice(mockUserId)).rejects.toThrow(
|
||||||
"User symmetric key not found",
|
"User symmetric key not found",
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -439,7 +433,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
// setup the spy to return undefined
|
// setup the spy to return undefined
|
||||||
cryptoSvcGetUserKeySpy.mockResolvedValue(undefined);
|
cryptoSvcGetUserKeySpy.mockResolvedValue(undefined);
|
||||||
// check if the expected error is thrown
|
// check if the expected error is thrown
|
||||||
await expect(deviceTrustCryptoService.trustDevice(mockUserId)).rejects.toThrow(
|
await expect(deviceTrustService.trustDevice(mockUserId)).rejects.toThrow(
|
||||||
"User symmetric key not found",
|
"User symmetric key not found",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -479,9 +473,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
it(`throws an error if ${method} fails`, async () => {
|
it(`throws an error if ${method} fails`, async () => {
|
||||||
const methodSpy = spy();
|
const methodSpy = spy();
|
||||||
methodSpy.mockRejectedValue(new Error(errorText));
|
methodSpy.mockRejectedValue(new Error(errorText));
|
||||||
await expect(deviceTrustCryptoService.trustDevice(mockUserId)).rejects.toThrow(
|
await expect(deviceTrustService.trustDevice(mockUserId)).rejects.toThrow(errorText);
|
||||||
errorText,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test.each([null, undefined])(
|
test.each([null, undefined])(
|
||||||
@@ -489,14 +481,14 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
async (invalidValue) => {
|
async (invalidValue) => {
|
||||||
const methodSpy = spy();
|
const methodSpy = spy();
|
||||||
methodSpy.mockResolvedValue(invalidValue);
|
methodSpy.mockResolvedValue(invalidValue);
|
||||||
await expect(deviceTrustCryptoService.trustDevice(mockUserId)).rejects.toThrow();
|
await expect(deviceTrustService.trustDevice(mockUserId)).rejects.toThrow();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
it("throws an error when a null user id is passed in", async () => {
|
it("throws an error when a null user id is passed in", async () => {
|
||||||
await expect(deviceTrustCryptoService.trustDevice(null)).rejects.toThrow(
|
await expect(deviceTrustService.trustDevice(null)).rejects.toThrow(
|
||||||
"UserId is required. Cannot trust device.",
|
"UserId is required. Cannot trust device.",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -530,7 +522,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
|
|
||||||
it("throws an error when a null user id is passed in", async () => {
|
it("throws an error when a null user id is passed in", async () => {
|
||||||
await expect(
|
await expect(
|
||||||
deviceTrustCryptoService.decryptUserKeyWithDeviceKey(
|
deviceTrustService.decryptUserKeyWithDeviceKey(
|
||||||
null,
|
null,
|
||||||
mockEncryptedDevicePrivateKey,
|
mockEncryptedDevicePrivateKey,
|
||||||
mockEncryptedUserKey,
|
mockEncryptedUserKey,
|
||||||
@@ -540,7 +532,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("returns null when device key isn't provided", async () => {
|
it("returns null when device key isn't provided", async () => {
|
||||||
const result = await deviceTrustCryptoService.decryptUserKeyWithDeviceKey(
|
const result = await deviceTrustService.decryptUserKeyWithDeviceKey(
|
||||||
mockUserId,
|
mockUserId,
|
||||||
mockEncryptedDevicePrivateKey,
|
mockEncryptedDevicePrivateKey,
|
||||||
mockEncryptedUserKey,
|
mockEncryptedUserKey,
|
||||||
@@ -558,7 +550,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
.spyOn(cryptoService, "rsaDecrypt")
|
.spyOn(cryptoService, "rsaDecrypt")
|
||||||
.mockResolvedValue(new Uint8Array(userKeyBytesLength));
|
.mockResolvedValue(new Uint8Array(userKeyBytesLength));
|
||||||
|
|
||||||
const result = await deviceTrustCryptoService.decryptUserKeyWithDeviceKey(
|
const result = await deviceTrustService.decryptUserKeyWithDeviceKey(
|
||||||
mockUserId,
|
mockUserId,
|
||||||
mockEncryptedDevicePrivateKey,
|
mockEncryptedDevicePrivateKey,
|
||||||
mockEncryptedUserKey,
|
mockEncryptedUserKey,
|
||||||
@@ -574,9 +566,9 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
const decryptToBytesSpy = jest
|
const decryptToBytesSpy = jest
|
||||||
.spyOn(encryptService, "decryptToBytes")
|
.spyOn(encryptService, "decryptToBytes")
|
||||||
.mockRejectedValue(new Error("Decryption error"));
|
.mockRejectedValue(new Error("Decryption error"));
|
||||||
const setDeviceKeySpy = jest.spyOn(deviceTrustCryptoService as any, "setDeviceKey");
|
const setDeviceKeySpy = jest.spyOn(deviceTrustService as any, "setDeviceKey");
|
||||||
|
|
||||||
const result = await deviceTrustCryptoService.decryptUserKeyWithDeviceKey(
|
const result = await deviceTrustService.decryptUserKeyWithDeviceKey(
|
||||||
mockUserId,
|
mockUserId,
|
||||||
mockEncryptedDevicePrivateKey,
|
mockEncryptedDevicePrivateKey,
|
||||||
mockEncryptedUserKey,
|
mockEncryptedUserKey,
|
||||||
@@ -606,7 +598,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
|
|
||||||
it("throws an error when a null user id is passed in", async () => {
|
it("throws an error when a null user id is passed in", async () => {
|
||||||
await expect(
|
await expect(
|
||||||
deviceTrustCryptoService.rotateDevicesTrust(null, fakeNewUserKey, ""),
|
deviceTrustService.rotateDevicesTrust(null, fakeNewUserKey, ""),
|
||||||
).rejects.toThrow("UserId is required. Cannot rotate device's trust.");
|
).rejects.toThrow("UserId is required. Cannot rotate device's trust.");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -615,7 +607,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
stateProvider.activeUser.getFake(DEVICE_KEY);
|
stateProvider.activeUser.getFake(DEVICE_KEY);
|
||||||
deviceKeyState.nextState(null);
|
deviceKeyState.nextState(null);
|
||||||
|
|
||||||
await deviceTrustCryptoService.rotateDevicesTrust(mockUserId, fakeNewUserKey, "");
|
await deviceTrustService.rotateDevicesTrust(mockUserId, fakeNewUserKey, "");
|
||||||
|
|
||||||
expect(devicesApiService.updateTrust).not.toHaveBeenCalled();
|
expect(devicesApiService.updateTrust).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
@@ -691,7 +683,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
await deviceTrustCryptoService.rotateDevicesTrust(
|
await deviceTrustService.rotateDevicesTrust(
|
||||||
mockUserId,
|
mockUserId,
|
||||||
fakeNewUserKey,
|
fakeNewUserKey,
|
||||||
"my_password_hash",
|
"my_password_hash",
|
||||||
@@ -713,10 +705,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
function createDeviceTrustCryptoService(
|
function createDeviceTrustService(mockUserId: UserId | null, supportsSecureStorage: boolean) {
|
||||||
mockUserId: UserId | null,
|
|
||||||
supportsSecureStorage: boolean,
|
|
||||||
) {
|
|
||||||
accountService = mockAccountServiceWith(mockUserId);
|
accountService = mockAccountServiceWith(mockUserId);
|
||||||
stateProvider = new FakeStateProvider(accountService);
|
stateProvider = new FakeStateProvider(accountService);
|
||||||
|
|
||||||
@@ -725,7 +714,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
decryptionOptions.next({} as any);
|
decryptionOptions.next({} as any);
|
||||||
userDecryptionOptionsService.userDecryptionOptions$ = decryptionOptions;
|
userDecryptionOptionsService.userDecryptionOptions$ = decryptionOptions;
|
||||||
|
|
||||||
return new DeviceTrustCryptoService(
|
return new DeviceTrustService(
|
||||||
keyGenerationService,
|
keyGenerationService,
|
||||||
cryptoFunctionService,
|
cryptoFunctionService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
@@ -49,7 +49,7 @@ import { AddKeyTypeToOrgKeysMigrator } from "./migrations/5-add-key-type-to-org-
|
|||||||
import { KeyConnectorMigrator } from "./migrations/50-move-key-connector-to-state-provider";
|
import { KeyConnectorMigrator } from "./migrations/50-move-key-connector-to-state-provider";
|
||||||
import { RememberedEmailMigrator } from "./migrations/51-move-remembered-email-to-state-providers";
|
import { RememberedEmailMigrator } from "./migrations/51-move-remembered-email-to-state-providers";
|
||||||
import { DeleteInstalledVersion } from "./migrations/52-delete-installed-version";
|
import { DeleteInstalledVersion } from "./migrations/52-delete-installed-version";
|
||||||
import { DeviceTrustCryptoServiceStateProviderMigrator } from "./migrations/53-migrate-device-trust-crypto-svc-to-state-providers";
|
import { DeviceTrustServiceStateProviderMigrator } from "./migrations/53-migrate-device-trust-svc-to-state-providers";
|
||||||
import { SendMigrator } from "./migrations/54-move-encrypted-sends";
|
import { SendMigrator } from "./migrations/54-move-encrypted-sends";
|
||||||
import { MoveMasterKeyStateToProviderMigrator } from "./migrations/55-move-master-key-state-to-provider";
|
import { MoveMasterKeyStateToProviderMigrator } from "./migrations/55-move-master-key-state-to-provider";
|
||||||
import { AuthRequestMigrator } from "./migrations/56-move-auth-requests";
|
import { AuthRequestMigrator } from "./migrations/56-move-auth-requests";
|
||||||
@@ -117,7 +117,7 @@ export function createMigrationBuilder() {
|
|||||||
.with(KeyConnectorMigrator, 49, 50)
|
.with(KeyConnectorMigrator, 49, 50)
|
||||||
.with(RememberedEmailMigrator, 50, 51)
|
.with(RememberedEmailMigrator, 50, 51)
|
||||||
.with(DeleteInstalledVersion, 51, 52)
|
.with(DeleteInstalledVersion, 51, 52)
|
||||||
.with(DeviceTrustCryptoServiceStateProviderMigrator, 52, 53)
|
.with(DeviceTrustServiceStateProviderMigrator, 52, 53)
|
||||||
.with(SendMigrator, 53, 54)
|
.with(SendMigrator, 53, 54)
|
||||||
.with(MoveMasterKeyStateToProviderMigrator, 54, 55)
|
.with(MoveMasterKeyStateToProviderMigrator, 54, 55)
|
||||||
.with(AuthRequestMigrator, 55, 56)
|
.with(AuthRequestMigrator, 55, 56)
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import { mockMigrationHelper } from "../migration-helper.spec";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
DEVICE_KEY,
|
DEVICE_KEY,
|
||||||
DeviceTrustCryptoServiceStateProviderMigrator,
|
DeviceTrustServiceStateProviderMigrator,
|
||||||
SHOULD_TRUST_DEVICE,
|
SHOULD_TRUST_DEVICE,
|
||||||
} from "./53-migrate-device-trust-crypto-svc-to-state-providers";
|
} from "./53-migrate-device-trust-svc-to-state-providers";
|
||||||
|
|
||||||
// Represents data in state service pre-migration
|
// Represents data in state service pre-migration
|
||||||
function preMigrationJson() {
|
function preMigrationJson() {
|
||||||
@@ -79,14 +79,14 @@ function rollbackJSON() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("DeviceTrustCryptoServiceStateProviderMigrator", () => {
|
describe("DeviceTrustServiceStateProviderMigrator", () => {
|
||||||
let helper: MockProxy<MigrationHelper>;
|
let helper: MockProxy<MigrationHelper>;
|
||||||
let sut: DeviceTrustCryptoServiceStateProviderMigrator;
|
let sut: DeviceTrustServiceStateProviderMigrator;
|
||||||
|
|
||||||
describe("migrate", () => {
|
describe("migrate", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
helper = mockMigrationHelper(preMigrationJson(), 52);
|
helper = mockMigrationHelper(preMigrationJson(), 52);
|
||||||
sut = new DeviceTrustCryptoServiceStateProviderMigrator(52, 53);
|
sut = new DeviceTrustServiceStateProviderMigrator(52, 53);
|
||||||
});
|
});
|
||||||
|
|
||||||
// it should remove deviceKey and trustDeviceChoiceForDecryption from all accounts
|
// it should remove deviceKey and trustDeviceChoiceForDecryption from all accounts
|
||||||
@@ -126,7 +126,7 @@ describe("DeviceTrustCryptoServiceStateProviderMigrator", () => {
|
|||||||
describe("rollback", () => {
|
describe("rollback", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
helper = mockMigrationHelper(rollbackJSON(), 53);
|
helper = mockMigrationHelper(rollbackJSON(), 53);
|
||||||
sut = new DeviceTrustCryptoServiceStateProviderMigrator(52, 53);
|
sut = new DeviceTrustServiceStateProviderMigrator(52, 53);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should null out newly migrated entries in state provider framework", async () => {
|
it("should null out newly migrated entries in state provider framework", async () => {
|
||||||
@@ -16,7 +16,7 @@ type ExpectedAccountType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const DEVICE_KEY: KeyDefinitionLike = {
|
export const DEVICE_KEY: KeyDefinitionLike = {
|
||||||
key: "deviceKey", // matches KeyDefinition.key in DeviceTrustCryptoService
|
key: "deviceKey", // matches KeyDefinition.key in DeviceTrustService
|
||||||
stateDefinition: {
|
stateDefinition: {
|
||||||
name: "deviceTrust", // matches StateDefinition.name in StateDefinitions
|
name: "deviceTrust", // matches StateDefinition.name in StateDefinitions
|
||||||
},
|
},
|
||||||
@@ -29,7 +29,7 @@ export const SHOULD_TRUST_DEVICE: KeyDefinitionLike = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export class DeviceTrustCryptoServiceStateProviderMigrator extends Migrator<52, 53> {
|
export class DeviceTrustServiceStateProviderMigrator extends Migrator<52, 53> {
|
||||||
async migrate(helper: MigrationHelper): Promise<void> {
|
async migrate(helper: MigrationHelper): Promise<void> {
|
||||||
const accounts = await helper.getAccounts<ExpectedAccountType>();
|
const accounts = await helper.getAccounts<ExpectedAccountType>();
|
||||||
async function migrateAccount(userId: string, account: ExpectedAccountType): Promise<void> {
|
async function migrateAccount(userId: string, account: ExpectedAccountType): Promise<void> {
|
||||||
@@ -4,7 +4,7 @@ import { IRREVERSIBLE, Migrator } from "../migrator";
|
|||||||
type ExpectedAccountType = NonNullable<unknown>;
|
type ExpectedAccountType = NonNullable<unknown>;
|
||||||
|
|
||||||
export const REFRESH_TOKEN_MIGRATED_TO_SECURE_STORAGE: KeyDefinitionLike = {
|
export const REFRESH_TOKEN_MIGRATED_TO_SECURE_STORAGE: KeyDefinitionLike = {
|
||||||
key: "refreshTokenMigratedToSecureStorage", // matches KeyDefinition.key in DeviceTrustCryptoService
|
key: "refreshTokenMigratedToSecureStorage", // matches KeyDefinition.key
|
||||||
stateDefinition: {
|
stateDefinition: {
|
||||||
name: "token", // matches StateDefinition.name in StateDefinitions
|
name: "token", // matches StateDefinition.name in StateDefinitions
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user