Android SQLite API based on SQLCipher

Overview

Download Source and Binaries

The latest AAR binary package information can be here, the source can be found here.

Compatibility

SQLCipher for Android runs on Android 4.1–Android 10, for armeabi-v7a, x86, x86_64, and arm64_v8a architectures.

Contributions

We welcome contributions, to contribute to SQLCipher for Android, a contributor agreement needs to be submitted. All submissions should be based on the master branch.

An Illustrative Terminal Listing

A typical SQLite database in unencrypted, and visually parseable even as encoded text. The following example shows the difference between hexdumps of a standard SQLite database and one implementing SQLCipher.

~ sjlombardo$ hexdump -C sqlite.db
00000000 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 |SQLite format 3.|
…
000003c0 65 74 32 74 32 03 43 52 45 41 54 45 20 54 41 42 |et2t2.CREATE TAB|
000003d0 4c 45 20 74 32 28 61 2c 62 29 24 01 06 17 11 11 |LE t2(a,b)$…..|
…
000007e0 20 74 68 65 20 73 68 6f 77 15 01 03 01 2f 01 6f | the show…./.o|
000007f0 6e 65 20 66 6f 72 20 74 68 65 20 6d 6f 6e 65 79 |ne for the money|

~ $ sqlite3 sqlcipher.db
sqlite> PRAGMA KEY=’test123′;
sqlite> CREATE TABLE t1(a,b);
sqlite> INSERT INTO t1(a,b) VALUES (‘one for the money’, ‘two for the show’);
sqlite> .quit

