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) => {
|
.then((content) => {
|
||||||
let cryptoConfig = JSON.parse(content) as PouchdbCryptConfig
|
let cryptoConfig = JSON.parse(content) as PouchdbCryptConfig
|
||||||
|
|
||||||
if(cryptoConfig.key && cryptoConfig.config){
|
if(!cryptoConfig.key || !cryptoConfig.config){
|
||||||
return PouchdbCrypto.StoreCryptConfig(cryptoConfig)
|
|
||||||
} else {
|
|
||||||
//throw an error & notify user
|
|
||||||
this.importCustomFileError = "Invalid crypto configuration file"
|
this.importCustomFileError = "Invalid crypto configuration file"
|
||||||
throw new Error(this.importCustomFileError)
|
throw new Error(this.importCustomFileError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return PouchdbCrypto.StoreCryptConfig(cryptoConfig)
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
//go to step 2
|
//go to step 2
|
||||||
|
@ -156,13 +155,17 @@ export class EncryptionManagerComponent implements OnInit {
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
//an error occurred while importing credential
|
// delete invalid encryption key
|
||||||
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)
|
|
||||||
this.currentStep = 1
|
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
|
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 = {}) {
|
public static async crypto(db, cryptConfig: PouchdbCryptConfig, options: PouchdbCryptoOptions = {}) {
|
||||||
|
|
Loading…
Reference in New Issue