Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3350103
D4846.id15642.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D4846.id15642.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D4846: Check for the case of database encrypted with key that is lost
Attached
Detach File
Event Timeline
Log In to Comment