~ $ hexdump -C sqlcipher.db
00000000 84 d1 36 18 eb b5 82 90 c4 70 0d ee 43 cb 61 87 |.?6.?..?p.?C?a.|
00000010 91 42 3c cd 55 24 ab c6 c4 1d c6 67 b4 e3 96 bb |.B?..?|
00000bf0 8e 99 ee 28 23 43 ab a4 97 cd 63 42 8a 8e 7c c6 |..?(#C??.?cB..|?|

~ $ sqlite3 sqlcipher.db
sqlite> SELECT * FROM t1;
Error: file is encrypted or is not a database

(example courtesy of SQLCipher)

Application Integration

You have a two main options for using SQLCipher for Android in your app:

  • Using it with Room or other consumers of the androidx.sqlite API

  • Using the native SQLCipher for Android classes

In both cases, you will need to add a dependency on net.zetetic:android-database-sqlcipher, such as having the following line in your module's build.gradle dependencies closure:

implementation "net.zetetic:android-database-sqlcipher:4.4.2"
implementation "androidx.sqlite:sqlite:2.0.1"

(replacing 4.4.2 with the version you want)

Using SQLCipher for Android With Room

SQLCipher for Android has a SupportFactory class in the net.sqlcipher.database package that can be used to configure Room to use SQLCipher for Android.

There are three SupportFactory constructors:

  • SupportFactory(byte[] passphrase)
  • SupportFactory(byte[] passphrase, SQLiteDatabaseHook hook)
  • SupportFactory(byte[] passphrase, SQLiteDatabaseHook hook, boolean clearPassphrase)

All three take a byte[] to use as the passphrase (if you have a char[], use SQLiteDatabase.getBytes() to get a suitable byte[] to use).

Two offer a SQLiteDatabaseHook parameter that you can use for executing SQL statements before or after the passphrase is used to key the database.

The three-parameter constructor also offers clearPassphrase, which defaults to true in the other two constructors. If clearPassphrase is set to true, this will zero out the bytes of the byte[] after we open the database. This is safest from a security standpoint, but it does mean that the SupportFactory instance is a single-use object. Attempting to reuse the SupportFactory instance later will result in being unable to open the database, because the passphrase will be wrong. If you think that you might need to reuse the SupportFactory instance, pass false for clearPassphrase.

Then, pass your SupportFactory to openHelperFactory() on your RoomDatabase.Builder:

final byte[] passphrase = SQLiteDatabase.getBytes(userEnteredPassphrase);
final SupportFactory factory = new SupportFactory(passphrase);
final SomeDatabase room = Room.databaseBuilder(activity, SomeDatabase.class, DB_NAME)
  .openHelperFactory(factory)
  .build();

Now, Room will make all of its database requests using SQLCipher for Android instead of the framework copy of SQLCipher.

Note that SupportFactory should work with other consumers of the androidx.sqlite API; Room is merely a prominent example.

Using SQLCipher for Android's Native API

If you have existing SQLite code using classes like SQLiteDatabase and SQLiteOpenHelper, converting your code to use SQLCipher for Android mostly is a three-step process:

  1. Replace all android.database.sqlite.* import statements with ones that use net.sqlcipher.database.* (e.g., convert android.database.sqlite.SQLiteDatabase to net.sqlcipher.database.SQLiteDatabase)

  2. Before attempting to open a database, call SQLiteDatabase.loadLibs(), passing in a Context (e.g., add this to onCreate() of your Application subclass, using the Application itself as the Context)

  3. When opening a database (e.g., SQLiteDatabase.openOrCreateDatabase()), pass in the passphrase as a char[] or byte[]

The rest of your code may not need any changes.

An article covering both integration of SQLCipher into an Android application as well as building the source can be found here.

ProGuard

For applications which utilize ProGuard, a few additional rules must be included when using SQLCipher for Android. These rules instruct ProGuard to omit the renaming of the internal SQLCipher classes which are used via lookup from the JNI layer. It is worth noting that since SQLCipher or Android is based on open source code there is little value in obfuscating the library anyway. The more important use of ProGuard is to protect your application code and business logic.

-keep,includedescriptorclasses class net.sqlcipher.** { *; }
-keep,includedescriptorclasses interface net.sqlcipher.** { *; }

Building

In order to build android-database-sqlcipher from source you will need both the Android SDK, Gradle, Android NDK, SQLCipher core source directory, and an OpenSSL source directory. We currently recommend using Android NDK version r20. To complete the make command, the ANDROID_NDK_HOME environment variable must be defined which should point to your NDK root. Once you have cloned the repo, change directory into the root of the repository and run the following commands:

SQLCIPHER_ROOT=/some/path/to/sqlcipher-folder \
OPENSSL_ROOT=/some/path/to/openssl-folder \
SQLCIPHER_ANDROID_VERSION="4.4.2" \
SQLCIPHER_CFLAGS="-DSQLITE_HAS_CODEC" \
OPENSSL_ANDROID_LIB_ROOT=/some/path/for/android/native/lib/creation \
make build-release

License

The Android support libraries are licensed under Apache 2.0, in line with the Android OS code on which they are based. The SQLCipher code itself is licensed under a BSD-style license from Zetetic LLC. Finally, the original SQLite code itself is in the public domain.

Comments
  • Missing Android N compatibility because of behavior changes

    Missing Android N compatibility because of behavior changes

    Hello,

    Google changed some things regarding linking/loading libs: https://developer.android.com/preview/behavior-changes.html#ndk

    This also affects SQLCipher. E.g. the Test-Suite failed 10 out of 32 tests. screenshot_20160310-091222

    Log show up following:

    03-10 09:09:17.497 26856-26869/net.zetetic:provider W/linker: library "libutils.so" ("/system/lib/libutils.so") needed or dlopened by "/data/app/net.zetetic-1/lib/arm/libsqlcipher_android.so" is not accessible for the namespace "classloader-namespace" - the access is temporarily granted as a workaround for http://b/26394120
    03-10 09:09:17.497 26856-26869/net.zetetic:provider W/linker: library "libcutils.so" ("/system/lib/libcutils.so") needed or dlopened by "/data/app/net.zetetic-1/lib/arm/libsqlcipher_android.so" is not accessible for the namespace "classloader-namespace" - the access is temporarily granted as a workaround for http://b/26394120
    03-10 09:09:17.517 26856-26869/net.zetetic:provider W/linker: library "libnativehelper.so" ("/system/lib/libnativehelper.so") needed or dlopened by "/data/app/net.zetetic-1/lib/arm/libdatabase_sqlcipher.so" is not accessible for the namespace "classloader-namespace" - the access is temporarily granted as a workaround for http://b/26394120
    03-10 09:09:17.518 26856-26869/net.zetetic:provider W/linker: library "libandroid_runtime.so" ("/system/lib/libandroid_runtime.so") needed or dlopened by "/data/app/net.zetetic-1/lib/arm/libdatabase_sqlcipher.so" is not accessible for the namespace "classloader-namespace" - the access is temporarily granted as a workaround for http://b/26394120
    03-10 09:09:17.518 26856-26869/net.zetetic:provider W/linker: library "libbinder.so" ("/system/lib/libbinder.so") needed or dlopened by "/data/app/net.zetetic-1/lib/arm/libdatabase_sqlcipher.so" is not accessible for the namespace "classloader-namespace" - the access is temporarily granted as a workaround for http://b/26394120
    
    opened by TheNephilim88 77
  • attempt to write a readonly database, crashes on android 5.0v devices while using SqlCipher

    attempt to write a readonly database, crashes on android 5.0v devices while using SqlCipher

    Im getting following log on app crash, on android 5.0v devices

    Caused by: net.sqlcipher.database.SQLiteException: attempt to write a readonly database at net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method) at net.sqlcipher.database.SQLiteDatabase.setLocale(SQLiteDatabase.java:2096) at net.sqlcipher.database.SQLiteDatabase.(SQLiteDatabase.java:1962) at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:881) at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:913) at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:132) at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:99) at PackageName.DBHelperCipher.(DBHelperCipher.java:93) at PackageName.ProcessDBCipherInitTask.doInBackground(ProcessDBCipherInitTask.java:20) at PackageName.ProcessDBCipherInitTask.doInBackground(ProcessDBCipherInitTask.java:1) at android.os.AsyncTask$2.call(AsyncTask.java:288) at java.util.concurrent.FutureTask.run(FutureTask.java:237)

    I've submitted a question on StackOverflow, http://stackoverflow.com/q/29988933/341443. Can you please help on this.

    Thank you.

    opened by praveenb 70
  • Fatal Exception: net.sqlcipher.database.SQLiteException: file is encrypted or is not a database: while compiling: select count(*) from sqlite_master

    Fatal Exception: net.sqlcipher.database.SQLiteException: file is encrypted or is not a database: while compiling: select count(*) from sqlite_master

    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)

    opened by surajnavkudkarpersonal 62
  • Support arm64v8a and x86_64 (64-bit) in Sqlcipher

    Support arm64v8a and x86_64 (64-bit) in Sqlcipher

    With the 64-bit capable android devices already out there, it is necessary to be able to have native 64-bit compilation for increased performance. MIPS64 has not been included, because the corresponding AOSP version does not seem to compile.

    opened by gmetal 46
  •  net.sqlcipher.database.SQLiteException ??? not error exception on SQLiteDatabase.dbOpen

    net.sqlcipher.database.SQLiteException ??? not error exception on SQLiteDatabase.dbOpen

    I cannot found clear conditions to reproduce bug. But 2-5% my application starts are interrupted with this.

    I have icudt46l.zip in assets. I've checked and found that /icu/icudt46l.dat is exists in my app data folder.

    To be sure i run loadLibs() in application class. However sometimes(!) i got this.

    net.sqlcipher.database.SQLiteException: not an error
       at net.sqlcipher.database.SQLiteDatabase.dbopen(SQLiteDatabase.java)
       at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1942)
       at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:875)
       at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:907)
    

    Android 4.4.4 on nexus 7

    opened by kivsiak 44
  • Build failure for v4.3.0

    Build failure for v4.3.0

    Expected Behavior

    Build succeedes

    Actual Behavior

    Build aborts at ndk-build step in Task :android-database-sqlcipher:buildNative FAILED

    Steps to Reproduce

    1. Fresh installed android SDK
    2. Using side-by-side NDK (version does not matter, tried from 16 up to 21)
    3. Fresh clone of this repository, check out tag v4.3.0 (same is true for master)
    4. make init && make build-debug
      1. See OpenSSL being build
      2. See build abort at sqlcipher step
    opened by akallabeth 41
  • Crash on Android 6.0 emulator

    Crash on Android 6.0 emulator

    I am getting a crash on launch when trying to test on an Android 6.0 emulator

    java.lang.UnsatisfiedLinkError: dlopen failed: ... lib/x86/libsqlcipher_android.so: has text relocations

    Using: sqlcipher-for-android-v3.3.1 Android emulator x86 API 23 (6.0)

    opened by TomAtRB 36
  • net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master

    net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master

    Expected Behavior

    The app should open.

    Actual Behavior

    The app crashes before starting

    Steps to Reproduce

    Open the app on Android 12 - os S version

    SQLCipher version (can be identified by executing PRAGMA cipher_version;):

    SQLCipher for Android version: 4.4.2@aar

    Are you able to reproduce this issue within the SQLCipher for Android test suite?

    We are not able to get that test suite running. Need some support on the running test for library compatibility on Android 12 OS S.

    Note: If you are not posting a specific issue for the SQLCipher library, please post your question to the SQLCipher discuss site. Thanks!

    E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-3 Process: com.mobile.android.debug, PID: 26682 net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master; at net.sqlcipher.database.SQLiteCompiledSql.native_compile(Native Method) at net.sqlcipher.database.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:89) at net.sqlcipher.database.SQLiteCompiledSql.(SQLiteCompiledSql.java:62) at net.sqlcipher.database.SQLiteProgram.(SQLiteProgram.java:91) at net.sqlcipher.database.SQLiteQuery.(SQLiteQuery.java:48) at net.sqlcipher.database.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:60) at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:2016) at net.sqlcipher.database.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1902) at net.sqlcipher.database.SQLiteDatabase.keyDatabase(SQLiteDatabase.java:2669) at net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal(SQLiteDatabase.java:2599) at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1247) at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1322) at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:166) at net.sqlcipher.database.SupportHelper.getWritableDatabase(SupportHelper.java:83) at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:476) at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:281) at com.android.repository.login.UserAccountDao_Impl.getUserByStatus(UserAccountDao_Impl.java:)

    we are using a keypair generator for android

    val keyPairGenerator = KeyPairGenerator.getInstance( TYPE_RSA, PROVIDER_ANDROID_KEYSTORE ) spec = KeyGenParameterSpec.Builder( KEY_ALIAS, KeyProperties.PURPOSE_SIGN or KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT ) .setCertificateSerialNumber(BigInteger.ONE) .setKeyValidityEnd(endDate.time) .setCertificateSubject( X500Principal( context.getString(R.string.certificate).format( KEY_ALIAS ) ) ) .setUserAuthenticationRequired(false) .setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA1) .setSignaturePaddings(KeyProperties.SIGNATURE_PADDING_RSA_PKCS1) .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1).build()

    We also use the SupportFactory using the SQLiteDatabaseHook as mentioned in your document.

    val factory = SupportFactory(SQLiteDatabase.getBytes(key.toCharArray()), object : SQLiteDatabaseHook { override fun preKey(database: SQLiteDatabase) { // Nothing specific needs to be done for before loading database }

                override fun postKey(database: SQLiteDatabase) {
                    val cursor = database.rawQuery("PRAGMA cipher_migrate", arrayOf())
                    var value: String? = ""
                    cursor?.let {
                        it.moveToFirst()
                        value = it.getString(0)
                        it.close()
                    }
                    Logger.debug("CMS : Database cipher_migrate: $value")
                }
            })
    

    On launch of the app, we have few parallel calls,

    • we do prefetch the existing toggle values from our local DB table.
    • we query a table for checking if user exists
    • when we get new toggle values from server, we update the toggle values back to the DB.

    We are seeing the crash everytime when we launch the app on either of the 3 scenarios getting this crash.

    stale 
    opened by sunilcnair 33
  • native crash libsqlcipher.so 000c6008

    native crash libsqlcipher.so 000c6008

    Expected Behavior

    Actual Behavior

    Crash type: 'native'
    Start time: '2019-08-19T08:52:51.198+0800'
    Crash time: '2019-08-19T08:52:51.208+0800'
    App ID: 'com.demo.ksk'
    App version: '5.3.2'
    CPU loadavg: 'unknown'
    CPU online: '0-7'
    CPU offline: ''
    System memory total: '3805108 kB'
    System memory used: '3150420 kB'
    Number of threads: '50'
    Rooted: 'No'
    API level: '28'
    OS version: '9'
    Kernel version: 'Linux version 4.9.111 #1 SMP PREEMPT Fri Mar 29 23:12:42 CST 2019 (armv8l)'
    ABI list: 'arm64-v8a,armeabi-v7a,armeabi'
    Manufacturer: 'HUAWEI'
    Brand: 'HUAWEI'
    Model: 'MHA-AL00'
    Build fingerprint: 'HUAWEI/MHA-AL00/HWMHA:9/HUAWEIMHA-AL00/179C00R1:user/release-keys'
    Revision: '0'
    ABI: 'arm'
    pid: 22897, tid: 23106, name: Thread-17  >>> com.demo.ksk <<<
    signal 4 (SIGILL), code 1 (ILL_ILLOPC), fault addr 0xc3c2a008
        r0  00000000  r1  20000011  r2  c5aea220  r3  00000008
        r4  c3d3a6a8  r5  c47ec070  r6  00000001  r7  fffffb27
        r8  c3b7fbd8  r9  f10182c0  r10 00000000  r11 f1018628
        ip  50b1bcf1  sp  c47ec050  lr  c3b7fcf8  pc  c3c2a008
    
    backtrace:
        #00 pc 000c6008  /data/app/com.demo.ksk-aiBDkGn3pZ-yJU_8cCthdg==/lib/arm/libsqlcipher.so
    
    
    java stacktrace:
        at java.lang.Runtime.nativeLoad(Native Method)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1014)
        at java.lang.System.loadLibrary(System.java:1672)
        at net.sqlcipher.database.SQLiteDatabase$1.loadLibraries(src:223)
        at net.sqlcipher.database.SQLiteDatabase.loadLibs(src:240)
        at net.sqlcipher.database.SQLiteDatabase.loadLibs(src:219)
        at net.sqlcipher.database.SQLiteDatabase.loadLibs(src:212)
        at com.demo.ksk.service.dao.DaoCipherInit.(src:42)
        at com.demo.ksk.service.DaoManager.a(src:71)
        at com.demo.ksk.service.ConfigManager.a(src:28)
        at com.demo.ksk.service.ServiceProvider.b(src:47)
        at com.demo.ksk.manager.Manager.a(src:176)
        at com.demo.ksk.access.Engine$1.run(src:163)
        at java.lang.Thread.run(Thread.java:784)
    

    Steps to Reproduce

    SQLCipher version (can be identified by executing PRAGMA cipher_version;):

    SQLCipher for Android version: api 'net.zetetic:android-database-sqlcipher:4.1.3'

    Note: If you are not posting a specific issue for the SQLCipher library, please consider posting your question to the SQLCipher discuss site. Thanks!

    bug 
    opened by KSKjust 33
  • Patch: Fix SQLiteCursor locking issue.

    Patch: Fix SQLiteCursor locking issue.

    Hi, I have encountered deadlock problem when applying SQLCipher to my application.

    There is a closed issue about it : https://github.com/sqlcipher/android-database-sqlcipher/issues/97

    I compared the lock method used in SQLCipher with AOSP4.0.1, and found that there are some difference.

    After doing some changes, I finally get rid of deadlock problem. Here is the patch: https://github.com/promeG/SQLCipher-Android-Fix-Deadlock-Patch

    I hope it can help with other people who have the same problem.

    SQLCipher is a great project, thank you for your hard work!

    opened by promeG 32
  • Fatal Exception: java.lang.UnsatisfiedLinkError

    Fatal Exception: java.lang.UnsatisfiedLinkError

    Expected Behavior

    sqlcipher to work

    Actual Behavior

    On a certain device (Other devices seem to be ok with it), I got the above crash with the following stack trace:

    Fatal Exception: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.app.appm-oMdSgIjvGcgfbLLnMzQlIw==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.appm-oMdSgIjvGcgfbLLnMzQlIw==/lib/arm64, /system/lib64, /vendor/lib64]]] couldn't find "libsqlcipher.so" at java.lang.Runtime.loadLibrary0 + 1011(Runtime.java:1011) at java.lang.System.loadLibrary + 1657(System.java:1657) at net.sqlcipher.database.SQLiteDatabase$1.loadLibraries + 223(SQLiteDatabase.java:223) at net.sqlcipher.database.SQLiteDatabase.loadLibs + 240(SQLiteDatabase.java:240) at net.sqlcipher.database.SQLiteDatabase.loadLibs + 219(SQLiteDatabase.java:219) at net.sqlcipher.database.SQLiteDatabase.loadLibs + 212(SQLiteDatabase.java:212) at com.commonsware.cwac.saferoom.Helper. + 39(Helper.java:39) at com.commonsware.cwac.saferoom.SafeHelperFactory.create + 190(SafeHelperFactory.java:190) at com.commonsware.cwac.saferoom.SafeHelperFactory.create + 184(SafeHelperFactory.java:184) at com.app.appm.dbRoom.AppDatabase_Impl.createOpenHelper + 96(AppDatabase_Impl.java:96) at androidx.room.RoomDatabase.init + 159(RoomDatabase.java:159) at androidx.room.RoomDatabase$Builder.build + 852(RoomDatabase.java:852) at com.app.appm.dbRoom.DatabaseClient. + 19(DatabaseClient.java:19) at com.app.appm.dbRoom.DatabaseClient.getInstance + 24(DatabaseClient.java:24) at com.app.appm.MainActivity$2.run + 129(MainActivity.java:129) at android.os.AsyncTask$SerialExecutor$1.run + 245(AsyncTask.java:245) at java.util.concurrent.ThreadPoolExecutor.runWorker + 1162(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run + 636(ThreadPoolExecutor.java:636) at java.lang.Thread.run + 764(Thread.java:764)

    Steps to Reproduce

    Not sure, it's a crash on a user's device, I guess he just opened the app Android version: 8.1.0 LGE nexus 5

    Thanks

    stale 
    opened by ghost 23
  • Vulnerability in SQLite3.39.2 CVE-2022-46908

    Vulnerability in SQLite3.39.2 CVE-2022-46908

    Our internal tool reported that there is a Vulnerability in SQLite3.39.2

    CVE-2022-46908

    Description SQLite through 3.40.0, when relying on --safe for execution of an untrusted CLI script, does not properly implement the azProhibitedFunctions protection mechanism, and instead allows UDF functions such as WRITEFILE.

    opened by sankar-gp 4
  • i have histroy data with room,when i use sqlcipher, crash: net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;

    i have histroy data with room,when i use sqlcipher, crash: net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;

    Expected Behavior

    Actual Behavior

    Steps to Reproduce

    SQLCipher version (can be identified by executing PRAGMA cipher_version;):

    SQLCipher for Android version:

    Are you able to reproduce this issue within the SQLCipher for Android test suite?

    Note: If you are not posting a specific issue for the SQLCipher library, please post your question to the SQLCipher discuss site. Thanks!

    opened by kangshifu 1
  • net.sqlcipher.database.SQLiteException: not an error: BEGIN EXCLUSIVE;

    net.sqlcipher.database.SQLiteException: not an error: BEGIN EXCLUSIVE;

    Expected Behavior

    Want to known which scenes will occurrenced. So i can do something.

    Actual Behavior

    My project is an multipule processes application. Used android-database-sqlcipher(4.5.1) and androidx.room(2.2.0). Each process open an database on singleInstance. This crash was occurrenced by stability monkey test, and on firebase also has few this crash.I can't reproduce this crash by normal operation. Our JournalMode set JournalMode.TRUNCATE forced. On our code,we retry beginTransaction when accept SQLiteDatabaseException(message is startwith database is locked).

        boolean retry;
        int tryCount = 0;
        do {
            retry = false;
            try {
                if (withListener) {
                    mDelegate.beginTransactionWithListener(transactionListener);
                } else {
                    mDelegate.beginTransaction();
                }
                if (DEBUG && tryCount > 0) {
                    Log.d(TAG, "beginTransactionSafely()-> tryCount = " + tryCount);
                }
            } catch (SQLiteException exception) {
                String message = exception.getMessage();
                if (message != null && message.startsWith("database is locked")) {
                    if (DEBUG) {
                        Log.d(TAG, "beginTransactionSafely()-> " + message);
                    }
                    long sleepTime = Math.min(160, (tryCount + 1) * 20);
                    SystemClock.sleep(sleepTime);
                    tryCount++;
                    retry = true;
                } else {
                    throw exception;
                }
            }
        } while (retry);
    

    Steps to Reproduce

    I query sqlite doc how problem occur.But nothing get. Also i read sqlite source code, but i can't understander all code. Only i can known is sqlite3_step() return SQLite_OK but not SQLite_Done. I don't known why return SQLite_OK and which scenes occurrence.

    SQLCipher version (can be identified by executing PRAGMA cipher_version;): 4.5.1 community SQLCipher for Android version: 4.5.1

    Crash Stack

    Build Info: 'unknown:alps-mp-q0.mp1-V3_reallytek.q0mp1.k61v1.64.bsp_P93:mt6761:S01,TECNO/H624/TECNO-KB8:10/QP1A.190711.020/BNPQ-201230V852:user/release-keys'
    MSSI Info: 'TECNO/H624/TECNO-KB8:10/QP1A.190711.020/BNPQ-201230V852:user/release-keys'
    Exception Log Time:[Tue Oct 11 13:43:41 WAT 2022] [7593.371736]
    
    Exception Class: Java (JE)
    Exception Type: system_app_crash
    
    Current Executing Process: 
    net.bat.store
    net.bat.store v2911 (V5.1.39.11)
    
    
    Trigger time:[2022-10-11 13:43:41.357436] pid:11587
    
    Backtrace: 
    Process: net.bat.store
    PID: 11587
    UID: 10064
    Flags: 0x38d83ec5
    Package: net.bat.store v2911 (V5.1.39.11)
    Foreground: Yes
    Build: TECNO/H624/TECNO-KB8:10/QP1A.190711.020/BNPQ-201230V852:user/release-keys
    
    net.sqlcipher.database.SQLiteException: not an error: BEGIN EXCLUSIVE;
    	at net.sqlcipher.database.SQLiteDatabase.native_execSQL(Native Method)
    	at net.sqlcipher.database.SQLiteDatabase.execSQL(SourceFile:4)
    	at net.sqlcipher.database.SQLiteDatabase.beginTransactionWithListenerInternal(SourceFile:8)
    	at net.sqlcipher.database.SQLiteDatabase.beginTransactionWithListener(SourceFile:1)
    	at net.sqlcipher.database.SQLiteDatabase.beginTransaction(SourceFile:1)
    	at net.bat.store.datamanager.db.AhaSupportSQLiteDatabase.beginTransactionSafely(SourceFile:2)
    	at net.bat.store.datamanager.db.AhaSupportSQLiteDatabase.beginTransaction(SourceFile:1)
    	at androidx.room.RoomDatabase.beginTransaction(SourceFile:4)
    	at net.bat.store.datamanager.dao.GameDao_Impl.insertOrIgnoreGame(SourceFile:2)
    	at net.bat.store.datamanager.server.GameDaoImpl.insertOrIgnoreGame(SourceFile:1)
    	at net.bat.store.datamanager.client.proxy.GameDaoProxy.insertOrIgnoreGame(SourceFile:1)
    	at net.bat.store.runtime.util.OpenGame$1.run(SourceFile:1)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    	at net.bat.store.thread.BaseThreadPoolExecutor$BaseThreadFactory.lambda$newThread$0(SourceFile:2)
    	at net.bat.store.thread.-$$Lambda$BaseThreadPoolExecutor$BaseThreadFactory$lEX5z4jVWLqetPCsXEvyDjhH5Vg.run(Unknown Source:2)
    	at java.lang.Thread.run(Thread.java:919)
    

    MyCode

    GameDao_Impl.java
    public void insertOrIgnoreGame(final GameTable gameTable) {
        __db.assertNotSuspendingTransaction();
        __db.beginTransaction();
        try {
          __insertionAdapterOfGameTable_1.insert(gameTable);
          __db.setTransactionSuccessful();
        } finally {
          __db.endTransaction();
        }
      }
    
    AhaSupportSQLiteDatabase.java
        public void beginTransaction() {
            beginTransactionSafely(false, null);
        }
    
        private void beginTransactionSafely(boolean withListener, SQLiteTransactionListener transactionListener) {
            boolean retry;
            int tryCount = 0;
            do {
                retry = false;
                try {
                    if (withListener) {
                        mDelegate.beginTransactionWithListener(transactionListener);
                    } else {
                        mDelegate.beginTransaction();
                    }
                    if (DEBUG && tryCount > 0) {
                        Log.d(TAG, "beginTransactionSafely()-> tryCount = " + tryCount);
                    }
                } catch (SQLiteException exception) {
                    String message = exception.getMessage();
                    if (message != null && message.startsWith("database is locked")) {
                        if (DEBUG) {
                            Log.d(TAG, "beginTransactionSafely()-> " + message);
                        }
                        long sleepTime = Math.min(160, (tryCount + 1) * 20);
                        SystemClock.sleep(sleepTime);
                        tryCount++;
                        retry = true;
                    } else {
                        throw exception;
                    }
                }
            } while (retry);
        }
    

    I can provider all stability log if you need!

    opened by linchengchan 9
  • Native exception

    Native exception

    We are seeing quite a number of native crashes similar to this:

      #00  pc 0x00000000000a534c  /data/app/~~7iQyW4InSEfqBNSIgjKtQg==/<app>-s-QQmPamI42JEad6zo-x_Q==/lib/arm64/libsqlcipher.so
      #00  pc 0x00000000000a509c  /data/app/~~7iQyW4InSEfqBNSIgjKtQg==/<app>-s-QQmPamI42JEad6zo-x_Q==/lib/arm64/libsqlcipher.so
      #00  pc 0x00000000001cf828  /data/app/~~7iQyW4InSEfqBNSIgjKtQg==/<app>-s-QQmPamI42JEad6zo-x_Q==/lib/arm64/libsqlcipher.so
      #00  pc 0x0000000000183d28  /data/app/~~7iQyW4InSEfqBNSIgjKtQg==/<app>-s-QQmPamI42JEad6zo-x_Q==/oat/arm64/base.odex (art_jni_trampoline)
      #00  pc 0x00000000007909a4  /data/app/~~7iQyW4InSEfqBNSIgjKtQg==/<app>-s-QQmPamI42JEad6zo-x_Q==/oat/arm64/base.odex (net.sqlcipher.database.SQLiteProgram.bindString)
      #00  pc 0x000000000078fbe8  /data/app/~~7iQyW4InSEfqBNSIgjKtQg==/<app>-s-QQmPamI42JEad6zo-x_Q==/oat/arm64/base.odex (net.sqlcipher.database.SQLiteDirectCursorDriver.query)
      #00  pc 0x000000000078f3f8  /data/app/~~7iQyW4InSEfqBNSIgjKtQg==/<app>-s-QQmPamI42JEad6zo-x_Q==/oat/arm64/base.odex (net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory)
      #00  pc 0x000000000078f1c4  /data/app/~~7iQyW4InSEfqBNSIgjKtQg==/<app>-s-QQmPamI42JEad6zo-x_Q==/oat/arm64/base.odex (net.sqlcipher.database.SQLiteDatabase.rawQuery)
    
    • it happens on all Android versions supported by the app
    • it appears to only happen on arm64 devices, though that's probably just because most/all users are on arm64 devices
    • In the last 30 days there have been 221 instances of this crash affecting 217 users, so the crash appears to be randomly distributed

    Expected Behavior

    App not crashing

    Actual Behavior

    App crashed

    Steps to Reproduce

    Unknown, they are captured by Google Play Console

    SQLCipher version (can be identified by executing PRAGMA cipher_version;): 3.4.2

    SQLCipher for Android version: 3.5.9

    Are you able to reproduce this issue within the SQLCipher for Android test suite? No

    opened by kaichunlin 2
  • file is not a database: , while compiling: select count(*) from sqlite_master;

    file is not a database: , while compiling: select count(*) from sqlite_master;

    I've run into an issue where the error in the title is faced by a tiny portion of our users. I haven't been able to reproduce the issue on any devices myself, but based on previous reports, this should mean that the passphrase has changed (or rather, is different from what was initially used). However, I don't see how it could possibly happen, as it only happens for less than 1% of our users. The reports seem to spike after each update we release, but cannot figure out what could cause this.

    The stack trace from Crashlytics looks like this:

    Fatal Exception: net.sqlcipher.database.SQLiteException: file 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:89)
           at net.sqlcipher.database.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:62)
           at net.sqlcipher.database.SQLiteProgram.<init>(SQLiteProgram.java:91)
           at net.sqlcipher.database.SQLiteQuery.<init>(SQLiteQuery.java:48)
           at net.sqlcipher.database.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:60)
           at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:2016)
           at net.sqlcipher.database.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1902)
           at net.sqlcipher.database.SQLiteDatabase.keyDatabase(SQLiteDatabase.java:2669)
           at net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal(SQLiteDatabase.java:2599)
           at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1247)
           at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1322)
           at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:166)
           at net.sqlcipher.database.SupportHelper.getWritableDatabase(SupportHelper.java:83)
           at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:706)
           at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:483)
           at androidx.room.RoomDatabase.query(RoomDatabase.java:526)
           at androidx.room.util.DBUtil.query(DBUtil.java:86)
    

    The passphrase we use is essentially a hard-coded constant value, so it seems weird that it would appear to be changing.

    needs-details 
    opened by manabreak 8
  • android.database.CursorWindowAllocationException

    android.database.CursorWindowAllocationException

    Carsh info: android.database.CursorWindowAllocationException: at android.database.CursorWindow. (CursorWindow.java:108) at android.database.CursorWindow. (CursorWindow.java:143) at net.sqlcipher.CursorWindow. (CursorWindow.java:67) at net.sqlcipher.database.SQLiteCursor.fillWindow (SQLiteCursor.java:301) at net.sqlcipher.database.SQLiteCursor.getCount (SQLiteCursor.java:292) at android.database.CursorWrapper.getCount (CursorWrapper.java:57) at Samsung Galaxy Note3 Android 5.0 (SDK 21)

    needs-details 
    opened by SmileEveryDayDay 1
