project-imas / encrypted-core-data

v2.0 - iOS Core Data encrypted SQLite store using SQLCipher
Other
785 stars 236 forks source link

changing passcode with wrong oldPasscode results in broken db #254

Open pteasima opened 8 years ago

pteasima commented 8 years ago

If I call try encryptedStore?.changeDatabasePassphrase(oldPassword, toNewPassphrase: newPassword) with the wrong oldPassword, it does throw an error, but the database probably ends up in an inconsistent state. From this point on, calling try encryptedStore?.changeDatabasePassphrase(oldPassword2, toNewPassphrase: newPassword) always fails, even if oldPassword2 is correct. This gets fixed by restarting the app.

I was able to work around this by always calling try encryptedStore?.validateDatabasePassphrase(oldPassword) before changing the passcode, however, I think we shouldnt put this requirement on the client code. Instead, changeDatabasePassphrase should perform this check internally.

Let me know if you agree and if you would accept a pull request (I can see that this repository isnt very active).