You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SQL Logic Error when attempting to change SQLCipher password #1690
Related to this (but I guess should ideally be a separate issue) if 'Tools' and 'Set Encryption' is successfully run (using an older nightly) there is nothing logged in the application 'log' window.
Why is sqlcipher_export being used to change the password?
Very much like the 'Modify Structure' dialog, the 'Set Encryption' (and change password, which uses the same code) creates a new database using the new settings, then copies all the data, renames the databases, then deletes the old database.
The error in question is happening here but I don't know enough to know why its suddenly doing it. Looking back to a working version, that code hasn't changed.
That's weird - it's working fine for me. But I'm still using SQLCipher 3.4 instead of 4.0. Can somebody check with 3.4 and with 4.0?
The reason we use sqlcipher_export is mainly for simplicity because we need to support the current approach either way while the rekey approach is an optional optimisation. That said, we should probably add that some time 😉 Can you open a separate issue for that? 😄
That's the process I tried initially. Theoretically its doing the same thing - creating an encrypted database, copying the data, then deleting the original.
ok = db.executeSQL(QString("ATTACH DATABASE '%1' AS sqlitebrowser_edit_encryption KEY %2;").arg(db.currentFile() + ".enctemp").arg(cipherSettings.getPassword()),
false, false);
qApp->processEvents();
if(ok)
ok = db.executeSQL(QString("PRAGMA sqlitebrowser_edit_encryption.cipher_page_size = %1").arg(cipherSettings.getPageSize()), false, false);
if(ok)
ok = db.executeSQL(QString("PRAGMA sqlitebrowser_edit_encryption.kdf_iter = %1").arg(cipherSettings.getKdfIterations()), false, false);
if(ok)
ok = db.executeSQL(QString("PRAGMA sqlitebrowser_edit_encryption.cipher_hmac_algorithm = %1").arg(cipherSettings.getHmacAlgorithm()), false, false);
if(ok)
ok = db.executeSQL(QString("PRAGMA sqlitebrowser_edit_encryption.cipher_kdf_algorithm = %1").arg(cipherSettings.getKdfAlgorithm()), false, false);
// Export the current database to the new one
qApp->processEvents();
if(ok)
ok = db.executeSQL("SELECT sqlcipher_export('sqlitebrowser_edit_encryption');", false, false);
// Set user version of the new database
qApp->processEvents();
if (ok)
ok = db.executeSQL(QString("PRAGMA sqlitebrowser_edit_encryption.user_version = %1;").arg(db.getPragma("user_version").toInt()), false, false);
The specific string shown in the dialog isn't inside a QString() call, unlike the sibling SQL statement around it. Is there any way that could be leading things astray? 😄
The other possibility that comes to mind, is that since it's a SELECT it'll be returning a value. The other statements around it are ones which don't always return a value, so maybe it's a case of executeSQL() not being the right function call for running it?
@justinclift The QString() bit makes no difference. You can tell from the fact that the SQL statement is printed in the error message, so it definitely get passed correctly to the executeSQL() function. The reason why we add QString() to the other lines is to be able to call the QString().tr() function which we don't need for the other line.
The SELECT should be fine too. executeSQL() discards the returned value which is why we usually don't use it for SELECT statements. But in this case we're actually not interested in the returned values (if indeed there is any) because the SELECT is only a syntactic thing to call the sqlcipher_export extension function.
What's weird here is that @mtissington says that it happens with SQLCipher 3.4 as well as with 4.0. Not sure what to make of this because it definitely worked before. I have found this issue though which says:
On c19c72f I cannot perform any operation on encrypted databases. As soon as PRAGMA key = 'some_key'; is executed, then next SQL operation fails with "Error: SQL logic error or missing database". This error also occurs after performing an ATTACH with a KEY specified.
That said, we've seen similar errors to what you described in the past due to mismatched OpenSSL headers. For instance, if you include OpenSSL headers for one version but then another version is dynamically loaded at runtime you can see this behavior. Can you please make sure that you don't have any OpenSSL headers in the include path other than the ones in /usr/include/openssl?
So maybe it is after all impossible to just drop-in replace the SQLCipher DLL?
I just replaced sqlcipher.dll with a version I had build against OpenSSL 1.1.1a (also need libcrypto-1_1)
and I get exactly the same issue. But everything else seems to still work.
I don't know if this is related but when I try the following in DB4S the ATTACH fails saying it can't find the database instead of creating a new one. When I do the same in sqlcipher.exe it works correctly.
First I create a new empty database then in a SQL window
This one sounds like it'll need some special effort to debug. Probably need to replicate the problem, and attach a debugger to it in order to step through the code as the bug occurs.
Setup a working dev environment (Qt Creator) on Windows, with Qt 5.11.3, SQLCipher 4.0.1.
Build DB4S in debug mode
Step through the problem code
Technically I could do it, however I'm presently knocking myself out (not literally) getting new online infrastructure + monitoring set up for it. That's probably more important than this, at least for the moment.
The version numbers will be out of bonk as they're one off builds, so the same (or lower) version numbers.
I'd recommend downloading the .ZIPs, extracting to a folder, and running the .exe from that folder. No need to install.
@mtissington Yeah, I dumbly made the v1 builds based off of our master branch (effectively 3.12.x development code). For the v2, realised it would be better built from the same code as the 3.11.1 release, so did that. Thus the complaining from it that v1 (3.12.x) is newer. 😉
Activity
justinclift commentedon Dec 26, 2018
Thanks @mtissington. That'll definitely need looking into. 😄
mtissington commentedon Dec 27, 2018
Why is sqlcipher_export being used to change the password?
According to sqlcipher api
PRAGMA rekeyis all that is required.chrisjlocke commentedon Dec 27, 2018
Related to this (but I guess should ideally be a separate issue) if 'Tools' and 'Set Encryption' is successfully run (using an older nightly) there is nothing logged in the application 'log' window.
After opening a database then encrypting it, that was all that was in the sql log.
chrisjlocke commentedon Dec 27, 2018
Very much like the 'Modify Structure' dialog, the 'Set Encryption' (and change password, which uses the same code) creates a new database using the new settings, then copies all the data, renames the databases, then deletes the old database.
The error in question is happening here but I don't know enough to know why its suddenly doing it. Looking back to a working version, that code hasn't changed.
MKleusberg commentedon Dec 27, 2018
That's weird - it's working fine for me. But I'm still using SQLCipher 3.4 instead of 4.0. Can somebody check with 3.4 and with 4.0?
The reason we use
sqlcipher_exportis mainly for simplicity because we need to support the current approach either way while therekeyapproach is an optional optimisation. That said, we should probably add that some time 😉 Can you open a separate issue for that? 😄mtissington commentedon Dec 27, 2018
I get the same error when I start with a NON encrypted database and then try to encrypt it (either with 3.4 or 4)
chrisjlocke commentedon Dec 27, 2018
That's the process I tried initially. Theoretically its doing the same thing - creating an encrypted database, copying the data, then deleting the original.
justinclift commentedon Dec 28, 2018
@MKleusberg Looking at the code that error message comes from:
sqlitebrowser/src/MainWindow.cpp
Lines 3059 to 3080 in 1925ccf
The specific string shown in the dialog isn't inside a
QString()call, unlike the sibling SQL statement around it. Is there any way that could be leading things astray? 😄The other possibility that comes to mind, is that since it's a
SELECTit'll be returning a value. The other statements around it are ones which don't always return a value, so maybe it's a case ofexecuteSQL()not being the right function call for running it?MKleusberg commentedon Dec 29, 2018
@justinclift The
QString()bit makes no difference. You can tell from the fact that the SQL statement is printed in the error message, so it definitely get passed correctly to theexecuteSQL()function. The reason why we addQString()to the other lines is to be able to call theQString().tr()function which we don't need for the other line.The
SELECTshould be fine too.executeSQL()discards the returned value which is why we usually don't use it forSELECTstatements. But in this case we're actually not interested in the returned values (if indeed there is any) because theSELECTis only a syntactic thing to call thesqlcipher_exportextension function.What's weird here is that @mtissington says that it happens with SQLCipher 3.4 as well as with 4.0. Not sure what to make of this because it definitely worked before. I have found this issue though which says:
So maybe it is after all impossible to just drop-in replace the SQLCipher DLL?
mtissington commentedon Dec 29, 2018
I just replaced sqlcipher.dll with a version I had build against OpenSSL 1.1.1a (also need libcrypto-1_1)
and I get exactly the same issue. But everything else seems to still work.
mtissington commentedon Dec 31, 2018
I don't know if this is related but when I try the following in DB4S the ATTACH fails saying it can't find the database instead of creating a new one. When I do the same in sqlcipher.exe it works correctly.
First I create a new empty database then in a SQL window
justinclift commentedon Dec 31, 2018
This one sounds like it'll need some special effort to debug. Probably need to replicate the problem, and attach a debugger to it in order to step through the code as the bug occurs.
Technically I could do it, however I'm presently knocking myself out (not literally) getting new online infrastructure + monitoring set up for it. That's probably more important than this, at least for the moment.
chrisjlocke commentedon Dec 31, 2018
@mtissington - what version of DB4S? I'm using the nightly from 28 Dec, and that works fine.
I initially thought the 'key' part might be confusing DB4S, as it obviously doesn't support that, but it seemed to work.
19 remaining items
sqlcipher: Fix editing the encryption for SQLCipher4
sqlcipher: Fix editing the encryption for SQLCipher4
justinclift commentedon Feb 12, 2019
Updated Win64 builds:
mtissington commentedon Feb 12, 2019
Hmm, so I installed 1732v1 and now when I attempt to install v2 it says a later version is already installed.
chrisjlocke commentedon Feb 12, 2019
The version numbers will be out of bonk as they're one off builds, so the same (or lower) version numbers.
I'd recommend downloading the .ZIPs, extracting to a folder, and running the .exe from that folder. No need to install.
justinclift commentedon Feb 12, 2019
@mtissington Yeah, I dumbly made the v1 builds based off of our
masterbranch (effectively 3.12.x development code). For the v2, realised it would be better built from the same code as the 3.11.1 release, so did that. Thus the complaining from it that v1 (3.12.x) is newer. 😉@chrisjlocke Good idea. 😄
mtissington commentedon Feb 12, 2019
how do this differ to the nightly?
justinclift commentedon Feb 12, 2019
The nightly is also built from the
masterbranch. The v1 was (quite literally) nightly + experimental fix applied.The v2 was an updated (slightly tweaked for future compatibility) fix, but applied to the v3.11.x code base instead.
sqlcipher: Fix editing the encryption for SQLCipher4
MKleusberg commentedon Aug 10, 2019
I think we fixed this issue some time ago. Can you give the last nightly build a try, @mtissington? 😄
mtissington commentedon Aug 10, 2019
fixed a while back and confirmed still fixed 😄
MKleusberg commentedon Aug 11, 2019
Awesome! Thank you for confirming 😄