[libgda] SQLCipher: updated to version 1.1.8



commit d95983868dab029e4ea18aa9b9c48c10218db8ca
Author: Vivien Malerba <malerba gnome-db org>
Date:   Tue Oct 5 20:24:20 2010 +0200

    SQLCipher: updated to version 1.1.8

 providers/sqlcipher/sqlcipher.patch |   47 ++++++++++++++++++++++++++---------
 1 files changed, 35 insertions(+), 12 deletions(-)
---
diff --git a/providers/sqlcipher/sqlcipher.patch b/providers/sqlcipher/sqlcipher.patch
index 77d2090..1bc56f3 100644
--- a/providers/sqlcipher/sqlcipher.patch
+++ b/providers/sqlcipher/sqlcipher.patch
@@ -1,6 +1,6 @@
---- sqlite3.c.sqlite	2010-09-13 21:54:33.000000000 +0200
-+++ sqlite3.c	2010-09-13 21:51:52.000000000 +0200
-@@ -10994,6 +10994,1320 @@
+--- sqlite3.c.sqlite	2010-10-05 08:59:19.000000000 +0200
++++ sqlite3.c	2010-10-05 08:58:35.000000000 +0200
+@@ -10994,6 +10994,1343 @@
  #endif /* _SQLITEINT_H_ */
  
  /************** End of sqliteInt.h *******************************************/
@@ -1080,7 +1080,7 @@
 + */
 +void* sqlite3Codec(void *iCtx, void *data, Pgno pgno, int mode) {
 +  codec_ctx *ctx = (codec_ctx *) iCtx;
-+  int pg_sz = sqlite3BtreeGetPageSize(ctx->pBt);
++  int pg_sz = SQLITE_DEFAULT_PAGE_SIZE;
 +  int offset = 0;
 +  unsigned char *pData = (unsigned char *) data;
 + 
@@ -1155,7 +1155,7 @@
 +    /* pre-allocate a page buffer of PageSize bytes. This will
 +       be used as a persistent buffer for encryption and decryption 
 +       operations to avoid overhead of multiple memory allocations*/
-+    ctx->buffer = sqlite3Malloc(sqlite3BtreeGetPageSize(ctx->pBt));
++    ctx->buffer = sqlite3Malloc(SQLITE_DEFAULT_PAGE_SIZE);
 +    if(ctx->buffer == NULL) return SQLITE_NOMEM;
 +     
 +    /* allocate space for salt data. Then read the first 16 bytes 
@@ -1166,6 +1166,7 @@
 +    ctx->kdf_salt = sqlite3Malloc(ctx->kdf_salt_sz);
 +    if(ctx->kdf_salt == NULL) return SQLITE_NOMEM;
 +
++
 +    fd = sqlite3Pager_get_fd(pPager);
 +    if(fd == NULL || sqlite3OsRead(fd, ctx->kdf_salt, FILE_HEADER_SZ, 0) != SQLITE_OK) {
 +      /* if unable to read the bytes, generate random salt */
@@ -1178,8 +1179,27 @@
 +    codec_set_kdf_iter(db, nDb, PBKDF2_ITER, 0);
 +    codec_set_pass_key(db, nDb, zKey, nKey, 0);
 +    cipher_ctx_copy(ctx->write_ctx, ctx->read_ctx);
++
++    sqlite3_mutex_enter(db->mutex);
 +    
-+    sqlite3BtreeSetPageSize(ctx->pBt, sqlite3BtreeGetPageSize(ctx->pBt), EVP_MAX_IV_LENGTH, 0);
++    /* Always overwrite page size and set to the default because the first page of the database
++       in encrypted and thus sqlite can't effectively determine the pagesize. this causes an issue in 
++       cases where bytes 16 & 17 of the page header are a power of 2 as reported by John Lehman
++
++       Note: before forcing the page size we need to force pageSizeFixed to 0, else  
++             sqliteBtreeSetPageSize will block the change 
++    */
++    pDb->pBt->pBt->pageSizeFixed = 0; 
++    sqlite3BtreeSetPageSize(ctx->pBt, SQLITE_DEFAULT_PAGE_SIZE, EVP_MAX_IV_LENGTH, 0);
++
++    /* if fd is null, then this is an in-memory database and
++       we dont' want to overwrite the AutoVacuum settings
++       if not null, then set to the default */
++    if(fd != NULL) { 
++      sqlite3BtreeSetAutoVacuum(ctx->pBt, SQLITE_DEFAULT_AUTOVACUUM);
++    }
++
++    sqlite3_mutex_leave(db->mutex);
 +  }
 +  return SQLITE_OK;
 +}
