Page MenuHomePhabricator

D4846.id15642.diff
No OneTemporary

D4846.id15642.diff

diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
--- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
+++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
@@ -329,7 +329,18 @@
sqlite3 *db;
sqlite3_open(SQLiteQueryExecutor::sqliteFilePath.c_str(), &db);
+ char *unencrypted_assertion_error;
+ // If database is encrypted with encryption key that was
+ // lost this SQL statement will fail. Otherwise it will succeed
+ sqlite3_exec(
+ db,
+ "SELECT COUNT(*) FROM sqlite_master;",
+ nullptr,
+ nullptr,
+ &unencrypted_assertion_error);
+ sqlite3_close(db);
+ sqlite3_open(SQLiteQueryExecutor::sqliteFilePath.c_str(), &db);
set_encryption_key(db);
char *key_validation_error;
// According to SQLCipher documentation running some SELECT is the only way to
@@ -348,8 +359,18 @@
return;
}
+ if (unencrypted_assertion_error) {
+ Logger::log(
+ "Database exists but it is encrypted with key that was lost. "
+ "Attempting database deletion.");
+ attempt_delete_file(
+ SQLiteQueryExecutor::sqliteFilePath.c_str(),
+ "Failed to delete database encrypted with lost key.");
+ }
+
Logger::log(
- "Validation of encryption key failed. Attempting encryption process.");
+ "Database exists but it is not encrypted. Attempting encryption "
+ "process.");
sqlite3_open(SQLiteQueryExecutor::sqliteFilePath.c_str(), &db);
std::string createEncryptedCopySQL = "ATTACH DATABASE '" +

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 8:46 PM (20 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2572387
Default Alt Text
D4846.id15642.diff (1 KB)

Event Timeline