YapDatabase icon indicating copy to clipboard operation
YapDatabase copied to clipboard

Runtime check for SQLCipher

Open chrisballinger opened this issue 9 years ago • 1 comments

With Xcode 8 / iOS 10 it's possible to link against both Apple's sqlite library and SQLCipher and won't warn about duplicate symbols. I experienced an issue with this scenario here, where Apple's library was used for sqlite3_open but SQLCipher was used for sqlite3_key: https://github.com/sqlcipher/sqlcipher/issues/179

YapDatabase/SQLCipher was unaffected but regardless they recommend adding a snippet to double check that the database is actually using SQLCipher. https://discuss.zetetic.net/t/important-advisory-sqlcipher-with-xcode-8-and-ios-10/1688

bool is_sqlcipher = NO;
sqlite3_stmt *stmt;

if(sqlite3_prepare_v2(database, "PRAGMA cipher_version;", -1, &stmt, NULL) == SQLITE_OK) {
  if(sqlite3_step(stmt)== SQLITE_ROW) {
    const unsigned char *ver = sqlite3_column_text(stmt, 0);
    if(ver != NULL) {
      is_sqlcipher = YES;
    }
  }
  sqlite3_finalize(stmt);
}

chrisballinger avatar Sep 15 '16 01:09 chrisballinger

This may be already addressed by the preprocessor check to see if both YapDatabase and YapDatabase/SQLCipher subspecs are used at the same time.

chrisballinger avatar Sep 15 '16 01:09 chrisballinger