Finally done bugfixing for now for alias & PIN authrecall

This commit is contained in:
mhelander 2018-01-30 01:13:26 +02:00
parent e75854b73e
commit 0eb32c0e2d

15
sea.js
View File

@ -506,23 +506,26 @@
const props = args || parseProps(await seaRead(remember, pub, true)) const props = args || parseProps(await seaRead(remember, pub, true))
let { pin, alias: aLias } = props let { pin, alias: aLias } = props
return (!pin && alias === aLias) const data = (!pin && alias === aLias)
// No PIN, let's try short-term proof if for matching alias // No PIN, let's try short-term proof if for matching alias
? await checkRememberData(props) ? await checkRememberData(props)
// Got PIN so get IndexedDB secret if signature is ok // Got PIN so get IndexedDB secret if signature is ok
: await checkRememberData(await readAndDecrypt(await seaIndexedDb.get(alias, 'auth'), pub, pin)) : await checkRememberData(await readAndDecrypt(await seaIndexedDb.get(alias, 'auth'), pub, pin))
pin = pin || data.pin
delete data.pin
return { pin, data }
} }
// got pub, try auth with pin & alias :: or unwrap Storage data... // got pub, try auth with pin & alias :: or unwrap Storage data...
const args = await readStorageData(pin && { pin, alias }) const { data, pin: newPin } = await readStorageData(pin && { pin, alias })
const { proof } = args || {} const { proof } = data || {}
if (!proof) { if (!proof) {
if (!args) { if (!data) {
err = 'No valid authentication session found!' err = 'No valid authentication session found!'
return return
} }
try { // Wipes IndexedDB silently try { // Wipes IndexedDB silently
await updatestorage()(args) await updatestorage()(data)
} catch (e) {} //eslint-disable-line no-empty } catch (e) {} //eslint-disable-line no-empty
err = 'Expired session!' err = 'Expired session!'
return return
@ -539,7 +542,7 @@
const { epub } = at.put const { epub } = at.put
// Success! we've found our private data! // Success! we've found our private data!
err = null err = null
return { proof, at, pin, key: { pub, priv, epriv, epub } } return { proof, at, pin: newPin, key: { pub, priv, epriv, epub } }
} catch (e) { } catch (e) {
err = 'Failed to decrypt private key!' err = 'Failed to decrypt private key!'
return return