-
Notifications
You must be signed in to change notification settings - Fork 569
Fatal Exception: net.sqlcipher.database.SQLiteException: file is encrypted or is not a database: while compiling: select count(*) from sqlite_master #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @suraj9781 Are you able to reproduce this issue within the SQLCipher for Android test suite? |
We are getting this too. For us it happens when the app is killed by Android or the user, after a large commit. In our case we have some migration code that runs to upgrade a 2.x database to 3.x. Part of that migration involves copying some large tables to change their schema (the migration is all inside a single transaction in the onUpgrade function of the database helper). If you kill the app within a few minutes of that code running, on next start of the app you get that exception when it tries to open the database. We're working on tracking this down further. |
Hi @draak567 You mention you are upgrading from 2.x to 3.x, is it correct that you mean you are upgrading the SQLCipher database format? If so, and you are receiving an error attempting to open the connection after you have cancelled the upgrade, it is possible the file format migration has not completed. If that is the case, you would need to adjust the KDF iteration length to 4000 to be compatible with a 2.x format. Can you share the upgrade logic you are using? |
@developernotes it's basically something like this:
What's confusing me is that I have several other databases in this app upgraded with this code and they all work fine except for this one. By the way I'm not sure if this is normal but for all the other databases I have to always use KDF iteration 4000 even after migration in the pre-key hook. I've read the documentation and it doesn't imply that is needed, but without that I can't open the database files after migration. I'm starting to think maybe cipher_migrate doesn't actually work even through the return value is zero. |
Hi @draak567
How specifically are you setting the KDF iteration?
Can you pull the database off device to further test access of the content via a SQLCipher command line shell? |
Moving to cipher_default_kdf_iter in preKey fixed it (actually that needed to be done anyway because we attach some databases as well). I'm not quite sure why the previous code seemed to be working for some of the databases but not the others. When I refactored the migration into a single function that opened all of them, migrated them, and closed them immediately, they all started failing without kdf_iter in postKey, or cipher_default_kdf_iter in preKey. |
Hello @draak567 I'm glad to hear your issue has been resolved, take care! |
When we changed code to change password of database from mDatabase.changePassword(); We observed only one crash. OS Version: 5.1.1 . Crashed: AsyncTask #3: 0 0 0x0000000000000000 Fatal Exception: java.lang.RuntimeException: An error occured while executing doInBackground() |
Hi @suraj9781 Is there a reason you are not calling |
Yes . Actually, there are 4 transactions which each run sequentially for first three transactions there is no issue but in the fourth transaction, this crash occurs on above 2 devices . |
Hi @suraj9781 Are you trying to change the password to the database while another transaction is occurring? Also, why are you not using the |
Hello @developernotes , I have the similar exception (SQLiteException: file is encrypted or is not a database: , while compiling: select count(*) from sqlite_master). But, when I have migrated from 3.3.1-1 to 3.5.3 version. Nothing was changed. What is the problem ? Thanks. |
Hi @supervital Would you pull the database off your device/emulator and attempt to access the content with the SQLCipher command line shell? Are you certain you were providing the correct password to the database? |
Yes, the password is correct. I just changed the version in build.gradle. I haven't tried to open encrypted database ,but with password "" it works. Also, when I change back to 3.3.1-1 version, app works. |
Please let us know the results of pulling the database off device/emulator and attempting to access the content.
Is that with a new database, or an existing database? |
with an existing db. There is next scenario: without a password (getReadableDatabase("")) migration from 3.3.1-1 to 3.5.3 version works! Database is ok. Everything works! But with a password after upgrading to 3.5.3 ver. app crashes with the Exception. I will try to get access to the content of encrypted database, later. But I think is everything ok with the database. Thanks. |
Hello @developernotes Are you trying to change the password to the database while another transaction is occurring?
Also, why are you not using the changePassowrd(…); function?
|
Hello, I found the problem! So, there is next issue: the password is encrypted with the XOR algorithm. On 3.3.1-1 it works, but on 3.5.3 it crashes if the pass is encrypted with the algorithm. How can it be fixed, or should I create a workaround using changePassowrd(…); function ? Thanks. |
Hi @supervital Can you provide an test of the scenario that fails for you as a test within the SQLCipher for Android test suite, we would be happy to look into a reproducible example. Thanks! |
Hi @suraj9781
Where does the password change occur with regard to these 4 transactions, is it before, during or after?
If you have already keyed the database, executing a |
Yes, I can. So, I need to install the test application, next I have to reproduce the issue and finally run a test on the test app ? Is it correct ? |
Hi @supervital You would need to fork the test suite, create a new test, add it to the runner and then you can verify the behavior on device/emulator. Please then send a pull request and we will take a look into it further. Thanks! |
Where does the password change occur with regard to these 4 transactions, is it before, during or after?
|
Hi @suraj9781 We would be happy to look into it further if you can provide a unit test within the test suite that reproduces the error you are seeing. Thanks! |
Hello, guys. Actually, I have found the reason of issue mentioned by @supervital . Database was encrypted with unique key, containing chars like (int)[] [80, 46, 0, 30, 44, 8, 1 ... ] I noticed the commit changing the key passing logic here 3f36025 with change of void native_key_char(JNIEnv* env, jobject object, jcharArray jKey) method. Native methods converting jcharArray to char* used to call but now
As described in Oracle documentation,
so, zero-byte char is parsed into two bytes. Also, tip from the book by the following link advices to use native methods without 'UTF' Thus, it is impossible to even rekey the existing DB using sqlcipher:3.5+ I have verified the conclusion. Without zero-byte char sqlitecipher versions are compatible. With \u0000 char they are not. Could you please give some advice how to migrate into updated sqlcipher without regression? Thank you in advance. |
Hello @YuriyWozniak, @supervital, Thank you for providing some additional context around the issue you are seeing. Would you mind sharing how you are sourcing the key material that is causing this situation to occur? We are currently reviewing a possible solution. Thanks! |
Hello, @developernotes , Thank for your feedback Algorithm looks like next:
... In case when input.charAt() == secret.charAt(), xor char, char = 0. That`s why zero char is present. Well... Algorithm looks a bit legacy and tricky, however, we are already using keys generated with it as zero-char is allowed to use in key. Thanks for your support. |
Hello @YuriyWozniak - could you provide some additional details about how generateSecret() works and the contents of DATABASE_PASSWORD? Is it possible for either of those to return non-ASCII characters (i.e. with a numeric value > 127)? |
Hello, @sjlombardo . Sure, if it can help somehow. DATABASE_PASSWORD is just an ASCII constant, e.g. like
generateSecret is also ASCII string as concatenation of some unique identifiers.
theoretically, yes. But practically we weren`t observing such a case. Maybe it would be better to change the algo, or for example, base64 the final key. However, we are using the mentioned approach for now :( Thanks for support. |
Hello, @sjlombardo , In my case, i am using UDID as password String lNewDBPassword = Secure.getString(pContext.getContentResolver(), |
Hi @girishcsed, Can you verify the database is being provided the same password each time, including when the user returns from the Settings application? Can you verify you are able to access the database from the SQLCipher command line shell with the same password you are providing within the application? Thanks! |
Hi,
|
Hi @girishcsed Can you verify you are calling |
Yes, made sure that im calling SQLiteDatabase.loadLibs(this); before making any interactions with SQLiteDatabase. |
Hello @girishcsed We would be happy to look into this further if you can provide a reproducible test case within the SQLCipher for Android test suite. Thanks! |
Hello,
|
Hello @girishcsed, The log messages are often expected within the SQLCipher for Android test suite as they recreate certain scenarios where an exception might occur. |
net.sqlcipher.database.SQLiteException: file is encrypted or is not a database: , while compiling: select count(*) from sqlite_master; is the exact same crash that our app users are getting. I cant reproduce this crash but our analytics show that there have been a lot of crashes with the above logs. |
Is it possible to handle such type of exceptions on the library? |
Hi @girishcsed, Your application can catch the |
I made sure that we are opening the database with correct password. I'll handle all sqlite exceptions on our App. Thanks for your help. |
Hello, guys. Hello, @developernotes. Noticed the updated release 3.5.4. We had tested it, and issue with zero-byte symbol in db key looks fixed. Many thanks for your support! |
Hello @YuriyWozniak, Thank you for getting back to us, we are happy to hear the latest release has addressed the issue you were seeing. Take care! |
I have met the same issue, and this issue was fixed on 3.5.4? we can't reproduce this issue on our devices, this is the crash log from user: #4366 09-25 14:58:37.829 7200 E Database Failed to setLocale() when constructing, closing the database |
What version of SQLCipher for Android are you using? If you are not on 3.5.4, would you try that as it is the latest build. Thank! |
Hello,
I am on 3.5.4. |
Are you able to create a test within the test suite that consistently replicates the behavior you are seeing? You can not change the password of the tests you listed above, those tests utilize sample databases included with the test suite where a specific password was used. |
@developernotes my database seemed to be working with the input password "password" but now is not working and throwing the same exceptions as above. I am building an app that when starts up, asks for a passphrase, then using that, I am trying to open the database and get what is inside it, and store the information into an array. Any help would be awesome! |
A few additional follow up questions:
|
I actually stepped thru my code and found that I was stuck in a while loop, trying to endlessly access data from the database. I believe I am using 3.5.6 or whatever is the latest version. Thank you for the response though! |
We are glad to hear you resolved your error. Take care! |
Hello, I am getting this exception when calling The database from the older version is readable just fine when pulling it off a device so not sure whats causing it. Thanks in advance. |
Hi @nirmalspeed Would you please open a separate Github issue, or posting on our discuss site with further details regarding your crash. Also, please note what version of SQLCipher was used to create the original database file and any other runtime specific configurations you have. Thanks! |
Hi @developernotes |
Hi @lavan80 Does this error always occur for you? Are you able to reproduce this issue consistently? Would you try upgrading to the latest version, currently 3.5.9 and let us know if you are still receiving the error message? |
HI @developernotes |
Hi @lavan80 Unfortunately, without additional information such as what SQL statement is being executed and further details such as the device and Android OS version, we are not able to provide any additional information regarding the stack track that your provided above. Again, we would recommend updating to the latest version of SQLCipher for Android, currently at 3.5.9 and testing to see if the behavior continues or is resolved. If the behavior continues, we would need additional information to investigate it further. |
Uh oh!
There was an error while loading. Please reload this page.
Hi ,
App is getting crashed due to above exception on following two devices
1)\ Device: ASUS_Z00VD
OS Version: 5.1
2)Panasonic P41HD
OS Version:4.4.2
Library version used 3.5.2.
Same crash has occurred on below two devices for the previous version of library also
Fatal Exception: net.sqlcipher.database.SQLiteException: file is encrypted or is not a database: , while compiling: select count(*) from sqlite_master;
at net.sqlcipher.database.SQLiteCompiledSql.native_compile(SQLiteCompiledSql.java)
at net.sqlcipher.database.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
at net.sqlcipher.database.SQLiteCompiledSql.(SQLiteCompiledSql.java:64)
at net.sqlcipher.database.SQLiteProgram.(SQLiteProgram.java:83)
at net.sqlcipher.database.SQLiteQuery.(SQLiteQuery.java:49)
at net.sqlcipher.database.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1762)
at net.sqlcipher.database.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1727)
at net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal(SQLiteDatabase.java:2344)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1091)
at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1154)
at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:162)
at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:129)
at com.xxx.xxx.database.DBOperation.getDatabase(DBOperation.java:37)
at com.xxx.xxx.database.DBOperation.endTransaction(DBOperation.java:58)
The text was updated successfully, but these errors were encountered: