From c101969647ec595a0da2d0fb470967a28004dbd5 Mon Sep 17 00:00:00 2001 From: Jens Alfke Date: Tue, 17 Feb 2015 09:29:33 -0800 Subject: [PATCH 1/3] Tweaked Xcode build settings for Couchbase Lite * Defined SQLITE_ENABLE_FTS3 and SQLITE_ENABLE_RTREE=1 * Build all architectures (not just the active one) on OS X * Removed some obsolete armv6 settings --- sqlcipher.xcodeproj/project.pbxproj | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/sqlcipher.xcodeproj/project.pbxproj b/sqlcipher.xcodeproj/project.pbxproj index 5c66f770b8..325bd99690 100644 --- a/sqlcipher.xcodeproj/project.pbxproj +++ b/sqlcipher.xcodeproj/project.pbxproj @@ -200,13 +200,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; @@ -229,15 +224,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; @@ -265,7 +253,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"; From 0f6b07c4590431f72eceb1f25241234bc20e0a71 Mon Sep 17 00:00:00 2001 From: Jens Alfke Date: Tue, 17 Feb 2015 11:24:35 -0800 Subject: [PATCH 2/3] Added Couchbase Lite build script and README --- .gitignore | 2 ++ CouchbaseLite/README-CouchbaseLite.md | 13 +++++++++++++ CouchbaseLite/build.sh | 23 +++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 CouchbaseLite/README-CouchbaseLite.md create mode 100755 CouchbaseLite/build.sh 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 From 740a7e73d4dbfa8303aaa3fdd6e9b4748ee1d16e Mon Sep 17 00:00:00 2001 From: Jim Borden Date: Sat, 1 Jul 2017 15:44:37 +0900 Subject: [PATCH 3/3] Add configuration for mbed TLS implementation --- src/crypto.h | 3 ++- src/crypto_impl.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) 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