Owner
SQLCipher
SQLCipher is an open source extension to SQLite that provides transparent 256-bit AES encryption of database files.
SQLCipher
greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.

Check out ObjectBox Check out our new mobile database ObjectBox (GitHub repo). ObjectBox is a superfast object-oriented database with strong relation

Markus Junginger 12.6k Jan 3, 2023
An Android library that makes developers use SQLite database extremely easy.

LitePal for Android 中文文档 LitePal is an open source Android library that allows developers to use SQLite database extremely easy. You can finish most o

Lin Guo 7.9k Dec 31, 2022
Active record style SQLite persistence for Android

ActiveAndroid ActiveAndroid is an active record style ORM (object relational mapper). What does that mean exactly? Well, ActiveAndroid allows you to s

Michael Pardo 4.7k Dec 29, 2022
SquiDB is a SQLite database library for Android and iOS

Most ongoing development is currently taking place on the dev_4.0 branch. Click here to see the latest changes and try out the 4.0 beta. Introducing S

Yahoo 1.3k Dec 26, 2022
Extended SQLite functionality for Android

sqlite-provider A simplification of database access for Android. Description sqlite-provider implements a ContentProvider for you that allows database

Novoda 308 Nov 20, 2022
lightweight and minimalist ORM for Java/Android. works with SQLite & MySQL. (not actively maintained)

