change interface

This commit is contained in:
Thomas Avery 2024-11-01 15:38:14 -05:00
parent 654ae056b3
commit 5c090ce40d
No known key found for this signature in database
GPG Key ID: 44A02A0410B0F429
4 changed files with 23 additions and 8 deletions

View File

@ -440,7 +440,6 @@ const safeProviders: SafeProvider[] = [
KdfConfigServiceAbstraction,
TaskSchedulerService,
UserAsymmetricKeysRegenerationService,
ConfigService,
],
}),
safeProvider({
@ -1387,6 +1386,7 @@ const safeProviders: SafeProvider[] = [
LogService,
SdkService,
ApiServiceAbstraction,
ConfigService,
],
}),
];

View File

@ -29,7 +29,6 @@ import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abs
import { PreloginRequest } from "@bitwarden/common/models/request/prelogin.request";
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
@ -116,7 +115,6 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
protected kdfConfigService: KdfConfigService,
protected taskSchedulerService: TaskSchedulerService,
protected userAsymmetricKeysRegenerationService: UserAsymmetricKeysRegenerationService,
protected configService: ConfigService,
) {
this.currentAuthnTypeState = this.stateProvider.get(CURRENT_LOGIN_STRATEGY_KEY);
this.loginStrategyCacheState = this.stateProvider.get(CACHE_KEY);
@ -337,7 +335,6 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
this.vaultTimeoutSettingsService,
this.kdfConfigService,
this.userAsymmetricKeysRegenerationService,
this.configService,
];
return source.pipe(

View File

@ -1,6 +1,8 @@
import { UserId } from "@bitwarden/common/types/guid";
export abstract class UserAsymmetricKeysRegenerationService {
abstract shouldRegenerate: (userId: UserId) => Promise<boolean>;
abstract regenerateUserAsymmetricKeys: (userId: UserId) => Promise<void>;
/**
* Handle regeneration of the user's asymmetric keys if they are invalid.
*/
abstract handleUserAsymmetricKeysRegeneration: (userId: UserId) => Promise<void>;
}

View File

@ -1,6 +1,8 @@
import { firstValueFrom, map } from "rxjs";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
@ -24,9 +26,23 @@ export class DefaultUserAsymmetricKeysRegenerationService
protected logService: LogService,
protected sdkService: SdkService,
protected apiService: ApiService,
protected configService: ConfigService,
) {}
async shouldRegenerate(userId: UserId): Promise<boolean> {
async handleUserAsymmetricKeysRegeneration(userId: UserId): Promise<void> {
const privateKeyRegenerationFlag = await this.configService.getFeatureFlag(
FeatureFlag.PrivateKeyRegeneration,
);
if (privateKeyRegenerationFlag) {
const shouldRegenerate = await this.shouldRegenerate(userId);
if (shouldRegenerate) {
await this.regenerateUserAsymmetricKeys(userId);
}
}
}
private async shouldRegenerate(userId: UserId): Promise<boolean> {
const [userKey, userKeyEncryptedPrivateKey, publicKeyResponse] = await Promise.all([
firstValueFrom(this.keyService.userKey$(userId)),
firstValueFrom(this.keyService.userEncryptedPrivateKey$(userId)),
@ -71,7 +87,7 @@ export class DefaultUserAsymmetricKeysRegenerationService
return false;
}
async regenerateUserAsymmetricKeys(userId: UserId): Promise<void> {
private async regenerateUserAsymmetricKeys(userId: UserId): Promise<void> {
const makeKeyPairResponse = await firstValueFrom(
this.sdkService.userClient$(userId).pipe(map((sdk) => sdk.crypto().make_key_pair())),
);