Skip to content

Commit 450a4a5

Browse files
authored
Merge pull request #724 from Authenticator-Extension/fix-encryption-check
2 parents a4a038d + 70fb304 commit 450a4a5

File tree

9 files changed

+40
-9989
lines changed

9 files changed

+40
-9989
lines changed

package-lock.json

Lines changed: 23 additions & 9939 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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/components/Popup/DrivePage.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ export default Vue.extend({
104104
},
105105
async backupUpload() {
106106
const drive = new Drive();
107-
const response = await drive.upload(this.$store.state.encryption);
107+
const response = await drive.upload(
108+
this.$store.state.accounts.encryption
109+
);
108110
if (response === true) {
109111
this.$store.commit("notification/alert", this.i18n.updateSuccess);
110112
} else if (localStorage.driveRevoked === "true") {

src/components/Popup/DropboxPage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export default Vue.extend({
9292
},
9393
async backupUpload() {
9494
const dbox = new Dropbox();
95-
const response = await dbox.upload(this.$store.state.encryption);
95+
const response = await dbox.upload(this.$store.state.accounts.encryption);
9696
if (response === true) {
9797
this.$store.commit("notification/alert", this.i18n.updateSuccess);
9898
} else if (localStorage.dropboxRevoked === "true") {

src/components/Popup/OneDrivePage.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ export default Vue.extend({
9393
},
9494
async backupUpload() {
9595
const oneDrive = new OneDrive();
96-
const response = await oneDrive.upload(this.$store.state.encryption);
96+
const response = await oneDrive.upload(
97+
this.$store.state.accounts.encryption
98+
);
9799
if (response === true) {
98100
this.$store.commit("notification/alert", this.i18n.updateSuccess);
99101
} else if (localStorage.oneDriveRevoked === "true") {

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/popup.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { Notification } from "./store/Notification";
1818
import { Qr } from "./store/Qr";
1919
import { Advisor } from "./store/Advisor";
2020
import { Dropbox, Drive, OneDrive } from "./models/backup";
21-
import { EntryStorage } from "./models/storage";
2221

2322
async function init() {
2423
// Add globals
@@ -62,27 +61,12 @@ async function init() {
6261

6362
// Prompt for password if needed
6463
if (instance.$store.state.accounts.shouldShowPassphrase) {
65-
instance.$store.commit("style/showInfo", true);
6664
// If we have cached password, use that
6765
if (instance.$store.state.accounts.encryption.getEncryptionStatus()) {
6866
instance.$store.commit("currentView/changeView", "LoadingPage");
69-
for (const entry of instance.$store.state.accounts.entries) {
70-
await entry.applyEncryption(instance.$store.state.accounts.encryption);
71-
}
72-
instance.$store.commit(
73-
"accounts/updateExport",
74-
await EntryStorage.getExport(instance.$store.state.accounts.entries)
75-
);
76-
instance.$store.commit(
77-
"accounts/updateEncExport",
78-
await EntryStorage.getExport(
79-
instance.$store.state.accounts.entries,
80-
true
81-
)
82-
);
83-
instance.$store.commit("accounts/updateCodes");
84-
instance.$store.commit("style/hideInfo", true);
67+
await instance.$store.dispatch("accounts/updateEntries");
8568
} else {
69+
instance.$store.commit("style/showInfo", true);
8670
instance.$store.commit("currentView/changeView", "EnterPasswordPage");
8771
}
8872
}

src/store/Accounts.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
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
12-
? false
13-
: await EntryStorage.hasEncryptedEntry();
11+
const shouldShowPassphrase = await EntryStorage.hasEncryptionKey();
1412
const entries = shouldShowPassphrase ? [] : await this.getEntries();
1513

16-
for (let i = 0; i < entries.length; i++) {
17-
if (entries[i].code === CodeState.Encrypted) {
18-
shouldShowPassphrase = true;
19-
break;
20-
}
21-
}
22-
2314
return {
2415
state: {
2516
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)