make sure we delete invalid keys if they fail validation.
This commit is contained in:
parent
53c0c66ceb
commit
0d7d64e089
|
@ -129,13 +129,12 @@ export class EncryptionManagerComponent implements OnInit {
|
|||
.then((content) => {
|
||||
let cryptoConfig = JSON.parse(content) as PouchdbCryptConfig
|
||||
|
||||
if(cryptoConfig.key && cryptoConfig.config){
|
||||
return PouchdbCrypto.StoreCryptConfig(cryptoConfig)
|
||||
} else {
|
||||
//throw an error & notify user
|
||||
if(!cryptoConfig.key || !cryptoConfig.config){
|
||||
this.importCustomFileError = "Invalid crypto configuration file"
|
||||
throw new Error(this.importCustomFileError)
|
||||
}
|
||||
|
||||
return PouchdbCrypto.StoreCryptConfig(cryptoConfig)
|
||||
})
|
||||
.then(() => {
|
||||
//go to step 2
|
||||
|
@ -156,13 +155,17 @@ export class EncryptionManagerComponent implements OnInit {
|
|||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
//an error occurred while importing credential
|
||||
const toastNotification = new ToastNotification()
|
||||
toastNotification.type = ToastType.Error
|
||||
toastNotification.message = "Provided encryption key does not match. Please try a different key"
|
||||
toastNotification.autohide = false
|
||||
this.toastService.show(toastNotification)
|
||||
// delete invalid encryption key
|
||||
this.currentStep = 1
|
||||
return PouchdbCrypto.DeleteCryptConfig(this.fastenDbService.current_user)
|
||||
.then(() => {
|
||||
//an error occurred while importing credential
|
||||
const toastNotification = new ToastNotification()
|
||||
toastNotification.type = ToastType.Error
|
||||
toastNotification.message = "Provided encryption key does not match. Please try a different key"
|
||||
toastNotification.autohide = false
|
||||
this.toastService.show(toastNotification)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,10 @@ export class PouchdbCrypto {
|
|||
}
|
||||
return JSON.parse(cryptConfigStr) as PouchdbCryptConfig
|
||||
}
|
||||
public static async DeleteCryptConfig(currentUser: string): Promise<void>{
|
||||
const localDb = await PouchdbCrypto.localIdb()
|
||||
return await localDb.delete('crypto',`encryption_data_${currentUser}`)
|
||||
}
|
||||
|
||||
|
||||
public static async crypto(db, cryptConfig: PouchdbCryptConfig, options: PouchdbCryptoOptions = {}) {
|
||||
|
|
Loading…
Reference in New Issue