diff --git a/jslib b/jslib index 00562d083b6..0d15ae86157 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 00562d083b687fb566b09c0df8a05e90b86f9e5a +Subproject commit 0d15ae8615771842ec18567da001cf6e8b40e3e1 diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 7ddf30e044c..f58b43dbd8e 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -75,6 +75,7 @@ import { AccountComponent } from './settings/account.component'; import { AdjustPaymentComponent } from './settings/adjust-payment.component'; import { AdjustStorageComponent } from './settings/adjust-storage.component'; import { ChangeEmailComponent } from './settings/change-email.component'; +import { ChangeKdfComponent } from './settings/change-kdf.component'; import { ChangePasswordComponent } from './settings/change-password.component'; import { CreateOrganizationComponent } from './settings/create-organization.component'; import { DeauthorizeSessionsComponent } from './settings/deauthorize-sessions.component'; @@ -204,6 +205,7 @@ registerLocaleData(localeZhCn, 'zh-CN'); BulkShareComponent, CalloutComponent, ChangeEmailComponent, + ChangeKdfComponent, ChangePasswordComponent, CiphersComponent, CollectionsComponent, diff --git a/src/app/settings/account.component.html b/src/app/settings/account.component.html index 26aa42d9d3e..7d3a7028652 100644 --- a/src/app/settings/account.component.html +++ b/src/app/settings/account.component.html @@ -10,6 +10,10 @@

{{'changeMasterPassword' | i18n}}

+
+

{{'encKeySettings' | i18n}}

+
+

{{'dangerZone' | i18n}}

diff --git a/src/app/settings/change-kdf.component.html b/src/app/settings/change-kdf.component.html new file mode 100644 index 00000000000..6544d4250e3 --- /dev/null +++ b/src/app/settings/change-kdf.component.html @@ -0,0 +1,47 @@ +{{'loggedOutWarning' | i18n}} +
+
+
+
+ + +
+
+
+
+
+
+ + + + + +
+
+
+
+ + + + + +
+
+
+
+
+

{{'kdfIterationsDesc' | i18n : (100000 | number)}}

+ {{'warning' | i18n}}: {{'kdfIterationsWarning' | i18n : (50000 | number)}} +
+
+
+
+ +
diff --git a/src/app/settings/change-kdf.component.ts b/src/app/settings/change-kdf.component.ts new file mode 100644 index 00000000000..f5449ae1841 --- /dev/null +++ b/src/app/settings/change-kdf.component.ts @@ -0,0 +1,69 @@ +import { + Component, + OnInit, +} from '@angular/core'; + +import { ToasterService } from 'angular2-toaster'; +import { Angulartics2 } from 'angulartics2'; + +import { ApiService } from 'jslib/abstractions/api.service'; +import { CryptoService } from 'jslib/abstractions/crypto.service'; +import { I18nService } from 'jslib/abstractions/i18n.service'; +import { MessagingService } from 'jslib/abstractions/messaging.service'; +import { UserService } from 'jslib/abstractions/user.service'; + +import { KdfRequest } from 'jslib/models/request/kdfRequest'; + +import { KdfType } from 'jslib/enums/kdfType'; + +@Component({ + selector: 'app-change-kdf', + templateUrl: 'change-kdf.component.html', +}) +export class ChangeKdfComponent implements OnInit { + masterPassword: string; + kdfIterations: number; + kdf = KdfType.PBKDF2_SHA256; + kdfOptions: any[] = []; + formPromise: Promise; + + constructor(private apiService: ApiService, private i18nService: I18nService, + private analytics: Angulartics2, private toasterService: ToasterService, + private cryptoService: CryptoService, private messagingService: MessagingService, + private userService: UserService) { + this.kdfOptions = [ + { name: 'PBKDF2 SHA-256', value: KdfType.PBKDF2_SHA256 }, + ]; + } + + async ngOnInit() { + this.kdf = await this.userService.getKdf(); + this.kdfIterations = await this.userService.getKdfIterations(); + } + + async submit() { + const hasEncKey = await this.cryptoService.hasEncKey(); + if (!hasEncKey) { + this.toasterService.popAsync('error', null, this.i18nService.t('updateKey')); + return; + } + + const request = new KdfRequest(); + request.kdf = this.kdf; + request.kdfIterations = this.kdfIterations; + request.masterPasswordHash = await this.cryptoService.hashPassword(this.masterPassword, null); + const email = await this.userService.getEmail(); + const newKey = await this.cryptoService.makeKey(this.masterPassword, email, this.kdf, this.kdfIterations); + request.newMasterPasswordHash = await this.cryptoService.hashPassword(this.masterPassword, newKey); + const newEncKey = await this.cryptoService.remakeEncKey(newKey); + request.key = newEncKey[1].encryptedString; + try { + this.formPromise = this.apiService.postAccountKdf(request); + await this.formPromise; + this.analytics.eventTrack.next({ action: 'Changed KDF' }); + this.toasterService.popAsync('success', this.i18nService.t('encKeySettingsChanged'), + this.i18nService.t('logBackIn')); + this.messagingService.send('logout'); + } catch { } + } +} diff --git a/src/app/settings/change-password.component.html b/src/app/settings/change-password.component.html index 424555694f6..70d3fba7826 100644 --- a/src/app/settings/change-password.component.html +++ b/src/app/settings/change-password.component.html @@ -7,11 +7,17 @@ + + +
+
+
+