Coder Social home page Coder Social logo

sqlcipher / android-database-sqlcipher Goto Github PK

View Code? Open in Web Editor NEW
2.7K 2.7K 564.0 72.79 MB

Android SQLite API based on SQLCipher

Home Page: https://www.zetetic.net/sqlcipher/sqlcipher-for-android/

License: Other

Makefile 0.85% Shell 0.62% Java 76.73% C++ 21.33% C 0.28% AIDL 0.19%

android-database-sqlcipher's Introduction

SQLCipher

SQLCipher is a standalone fork of the SQLite database library that adds 256 bit AES encryption of database files and other security features like:

  • on-the-fly encryption
  • tamper detection
  • memory sanitization
  • strong key derivation

SQLCipher is based on SQLite and stable upstream release features are periodically integrated. While SQLCipher is maintained as a separate version of the source tree, the project minimizes alterations to core SQLite code whenever possible.

SQLCipher is maintained by Zetetic, LLC, and additional information and documentation is available on the official SQLCipher site.

Features

  • Fast performance with as little as 5-15% overhead for encryption on many operations
  • 100% of data in the database file is encrypted
  • Good security practices (CBC mode, HMAC, key derivation)
  • Zero-configuration and application level cryptography
  • Algorithms provided by the peer reviewed OpenSSL crypto library.
  • Configurable crypto providers

Compatibility

SQLCipher maintains database format compatibility within the same major version number so an application on any platform can open databases created by any other application provided the major version of SQLCipher is the same between them. However, major version updates (e.g. from 3.x to 4.x) often include changes to default settings. This means that newer major versions of SQLCipher will not open databases created by older versions without using special settings. For example, SQLCipher 4 introduces many new performance and security enhancements. The new default algorithms, increased KDF iterations, and larger page size mean that SQLCipher 4 will not open databases created by SQLCipher 1.x, 2.x, or 3.x by default. Instead, an application would either need to migrate the older databases to use the new format or enable a special backwards-compatibility mode. The available options are described in SQLCipher's upgrade documentation.

SQLCipher is also compatible with standard SQLite databases. When a key is not provided, SQLCipher will behave just like the standard SQLite library. It is also possible to convert from a plaintext database (standard SQLite) to an encrypted SQLCipher database using ATTACH and the sqlcipher_export() convenience function.

Contributions

The SQLCipher team welcomes contributions to the core library. All contributions including pull requests and patches should be based on the prerelease branch, and must be accompanied by a contributor agreement. We strongly encourage discussion of the proposed change prior to development and submission.

Compiling

Building SQLCipher is similar to compiling a regular version of SQLite from source, with a couple of small exceptions:

  1. You must define SQLITE_HAS_CODEC and either SQLITE_TEMP_STORE=2 or SQLITE_TEMP_STORE=3
  2. You will need to link against a support cryptographic provider (OpenSSL, LibTomCrypt, CommonCrypto/Security.framework, or NSS)

The following examples demonstrate linking against OpenSSL, which is a readily available provider on most Unix-like systems.

Example 1. Static linking (replace /opt/local/lib with the path to libcrypto.a). Note in this example, --enable-tempstore=yes is setting SQLITE_TEMP_STORE=2 for the build.

$ ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" \
	LDFLAGS="/opt/local/lib/libcrypto.a"
$ make

Example 2. Dynamic linking

$ ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" \
	LDFLAGS="-lcrypto"
$ make

Testing

The full SQLite test suite will not complete successfully when using SQLCipher. In some cases encryption interferes with low-level tests that require access to database file data or features which are unsupported by SQLCipher. Those tests that are intended to support encryption are intended for non-SQLCipher implementations. In addition, because SQLite tests are not always isolated, if one test fails it can trigger a domino effect with other failures in later steps.

As a result, the SQLCipher package includes it's own independent tests that exercise and verify the core functionality of the SQLCipher extensions. This test suite is intended to provide an abbreviated verification of SQLCipher's internal logic; it does not perform an exhaustive test of the SQLite database system as a whole or verify functionality on specific platforms. Because SQLCipher is based on stable upstream builds of SQLite, it is considered a basic assumption that the core SQLite library code is operating properly (the SQLite core is almost untouched in SQLCipher). Thus, the additional SQLCipher-specific test provide the requisite verification that the library is operating as expected with SQLCipher's security features enabled.

To run SQLCipher specific tests, configure as described here and run the following to execute the tests and receive a report of the results:

$ ./configure --enable-tempstore=yes --enable-fts5 CFLAGS="-DSQLITE_HAS_CODEC -DSQLCIPHER_TEST" \
	LDFLAGS="-lcrypto"
$ make testfixture
$ ./testfixture test/sqlcipher.test

Encrypting a database

To specify an encryption passphrase for the database via the SQL interface you use a PRAGMA. The passphrase you enter is passed through PBKDF2 key derivation to obtain the encryption key for the database

PRAGMA key = 'passphrase';

Alternately, you can specify an exact byte sequence using a blob literal. If you use this method it is your responsibility to ensure that the data you provide is a 64 character hex string, which will be converted directly to 32 bytes (256 bits) of key data without key derivation.

PRAGMA key = "x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'";

To encrypt a database programmatically you can use the sqlite3_key function. The data provided in pKey is converted to an encryption key according to the same rules as PRAGMA key.

int sqlite3_key(sqlite3 *db, const void *pKey, int nKey);

PRAGMA key or sqlite3_key should be called as the first operation when a database is open.

Changing a database key

To change the encryption passphrase for an existing database you may use the rekey PRAGMA after you've supplied the correct database password;

PRAGMA key = 'passphrase'; -- start with the existing database passphrase
PRAGMA rekey = 'new-passphrase'; -- rekey will reencrypt with the new passphrase

The hex rekey pragma may be used to rekey to a specific binary value

PRAGMA rekey = "x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'";

This can be accomplished programmatically by using sqlite3_rekey;

sqlite3_rekey(sqlite3 *db, const void *pKey, int nKey)

Support

The primary source for complete documentation (design, API, platforms, usage) is the SQLCipher website:

https://www.zetetic.net/sqlcipher/documentation

The primary avenue for support and discussions is the SQLCipher discuss site:

https://discuss.zetetic.net/c/sqlcipher

Issues or support questions on using SQLCipher should be entered into the GitHub Issue tracker:

https://github.com/sqlcipher/sqlcipher/issues

Please DO NOT post issues, support questions, or other problems to blog posts about SQLCipher as we do not monitor them frequently.

If you are using SQLCipher in your own software please let us know at [email protected]!

Community Edition Open Source License

Copyright (c) 2020, ZETETIC LLC All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the ZETETIC LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ZETETIC LLC ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ZETETIC LLC BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Begin SQLite README.md

SQLite Source Repository

This repository contains the complete source code for the SQLite database engine. Some test scripts are also included. However, many other test scripts and most of the documentation are managed separately.

Version Control

SQLite sources are managed using Fossil, a distributed version control system that was specifically designed and written to support SQLite development. The Fossil repository contains the urtext.

If you are reading this on GitHub or some other Git repository or service, then you are looking at a mirror. The names of check-ins and other artifacts in a Git mirror are different from the official names for those objects. The official names for check-ins are found in a footer on the check-in comment for authorized mirrors. The official check-in name can also be seen in the manifest.uuid file in the root of the tree. Always use the official name, not the Git-name, when communicating about an SQLite check-in.

If you pulled your SQLite source code from a secondary source and want to verify its integrity, there are hints on how to do that in the Verifying Code Authenticity section below.

Contacting The SQLite Developers

The preferred way to ask questions or make comments about SQLite or to report bugs against SQLite is to visit the SQLite Forum at https://sqlite.org/forum/. Anonymous postings are permitted.

