yapstudios / YapDatabase

YapDB is a collection/key/value store with a plugin architecture. It's built atop sqlite, for Swift & objective-c developers.
Other
3.35k stars 365 forks source link

Runtime check for SQLCipher #362

Open chrisballinger opened 7 years ago

chrisballinger commented 7 years ago

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 commented 7 years ago

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