Description ORMAN is an minimalistic and lightweight ORM framework for Java which can handle your common database usage without writing SQL and strugg

Ahmet Alp Balkan 246 Nov 20, 2022
A Java/Kotlin library for Android platform, to manage bean's persistence in SQLite, SharedPreferences, JSON, XML, Properties, Yaml, CBOR.

Thanks to JetBrains for support Kripton Persistence Library project! Kripton Persistence Library Kripton is a java library, for Android platform, that

xcesco 117 Nov 11, 2022
Compile time processed, annotation driven, no reflection SQLite database layer for Android

SqliteMagic Simple yet powerful SQLite database layer for Android that makes database handling feel like magic. Overview: Simple, intuitive & typesafe

Siim Kinks 118 Dec 22, 2022
android 数据库框架,sqlite database

DBExecutor 主要的功能 1.使用了读写锁,支持多线程操作数据。 2.支持事务 3.支持ORM 4.缓存Sql,缓存表结构 这个类库主要用于android 数据库操作。 始终围绕着一个类对应一个表的概念。 只要创建一个实体类,就不用当心它怎么存储在数据库中,不用重新写增删改查的代码。基本的功

null 77 May 31, 2021
AndroidQuery is an Android ORM for SQLite and ContentProvider which focuses on easy of use and performances thanks to annotation processing and code generation

