Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-16982] Make argon2 the default kdf for new accounts #12614

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/browser/src/auth/popup/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { LoginStrategyServiceAbstraction } from "@bitwarden/auth/common";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { AuditService } from "@bitwarden/common/abstractions/audit.service";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";

Check warning on line 12 in apps/browser/src/auth/popup/register.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/auth/popup/register.component.ts#L12

Added line #L12 was not covered by tests
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
Expand Down Expand Up @@ -42,6 +43,7 @@
auditService: AuditService,
dialogService: DialogService,
toastService: ToastService,
configService: ConfigService,
) {
super(
formValidationErrorService,
Expand All @@ -59,6 +61,7 @@
auditService,
dialogService,
toastService,
configService,
);
}
}
3 changes: 3 additions & 0 deletions apps/desktop/src/auth/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { AuditService } from "@bitwarden/common/abstractions/audit.service";
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";

Check warning on line 11 in apps/desktop/src/auth/register.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/auth/register.component.ts#L11

Added line #L11 was not covered by tests
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
Expand Down Expand Up @@ -42,6 +43,7 @@
auditService: AuditService,
dialogService: DialogService,
toastService: ToastService,
configService: ConfigService,
) {
super(
formValidationErrorService,
Expand All @@ -59,6 +61,7 @@
auditService,
dialogService,
toastService,
configService,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { PolicyService } from "@bitwarden/common/admin-console/abstractions/poli
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
import { ReferenceEventRequest } from "@bitwarden/common/models/request/reference-event.request";
import { RegisterRequest } from "@bitwarden/common/models/request/register.request";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
Expand Down Expand Up @@ -55,6 +56,7 @@ export class RegisterFormComponent extends BaseRegisterComponent implements OnIn
dialogService: DialogService,
acceptOrgInviteService: AcceptOrganizationInviteService,
toastService: ToastService,
configService: ConfigService,
) {
super(
formValidationErrorService,
Expand All @@ -72,6 +74,7 @@ export class RegisterFormComponent extends BaseRegisterComponent implements OnIn
auditService,
dialogService,
toastService,
configService,
);
this.modifyRegisterRequest = async (request: RegisterRequest) => {
// Org invites are deep linked. Non-existent accounts are redirected to the register page.
Expand Down
18 changes: 16 additions & 2 deletions libs/angular/src/auth/components/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { AuditService } from "@bitwarden/common/abstractions/audit.service";
import { RegisterResponse } from "@bitwarden/common/auth/models/response/register.response";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";

Check warning on line 11 in libs/angular/src/auth/components/register.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/auth/components/register.component.ts#L11

Added line #L11 was not covered by tests
import { KeysRequest } from "@bitwarden/common/models/request/keys.request";
import { ReferenceEventRequest } from "@bitwarden/common/models/request/reference-event.request";
import { RegisterRequest } from "@bitwarden/common/models/request/register.request";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";

Check warning on line 15 in libs/angular/src/auth/components/register.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/auth/components/register.component.ts#L15

Added line #L15 was not covered by tests
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
Expand All @@ -19,7 +21,12 @@
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { DialogService, ToastService } from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
import { DEFAULT_KDF_CONFIG, KeyService } from "@bitwarden/key-management";
import {

Check warning on line 24 in libs/angular/src/auth/components/register.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/auth/components/register.component.ts#L24

Added line #L24 was not covered by tests
DEFAULT_KDF_CONFIG,
KdfConfig,
KeyService,
NEW_ARGON2_DEFAULT_KDF_CONFIG,
} from "@bitwarden/key-management";

import {
AllValidationErrors,
Expand Down Expand Up @@ -99,6 +106,7 @@
protected auditService: AuditService,
protected dialogService: DialogService,
protected toastService: ToastService,
private configService: ConfigService,

Check warning on line 109 in libs/angular/src/auth/components/register.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/auth/components/register.component.ts#L109

Added line #L109 was not covered by tests
) {
super(environmentService, i18nService, platformUtilsService, toastService);
this.showTerms = !platformUtilsService.isSelfHost();
Expand Down Expand Up @@ -283,7 +291,11 @@
name: string,
): Promise<RegisterRequest> {
const hint = this.formGroup.value.hint;
const kdfConfig = DEFAULT_KDF_CONFIG;
// Create and hash new master key
let kdfConfig: KdfConfig = DEFAULT_KDF_CONFIG;

Check warning on line 295 in libs/angular/src/auth/components/register.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/auth/components/register.component.ts#L295

Added line #L295 was not covered by tests
if (await this.configService.getFeatureFlag(FeatureFlag.Argon2Default)) {
kdfConfig = NEW_ARGON2_DEFAULT_KDF_CONFIG;

Check warning on line 297 in libs/angular/src/auth/components/register.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/auth/components/register.component.ts#L297

Added line #L297 was not covered by tests
}
const key = await this.keyService.makeMasterKey(masterPassword, email, kdfConfig);
const newUserKey = await this.keyService.makeUserKey(key);
const masterKeyHash = await this.keyService.hashMasterKey(masterPassword, key);
Expand All @@ -298,6 +310,8 @@
this.captchaToken,
kdfConfig.kdfType,
kdfConfig.iterations,
kdfConfig.memory,
kdfConfig.parallelism,
);
request.keys = new KeysRequest(keys[0], keys[1].encryptedString);
if (this.modifyRegisterRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import { AuditService } from "@bitwarden/common/abstractions/audit.service";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";

Check warning on line 15 in libs/auth/src/angular/input-password/input-password.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/auth/src/angular/input-password/input-password.component.ts#L14-L15

Added lines #L14 - L15 were not covered by tests
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { HashPurpose } from "@bitwarden/common/platform/enums";
import { Utils } from "@bitwarden/common/platform/misc/utils";
Expand All @@ -24,7 +26,12 @@
InputModule,
ToastService,
} from "@bitwarden/components";
import { DEFAULT_KDF_CONFIG, KeyService } from "@bitwarden/key-management";
import {

Check warning on line 29 in libs/auth/src/angular/input-password/input-password.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/auth/src/angular/input-password/input-password.component.ts#L29

Added line #L29 was not covered by tests
DEFAULT_KDF_CONFIG,
KdfConfig,
KeyService,
NEW_ARGON2_DEFAULT_KDF_CONFIG,
} from "@bitwarden/key-management";

// FIXME: remove `src` and fix import
// eslint-disable-next-line no-restricted-imports
Expand Down Expand Up @@ -107,6 +114,7 @@
private i18nService: I18nService,
private policyService: PolicyService,
private toastService: ToastService,
private configService: ConfigService,

Check warning on line 117 in libs/auth/src/angular/input-password/input-password.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/auth/src/angular/input-password/input-password.component.ts#L117

Added line #L117 was not covered by tests
) {}

get minPasswordLengthMsg() {
Expand Down Expand Up @@ -145,7 +153,10 @@
}

// Create and hash new master key
const kdfConfig = DEFAULT_KDF_CONFIG;
let kdfConfig: KdfConfig = DEFAULT_KDF_CONFIG;

Check warning on line 156 in libs/auth/src/angular/input-password/input-password.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/auth/src/angular/input-password/input-password.component.ts#L156

Added line #L156 was not covered by tests
if (await this.configService.getFeatureFlag(FeatureFlag.Argon2Default)) {
kdfConfig = NEW_ARGON2_DEFAULT_KDF_CONFIG;

Check warning on line 158 in libs/auth/src/angular/input-password/input-password.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/auth/src/angular/input-password/input-password.component.ts#L158

Added line #L158 was not covered by tests
}

if (this.email == null) {
throw new Error("Email is required to create master key.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { MasterKey } from "@bitwarden/common/types/key";
import { PBKDF2KdfConfig } from "@bitwarden/key-management";
import { KdfConfig } from "@bitwarden/key-management";

export interface PasswordInputResult {
masterKey: MasterKey;
masterKeyHash: string;
localMasterKeyHash: string;
kdfConfig: PBKDF2KdfConfig;
kdfConfig: KdfConfig;
hint: string;
password: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Utils } from "@bitwarden/common/platform/misc/utils";
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
import { UserId } from "@bitwarden/common/types/guid";
import { MasterKey, UserKey } from "@bitwarden/common/types/key";
import { PBKDF2KdfConfig, KdfConfigService, KeyService } from "@bitwarden/key-management";
import { KdfConfigService, KeyService, KdfConfig } from "@bitwarden/key-management";

import {
SetPasswordCredentials,
Expand Down Expand Up @@ -125,7 +125,7 @@ export class DefaultSetPasswordJitService implements SetPasswordJitService {

private async updateAccountDecryptionProperties(
masterKey: MasterKey,
kdfConfig: PBKDF2KdfConfig,
kdfConfig: KdfConfig,
protectedUserKey: [UserKey, EncString],
userId: UserId,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// @ts-strict-ignore
import { UserId } from "@bitwarden/common/types/guid";
import { MasterKey } from "@bitwarden/common/types/key";
import { PBKDF2KdfConfig } from "@bitwarden/key-management";
import { KdfConfig } from "@bitwarden/key-management";

export interface SetPasswordCredentials {
masterKey: MasterKey;
masterKeyHash: string;
localMasterKeyHash: string;
kdfConfig: PBKDF2KdfConfig;
kdfConfig: KdfConfig;
hint: string;
orgSsoIdentifier: string;
orgId: string;
Expand Down
2 changes: 2 additions & 0 deletions libs/common/src/enums/feature-flag.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export enum FeatureFlag {
PM12443RemovePagingLogic = "pm-12443-remove-paging-logic",
PrivateKeyRegeneration = "pm-12241-private-key-regeneration",
ResellerManagedOrgAlert = "PM-15814-alert-owners-of-reseller-managed-orgs",
Argon2Default = "argon2-default",
}

export type AllowedFeatureFlagTypes = boolean | number | string;
Expand Down Expand Up @@ -100,6 +101,7 @@ export const DefaultFeatureFlagValue = {
[FeatureFlag.PM12443RemovePagingLogic]: FALSE,
[FeatureFlag.PrivateKeyRegeneration]: FALSE,
[FeatureFlag.ResellerManagedOrgAlert]: FALSE,
[FeatureFlag.Argon2Default]: FALSE,
} satisfies Record<FeatureFlag, AllowedFeatureFlagTypes>;

export type DefaultFeatureFlagValueType = typeof DefaultFeatureFlagValue;
Expand Down
1 change: 1 addition & 0 deletions libs/key-management/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Argon2KdfConfig,
KdfConfig,
DEFAULT_KDF_CONFIG,
NEW_ARGON2_DEFAULT_KDF_CONFIG,

Check warning on line 18 in libs/key-management/src/index.ts

View check run for this annotation

Codecov / codecov/patch

libs/key-management/src/index.ts#L18

Added line #L18 was not covered by tests
} from "./models/kdf-config";
export { KdfConfigService } from "./abstractions/kdf-config.service";
export { DefaultKdfConfigService } from "./kdf-config.service";
Expand Down
13 changes: 13 additions & 0 deletions libs/key-management/src/models/kdf-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
}
}

get memory(): number | undefined {
return undefined;

Check warning on line 51 in libs/key-management/src/models/kdf-config.ts

View check run for this annotation

Codecov / codecov/patch

libs/key-management/src/models/kdf-config.ts#L51

Added line #L51 was not covered by tests
}

get parallelism(): number | undefined {
return undefined;

Check warning on line 55 in libs/key-management/src/models/kdf-config.ts

View check run for this annotation

Codecov / codecov/patch

libs/key-management/src/models/kdf-config.ts#L55

Added line #L55 was not covered by tests
}

static fromJSON(json: Jsonify<PBKDF2KdfConfig>): PBKDF2KdfConfig {
return new PBKDF2KdfConfig(json.iterations);
}
Expand Down Expand Up @@ -128,3 +136,8 @@
}

export const DEFAULT_KDF_CONFIG = new PBKDF2KdfConfig(PBKDF2KdfConfig.ITERATIONS.defaultValue);
export const NEW_ARGON2_DEFAULT_KDF_CONFIG = new Argon2KdfConfig(
Argon2KdfConfig.ITERATIONS.defaultValue,
Argon2KdfConfig.MEMORY.defaultValue,
Argon2KdfConfig.PARALLELISM.defaultValue,
);
Loading