If you think you have found a bug that has security implications and you do not want to report it on the public forum, you can send a private email to drh at sqlite dot org.

Public Domain

The SQLite source code is in the public domain. See https://sqlite.org/copyright.html for details.

Because SQLite is in the public domain, we do not normally accept pull requests, because if we did take a pull request, the changes in that pull request might carry a copyright and the SQLite source code would then no longer be fully in the public domain.

Obtaining The SQLite Source Code

If you do not want to use Fossil, you can download tarballs or ZIP archives or SQLite archives as follows:

  • Latest trunk check-in as Tarball, ZIP-archive, or SQLite-archive.

  • Latest release as Tarball, ZIP-archive, or SQLite-archive.

  • For other check-ins, substitute an appropriate branch name or tag or hash prefix in place of "release" in the URLs of the previous bullet. Or browse the timeline to locate the check-in desired, click on its information page link, then click on the "Tarball" or "ZIP Archive" links on the information page.

If you do want to use Fossil to check out the source tree, first install Fossil version 2.0 or later. (Source tarballs and precompiled binaries available here. Fossil is a stand-alone program. To install, simply download or build the single executable file and put that file someplace on your $PATH.) Then run commands like this:

    mkdir -p ~/sqlite ~/Fossils
    cd ~/sqlite
    fossil clone https://www.sqlite.org/src ~/Fossils/sqlite.fossil
    fossil open ~/Fossils/sqlite.fossil

After setting up a repository using the steps above, you can always update to the latest version using:

    fossil update trunk   ;# latest trunk check-in
    fossil update release ;# latest official release

Or type "fossil ui" to get a web-based user interface.

Compiling for Unix-like systems

First create a directory in which to place the build products. It is recommended, but not required, that the build directory be separate from the source directory. Cd into the build directory and then from the build directory run the configure script found at the root of the source tree. Then run "make".

For example:

    tar xzf sqlite.tar.gz    ;#  Unpack the source tree into "sqlite"
    mkdir bld                ;#  Build will occur in a sibling directory
    cd bld                   ;#  Change to the build directory
    ../sqlite/configure      ;#  Run the configure script
    make                     ;#  Builds the "sqlite3" command-line tool
    make sqlite3.c           ;#  Build the "amalgamation" source file
    make devtest             ;#  Run some tests (requires Tcl)

See the makefile for additional targets.

The configure script uses autoconf 2.61 and libtool. If the configure script does not work out for you, there is a generic makefile named "Makefile.linux-gcc" in the top directory of the source tree that you can copy and edit to suit your needs. Comments on the generic makefile show what changes are needed.

Compiling for Windows Using MSVC

On Windows, all applicable build products can be compiled with MSVC. You will also need a working installation of TCL. See the compile-for-windows.md document for additional information about how to install MSVC and TCL and configure your build environment.

If you want to run tests, you need to let SQLite know the location of your TCL library, using a command like this:

    set TCLDIR=c:\Tcl

SQLite uses "tclsh.exe" as part of the build process, and so that utility program will need to be somewhere on your %PATH%. The finished SQLite library does not contain any TCL code, but it does use TCL to help with the build process and to run tests.

Build using Makefile.msc. Example:

    nmake /f Makefile.msc
    nmake /f Makefile.msc sqlite3.c
    nmake /f Makefile.msc devtest
    nmake /f Makefile.msc releasetest

There are many other makefile targets. See comments in Makefile.msc for details.

Source Code Tour

Most of the core source files are in the src/ subdirectory. The src/ folder also contains files used to build the "testfixture" test harness. The names of the source files used by "testfixture" all begin with "test". The src/ also contains the "shell.c" file which is the main program for the "sqlite3.exe" command-line shell and the "tclsqlite.c" file which implements the Tcl bindings for SQLite. (Historical note: SQLite began as a Tcl extension and only later escaped to the wild as an independent library.)

Test scripts and programs are found in the test/ subdirectory. Additional test code is found in other source repositories. See How SQLite Is Tested for additional information.

The ext/ subdirectory contains code for extensions. The Full-text search engine is in ext/fts3. The R-Tree engine is in ext/rtree. The ext/misc subdirectory contains a number of smaller, single-file extensions, such as a REGEXP operator.

The tool/ subdirectory contains various scripts and programs used for building generated source code files or for testing or for generating accessory programs such as "sqlite3_analyzer(.exe)".

Generated Source Code Files

Several of the C-language source files used by SQLite are generated from other sources rather than being typed in manually by a programmer. This section will summarize those automatically-generated files. To create all of the automatically-generated files, simply run "make target_source". The "target_source" make target will create a subdirectory "tsrc/" and fill it with all the source files needed to build SQLite, both manually-edited files and automatically-generated files.

The SQLite interface is defined by the sqlite3.h header file, which is generated from src/sqlite.h.in, ./manifest.uuid, and ./VERSION. The Tcl script at tool/mksqlite3h.tcl does the conversion. The manifest.uuid file contains the SHA3 hash of the particular check-in and is used to generate the SQLITE_SOURCE_ID macro. The VERSION file contains the current SQLite version number. The sqlite3.h header is really just a copy of src/sqlite.h.in with the source-id and version number inserted at just the right spots. Note that comment text in the sqlite3.h file is used to generate much of the SQLite API documentation. The Tcl scripts used to generate that documentation are in a separate source repository.

The SQL language parser is parse.c which is generated from a grammar in the src/parse.y file. The conversion of "parse.y" into "parse.c" is done by the lemon LALR(1) parser generator. The source code for lemon is at tool/lemon.c. Lemon uses the tool/lempar.c file as a template for generating its parser. Lemon also generates the parse.h header file, at the same time it generates parse.c.

The opcodes.h header file contains macros that define the numbers corresponding to opcodes in the "VDBE" virtual machine. The opcodes.h file is generated by scanning the src/vdbe.c source file. The Tcl script at ./mkopcodeh.tcl does this scan and generates opcodes.h. A second Tcl script, ./mkopcodec.tcl, then scans opcodes.h to generate the opcodes.c source file, which contains a reverse mapping from opcode-number to opcode-name that is used for EXPLAIN output.

The keywordhash.h header file contains the definition of a hash table that maps SQL language keywords (ex: "CREATE", "SELECT", "INDEX", etc.) into the numeric codes used by the parse.c parser. The keywordhash.h file is generated by a C-language program at tool mkkeywordhash.c.

The pragma.h header file contains various definitions used to parse and implement the PRAGMA statements. The header is generated by a script tool/mkpragmatab.tcl. If you want to add a new PRAGMA, edit the tool/mkpragmatab.tcl file to insert the information needed by the parser for your new PRAGMA, then run the script to regenerate the pragma.h header file.

The Amalgamation

All of the individual C source code and header files (both manually-edited and automatically-generated) can be combined into a single big source file sqlite3.c called "the amalgamation". The amalgamation is the recommended way of using SQLite in a larger application. Combining all individual source code files into a single big source code file allows the C compiler to perform more cross-procedure analysis and generate better code. SQLite runs about 5% faster when compiled from the amalgamation versus when compiled from individual source files.

The amalgamation is generated from the tool/mksqlite3c.tcl Tcl script. First, all of the individual source files must be gathered into the tsrc/ subdirectory (using the equivalent of "make target_source") then the tool/mksqlite3c.tcl script is run to copy them all together in just the right order while resolving internal "#include" references.

The amalgamation source file is more than 200K lines long. Some symbolic debuggers (most notably MSVC) are unable to deal with files longer than 64K lines. To work around this, a separate Tcl script, tool/split-sqlite3c.tcl, can be run on the amalgamation to break it up into a single small C file called sqlite3-all.c that does #include on about seven other files named sqlite3-1.c, sqlite3-2.c, ..., sqlite3-7.c. In this way, all of the source code is contained within a single translation unit so that the compiler can do extra cross-procedure optimization, but no individual source file exceeds 32K lines in length.

