Skip to content
This repository was archived by the owner on Jul 18, 2026. It is now read-only.

Commit 0d7d64e

Browse files
committed
make sure we delete invalid keys if they fail validation.
1 parent 53c0c66 commit 0d7d64e

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

frontend/src/app/pages/encryption-manager/encryption-manager.component.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,12 @@ export class EncryptionManagerComponent implements OnInit {
129129
.then((content) => {
130130
let cryptoConfig = JSON.parse(content) as PouchdbCryptConfig
131131

132-
if(cryptoConfig.key && cryptoConfig.config){
133-
return PouchdbCrypto.StoreCryptConfig(cryptoConfig)
134-
} else {
135-
//throw an error & notify user
132+
if(!cryptoConfig.key || !cryptoConfig.config){
136133
this.importCustomFileError = "Invalid crypto configuration file"
137134
throw new Error(this.importCustomFileError)
138135
}
136+
137+
return PouchdbCrypto.StoreCryptConfig(cryptoConfig)
139138
})
140139
.then(() => {
141140
//go to step 2
@@ -156,13 +155,17 @@ export class EncryptionManagerComponent implements OnInit {
156155
})
157156
.catch((err) => {
158157
console.error(err)
159-
//an error occurred while importing credential
160-
const toastNotification = new ToastNotification()
161-
toastNotification.type = ToastType.Error
162-
toastNotification.message = "Provided encryption key does not match. Please try a different key"
163-
toastNotification.autohide = false
164-
this.toastService.show(toastNotification)
158+
// delete invalid encryption key
165159
this.currentStep = 1
160+
return PouchdbCrypto.DeleteCryptConfig(this.fastenDbService.current_user)
161+
.then(() => {
162+
//an error occurred while importing credential
163+
const toastNotification = new ToastNotification()
164+
toastNotification.type = ToastType.Error
165+
toastNotification.message = "Provided encryption key does not match. Please try a different key"
166+
toastNotification.autohide = false
167+
this.toastService.show(toastNotification)
168+
})
166169
})
167170
}
168171

frontend/src/lib/database/plugins/crypto.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export class PouchdbCrypto {
6969
}
7070
return JSON.parse(cryptConfigStr) as PouchdbCryptConfig
7171
}
72+
public static async DeleteCryptConfig(currentUser: string): Promise<void>{
73+
const localDb = await PouchdbCrypto.localIdb()
74+
return await localDb.delete('crypto',`encryption_data_${currentUser}`)
75+
}
7276

7377

7478
public static async crypto(db, cryptConfig: PouchdbCryptConfig, options: PouchdbCryptoOptions = {}) {

0 commit comments

Comments
 (0)