diff --git a/sqlcipher-2.3-testkey.db b/sqlcipher-3.0-testkey.db similarity index 100% rename from sqlcipher-2.3-testkey.db rename to sqlcipher-3.0-testkey.db diff --git a/src/crypto_impl.c b/src/crypto_impl.c index 804506f7..ae789745 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 22c5367a..968eff87 100644 --- a/test/crypto.test +++ b/test/crypto.test @@ -1643,10 +1643,10 @@ 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;