How It All Fits Together

SQLite is modular in design. See the architectural description for details. Other documents that are useful in (helping to understand how SQLite works include the file format description, the virtual machine that runs prepared statements, the description of how transactions work, and the overview of the query planner.

Years of effort have gone into optimizing SQLite, both for small size and high performance. And optimizations tend to result in complex code. So there is a lot of complexity in the current SQLite implementation. It will not be the easiest library in the world to hack.

Key files:

  • sqlite.h.in - This file defines the public interface to the SQLite library. Readers will need to be familiar with this interface before trying to understand how the library works internally.

  • sqliteInt.h - this header file defines many of the data objects used internally by SQLite. In addition to "sqliteInt.h", some subsystems have their own header files.

  • parse.y - This file describes the LALR(1) grammar that SQLite uses to parse SQL statements, and the actions that are taken at each step in the parsing process.

  • vdbe.c - This file implements the virtual machine that runs prepared statements. There are various helper files whose names begin with "vdbe". The VDBE has access to the vdbeInt.h header file which defines internal data objects. The rest of SQLite interacts with the VDBE through an interface defined by vdbe.h.

  • where.c - This file (together with its helper files named by "where*.c") analyzes the WHERE clause and generates virtual machine code to run queries efficiently. This file is sometimes called the "query optimizer". It has its own private header file, whereInt.h, that defines data objects used internally.

  • btree.c - This file contains the implementation of the B-Tree storage engine used by SQLite. The interface to the rest of the system is defined by "btree.h". The "btreeInt.h" header defines objects used internally by btree.c and not published to the rest of the system.

  • pager.c - This file contains the "pager" implementation, the module that implements transactions. The "pager.h" header file defines the interface between pager.c and the rest of the system.

  • os_unix.c and os_win.c - These two files implement the interface between SQLite and the underlying operating system using the run-time pluggable VFS interface.

  • shell.c.in - This file is not part of the core SQLite library. This is the file that, when linked against sqlite3.a, generates the "sqlite3.exe" command-line shell. The "shell.c.in" file is transformed into "shell.c" as part of the build process.

  • tclsqlite.c - This file implements the Tcl bindings for SQLite. It is not part of the core SQLite library. But as most of the tests in this repository are written in Tcl, the Tcl language bindings are important.

  • test*.c - Files in the src/ folder that begin with "test" go into building the "testfixture.exe" program. The testfixture.exe program is an enhanced Tcl shell. The testfixture.exe program runs scripts in the test/ folder to validate the core SQLite code. The testfixture program (and some other test programs too) is built and run when you type "make test".

There are many other source files. Each has a succinct header comment that describes its purpose and role within the larger system.

Verifying Code Authenticity

The manifest file at the root directory of the source tree contains either a SHA3-256 hash or a SHA1 hash for every source file in the repository. The name of the version of the entire source tree is just the SHA3-256 hash of the manifest file itself, possibly with the last line of that file omitted if the last line begins with "# Remove this line". The manifest.uuid file should contain the SHA3-256 hash of the manifest file. If all of the above hash comparisons are correct, then you can be confident that your source tree is authentic and unadulterated. Details on the format for the manifest files are available on the Fossil website.

The process of checking source code authenticity is automated by the makefile:

make verify-source

Or on windows:

nmake /f Makefile.msc verify-source

Using the makefile to verify source integrity is good for detecting accidental changes to the source tree, but malicious changes could be hidden by also modifying the makefiles.

Contacts

The main SQLite website is https://sqlite.org/ with geographically distributed backups at https://www2.sqlite.org/ and https://www3.sqlite.org/.

android-database-sqlcipher's People

Contributors

abeluck avatar afzalive avatar brodybits avatar commonsguy avatar developernotes avatar eighthave avatar fairchild88 avatar hannesa2 avatar illarionov avatar jeffdcamp avatar n8fr8 avatar nuumio avatar sjlombardo avatar sschuberth avatar superfell avatar tapchicoma avatar zackjp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-database-sqlcipher's Issues

Encrypt Preloaded Database. Is this possible?

I am using a preloaded database (stored in the assets folder) of my android project.

I want to encrypt the already defined database. Is this possible please?

Thanks for your time.

no such function: sqlcipher_export

Hello,

I was trying to run this code (Android/Java/Eclipse)

private SQLiteDatabase vgpdb;

    SQLiteDatabase.loadLibs(appcontext);

vgpdb = SQLiteDatabase.openOrCreateDatabase(database1, "Test1234, null);
vgpdb.execSQL("ATTACH DATABASE '/mnt/sdcard/Empty.sqlite' AS plaintext KEY '';");
vgpdb.execSQL("SELECT sqlcipher_export('plaintext');"); 
    vgpdb.execSQL("DETACH DATABASE plaintext;");
vgpdb.close();

When it gets to the sqlcipher_export line I get an exception, "05-10 10:13:35.420: E/Database(13730): Failure 1 (no such function: sqlcipher_export) on 0x1b8c030 when preparing 'SELECT sqlcipher_export('plaintext');'."

I am using the Anrdroid 1.1.0 package with the assets zip file icudt46l.zip, any advice would be helpfull.

thanks

Unable to access database using raw key data after forcing app to stop

Hi,

I'm trying to use a row key data in order to avoid key derivation (According to the documentation http://sqlcipher.net/sqlcipher-api/#key):

this.myDb = SQLiteDatabase.openOrCreateDatabase(databaseFile, "", null);
this.myDb.rawExecSQL("PRAGMA key = \"x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'\"");
Cursor myCursor = this.myDb.rawQuery(query, params);

When I force the application to stop, accessing the data becomes impossible.

This behaviour does not happen without using SQLCipher. The database is readable even after forcing application to stop.

I'm I doing something wrong ?

Thanks in advance,

Q on licensing, deployment and 2.1

Hi,
three questions:

  1. I'm not quite sure but it seems the libs are working with 2.1 too? You do explicitly declare 2.2 and above, but what about 2.1?
  2. I'm having to deploy the 3 libs to the target machine, right?
  3. Do I have to add additional license files to my deployment?

Regards

No implementation found for native Lnet/sqlcipher/database/SQLiteDatabase;.dbopen (Ljava/lang/String;I)V

06-26 11:38:53.559: W/dalvikvm(22382): No implementation found for native Lnet/sqlcipher/database/SQLiteDatabase;.dbopen (Ljava/lang/String;I)V
06-26 11:38:53.559: D/AndroidRuntime(22382): Shutting down VM
06-26 11:38:53.559: W/dalvikvm(22382): threadid=1: thread exiting with uncaught exception (group=0x40018560)
06-26 11:38:53.569: E/AndroidRuntime(22382): FATAL EXCEPTION: main
06-26 11:38:53.569: E/AndroidRuntime(22382): java.lang.UnsatisfiedLinkError: dbopen
06-26 11:38:53.569: E/AndroidRuntime(22382): at net.sqlcipher.database.SQLiteDatabase.dbopen(Native Method)
06-26 11:38:53.569: E/AndroidRuntime(22382): at net.sqlcipher.database.SQLiteDatabase.(SQLiteDatabase.java:2030)
06-26 11:38:53.569: E/AndroidRuntime(22382): at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:931)
06-26 11:38:53.569: E/AndroidRuntime(22382): at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1010)
06-26 11:38:53.569: E/AndroidRuntime(22382): at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:236)
06-26 11:38:53.569: E/AndroidRuntime(22382): at com.viber.voip.contacts.ViberContactsProvider.onCreate(ViberContactsProvider.java:53)
06-26 11:38:53.569: E/AndroidRuntime(22382): at android.content.ContentProvider.attachInfo(ContentProvider.java:798)
06-26 11:38:53.569: E/AndroidRuntime(22382): at android.app.ActivityThread.installProvider(ActivityThread.java:3706)
06-26 11:38:53.569: E/AndroidRuntime(22382): at android.app.ActivityThread.installContentProviders(ActivityThread.java:3461)
06-26 11:38:53.569: E/AndroidRuntime(22382): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3417)
06-26 11:38:53.569: E/AndroidRuntime(22382): at android.app.ActivityThread.access$2200(ActivityThread.java:123)
06-26 11:38:53.569: E/AndroidRuntime(22382): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:977)
06-26 11:38:53.569: E/AndroidRuntime(22382): at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 11:38:53.569: E/AndroidRuntime(22382): at android.os.Looper.loop(Looper.java:130)
06-26 11:38:53.569: E/AndroidRuntime(22382): at android.app.ActivityThread.main(ActivityThread.java:3835)
06-26 11:38:53.569: E/AndroidRuntime(22382): at java.lang.reflect.Method.invokeNative(Native Method)
06-26 11:38:53.569: E/AndroidRuntime(22382): at java.lang.reflect.Method.invoke(Method.java:507)
06-26 11:38:53.569: E/AndroidRuntime(22382): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
06-26 11:38:53.569: E/AndroidRuntime(22382): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
06-26 11:38:53.569: E/AndroidRuntime(22382): at dalvik.system.NativeStart.main(Native Method)
06-26 11:38:53.589: W/ActivityManager(224): Force finishing activity com.viber.voip/.Encrypt
06-26 11:38:54.089: W/ActivityManager(224): Activity pause timeout for HistoryRecord{4057b378 com.viber.voip/.Encrypt}

