Migration: Issue with reading StreamingAeadWithFallback
input stream after fallback
#15
Labels
bug
Something isn't working
Refs #14
I am trying to update an app that currently uses the encrypted Preferences DataStore implementation from
encrypted-datastore:1.0.0-alpha02
. The DataStore was setup as follows:I have updated to
security-crypto-datastore-preferences:1.0.0-alpha04
and changed the setup as follows to enableAead
fallback for existing users as follows:When the app runs, no errors are raised, but any previously saved datastore key/values are not decrypting properly.
Debugging revealed that when the fallback lambda is executed to get the
Aead
decryptedFileInputStream
, this method is always just returning the original encryptedFileInputStream
, because itsavailable()
method returns 0 (suggesting that it has already been read).encrypted-datastore/encrypted-datastore/src/main/kotlin/Aead.kt
Lines 6 to 12 in 22f8a5d
I discovered I could fix the issue by adding a call to
stream.close()
in the fallback catch block just before stream is reassigned, so that the abortedStreamingAead
input stream is closed first before reading from the fallbackAead
stream.encrypted-datastore/encrypted-datastore/src/main/kotlin/migration/StreamingAeadWithFallback.kt
Lines 33 to 42 in 22f8a5d
I am honestly not sure why it is behaving this way. Perhaps there are some subtle differences between
FileInputStream
and theByteArrayInputStream
used in the tests?Hopefully there is enough information here for you to reproduce the issue. Let me know if not.
The text was updated successfully, but these errors were encountered: