diff --git a/.gitignore b/.gitignore index f68644eb92..3bc185ae51 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,5 @@ xcuserdata/* /sqlite3ext.h /libsqlcipher.la /.DS_Store +/build +/CouchbaseLite/SQLCipher/ \ No newline at end of file diff --git a/CouchbaseLite/README-CouchbaseLite.md b/CouchbaseLite/README-CouchbaseLite.md new file mode 100644 index 0000000000..3552ee604a --- /dev/null +++ b/CouchbaseLite/README-CouchbaseLite.md @@ -0,0 +1,13 @@ +This is a build of [SQLCipher][SQLCIPHER] -- a variant of SQLite with encryption support added -- for use with [Couchbase Lite][CBL]. Binaries are provided for Mac OS and iOS; the latter one is 'fat' so it supports both the simulator and real devices. + +To enable database encryption in Couchbase Lite, do the following: + +1. Add the appropriate libsqlcipher library from this folder to your Xcode project. +2. In your application target's Build Phases tab, open 'Link Binary With Libraries' and: + 1. Remove libsqlite.dylib (if present.) + 2. Press the "+" button and add the libsqlcipher library that you added to the project in step 1. +3. Encryption is _not_ automatic. Modify your source code to call `-[CBLManager registerEncryptionKey:forDatabaseNamed:]` before opening or creating any database that should be encrypted. See this method's API documentation in CBLManager.h for more details. + Alternatively, you can use the utility class CBLEncryptionController, which includes the UI support for prompting the user for passwords, and for using Touch ID authentication on compatible devices. You'll find it in the 'Extras' folder of the Couchbase Lite distribution. Just add the .m and .h files to your target. + +[SQLCIPHER]: http://sqlcipher.net +[CBL]: https://github.com/couchbase/couchbase-lite-ios diff --git a/CouchbaseLite/build.sh b/CouchbaseLite/build.sh new file mode 100755 index 0000000000..db29091553 --- /dev/null +++ b/CouchbaseLite/build.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +BUILD=../build +DST=SQLCipher + +#rm -rf $BUILD +rm -rf $DST + +pushd .. +xcodebuild -sdk macosx10.10 +xcodebuild -sdk iphoneos8.1 +xcodebuild -sdk iphonesimulator8.1 +popd + +echo "Copying built libraries to '$DST' ..." +mkdir $DST +cp $BUILD/Release/libsqlcipher.a $DST/libsqlcipher-macos.a +lipo -create $BUILD/Release-iphoneos/libsqlcipher.a $BUILD/Release-iphonesimulator/libsqlcipher.a \ + -output $DST/libsqlcipher-ios.a +cp README-CouchbaseLite.md $DST/README.md + +echo "Done!" \ No newline at end of file diff --git a/sqlcipher.xcodeproj/project.pbxproj b/sqlcipher.xcodeproj/project.pbxproj index b15edccc5b..bad5927ce5 100644 --- a/sqlcipher.xcodeproj/project.pbxproj +++ b/sqlcipher.xcodeproj/project.pbxproj @@ -516,13 +516,8 @@ "-DSQLITE_TEMP_STORE=2", "-DSQLITE_THREADSAFE", "-DSQLCIPHER_CRYPTO_CC", - ); - "OTHER_CFLAGS[arch=armv6]" = ( - "-mno-thumb", - "-DSQLITE_HAS_CODEC", - "-DSQLITE_TEMP_STORE=2", - "-DSQLITE_THREADSAFE", - "-DSQLCIPHER_CRYPTO_CC", + "-DSQLITE_ENABLE_RTREE=1", + "-DSQLITE_ENABLE_FTS3", ); OTHER_LDFLAGS = ""; PRODUCT_NAME = sqlcipher; @@ -545,15 +540,8 @@ "-DSQLITE_TEMP_STORE=2", "-DSQLITE_THREADSAFE", "-DSQLCIPHER_CRYPTO_CC", - ); - "OTHER_CFLAGS[arch=armv6]" = ( - "-mno-thumb", - "-DSQLITE_HAS_CODEC", - "-DNDEBUG", - "-DSQLITE_OS_UNIX=1", - "-DSQLITE_TEMP_STORE=2", - "-DSQLITE_THREADSAFE", - "-DSQLCIPHER_CRYPTO_CC", + "-DSQLITE_ENABLE_FTS3", + "-DSQLITE_ENABLE_RTREE=1", ); OTHER_LDFLAGS = ""; PRODUCT_NAME = sqlcipher; @@ -582,7 +570,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 4.3; "IPHONEOS_DEPLOYMENT_TARGET[arch=arm64]" = 7.0; - ONLY_ACTIVE_ARCH = YES; + ONLY_ACTIVE_ARCH = NO; SDKROOT = iphoneos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator macosx iphoneos"; diff --git a/src/crypto.h b/src/crypto.h index 695ff3cc74..65fb48d6f8 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -37,7 +37,8 @@ #if !defined (SQLCIPHER_CRYPTO_CC) \ && !defined (SQLCIPHER_CRYPTO_LIBTOMCRYPT) \ - && !defined (SQLCIPHER_CRYPTO_OPENSSL) + && !defined (SQLCIPHER_CRYPTO_OPENSSL) \ + && !defined (SQLCIPHER_CRYPTO_MBEDTLS) #define SQLCIPHER_CRYPTO_OPENSSL #endif diff --git a/src/crypto_impl.c b/src/crypto_impl.c index e43704df68..7270cf721c 100644 --- a/src/crypto_impl.c +++ b/src/crypto_impl.c @@ -130,6 +130,9 @@ void sqlcipher_activate() { #elif defined (SQLCIPHER_CRYPTO_OPENSSL) extern int sqlcipher_openssl_setup(sqlcipher_provider *p); sqlcipher_openssl_setup(p); +#elif defined (SQLCIPHER_CRYPTO_MBEDTLS) + extern int sqlcipher_mbedtls_setup(sqlcipher_provider *p); + sqlcipher_mbedtls_setup(p); #else #error "NO DEFAULT SQLCIPHER CRYPTO PROVIDER DEFINED" #endif