report a crash bug of sqlcipher on Android 4.0.3

the problem i met here is :
when you use beginTransaction() function, if there are too many sql statements lines between beginTransaction() function and endTranaction() . the code will crash and return error code "sqlite SQL logic error or missing database "
and code here is example, the problem is Complete reproducibility.

[code]
db = SQLiteDatabase.openOrCreateDatabase(databaseFile, "test123", null);
// LOG.d("db", "call from" + Thread.currentThread().getId());
String _ID = "_id";
db.beginTransaction();
db.execSQL(" CREATE TABLE IF NOT EXISTS ttt (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
db.execSQL(" CREATE TABLE IF NOT EXISTS rwerw (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
db.execSQL(" CREATE TABLE IF NOT EXISTS erwe (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
db.execSQL(" CREATE TABLE IF NOT EXISTS werwe (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
db.execSQL(" CREATE TABLE IF NOT EXISTS wqrwe (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
db.execSQL(" CREATE TABLE IF NOT EXISTS werwerwet (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
db.execSQL(" CREATE TABLE IF NOT EXISTS twee (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
db.execSQL(" CREATE TABLE IF NOT EXISTS ouio (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");

    db.execSQL(" CREATE TABLE IF NOT EXISTS ouio1 (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
    db.execSQL(" CREATE TABLE IF NOT EXISTS ouio2 (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
    db.execSQL(" CREATE TABLE IF NOT EXISTS ouio3 (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
    db.execSQL(" CREATE TABLE IF NOT EXISTS ouio4 (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");

    db.execSQL(" CREATE TABLE IF NOT EXISTS ouio41 (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
    db.execSQL(" CREATE TABLE IF NOT EXISTS ouio42 (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
    db.execSQL(" CREATE TABLE IF NOT EXISTS ouio43 (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
    db.execSQL(" CREATE TABLE IF NOT EXISTS ouio44 (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
    db.execSQL(" CREATE TABLE IF NOT EXISTS ouio45 (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
    db.execSQL(" CREATE TABLE IF NOT EXISTS ouio46 (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
    db.execSQL(" CREATE TABLE IF NOT EXISTS ouio47 (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
    db.execSQL(" CREATE TABLE IF NOT EXISTS ouio48 (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
    db.execSQL(" CREATE TABLE IF NOT EXISTS ouio49 (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ttt TEXT);");
    db.endTransaction();

[/code]

SQLCipher under Android 4.0.3

Hello,

I am writing an Android APP using SQLite, I looked at using SQLCipher but this crashes, on first DB commands, I have since sorted library loading issues and got the icu46.zip patch, still crashes.

I then downloaded NoteCipher to see if this worked and it did not.

Does this mean the SQLCipher will not work in my Android enviroment ?

I have looked at some other forum questions and some developers are re-building the SQLCipher from source themselves. If you want I can provide traces from logcat but it appears to be a similar issue as reported in issues #34 and #36.

Any suggestions ?

Android internal db path

Hi,

I am trying to create a database with path as default database path in android, with code as below. I get unable to open database file exception. If i give sdcard path it works perfectly, however i do not want my db available in sdcard. Is there a way to make this work internally? (I do not use dbhelper)

Code:

String dbPath = context.getDatabasePath(DATABASE_NAME).toString()
sqLiteDatabase = SQLiteDatabase.openOrCreateDatabase(dbPath, "password", null);

Exception:

info.guardianproject.database.sqlcipher.SQLiteException: unable to open database file

Thanks & Regards,
Swarna

Database directory not lazy-created

Environment: SQLCipher for Android 2.0.5, as tested on Android 2.2 and 4.0.3 ARM emulators.

Scenario: Install an app, so there is no database directory for the app. Attempt to open a readable database using SQLiteOpenHelper. You crash with:

sqlite3_open_v2("/data/data/com.commonsware.sct/databases/constants.db", &handle, 6, NULL) failed

Or, if you create the directory (e.g., context.getDatabasePath(DATABASE_NAME).getParentFile().mkdirs();), and you attempt to open a readable database, you crash with:

E/AndroidRuntime(1293): Caused by: net.sqlcipher.database.SQLiteException: Can't upgrade read-only database from version 0 to 1: /data/data/com.commonsware.sct/databases/constants.db

Workaround: Don't open a readable database unless the database already exists. Open a writable database instead.

What Should Happen: The database directory should be lazy-created and a database created, even if you said you only needed a readable database.

Sample Code: http://misc.commonsware.com/SQLCipherTest.zip

Any roadmap or declared release date for v2?

Hello,
Sorry if this is already discussed. Is there any roadmap or declared release date for stable v2? The github milestone shows it passed 4 months ago? Any update on that?

Thanks in advance for your time!

SQlitecipher and SQlite on android

I have a question about SQliteCipher being based on Sqlite, does it tend to create a new db which is compatible with Sqlite API and db.
I understand Sqlitecipher is forked off, how do we know its fully compliant with Sqlite in Android 2.x and 3.X

thanks!

regards,
S.Abdullah

CursorWindow need to grow crash

I am using the libraries that come with SQLCipherForAndroid-SDK-0.0.5-Beta.tar.gz. My database is created successfully. My first sql query works fine but 2nd one("SELECT count(A) FROM B)" fails when I try to use cursor object returned(which is not null). I test on Samsung Galaxy Gio device.

According to error, it seems that memory allocation fails. (I don't understand why this >2MB allocation is needed, since my query returns empty result. Galaxy Gio is a cheap device, so maybe less heap memory allowed per app?)

The code that leads to this crash is cursor.moveToNext(); but also other calls cursor methods cause this crash. A weird thing is that, this crash doesn't happen if I dig into attached jar's source code with eclipse.

My program works fine if I don't use sqlcipher..

I get the following error in logcat:

10-19 10:55:13.483: ERROR/CursorWindow(2770): need to grow: mSize = 2097152, size = 9, freeSpace() = 0, numRows = 1
10-19 10:55:13.591: INFO/DEBUG(2187): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
10-19 10:55:13.591: INFO/DEBUG(2187): Build fingerprint: 'samsung/GT-S5660/GT-S5660/GT-S5660:2.2.1/FROYO/XXKC7:user/release-keys'
10-19 10:55:13.591: INFO/DEBUG(2187): pid: 2770, tid: 2770 >>> com.MyProject <<<
10-19 10:55:13.591: INFO/DEBUG(2187): signal 11 (SIGSEGV), fault addr 4f16c448
10-19 10:55:13.591: INFO/DEBUG(2187): r0 4f16c448 r1 00000000 r2 00000001 r3 80000000
10-19 10:55:13.591: INFO/DEBUG(2187): r4 00000000 r5 00000000 r6 00000000 r7 00000000
10-19 10:55:13.591: INFO/DEBUG(2187): r8 00000009 r9 00000000 10 00000001 fp 00000064
10-19 10:55:13.591: INFO/DEBUG(2187): ip 00000000 sp beaed430 lr 00000000 pc afd0f460 cpsr 80000010
10-19 10:55:13.591: INFO/DEBUG(2187): d0 0000002a42280000 d1 3ff0000042280000
10-19 10:55:13.591: INFO/DEBUG(2187): d2 bfd3441350baf6de d3 c1493000c1323800
10-19 10:55:13.591: INFO/DEBUG(2187): d4 4900000040dcb000 d5 000000000006e580
10-19 10:55:13.601: INFO/DEBUG(2187): d6 4515a00000000800 d7 40800000c48ee000
10-19 10:55:13.601: INFO/DEBUG(2187): d8 0000000000000000 d9 0000000000000000
10-19 10:55:13.601: INFO/DEBUG(2187): d10 0000000000000000 d11 0000000000000000
10-19 10:55:13.601: INFO/DEBUG(2187): d12 0000000000000000 d13 0000000000000000
10-19 10:55:13.601: INFO/DEBUG(2187): d14 0000000000000000 d15 0000000000000000
10-19 10:55:13.601: INFO/DEBUG(2187): scr 80000012
10-19 10:55:13.651: INFO/DEBUG(2187): #00 pc 0000f460 /system/lib/libc.so
10-19 10:55:13.651: INFO/DEBUG(2187): #1 pc 00002708 /data/data/com.MyProject/lib/libdatabase_sqlcipher.so
10-19 10:55:13.651: INFO/DEBUG(2187): #2 pc 00003b34 /data/data/com.MyProject/lib/libdatabase_sqlcipher.so
10-19 10:55:13.651: INFO/DEBUG(2187): #3 pc 000170b4 /system/lib/libdvm.so
10-19 10:55:13.651: INFO/DEBUG(2187): #4 pc 000039d6 /data/data/com.MyProject/lib/libdatabase_sqlcipher.so
10-19 10:55:13.651: INFO/DEBUG(2187): code around pc:
10-19 10:55:13.651: INFO/DEBUG(2187): afd0f440 e213301c 0a000008 e1530002 8202301c
10-19 10:55:13.661: INFO/DEBUG(2187): afd0f450 e0422003 e1b03e03 28a04002 28a04002
10-19 10:55:13.661: INFO/DEBUG(2187): afd0f460 48a04002 e1b03103 24801004 e2522020
10-19 10:55:13.661: INFO/DEBUG(2187): afd0f470 e1a03001 4a000002 e2522020 e8a050fa
10-19 10:55:13.661: INFO/DEBUG(2187): afd0f480 2afffffc e2822020 e1b02e02 28a0500a
10-19 10:55:13.661: INFO/DEBUG(2187): code around lr:
10-19 10:55:13.661: INFO/DEBUG(2187): stack:
10-19 10:55:13.661: INFO/DEBUG(2187): beaed3f0 4410eab4
10-19 10:55:13.661: INFO/DEBUG(2187): beaed3f4 44332464 /dev/ashmem/dalvik-LinearAlloc (deleted)
10-19 10:55:13.661: INFO/DEBUG(2187): beaed3f8 00000000
10-19 10:55:13.661: INFO/DEBUG(2187): beaed3fc 898c75f3
10-19 10:55:13.661: INFO/DEBUG(2187): beaed400 afd4172c /system/lib/libc.so
10-19 10:55:13.661: INFO/DEBUG(2187): beaed404 002803d8 [heap]
10-19 10:55:13.661: INFO/DEBUG(2187): beaed408 00000009
10-19 10:55:13.661: INFO/DEBUG(2187): beaed40c 00000000
10-19 10:55:13.661: INFO/DEBUG(2187): beaed410 81505128 /data/data/com.MyProject/lib/libdatabase_sqlcipher.so
10-19 10:55:13.661: INFO/DEBUG(2187): beaed414 815025f5 /data/data/com.MyProject/lib/libdatabase_sqlcipher.so
10-19 10:55:13.661: INFO/DEBUG(2187): beaed418 815043c0 /data/data/com.MyProject/lib/libdatabase_sqlcipher.so
10-19 10:55:13.661: INFO/DEBUG(2187): beaed41c 00200000 [heap]
10-19 10:55:13.661: INFO/DEBUG(2187): beaed420 00000009
10-19 10:55:13.661: INFO/DEBUG(2187): beaed424 00000000
10-19 10:55:13.661: INFO/DEBUG(2187): beaed428 df002777
10-19 10:55:13.661: INFO/DEBUG(2187): beaed42c e3a070ad
10-19 10:55:13.661: INFO/DEBUG(2187): #00 beaed430 4f16c448
10-19 10:55:13.661: INFO/DEBUG(2187): beaed434 002803d8 [heap]
10-19 10:55:13.661: INFO/DEBUG(2187): beaed438 4f16c448
10-19 10:55:13.661: INFO/DEBUG(2187): beaed43c 4eeec008 /dev/ashmem/CursorWindow (deleted)
10-19 10:55:13.661: INFO/DEBUG(2187): beaed440 00280448 [heap]
10-19 10:55:13.671: INFO/DEBUG(2187): beaed444 8150270b /data/data/com.MyProject/lib/libdatabase_sqlcipher.so
10-19 10:55:13.671: INFO/DEBUG(2187): #1 beaed448 00000000
10-19 10:55:13.671: INFO/DEBUG(2187): beaed44c 00000000
10-19 10:55:13.671: INFO/DEBUG(2187): beaed450 81506b84 /data/data/com.MyProject/lib/libdatabase_sqlcipher.so
10-19 10:55:13.671: INFO/DEBUG(2187): beaed454 002803d8 [heap]
10-19 10:55:13.671: INFO/DEBUG(2187): beaed458 00281ac8 [heap]
10-19 10:55:13.671: INFO/DEBUG(2187): beaed45c 81503b39 /data/data/com.MyProject/lib/libdatabase_sqlcipher.so

Couldn't load stlport_shared

Thank you for providing an open source project for protecting the database, as security is a very important feature in my app. I added the jars and so files as mentioned in the installation guide and made the code changes, but I am getting the following error in loadlibs. Can you please help me with this issue.

11-17 12:18:41.827: ERROR/AndroidRuntime(31107): java.lang.UnsatisfiedLinkError: Couldn't load stlport_shared: findLibrary returned null
11-17 12:18:41.827: ERROR/AndroidRuntime(31107): at java.lang.Runtime.loadLibrary(Runtime.java:429)
11-17 12:18:41.827: ERROR/AndroidRuntime(31107): at java.lang.System.loadLibrary(System.java:554)
11-17 12:18:41.827: ERROR/AndroidRuntime(31107): at info.guardianproject.database.sqlcipher.SQLiteDatabase.loadLibs(SQLiteDatabase.java:104)

Why is it not able to load stlport_shared, should i do any specific compilation for the so files?

build instructions

It'd be great to get the basic steps for doing a build from start to end documented.

Possible Feature: Compression

Problem with encrypted data: You cannot compress it efficiently.

In my case, I have a 50 MB database which is only like 10 MB zipped. Obviously this is no longer possible if the database is encrypted.

My suggestion is to add an compression layer which can compress the unencrypted chunks and encrypt it afterwards.

SQLCipher Fatal Exception on Android 4.0

Running on a Galaxy Nexus phone with Android 4.0. (Works find on 2.2 and 2.3.) The following exception is raised when calling getReadableDatabase().

12-15 16:47:27.819: ERROR/AndroidRuntime(28459): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{xyz.activity.SplashActivity}: info.guardianproject.database.sqlcipher.SQLiteException: not an error
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
at android.app.ActivityThread.access$600(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: info.guardianproject.database.sqlcipher.SQLiteException: not an error
at info.guardianproject.database.sqlcipher.SQLiteDatabase.dbopen(Native Method)
at info.guardianproject.database.sqlcipher.SQLiteDatabase.(SQLiteDatabase.java:1870)
at info.guardianproject.database.sqlcipher.SQLiteDatabase.openDatabase(SQLiteDatabase.java:863)
at info.guardianproject.database.sqlcipher.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:183)

PHONE_NUMBERS_EQUAL no longer works

It seems that the PHONE_NUMBERS_EQUAL function from SQLite no longer works once the database is switched over to SQLCipher. It's throwing the following error:
info.guardianproject.datbase.sqlcipher.SQLiteException: no such function: PHONE NUMBERS EQUAL
The code was working correctly immediately before being switched to SQLCipher.
This might be an issue with SQLCipher or an issue with an extension that doesn't interact properly with SQLCipher as opposed to SQLite.

Ambiguous behaviour of the database when the database is deleted and recreated

I use a SqliteOpenHelper to create a database (say "MyDB"). During a particular condition I have to clear the database. So I use context.deleteDatabase("MyDB") to remove the db and recreate it once again. But after this the database starts behaving erratically. For instance while fetching entries (using the same query) from the DB I get correct results during the first 2 times but 3rd time onwards I donot get any data.

On the other hand If I somehow manage to kill my app (using Task killer) and then repeat the above process everything works fine.

I have cross-checked my code a number of times and haven't found couldnot find any bug.

Documentation Issue: Link to Downloads

The first paragraph of the README links to the old repo location for the downloads, rather than to this repo's downloads area. Clicking on the erroneous link takes you to a "there are no downloads" page.

Andorid 3.0 support

This is just a query not a real issue.
As i'm exploring the sqlitecipher android here, it says it only supports 2.2 and 2.3.
What about 3.x (honey comb). Are there any known limitations, or is it just not tested yet.

SQLiteOpenHelper not calling onUpgrade

Hello,
I have upgraded my version of SQLCipher from 1.1.0 to 2.0.8, in order to get this to work I require to call upgradeDatabaseFormatFromVersion1To2 on the 1.1.0 DBs. How I have tried to implement this is to increase the DB version and then in the onUpgrade function call the upgradeDatabaseFormatFromVersion1To2 function.

The problem I am having is the onUpgrade function is not being called when I create my SQLiteOpenHelper class. I have check the versions of the DB using getVersion(), they are correct. I have also manually called the upgradeDatabaseFormatFromVersion1To2 function on a 1.1 DB and when I import the DB it works fine.

Any ideas why the onUpgrade is not firing, I thought of function template changes, or maybe the order in which I am calling these functions.

sqlcipher_export - "table android_metadata already exists"

Hi,

I'm testing the v2.0.0 RC5 version.

I'm trying to export files from an unencrypted database to an encrypted database.
I'm using sqlcipher_export() function to export it.
Whenever i call sqlcipher_export() the error "table android_metadata already exists" occurs.
The android_metadata table is a default table created automatically. Of course, when I delete android_metadata table in the target database before calling sqlcipher_export() it works. But it would be nice that SqlCipher for Android would handle this.

Or maybe I'm doing somthing wrong?

[source]
SQLiteDatabase database = SQLiteDatabase.openDatabase(unEncryptedDBPath, "", null, SQLiteDatabase.OPEN_READWRITE);
database.execSQL("ATTACH DATABASE '" + encryptedDBPath + "' AS encrypted KEY 'testit';");
database.rawExecSQL("SELECT sqlcipher_export('encrypted');");
database.execSQL("DETACH DATABASE encrypted;");
database.close();
[/source]

regards,
Tom

loadLibs() will load wrong library after OS update

loadLibs() doesn't do anything to ensure the existing library file that it copied for the previous run is for the correct OS version, this means if i update the OS on my phone, its going to continue to try and load the existing library file which is now for the previous OS version.

Using Content Provider

How can we use contentProvider with the package? when i m trying it, it says unable to get the MyContentProvider.

Error copying icu data fileicudt46l.zip on Android 4.1.1

Environment: Android 4.1.1 (Nexus S), 4.1 (ARM emulator); SQLCipher for Android 2.0.8

Symptoms: On getWriteableDatabase() call in SQLiteDatabase, an error is logged to LogCat (Error copying icu data fileicudt46l.zip), and the attempt to open the database fails in dbopen():

09-12 09:14:34.004: I/TestRunner(16903): net.sqlcipher.database.SQLiteException: not an error
09-12 09:14:34.004: I/TestRunner(16903): at net.sqlcipher.database.SQLiteDatabase.dbopen(Native Method)
09-12 09:14:34.004: I/TestRunner(16903): at net.sqlcipher.database.SQLiteDatabase.(SQLiteDatabase.java:1952)
09-12 09:14:34.004: I/TestRunner(16903): at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:902)
09-12 09:14:34.004: I/TestRunner(16903): at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:945)
09-12 09:14:34.004: I/TestRunner(16903): at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:107)

The same code works fine on 4.0.3 (emulator).

You can see this in action via https://github.com/commonsguy/cwac-prefs (a SharedPreferences implementation that uses SQLCipher for Android as a backing store). The test suite (in the tests/ sub-project) runs fine on 4.0.3 and fails on 4.1.x.

FTS3/4 MATCH not supported?

In the sqlcipher documentation I read, that one should favor FTS over LIKE for performance. I wonder why I get the following error. I reduced my real world example to this simplified case:

Schema:
CREATE VIRTUAL TABLE sites USING fts4(domain, url, title, meta_keys, body)
CREATE TABLE keywords (keyword TEXT)

Query:
SELECT keyword FROM keywords INNER JOIN sites ON sites.title MATCH keywords.keyword

I get a info.guardianproject.database.sqlcipher.SQLiteException: "SQL logic error or missing database".

info.guardianproject.database.sqlcipher.SQLiteQuery.native_fill_window(Native Method)
info.guardianproject.database.sqlcipher.SQLiteQuery.fillWindow(SQLiteQuery.java:73)
info.guardianproject.database.sqlcipher.SQLiteCursor.fillWindow(SQLiteCursor.java:290)
info.guardianproject.database.sqlcipher.SQLiteCursor.getCount(SQLiteCursor.java:271)
android.database.CursorWrapper.getCount(CursorWrapper.java:51)

What about Android 4.0 support?

It seems that the latest release (0.0.6-FINAL) doesn't work properly on Android 4.0 (at least on emulator).

I've tested the library on notepadbot application, as well as on this sample activity:

public class HelloSQLCipherActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        InitializeSQLCipher();
    }

    private void InitializeSQLCipher() {
        SQLiteDatabase.loadLibs(this);
        File databaseFile = getDatabasePath("demo.db");
        databaseFile.mkdirs();
        databaseFile.delete();
        SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(databaseFile, "test123", null);
        database.execSQL("create table t1(a, b)");
        database.execSQL("insert into t1(a, b) values(?, ?)", new Object[]{"one for the money",
                                                                        "two for the show"});
    }
}

And i'm always getting the next exception during the database creation:

12-07 13:02:44.364: E/AndroidRuntime(682): Caused by: info.guardianproject.database.sqlcipher.SQLiteException: not an error
12-07 13:02:44.364: E/AndroidRuntime(682):  at info.guardianproject.database.sqlcipher.SQLiteDatabase.dbopen(Native Method)
12-07 13:02:44.364: E/AndroidRuntime(682):  at info.guardianproject.database.sqlcipher.SQLiteDatabase.<init>(SQLiteDatabase.java:1870)
12-07 13:02:44.364: E/AndroidRuntime(682):  at info.guardianproject.database.sqlcipher.SQLiteDatabase.openDatabase(SQLiteDatabase.java:863)
12-07 13:02:44.364: E/AndroidRuntime(682):  at info.guardianproject.database.sqlcipher.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:897)
12-07 13:02:44.364: E/AndroidRuntime(682):  at info.guardianproject.database.sqlcipher.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:890)
12-07 13:02:44.364: E/AndroidRuntime(682):  at com.sqlcipher.test.SQLCipherTestActivity.initializeSQLCipher(SQLCipherTestActivity.java:23)
12-07 13:02:44.364: E/AndroidRuntime(682):  at com.sqlcipher.test.SQLCipherTestActivity.onCreate(SQLCipherTestActivity.java:15)
12-07 13:02:44.364: E/AndroidRuntime(682):  at android.app.Activity.performCreate(Activity.java:4465)
12-07 13:02:44.364: E/AndroidRuntime(682):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-07 13:02:44.364: E/AndroidRuntime(682):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
12-07 13:02:44.364: E/AndroidRuntime(682):  ... 11 more

On all version below 3.2 everything works fine.

Does SQLCipher for android currently supports version 4.0? Have it been tested yet? Is there some workaround?
(Or maybe i'm just doing something wrong?)

use cipher for existing database in other languages

Hi
I have a DB and add it to my project(in asset). my db has some character in Persian language. when I want create database from and open it, eclipse show followed error:(in logcat)
01-08 14:38:47.156: ERROR/Database(23739): SELECT locale FROM android_metadata failed
01-08 14:38:47.235: ERROR/Database(23739): Failed to setLocale() when constructing, closing the database
01-08 14:38:47.235: ERROR/Database(23739): info.guardianproject.database.sqlcipher.SQLiteException: file is encrypted or is not a database
01-08 14:38:47.235: ERROR/Database(23739): at info.guardianproject.database.sqlcipher.SQLiteDatabase.native_setLocale(Native Method)
.
.
.01-08 14:38:48.795: ERROR/Database(23739): CREATE TABLE android_metadata failed
01-08 14:38:48.836: ERROR/Database(23739): Failed to setLocale() when constructing, closing the database
01-08 14:38:48.836: ERROR/Database(23739): info.guardianproject.database.sqlcipher.SQLiteException: file is encrypted or is not a database
01-08 14:38:48.836: ERROR/Database(23739): at info.guardianproject.database.sqlcipher.SQLiteDatabase.native_setLocale(Native Method)
.
.
.
01-08 14:38:48.865: ERROR/SQLiteOpenHelper(23739): Couldn't open nutrition.db.mp3 for writing (will try read-only):
01-08 14:38:48.865: ERROR/SQLiteOpenHelper(23739): info.guardianproject.database.sqlcipher.SQLiteException: file is encrypted or is not a database
01-08 14:38:48.865: ERROR/SQLiteOpenHelper(23739): at info.guardianproject.database.sqlcipher.SQLiteDatabase.native_setLocale(Native Method)
.
,
.
01-08 14:38:50.716: ERROR/AndroidRuntime(23739): FATAL EXCEPTION: main
01-08 14:38:50.716: ERROR/AndroidRuntime(23739): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tebyan.diet/com.tebyan.diet.StartTabBar}: info.guardianproject.database.sqlcipher.SQLiteException: file is encrypted or is not a database
01-08 14:38:50.716: ERROR/AndroidRuntime(23739): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)

I think cipher can not make android_metadata table, but why?
I add this table manualy in DBMS but does not work!
thanks,
yarand

Lib won't load on 2.3.3

From the list:
http://lists.mayfirst.org/pipermail/guardian-dev/2011-July/000306.html

see the logcat PNG screenshot

Hi guys, first of all, sorry for my english, I attached a screenshot with
the Android logcat, and the exceptio. In the left side you can see the
structure of the files (I try to copy from yours projects).
If you can help me with the steps from zero, that I need to do for
develop
an app for Android I was very very grateful.

NullPointerException when launching example app

Hi,

First of all thanks so much for this project, I think is really important at the moment as there is not a secure way to store critical information in an android device, so this project fills an important gap.

At the moment the project throws a NullPointerException when executing as the EventDataSQLHelper object is still null when the getWritableDatabase is called on him in the onCreate method. Just that!

Thanks so much for your hard work.

Application crashes if Cursor content is bigger than 1MB

I know that this is a limit hard-coded in the CursorWindow implementation...
However I need to store a file in the encrypted db as a blob, but since it is bigger than 1mb I cannot retrive it without causing a crash... Is there a way to bypass this limitation? For example, is there a way to query the blob in chunks of max 1mb?

tags

It'd be really useful if you would create tags in the repo that matched the released downloads, right now, i have no idea which commit v0.4 actually is.

Thanks
Simon

java.lang.UnsatisfiedLinkError: dbopen

06-24 16:47:03.349: E/AndroidRuntime(6500): FATAL EXCEPTION: main
06-24 16:47:03.349: E/AndroidRuntime(6500): java.lang.UnsatisfiedLinkError: dbopen
06-24 16:47:03.349: E/AndroidRuntime(6500): at net.sqlcipher.database.SQLiteDatabase.dbopen(Native Method)
06-24 16:47:03.349: E/AndroidRuntime(6500): at net.sqlcipher.database.SQLiteDatabase.(SQLiteDatabase.java:2030)
06-24 16:47:03.349: E/AndroidRuntime(6500): at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:931)
06-24 16:47:03.349: E/AndroidRuntime(6500): at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1010)
06-24 16:47:03.349: E/AndroidRuntime(6500): at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:236)
06-24 16:47:03.349: E/AndroidRuntime(6500): at dbxyzptlk.l.c.a(Unknown Source)
06-24 16:47:03.349: E/AndroidRuntime(6500): at dbxyzptlk.l.c.(Unknown Source)
06-24 16:47:03.349: E/AndroidRuntime(6500): at com.dropbox.android.util.aE.b(Unknown Source)
06-24 16:47:03.349: E/AndroidRuntime(6500): at com.dropbox.android.util.aE.a(Unknown Source)
06-24 16:47:03.349: E/AndroidRuntime(6500): at com.dropbox.android.DropboxApplication.onCreate(Unknown Source)
06-24 16:47:03.349: E/AndroidRuntime(6500): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
06-24 16:47:03.349: E/AndroidRuntime(6500): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3424)
06-24 16:47:03.349: E/AndroidRuntime(6500): at android.app.ActivityThread.access$2200(ActivityThread.java:123)
06-24 16:47:03.349: E/AndroidRuntime(6500): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:977)
06-24 16:47:03.349: E/AndroidRuntime(6500): at android.os.Handler.dispatchMessage(Handler.java:99)
06-24 16:47:03.349: E/AndroidRuntime(6500): at android.os.Looper.loop(Looper.java:130)
06-24 16:47:03.349: E/AndroidRuntime(6500): at android.app.ActivityThread.main(ActivityThread.java:3835)
06-24 16:47:03.349: E/AndroidRuntime(6500): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 16:47:03.349: E/AndroidRuntime(6500): at java.lang.reflect.Method.invoke(Method.java:507)
06-24 16:47:03.349: E/AndroidRuntime(6500): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
06-24 16:47:03.349: E/AndroidRuntime(6500): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
06-24 16:47:03.349: E/AndroidRuntime(6500): at dalvik.system.NativeStart.main(Native Method)

info.guardianproject.database.sqlcipher.SQLiteException still thrown

On a bad passphrase entry I got this:

03-07 02:14:12.832: E/AndroidRuntime(1503): java.lang.NoClassDefFoundError: info/guardianproject/database/sqlcipher/SQLiteException
03-07 02:14:12.832: E/AndroidRuntime(1503): at net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method)
03-07 02:14:12.832: E/AndroidRuntime(1503): at net.sqlcipher.database.SQLiteDatabase.setLocale(SQLiteDatabase.java:2015)
03-07 02:14:12.832: E/AndroidRuntime(1503): at net.sqlcipher.database.SQLiteDatabase.(SQLiteDatabase.java:1881)
03-07 02:14:12.832: E/AndroidRuntime(1503): at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:864)

Trying to build for 3.0

I've grabbed the latest git repo - https://github.com/guardianproject/android-database-sqlcipher.git

Then I went in, grabbed some SO's from a 3.0 device, (I'm sure I got the majority of them but might be missing an stlport.so as I couldn't find that...).

ls external/android-3.0/
libcrypto.so libicui18n.so liblog.so libssl.so libutils.so
libcutils.so libicuuc.so libnativehelper.so libstlport.so

But when I go to build from Eclipse, I get a bunch of Cursor errors... along the lines of:

The type BulkCursorToCursorAdaptor must implement the inherited abstract method Cursor.getType(int)

This happens in BulkCursorToCursorAdpator.java, and similar issues about base classes in a few other cursor-related files...

So what am I doing wrong here? I went into the external and I can rebuild the libcrypto.so as well as the libssl.so but that doesn't seem like the right thing to do, it seems
that I need to align my so with the java via the jni but I must be missing a step...

Any thoughts??

Converting the existing database to use SQL cipher library

Hi,
I was wondering if there is an easy way to update the app which is already using an unencrypted SQLite database to use the ciphered one? Obviously, one could load each value from the database manually, encrypt it and then write it back and then continue using the library in a standard way, but is there a more straightforward way?

Thanks,
Andrej

IllegalStateException: UNKNOWN type 5 running query on Android 3.1

I'm using the beta release, my app runs fine on Android 2.2 & 2.3, but on 3.1 (on a galaxy tab) i see this "IllegalStateException: UNKNOWN type 5" error running a query.

E/AndroidRuntime( 1311): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime( 1311): java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime( 1311): at android.os.AsyncTask$3.done(AsyncTask.java:266)
E/AndroidRuntime( 1311): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
E/AndroidRuntime( 1311): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
E/AndroidRuntime( 1311): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
E/AndroidRuntime( 1311): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
E/AndroidRuntime( 1311): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
E/AndroidRuntime( 1311): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
E/AndroidRuntime( 1311): at java.lang.Thread.run(Thread.java:1020)
E/AndroidRuntime( 1311): Caused by: java.lang.IllegalStateException: UNKNOWN type 5
E/AndroidRuntime( 1311): at android.database.CursorWindow.getString_native(Native Method)
E/AndroidRuntime( 1311): at android.database.CursorWindow.getString(CursorWindow.java:372)
E/AndroidRuntime( 1311): at info.guardianproject.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:52)
E/AndroidRuntime( 1311): at com.salesforce.crm.db.CursorHelper.getString(CursorHelper.java:40)
E/AndroidRuntime( 1311): at com.salesforce.crm.datastore.SCTab.(SCTab.java:23)
E/AndroidRuntime( 1311): at com.salesforce.crm.datastore.SCFactory.getAllTabs(SCFactory.java:90)
E/AndroidRuntime( 1311): at com.salesforce.crm.HomeScreenMenuFragment$TabLoader.loadInBackground(HomeScreenMenuFragment.java:103)
E/AndroidRuntime( 1311): at com.salesforce.crm.HomeScreenMenuFragment$TabLoader.loadInBackground(HomeScreenMenuFragment.java:88)
E/AndroidRuntime( 1311): at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:243)
E/AndroidRuntime( 1311): at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:52)
E/AndroidRuntime( 1311): at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:41)
E/AndroidRuntime( 1311): at android.os.AsyncTask$2.call(AsyncTask.java:252)
E/AndroidRuntime( 1311): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
E/AndroidRuntime( 1311): ... 4 more

ICU dat file on SD card

Add the ability to specify the storage location of the unzipped ICU dat file. Specifically onto a SD card, this is a practical location for older devices that have limited onboard storage.

Cursor.copyStringToBuffer override is an empty method in 0.0.6

In the 0.0.6 update, the method SQLiteCursor.copyStringToBuffer override is an empty method, rendering it inoperable. Seems like it either needs to be rewritten or the method should be removed so it reverts to the AbstractWindowedCursor implementation.

file handle leak?

I have a test suite for my app that does a lot of open/rawQuery/execSQl/close calls on the database, using the standard SQLiteDatabase this test suite runs fine to completion (tested on both 2.1 & 2.2). When i switch to using sqlcipher the test suite gets about 50% through and the stops with a bunch of errors that all seem related to this log line

E/MemoryHeapBase( 1028): error creating ashmem region: Too many open files
E/CursorWindow( 1028): CursorWindow heap allocation failed
I/TestRunner( 1028): ----- begin exception -----
I/TestRunner( 1028):
I/TestRunner( 1028): java.lang.IllegalStateException: Couldn't init cursor window

Are you aware of any file handle leaks, or areas where you may manage file handles differently to the OS supplied SQLiteDatabase ? I'm working on putting together a simple repo case for this.

I've seen this with v0.4 & v0.3 releases.

Building android-database-sqlcipher

When I try to build this using ndk I get the following error, any ideas?

$ ndk-build
Compile++ thumb : database_sqlcipher <= CursorWindow.cpp
In file included from D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.cpp:20:
D:/cygwin/home/userX/sqlcipher/jni/include/utils/Log.h:31:24: error: cutils/log.h: No such file or directory
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.cpp:21:35: error: binder/MemoryHeapBase.h: No such file or directory
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.cpp:22:31: error: binder/MemoryBase.h: No such file or directory
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.cpp:29:21: error: JNIHelp.h: No such file or directory
In file included from D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.cpp:31:
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.h:29:28: error: binder/IMemory.h: No such file or directory
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.h:30:27: error: utils/RefBase.h: No such file or directory
In file included from D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.cpp:31:
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.h:110: error: expected unqualified-id before '<' token
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.h:110: error: expected ')' before '<' token
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.h:110: error: expected ';' before '<' token
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.h:114: error: ISO C++ forbids declaration of 'sp' with no type
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.h:114: error: invalid use of '::'
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.h:114: error: expected ';' before '<' token
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.h:116: error: expected ';' before 'size_t'
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.h:198: error: ISO C++ forbids declaration of 'sp' with no type
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.h:198: error: invalid use of '::'
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.h:198: error: expected ';' before '<' token
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.h: In member function 'bool android::CursorWindow::setNumColumns(uint32_t)':
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.h:129: error: 'LOGE' was not declared in this scope
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.cpp: At global scope:
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.cpp:41: error: expected unqualified-id before '<' token
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.cpp:41: error: expected ')' before '<' token
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.cpp:41: error: expected initializer before '<' token
D:/cygwin/home/userX/sqlcipher/jni/CursorWindow.cpp:413: error: expected '}' at end of input
make: *** [/home/userX/sqlcipher/obj/local/armeabi/objs/database_sqlcipher/CursorWindow.o] Error 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.