Skip to content

SqlLiteException.nativeKey crashes SQLiteException unknown error (code 1): Could not key db #83

@DiegoMitchell17

Description

@DiegoMitchell17

Hi,

We are using:

  • sqlcipher-android version 4.10
  • androidx-sqlite version 2.4.0
  • room version 2.6.1

With the last update of our app we are facing the following crash:

Fatal Exception: android.database.sqlite.SQLiteException: unknown error (code 1): Could not key db. at net.zetetic.database.sqlcipher.SQLiteConnection.nativeKey(SQLiteConnection.java) at net.zetetic.database.sqlcipher.SQLiteConnection.open(SQLiteConnection.java:233) at net.zetetic.database.sqlcipher.SQLiteConnection.open(SQLiteConnection.java:202) at net.zetetic.database.sqlcipher.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:474) at net.zetetic.database.sqlcipher.SQLiteConnectionPool.open(SQLiteConnectionPool.java:188) at net.zetetic.database.sqlcipher.SQLiteConnectionPool.open(SQLiteConnectionPool.java:180) at net.zetetic.database.sqlcipher.SQLiteDatabase.openInner(SQLiteDatabase.java:1028) at net.zetetic.database.sqlcipher.SQLiteDatabase.open(SQLiteDatabase.java) at net.zetetic.database.sqlcipher.SQLiteDatabase.openDatabase(SQLiteDatabase.java:840) at net.zetetic.database.sqlcipher.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:359) at net.zetetic.database.sqlcipher.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:278) at net.zetetic.database.sqlcipher.SupportHelper.getWritableDatabase(SupportHelper.java:60) at androidx.room.RoomDatabase.inTransaction(RoomDatabase.kt:632)

We have been using the library for many years and with many versions of our app. From Crashlytics, this crash occurs only on our last app version, however we haven't change anything critical on our DB on that version (only a small migration of a table of the DB)

The DB password is stored on our BuildConfig and provided as input to the SupportOpenHelperFactory (the password never changed)

object DbUtils {
    fun getRoomDbPassphrase(): ByteArray {
        return BuildConfig.ROOM_DB_KEY.toByteArray(Charsets.UTF_8)
    }
}

Browsing on your code the problem seems to be on the file android_database_SQLiteConnection.cpp where the exception is thrown

   if (rc != SQLITE_OK) {
        ALOGE("sqlite3_key(%p) failed: %d", connection->db, rc);
        throw_sqlite3_exception_errcode(env, rc, "Could not key db.");
    }

I guess because the rc = sqlite3_key(connection->db, key, size) fails for some reason.

The crash is NOT systematic, it occurs sometimes but the number on crashlytics are raising up.
Since for now we cannot update again the app with an upgrade of the libraries and with the exception handling, we are trying to understand the cause of the crash and its possible future impacts (if it keep raising too much).

Do you have any clue on what could be the reason?

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions