-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-3726] Force migration of legacy user's encryption key (#6195)
* [PM-3726] migrate legacy user's encryption key * [PM-3726] add 2fa support and pr feedback * [PM-3726] revert launch.json & webpack.config changes * [PM-3726] remove update key component - also remove card in vault since legacy users can't login * [PM-3726] Fix i18n & PR feedback * [PM-3726] make standalone component * [PM-3726] linter * [PM-3726] missing await * [PM-3726] logout legacy users with vault timeout to never * [PM-3726] add await * [PM-3726] skip auto key migration for legacy users * [PM-3726] pr feedback * [PM-3726] move check for web into migrate method --------- Co-authored-by: Jared Snider <[email protected]> (cherry picked from commit 8c06508)
- Loading branch information
Showing
30 changed files
with
834 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
apps/web/src/app/auth/migrate-encryption/migrate-legacy-encryption.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<form [formGroup]="formGroup" [bitSubmit]="submit"> | ||
<div class="tw-mt-12 tw-flex tw-justify-center"> | ||
<div class="tw-max-w-xl"> | ||
<h1 bitTypography="h1" class="tw-mb-4 tw-text-center">{{ "updateEncryptionKey" | i18n }}</h1> | ||
<div | ||
class="tw-block tw-rounded tw-border tw-border-solid tw-border-secondary-300 tw-bg-background tw-p-8" | ||
> | ||
<p> | ||
{{ "updateEncryptionSchemeDesc" | i18n }} | ||
<a | ||
href="https://bitwarden.com/help/account-encryption-key/#rotate-your-encryption-key" | ||
target="_blank" | ||
rel="noopener" | ||
>{{ "learnMore" | i18n }}</a | ||
> | ||
</p> | ||
<bit-callout type="warning">{{ "updateEncryptionKeyWarning" | i18n }}</bit-callout> | ||
|
||
<bit-form-field> | ||
<bit-label>{{ "masterPass" | i18n }}</bit-label> | ||
<input | ||
id="masterPassword" | ||
bitInput | ||
type="password" | ||
formControlName="masterPassword" | ||
appAutofocus | ||
/> | ||
<button type="button" bitIconButton bitSuffix bitPasswordInputToggle></button> | ||
</bit-form-field> | ||
<button type="submit" bitButton bitFormButton buttonType="primary" block> | ||
{{ "updateEncryptionKey" | i18n }} | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</form> |
82 changes: 82 additions & 0 deletions
82
apps/web/src/app/auth/migrate-encryption/migrate-legacy-encryption.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Component } from "@angular/core"; | ||
import { FormControl, FormGroup, Validators } from "@angular/forms"; | ||
|
||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service"; | ||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; | ||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; | ||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; | ||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; | ||
|
||
import { SharedModule } from "../../shared"; | ||
|
||
import { MigrateFromLegacyEncryptionService } from "./migrate-legacy-encryption.service"; | ||
|
||
// The master key was originally used to encrypt user data, before the user key was introduced. | ||
// This component is used to migrate from the old encryption scheme to the new one. | ||
@Component({ | ||
standalone: true, | ||
imports: [SharedModule], | ||
providers: [MigrateFromLegacyEncryptionService], | ||
templateUrl: "migrate-legacy-encryption.component.html", | ||
}) | ||
export class MigrateFromLegacyEncryptionComponent { | ||
protected formGroup = new FormGroup({ | ||
masterPassword: new FormControl("", [Validators.required]), | ||
}); | ||
|
||
constructor( | ||
private i18nService: I18nService, | ||
private platformUtilsService: PlatformUtilsService, | ||
private migrationService: MigrateFromLegacyEncryptionService, | ||
private cryptoService: CryptoService, | ||
private messagingService: MessagingService, | ||
private logService: LogService | ||
) {} | ||
|
||
submit = async () => { | ||
this.formGroup.markAsTouched(); | ||
|
||
if (this.formGroup.invalid) { | ||
return; | ||
} | ||
|
||
const hasUserKey = await this.cryptoService.hasUserKey(); | ||
if (hasUserKey) { | ||
this.messagingService.send("logout"); | ||
throw new Error("User key already exists, cannot migrate legacy encryption."); | ||
} | ||
|
||
const masterPassword = this.formGroup.value.masterPassword; | ||
|
||
try { | ||
// Create new user key | ||
const [newUserKey, masterKeyEncUserKey] = await this.migrationService.createNewUserKey( | ||
masterPassword | ||
); | ||
|
||
// Update admin recover keys | ||
await this.migrationService.updateAllAdminRecoveryKeys(masterPassword, newUserKey); | ||
|
||
// Update emergency access | ||
await this.migrationService.updateEmergencyAccesses(newUserKey); | ||
|
||
// Update keys, folders, ciphers, and sends | ||
await this.migrationService.updateKeysAndEncryptedData( | ||
masterPassword, | ||
newUserKey, | ||
masterKeyEncUserKey | ||
); | ||
|
||
this.platformUtilsService.showToast( | ||
"success", | ||
this.i18nService.t("keyUpdated"), | ||
this.i18nService.t("logBackInOthersToo"), | ||
{ timeout: 15000 } | ||
); | ||
this.messagingService.send("logout"); | ||
} catch (e) { | ||
this.logService.error(e); | ||
throw e; | ||
} | ||
}; | ||
} |
Oops, something went wrong.