Skip to content

Commit

Permalink
Use SQLCipher as SQLite engine on web
Browse files Browse the repository at this point in the history
Summary:
This differential compiles SQLCipher-amalgamation as SQLite engine instead of SQLite-amalgamation. Since SQLCipher-amalgamation compilation requires linking
against openssl we additionally compile openssl to emscripten wasm and link SQLCipher-amalgamation against it.

Test Plan:
1. Open web app before creating new WASM to create database handled by original WASM.
2. Hardcode encryption key in SQLiteQueryExecutor and build new WASM.
3. Ensure that database is re-encrypted by examining logs from shared worker.
4. Ensure that app is as usable as before.

Reviewers: kamil

Reviewed By: kamil

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D10450
  • Loading branch information
marcinwasowicz committed Jan 17, 2024
1 parent e5200cc commit 3be9c9a
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 132 deletions.
10 changes: 10 additions & 0 deletions native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,13 @@ void trace_queries(sqlite3 *db) {
}
}

// We don't want to run `PRAGMA key = ...;`
// on main web database. The context is here:
// https://linear.app/comm/issue/ENG-6398/issues-with-sqlcipher-on-web
void on_database_open(sqlite3 *db) {
#ifndef EMSCRIPTEN
set_encryption_key(db);
#endif
trace_queries(db);
}

Expand Down Expand Up @@ -868,7 +873,12 @@ bool set_up_database(sqlite3 *db) {
}

void SQLiteQueryExecutor::migrate() {
// We don't want to run `PRAGMA key = ...;`
// on main web database. The context is here:
// https://linear.app/comm/issue/ENG-6398/issues-with-sqlcipher-on-web
#ifndef EMSCRIPTEN
validate_encryption();
#endif

sqlite3 *db;
sqlite3_open(SQLiteQueryExecutor::sqliteFilePath.c_str(), &db);
Expand Down
Loading

0 comments on commit 3be9c9a

Please sign in to comment.