diff --git a/sqlcipher-1.1.8-testkey.db b/sqlcipher-1.1.8-testkey.db index 36ef196..1e069c5 100644 Binary files a/sqlcipher-1.1.8-testkey.db and b/sqlcipher-1.1.8-testkey.db differ diff --git a/sqlcipher-2.0-be-testkey.db b/sqlcipher-2.0-be-testkey.db index f6f70f8..fcabab3 100644 Binary files a/sqlcipher-2.0-be-testkey.db and b/sqlcipher-2.0-be-testkey.db differ diff --git a/sqlcipher-2.0-beta-testkey.db b/sqlcipher-2.0-beta-testkey.db index 5db36bb..394c915 100755 Binary files a/sqlcipher-2.0-beta-testkey.db and b/sqlcipher-2.0-beta-testkey.db differ diff --git a/sqlcipher-2.0-le-testkey.db b/sqlcipher-2.0-le-testkey.db index 00a431b..15a9723 100644 Binary files a/sqlcipher-2.0-le-testkey.db and b/sqlcipher-2.0-le-testkey.db differ diff --git a/sqlcipher-2.3-testkey.db b/sqlcipher-2.3-testkey.db deleted file mode 100644 index da27623..0000000 Binary files a/sqlcipher-2.3-testkey.db and /dev/null differ diff --git a/sqlcipher-3.0-testkey.db b/sqlcipher-3.0-testkey.db new file mode 100644 index 0000000..6af4430 Binary files /dev/null and b/sqlcipher-3.0-testkey.db differ diff --git a/sqlcipher.xcodeproj/project.pbxproj b/sqlcipher.xcodeproj/project.pbxproj index cc2230d..1e8ce83 100644 --- a/sqlcipher.xcodeproj/project.pbxproj +++ b/sqlcipher.xcodeproj/project.pbxproj @@ -149,7 +149,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "./configure --enable-tempstore=yes --with-crypto-lib=openssl CFLAGS=\"-DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2 -DSQLCIPHER_CRYPTO_OPENSSL\"\nmake sqlite3.c\nexit 0"; + shellScript = "./configure --enable-tempstore=yes --with-crypto-lib=commoncrypto CFLAGS=\"-DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2 -DSQLCIPHER_CRYPTO_CC\"\nmake sqlite3.c\nexit 0"; }; /* End PBXShellScriptBuildPhase section */ @@ -236,7 +236,8 @@ 1DEB91F008733DB70010E9CD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - "ARCHS[sdk=iphoneos*]" = "$(ARCHS_STANDARD)"; + "ARCHS[sdk=iphoneos*]" = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; + "ARCHS[sdk=iphonesimulator*]" = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; "ARCHS[sdk=macosx*]" = ( x86_64, i386, @@ -245,28 +246,34 @@ GCC_OPTIMIZATION_LEVEL = 0; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 4.3; + "IPHONEOS_DEPLOYMENT_TARGET[arch=arm64]" = 6.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator macosx iphoneos"; + VALID_ARCHS = "arm64 armv7 armv7s x86_64 i386"; }; name = Debug; }; 1DEB91F108733DB70010E9CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - "ARCHS[sdk=iphoneos*]" = ( - armv7s, - armv7, + "ARCHS[sdk=iphoneos*]" = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; + "ARCHS[sdk=iphonesimulator*]" = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; + "ARCHS[sdk=macosx*]" = ( + i386, + x86_64, ); - "ARCHS[sdk=macosx*]" = "$(ARCHS_STANDARD)"; GCC_C_LANGUAGE_STANDARD = c99; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 4.3; + "IPHONEOS_DEPLOYMENT_TARGET[arch=arm64]" = 6.0; SDKROOT = iphoneos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator macosx iphoneos"; + VALID_ARCHS = "arm64 armv7 armv7s x86_64 i386"; }; name = Release; }; diff --git a/src/crypto_impl.c b/src/crypto_impl.c index 804506f..ae78974 100644 --- a/src/crypto_impl.c +++ b/src/crypto_impl.c @@ -82,6 +82,7 @@ struct codec_ctx { Btree *pBt; cipher_ctx *read_ctx; cipher_ctx *write_ctx; + unsigned int skip_read_hmac; }; int sqlcipher_register_provider(sqlcipher_provider *p) { @@ -756,7 +757,7 @@ int sqlcipher_page_cipher(codec_ctx *ctx, int for_ctx, Pgno pgno, int mode, int memcpy(iv_out, iv_in, c_ctx->iv_sz); /* copy the iv from the input to output buffer */ } - if((c_ctx->flags & CIPHER_FLAG_HMAC) && (mode == CIPHER_DECRYPT)) { + if((c_ctx->flags & CIPHER_FLAG_HMAC) && (mode == CIPHER_DECRYPT) && !ctx->skip_read_hmac) { if(sqlcipher_page_hmac(c_ctx, pgno, in, size + c_ctx->iv_sz, hmac_out) != SQLITE_OK) { sqlcipher_memset(out, 0, page_sz); CODEC_TRACE(("codec_cipher: hmac operations failed for pgno=%d\n", pgno)); @@ -1048,7 +1049,7 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) { CODEC_TRACE(("cannot migrate - SQL statements in progress")); goto handle_error; } - + /* Save the current value of the database flags so that it can be ** restored before returning. Then set the writable-schema flag, and ** disable CHECK and foreign key constraints. */ @@ -1063,7 +1064,7 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) { pDest = db->aDb[0].pBt; pDb = &(db->aDb[db->nDb-1]); pSrc = pDb->pBt; - + rc = sqlite3_exec(db, "BEGIN;", NULL, NULL, NULL); rc = sqlite3BtreeBeginTrans(pSrc, 2); rc = sqlite3BtreeBeginTrans(pDest, 2); @@ -1071,17 +1072,18 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) { assert( 1==sqlite3BtreeIsInTrans(pDest) ); assert( 1==sqlite3BtreeIsInTrans(pSrc) ); - sqlite3CodecGetKey(db, db->nDb - 1, (void**)&key, &password_sz); sqlite3CodecAttach(db, 0, key, password_sz); + sqlite3pager_get_codec(pDest->pBt->pPager, (void**)&ctx); + ctx->skip_read_hmac = 1; for(i=0; iskip_read_hmac = 0; if( rc!=SQLITE_OK ) goto handle_error; rc = sqlite3BtreeCommit(pDest); diff --git a/test/crypto.test b/test/crypto.test index 22c5367..75c7f16 100644 --- a/test/crypto.test +++ b/test/crypto.test @@ -42,6 +42,7 @@ file delete -force test4.db set testdir [file dirname $argv0] source $testdir/tester.tcl +set old_pending_byte [sqlite3_test_control_pending_byte 0x40000000] # If the library is not compiled with has_codec support then # skip all tests in this file. @@ -932,17 +933,18 @@ file delete -force test.db # open a 1.1.8 database using the new code, HMAC disabled do_test open-1.1.8-database { - sqlite_orig db sqlcipher-1.1.8-testkey.db + file copy -force sqlcipher-1.1.8-testkey.db test.db + sqlite_orig db test.db execsql { PRAGMA key = 'testkey'; - PRAGMA cipher_use_hmac = OFF; + PRAGMA cipher_use_hmac = off; PRAGMA kdf_iter = 4000; SELECT count(*) FROM t1; - SELECT * FROM t1; + SELECT distinct * FROM t1; } -} {4 1 1 one one 1 2 one two} +} {75709 1 1 one one 1 2 one two 1 2} db close - +file delete -force test.db # open a 1.1.8 database without hmac, then copy the data do_test attach-and-copy-1.1.8 { @@ -963,9 +965,9 @@ do_test attach-and-copy-1.1.8 { execsql { PRAGMA key = 'testkey-hmac'; SELECT count(*) FROM t1; - SELECT * FROM t1; + SELECT distinct * FROM t1; } -} {4 1 1 one one 1 2 one two} +} {75709 1 1 one one 1 2 one two 1 2} db close file delete -force test.db @@ -1426,7 +1428,7 @@ do_test default-hmac-kdf-attach { PRAGMA cipher_default_use_hmac = ON; PRAGMA cipher_default_kdf_iter = 64000; } -} {4 4} +} {75709 75709} db close file delete -force test.db @@ -1469,7 +1471,7 @@ do_test change-default-hmac-kdf-attach { PRAGMA cipher_default_use_hmac = ON; PRAGMA cipher_default_kdf_iter = 64000; } -} {1 4} +} {1 75709} db close file delete -force test.db @@ -1643,16 +1645,16 @@ do_test multipage-schema-autovacuum-shortread-wal { db close file delete -force test.db -# open a 2.3 database with little endian hmac page numbers (default) +# open a 3.0 database with little endian hmac page numbers (default) # verify it can be opened -do_test open-2.3-le-database { - sqlite_orig db sqlcipher-2.3-testkey.db +do_test open-3.0-le-database { + sqlite_orig db sqlcipher-3.0-testkey.db execsql { PRAGMA key = 'testkey'; SELECT count(*) FROM t1; - SELECT * FROM t1; + SELECT distinct * FROM t1; } -} {4 1 1 one one 1 2 one two} +} {78536 1 1 one one 1 2 one two} db close # open a 2.0 database with little endian hmac page numbers (default) @@ -1663,9 +1665,9 @@ do_test open-2.0-le-database { PRAGMA key = 'testkey'; PRAGMA kdf_iter = 4000; SELECT count(*) FROM t1; - SELECT * FROM t1; + SELECT distinct * FROM t1; } -} {4 1 1 one one 1 2 one two} +} {78536 1 1 one one 1 2 one two} db close # open a 2.0 database with big-endian hmac page numbers @@ -1677,9 +1679,9 @@ do_test open-2.0-be-database { PRAGMA cipher_hmac_pgno = be; PRAGMA kdf_iter = 4000; SELECT count(*) FROM t1; - SELECT * FROM t1; + SELECT distinct * FROM t1; } -} {4 1 1 one one 1 2 one two} +} {78536 1 1 one one 1 2 one two} db close # open a 2.0 database with big-endian hmac page numbers @@ -1704,9 +1706,9 @@ do_test be-to-le-migration { execsql { PRAGMA key = 'testkey'; SELECT count(*) FROM t1; - SELECT * FROM t1; + SELECT distinct * FROM t1; } -} {4 1 1 one one 1 2 one two} +} {78536 1 1 one one 1 2 one two} db close file delete -force test.db @@ -1950,9 +1952,9 @@ do_test open-2.0-beta-database { PRAGMA fast_kdf_iter = 4000; PRAGMA cipher_hmac_salt_mask = "x'00'"; SELECT count(*) FROM t1; - SELECT * FROM t1; + SELECT distinct * FROM t1; } -} {2 test-0-0 test-0-1 test-1-0 test-1-1} +} {38768 test-0-0 test-0-1 test-1-0 test-1-1} db close # open a 2.0 beta database @@ -1981,7 +1983,7 @@ do_test 2.0-beta-to-2.0-migration { sqlite_orig db test.db execsql { PRAGMA key = 'testkey'; - SELECT * FROM t1; + SELECT distinct * FROM t1; } } {test-0-0 test-0-1 test-1-0 test-1-1} db close @@ -2112,4 +2114,5 @@ db close file delete -force test.db file delete -force new.db +sqlite3_test_control_pending_byte $old_pending_byte finish_test