mirror of
https://github.com/status-im/sqlcipher.git
synced 2025-02-22 16:58:14 +00:00
Ignore hmac read during Btree file copy
This commit is contained in:
parent
314f5735d9
commit
fc2fcff453
@ -82,6 +82,7 @@ struct codec_ctx {
|
|||||||
Btree *pBt;
|
Btree *pBt;
|
||||||
cipher_ctx *read_ctx;
|
cipher_ctx *read_ctx;
|
||||||
cipher_ctx *write_ctx;
|
cipher_ctx *write_ctx;
|
||||||
|
unsigned int skip_read_hmac;
|
||||||
};
|
};
|
||||||
|
|
||||||
int sqlcipher_register_provider(sqlcipher_provider *p) {
|
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 */
|
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) {
|
if(sqlcipher_page_hmac(c_ctx, pgno, in, size + c_ctx->iv_sz, hmac_out) != SQLITE_OK) {
|
||||||
sqlcipher_memset(out, 0, page_sz);
|
sqlcipher_memset(out, 0, page_sz);
|
||||||
CODEC_TRACE(("codec_cipher: hmac operations failed for pgno=%d\n", pgno));
|
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"));
|
CODEC_TRACE(("cannot migrate - SQL statements in progress"));
|
||||||
goto handle_error;
|
goto handle_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the current value of the database flags so that it can be
|
/* Save the current value of the database flags so that it can be
|
||||||
** restored before returning. Then set the writable-schema flag, and
|
** restored before returning. Then set the writable-schema flag, and
|
||||||
** disable CHECK and foreign key constraints. */
|
** disable CHECK and foreign key constraints. */
|
||||||
@ -1063,7 +1064,7 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
|
|||||||
pDest = db->aDb[0].pBt;
|
pDest = db->aDb[0].pBt;
|
||||||
pDb = &(db->aDb[db->nDb-1]);
|
pDb = &(db->aDb[db->nDb-1]);
|
||||||
pSrc = pDb->pBt;
|
pSrc = pDb->pBt;
|
||||||
|
|
||||||
rc = sqlite3_exec(db, "BEGIN;", NULL, NULL, NULL);
|
rc = sqlite3_exec(db, "BEGIN;", NULL, NULL, NULL);
|
||||||
rc = sqlite3BtreeBeginTrans(pSrc, 2);
|
rc = sqlite3BtreeBeginTrans(pSrc, 2);
|
||||||
rc = sqlite3BtreeBeginTrans(pDest, 2);
|
rc = sqlite3BtreeBeginTrans(pDest, 2);
|
||||||
@ -1071,17 +1072,18 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
|
|||||||
assert( 1==sqlite3BtreeIsInTrans(pDest) );
|
assert( 1==sqlite3BtreeIsInTrans(pDest) );
|
||||||
assert( 1==sqlite3BtreeIsInTrans(pSrc) );
|
assert( 1==sqlite3BtreeIsInTrans(pSrc) );
|
||||||
|
|
||||||
|
|
||||||
sqlite3CodecGetKey(db, db->nDb - 1, (void**)&key, &password_sz);
|
sqlite3CodecGetKey(db, db->nDb - 1, (void**)&key, &password_sz);
|
||||||
sqlite3CodecAttach(db, 0, 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; i<ArraySize(aCopy); i+=2){
|
for(i=0; i<ArraySize(aCopy); i+=2){
|
||||||
sqlite3BtreeGetMeta(pSrc, aCopy[i], &meta);
|
sqlite3BtreeGetMeta(pSrc, aCopy[i], &meta);
|
||||||
rc = sqlite3BtreeUpdateMeta(pDest, aCopy[i], meta+aCopy[i+1]);
|
rc = sqlite3BtreeUpdateMeta(pDest, aCopy[i], meta+aCopy[i+1]);
|
||||||
if( NEVER(rc!=SQLITE_OK) ) goto handle_error;
|
if( NEVER(rc!=SQLITE_OK) ) goto handle_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sqlite3BtreeCopyFile(pDest, pSrc);
|
rc = sqlite3BtreeCopyFile(pDest, pSrc);
|
||||||
|
ctx->skip_read_hmac = 0;
|
||||||
if( rc!=SQLITE_OK ) goto handle_error;
|
if( rc!=SQLITE_OK ) goto handle_error;
|
||||||
rc = sqlite3BtreeCommit(pDest);
|
rc = sqlite3BtreeCommit(pDest);
|
||||||
|
|
||||||
|
@ -1643,10 +1643,10 @@ do_test multipage-schema-autovacuum-shortread-wal {
|
|||||||
db close
|
db close
|
||||||
file delete -force test.db
|
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
|
# verify it can be opened
|
||||||
do_test open-2.3-le-database {
|
do_test open-3.0-le-database {
|
||||||
sqlite_orig db sqlcipher-2.3-testkey.db
|
sqlite_orig db sqlcipher-3.0-testkey.db
|
||||||
execsql {
|
execsql {
|
||||||
PRAGMA key = 'testkey';
|
PRAGMA key = 'testkey';
|
||||||
SELECT count(*) FROM t1;
|
SELECT count(*) FROM t1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user