@@ -1244,10 +1264,12 @@
 +        ctx->read_ctx->key_sz = ctx->read_ctx->iv_sz =  ctx->read_ctx->pass_sz = 0;
 +      }
 +
++      sqlite3_mutex_enter(db->mutex);
++
 +      if(ctx->read_ctx->iv_sz != ctx->write_ctx->iv_sz) {
 +        char *error;
 +        CODEC_TRACE(("sqlite3_rekey: updating page size for iv_sz change from %d to %d\n", ctx->read_ctx->iv_sz, ctx->write_ctx->iv_sz));
-+        db->nextPagesize = sqlite3BtreeGetPageSize(pDb->pBt);
++        db->nextPagesize = SQLITE_DEFAULT_PAGE_SIZE;
 +        pDb->pBt->pBt->pageSizeFixed = 0; /* required for sqlite3BtreeSetPageSize to modify pagesize setting */
 +        sqlite3BtreeSetPageSize(pDb->pBt, db->nextPagesize, EVP_MAX_IV_LENGTH, 0);
 +        sqlite3RunVacuum(&error, db);
@@ -1280,7 +1302,7 @@
 +      /* if commit was successful commit and copy the rekey data to current key, else rollback to release locks */
 +      if(rc == SQLITE_OK) { 
 +        CODEC_TRACE(("sqlite3_rekey: committing\n"));
-+        db->nextPagesize = sqlite3BtreeGetPageSize(pDb->pBt);
++        db->nextPagesize = SQLITE_DEFAULT_PAGE_SIZE;
 +        rc = sqlite3BtreeCommit(pDb->pBt); 
 +        cipher_ctx_copy(ctx->read_ctx, ctx->write_ctx);
 +      } else {
@@ -1289,6 +1311,7 @@
 +      }
 +
 +      ctx->mode_rekey = 0;
++      sqlite3_mutex_leave(db->mutex);
 +    }
 +    return SQLITE_OK;
 +  }
@@ -1321,7 +1344,7 @@
  /************** Begin file global.c ******************************************/
  /*
  ** 2008 June 13
-@@ -40807,11 +42121,40 @@
+@@ -40807,11 +42144,40 @@
    CODEC2(pPg->pPager, pPg->pData, pPg->pgno, 6, return 0, aData);
    return aData;
  }
@@ -1365,7 +1388,7 @@
  
  /************** End of pager.c ***********************************************/
  /************** Begin file wal.c *********************************************/
-@@ -43340,854 +44683,208 @@
+@@ -43340,854 +44706,208 @@
  #if defined(SQLITE_HAS_CODEC)
        if( (pData = sqlite3PagerCodec(pLast))==0 ) return SQLITE_NOMEM;
  #else
@@ -2395,7 +2418,7 @@
  #ifndef SQLITE_OMIT_SHARED_CACHE
  #if SQLITE_THREADSAFE
  
-@@ -85120,60 +85817,6 @@
+@@ -85120,60 +85840,6 @@
  
  #ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
    /*
@@ -2456,7 +2479,7 @@
    **   PRAGMA table_info(<table>)
    **
    ** Return a single row for each column of the named table. The columns of
-@@ -85795,6 +86438,24 @@
+@@ -85795,6 +86461,24 @@
        sqlite3_rekey(db, zKey, i/2);
      }
    }else



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]