change interface
This commit is contained in:
parent
654ae056b3
commit
5c090ce40d
|
@ -440,7 +440,6 @@ const safeProviders: SafeProvider[] = [
|
||||||
KdfConfigServiceAbstraction,
|
KdfConfigServiceAbstraction,
|
||||||
TaskSchedulerService,
|
TaskSchedulerService,
|
||||||
UserAsymmetricKeysRegenerationService,
|
UserAsymmetricKeysRegenerationService,
|
||||||
ConfigService,
|
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
|
@ -1387,6 +1386,7 @@ const safeProviders: SafeProvider[] = [
|
||||||
LogService,
|
LogService,
|
||||||
SdkService,
|
SdkService,
|
||||||
ApiServiceAbstraction,
|
ApiServiceAbstraction,
|
||||||
|
ConfigService,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
|
@ -29,7 +29,6 @@ import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abs
|
||||||
import { PreloginRequest } from "@bitwarden/common/models/request/prelogin.request";
|
import { PreloginRequest } from "@bitwarden/common/models/request/prelogin.request";
|
||||||
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
||||||
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
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 { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
|
@ -116,7 +115,6 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
|
||||||
protected kdfConfigService: KdfConfigService,
|
protected kdfConfigService: KdfConfigService,
|
||||||
protected taskSchedulerService: TaskSchedulerService,
|
protected taskSchedulerService: TaskSchedulerService,
|
||||||
protected userAsymmetricKeysRegenerationService: UserAsymmetricKeysRegenerationService,
|
protected userAsymmetricKeysRegenerationService: UserAsymmetricKeysRegenerationService,
|
||||||
protected configService: ConfigService,
|
|
||||||
) {
|
) {
|
||||||
this.currentAuthnTypeState = this.stateProvider.get(CURRENT_LOGIN_STRATEGY_KEY);
|
this.currentAuthnTypeState = this.stateProvider.get(CURRENT_LOGIN_STRATEGY_KEY);
|
||||||
this.loginStrategyCacheState = this.stateProvider.get(CACHE_KEY);
|
this.loginStrategyCacheState = this.stateProvider.get(CACHE_KEY);
|
||||||
|
@ -337,7 +335,6 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
|
||||||
this.vaultTimeoutSettingsService,
|
this.vaultTimeoutSettingsService,
|
||||||
this.kdfConfigService,
|
this.kdfConfigService,
|
||||||
this.userAsymmetricKeysRegenerationService,
|
this.userAsymmetricKeysRegenerationService,
|
||||||
this.configService,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return source.pipe(
|
return source.pipe(
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import { UserId } from "@bitwarden/common/types/guid";
|
import { UserId } from "@bitwarden/common/types/guid";
|
||||||
|
|
||||||
export abstract class UserAsymmetricKeysRegenerationService {
|
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>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import { firstValueFrom, map } from "rxjs";
|
import { firstValueFrom, map } from "rxjs";
|
||||||
|
|
||||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
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 { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||||
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
||||||
|
@ -24,9 +26,23 @@ export class DefaultUserAsymmetricKeysRegenerationService
|
||||||
protected logService: LogService,
|
protected logService: LogService,
|
||||||
protected sdkService: SdkService,
|
protected sdkService: SdkService,
|
||||||
protected apiService: ApiService,
|
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([
|
const [userKey, userKeyEncryptedPrivateKey, publicKeyResponse] = await Promise.all([
|
||||||
firstValueFrom(this.keyService.userKey$(userId)),
|
firstValueFrom(this.keyService.userKey$(userId)),
|
||||||
firstValueFrom(this.keyService.userEncryptedPrivateKey$(userId)),
|
firstValueFrom(this.keyService.userEncryptedPrivateKey$(userId)),
|
||||||
|
@ -71,7 +87,7 @@ export class DefaultUserAsymmetricKeysRegenerationService
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async regenerateUserAsymmetricKeys(userId: UserId): Promise<void> {
|
private async regenerateUserAsymmetricKeys(userId: UserId): Promise<void> {
|
||||||
const makeKeyPairResponse = await firstValueFrom(
|
const makeKeyPairResponse = await firstValueFrom(
|
||||||
this.sdkService.userClient$(userId).pipe(map((sdk) => sdk.crypto().make_key_pair())),
|
this.sdkService.userClient$(userId).pipe(map((sdk) => sdk.crypto().make_key_pair())),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue