Skip to content

Commit b5fa41f

Browse files
committed
improve password change and migrate logic
1 parent f0c8cf1 commit b5fa41f

File tree

4 files changed

+45
-18
lines changed

4 files changed

+45
-18
lines changed

src/components/Popup/SetPasswordPage.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export default Vue.extend({
4747
this.$store.commit("currentView/changeView", "LoadingPage");
4848
await this.$store.dispatch("accounts/changePassphrase", "");
4949
this.$store.commit("notification/alert", this.i18n.updateSuccess);
50+
this.$store.commit("style/hideInfo");
5051
return;
5152
},
5253
async changePassphrase() {

src/definitions/otp.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ interface IOTPEntry {
1313
update(): Promise<void>;
1414
next(): Promise<void>;
1515
applyEncryption(encryption: IEncryption): void;
16-
changeEncryption(encryption: IEncryption): Promise<void>;
16+
changeEncryption(encryption: IEncryption): void;
1717
delete(): Promise<void>;
1818
generate(): void;
19-
genUUID(): Promise<void>;
19+
genUUID(): void;
2020
}
2121

2222
interface IEncryption {

src/models/otp.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class OTPEntry implements IOTPEntry {
8484
return;
8585
}
8686

87-
async changeEncryption(encryption: Encryption) {
87+
changeEncryption(encryption: Encryption) {
8888
if (!this.secret) {
8989
return;
9090
}
@@ -94,8 +94,6 @@ export class OTPEntry implements IOTPEntry {
9494
} else {
9595
this.encSecret = null;
9696
}
97-
98-
await this.update();
9997
return;
10098
}
10199

@@ -130,10 +128,10 @@ export class OTPEntry implements IOTPEntry {
130128
return;
131129
}
132130

133-
async genUUID() {
134-
await this.delete();
131+
genUUID() {
132+
// await this.delete();
135133
this.hash = uuid();
136-
await this.create();
134+
// await this.create();
137135
}
138136

139137
generate() {

src/store/Accounts.ts

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,27 @@ export class Accounts implements IModule {
233233
return;
234234
}
235235

236-
// store key
237-
await BrowserStorage.set({
238-
key: { enc: encKey, hash: encKeyHash }
239-
});
240236
// change entry encryption to key and remove old hash
237+
let oldKeys: string[] = [];
241238
for (const entry of state.state.entries) {
242239
await entry.changeEncryption(
243240
new Encryption(wordArray.toString())
244241
);
245-
await entry.genUUID();
242+
oldKeys.push(entry.hash);
243+
entry.genUUID();
246244
}
247245

246+
// store key
247+
await BrowserStorage.set({
248+
key: { enc: encKey, hash: encKeyHash }
249+
});
250+
await EntryStorage.set(state.state.entries);
251+
await new Promise(resolve => {
252+
BrowserStorage.remove(oldKeys, () => {
253+
resolve();
254+
});
255+
});
256+
248257
state.state.encryption.updateEncryptionPassword(
249258
wordArray.toString()
250259
);
@@ -320,16 +329,34 @@ export class Accounts implements IModule {
320329
return;
321330
}
322331

323-
// store key
324-
await BrowserStorage.set({
325-
key: { enc: encKey, hash: encKeyHash }
326-
});
327332
// change entry encryption and regen hash
333+
let removeHashes: string[] = [];
328334
for (const entry of state.state.entries) {
329335
await entry.changeEncryption(
330336
new Encryption(wordArray.toString())
331337
);
332-
await entry.genUUID();
338+
// if not uuidv4 regen
339+
if (
340+
!entry.hash.match(
341+
/[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}/i
342+
)
343+
) {
344+
removeHashes.push(entry.hash);
345+
await entry.genUUID();
346+
}
347+
}
348+
349+
// store key
350+
await BrowserStorage.set({
351+
key: { enc: encKey, hash: encKeyHash }
352+
});
353+
await EntryStorage.set(state.state.entries);
354+
if (removeHashes) {
355+
await new Promise(resolve => {
356+
BrowserStorage.remove(removeHashes, () => {
357+
resolve();
358+
});
359+
});
333360
}
334361

335362
state.state.encryption.updateEncryptionPassword(
@@ -351,6 +378,7 @@ export class Accounts implements IModule {
351378
for (const entry of state.state.entries) {
352379
await entry.changeEncryption(new Encryption(""));
353380
}
381+
await EntryStorage.set(state.state.entries);
354382

355383
state.state.encryption.updateEncryptionPassword("");
356384

0 commit comments

Comments
 (0)