warn user and reseed storage if using Never lock option

This commit is contained in:
Kyle Spearrin 2018-10-03 22:46:11 -04:00
parent ba67561c9e
commit d16d1d1308
4 changed files with 32 additions and 13 deletions

View File

@ -1076,5 +1076,8 @@
"datePasswordUpdated": {
"message": "Password Updated",
"description": "ex. Date this password was updated"
},
"neverLockWarning": {
"message": "Are you sure you want to use the \"Never\" option? Setting your lock options to \"Never\" stores your vault's encryption key on your device. If you use this option you should ensure that you keep your device properly protected."
}
}

View File

@ -137,6 +137,9 @@ export default class RuntimeBackground {
case 'bgUpdateContextMenu':
await this.main.refreshBadgeAndMenu();
break;
case 'bgReseedStorage':
await this.reseedStorage();
break;
case 'collectPageDetailsResponse':
switch (msg.sender) {
case 'notificationBar':
@ -373,8 +376,6 @@ export default class RuntimeBackground {
if (this.onInstalledReason === 'install') {
BrowserApi.createNewTab('https://bitwarden.com/browser-start/');
await this.setDefaultSettings();
} else if (this.onInstalledReason === 'update') {
await this.reseedStorage();
}
this.analytics.ga('send', {
@ -397,12 +398,6 @@ export default class RuntimeBackground {
return;
}
const reseed124Key = 'reseededStorage124';
const reseeded124 = await this.storageService.get<boolean>(reseed124Key);
if (reseeded124) {
return;
}
const getStorage = (): Promise<any> => new Promise((resolve) => {
chrome.storage.local.get(null, (o: any) => resolve(o));
});
@ -418,11 +413,8 @@ export default class RuntimeBackground {
if (!storage.hasOwnProperty(key)) {
continue;
}
await this.storageService.save(key, storage[key]);
}
await this.storageService.save(reseed124Key, true);
}
private async setDefaultSettings() {

View File

@ -26,7 +26,8 @@
<div class="box-content single-line">
<div class="box-content-row display-block" appBoxRow>
<label for="lockOption">{{'lockOptions' | i18n}}</label>
<select id="lockOption" name="LockOptions" [(ngModel)]="lockOption" (change)="saveLockOption()">
<select #lockOptionsSelect id="lockOption" name="LockOptions" [ngModel]="lockOption"
(ngModelChange)="saveLockOption($event)">
<option *ngFor="let o of lockOptions" [ngValue]="o.value">{{o.name}}</option>
</select>
</div>

View File

@ -3,7 +3,9 @@ import swal from 'sweetalert';
import {
Component,
ElementRef,
OnInit,
ViewChild,
} from '@angular/core';
import { Router } from '@angular/router';
@ -40,8 +42,10 @@ const RateUrls = {
templateUrl: 'settings.component.html',
})
export class SettingsComponent implements OnInit {
@ViewChild('lockOptionsSelect', { read: ElementRef }) lockOptionsSelectRef: ElementRef;
lockOptions: any[];
lockOption: number = null;
previousLockOption: number = null;
constructor(private platformUtilsService: PlatformUtilsService, private i18nService: I18nService,
private analytics: Angulartics2, private lockService: LockService,
@ -79,10 +83,29 @@ export class SettingsComponent implements OnInit {
}
this.lockOption = option;
}
this.previousLockOption = this.lockOption;
}
async saveLockOption() {
async saveLockOption(newValue: number) {
if (newValue == null) {
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t('neverLockWarning'), null,
this.i18nService.t('yes'), this.i18nService.t('cancel'), 'warning');
if (!confirmed) {
this.lockOptions.forEach((option: any, i) => {
if (option.value === this.lockOption) {
this.lockOptionsSelectRef.nativeElement.value = i + ': ' + this.lockOption;
}
});
return;
}
}
this.previousLockOption = this.lockOption;
this.lockOption = newValue;
await this.lockService.setLockOption(this.lockOption != null ? this.lockOption : null);
if (this.previousLockOption == null) {
this.messagingService.send('bgReseedStorage');
}
}
async lock() {