WARNING: now that Room is out, I no longer maintain that library. If you need a library to easy access to default android ContentProvider, I would may

Frédéric Julian 19 Dec 11, 2021
LiteOrm is a fast, small, powerful ORM framework for Android. LiteOrm makes you do CRUD operarions on SQLite database with a sigle line of code efficiently.

#LiteOrm:Android高性能数据库框架 A fast, small, powerful ORM framework for Android. LiteOrm makes you do CRUD operarions on SQLite database with a sigle line

马天宇 1.5k Nov 19, 2022
lightweight and minimalist ORM for Java/Android. works with SQLite & MySQL. (not actively maintained)

Description ORMAN is an minimalistic and lightweight ORM framework for Java which can handle your common database usage without writing SQL and strugg

Ahmet Alp Balkan 246 Nov 20, 2022
Extended SQLite functionality for Android

sqlite-provider A simplification of database access for Android. Description sqlite-provider implements a ContentProvider for you that allows database

Novoda 308 Nov 20, 2022
An Android library that makes developers use SQLite database extremely easy.

LitePal for Android 中文文档 LitePal is an open source Android library that allows developers to use SQLite database extremely easy. You can finish most o

Lin Guo 7.9k Jan 4, 2023
Realm is a mobile database: a replacement for SQLite & ORMs

