Skip to content

Commit 2f2c7fa

Browse files
committed
Check for presense of key rather than an encrypted entry.
fixes #705
1 parent a4a038d commit 2f2c7fa

File tree

4 files changed

+9
-28
lines changed

4 files changed

+9
-28
lines changed

src/background.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ async function getTotp(text: string, silent = false) {
269269
entryData[hash].algorithm = algorithm;
270270
}
271271
if (
272-
(await EntryStorage.hasEncryptedEntry()) !==
272+
// If the entries are encrypted and we aren't unlocked, error.
273+
(await EntryStorage.hasEncryptionKey()) !==
273274
encryption.getEncryptionStatus()
274275
) {
275276
!silent && chrome.tabs.sendMessage(id, { action: "errorenc" });

src/models/storage.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -260,21 +260,8 @@ export class EntryStorage {
260260
}
261261
}
262262

263-
static hasEncryptedEntry() {
264-
return new Promise((resolve: (value: boolean) => void) => {
265-
BrowserStorage.get((_data: { [hash: string]: OTPStorage }) => {
266-
for (const hash of Object.keys(_data)) {
267-
if (!this.isValidEntry(_data, hash)) {
268-
continue;
269-
}
270-
if (_data[hash].encrypted) {
271-
return resolve(true);
272-
}
273-
}
274-
return resolve(false);
275-
});
276-
return;
277-
});
263+
static async hasEncryptionKey(): Promise<boolean> {
264+
return Boolean(await BrowserStorage.getKey());
278265
}
279266

280267
static getExport(data: OTPEntryInterface[], encrypted?: boolean) {

src/store/Accounts.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
import { EntryStorage, BrowserStorage } from "../models/storage";
22
import { Encryption } from "../models/encryption";
33
import * as CryptoJS from "crypto-js";
4-
import { OTPType, OTPAlgorithm, CodeState } from "../models/otp";
4+
import { OTPType, OTPAlgorithm } from "../models/otp";
55
import { ActionContext } from "vuex";
66

77
export class Accounts implements Module {
88
async getModule() {
99
const cachedPassphrase = await this.getCachedPassphrase();
1010
const encryption: Encryption = new Encryption(cachedPassphrase);
11-
let shouldShowPassphrase = cachedPassphrase
11+
const shouldShowPassphrase = cachedPassphrase
1212
? false
13-
: await EntryStorage.hasEncryptedEntry();
13+
: await EntryStorage.hasEncryptionKey();
1414
const entries = shouldShowPassphrase ? [] : await this.getEntries();
1515

16-
for (let i = 0; i < entries.length; i++) {
17-
if (entries[i].code === CodeState.Encrypted) {
18-
shouldShowPassphrase = true;
19-
break;
20-
}
21-
}
22-
2316
return {
2417
state: {
2518
entries,

src/store/Advisor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const insightsData: AdvisorInsightInterface[] = [
77
level: InsightLevel.danger,
88
description: chrome.i18n.getMessage("advisor_insight_password_not_set"),
99
validation: async () => {
10-
const hasEncryptedEntry = await EntryStorage.hasEncryptedEntry();
10+
const hasEncryptedEntry = await EntryStorage.hasEncryptionKey();
1111
return !hasEncryptedEntry;
1212
},
1313
},
@@ -16,7 +16,7 @@ const insightsData: AdvisorInsightInterface[] = [
1616
level: InsightLevel.warning,
1717
description: chrome.i18n.getMessage("advisor_insight_auto_lock_not_set"),
1818
validation: async () => {
19-
const hasEncryptedEntry = await EntryStorage.hasEncryptedEntry();
19+
const hasEncryptedEntry = await EntryStorage.hasEncryptionKey();
2020
return hasEncryptedEntry && !Number(localStorage.autolock);
2121
},
2222
},

0 commit comments

Comments
 (0)