Realm is a mobile database that runs directly inside phones, tablets or wearables. This repository holds the source code for the Java version of Realm

Realm 11.4k Jan 2, 2023
Exercicio praticando o SQLite, Room e Flow

Bus Scheduler App This folder contains the source code for the Bus Scheduler app codelab. Introduction The Bus Scheduler app displays a list of bus st

Lucas Caetano 0 Nov 26, 2021
requery - modern SQL based query & persistence for Java / Kotlin / Android

A light but powerful object mapping and SQL generator for Java/Kotlin/Android with RxJava and Java 8 support. Easily map to or create databases, perfo

requery 3.1k Dec 29, 2022
LiteGo is a Java-based asynchronous concurrency library. It has a smart executor, which can be freely set the maximum number of concurrent at same time , and the number of threads in waiting queue. It can also set waiting policies and overload strategies.

LiteGo:「迷你」的Android异步并发类库 LiteGo是一款基于Java语言的「异步并发类库」,它的核心是一枚「迷你」并发器,它可以自由地设置同一时段的最大「并发」数量,等待「排队」线程数量,还可以设置「排队策略」和「超载策略」。 LiteGo可以直接投入Runnable、Callable

马天宇 189 Nov 10, 2022
Newyork-book-listings - New york book listings using API from nytimes

New York Book Listings Project This is a project developed in Android Studio whi

Kushagra Jaiswal 0 Jan 8, 2022