cipher: Fix attaching unencrypted DB if main is encrypted and vice-versa

When attaching another database, SQLCipher assumes that it shares
passphrase and salt with the main database. Usually this isn't the case,
though. With this commit SQLiteBrowser tries to open the database to attach
before actually attaching it and asks for encryption details if needed.

This allows the user to attach unencrypted databases to an encrypted
master database and vice-versa. Note though, that attaching an encrypted
database with a non-default (i.e. <> 1024) cipher page size doesn't seem
to work - this however, is apparently a SQLCipher limitation.

See issue #174.
This commit is contained in:
Martin Kleusberg
2015-02-04 17:16:13 +01:00
parent 0457b7803e
commit f63b11925d
3 changed files with 132 additions and 70 deletions

View File

@@ -7,6 +7,7 @@
#include <QMultiMap>
#include <QByteArray>
class CipherDialog;
class sqlite3;
enum
@@ -45,6 +46,7 @@ public:
explicit DBBrowserDB () : _db( 0 ) {}
virtual ~DBBrowserDB (){}
bool open ( const QString & db);
bool attach(const QString& filename, QString attach_as = "");
bool create ( const QString & db);
bool close();
bool setRestorePoint(const QString& pointname = "RESTOREPOINT");
@@ -130,6 +132,8 @@ private:
QStringList savepointList;
bool isEncrypted;
bool tryEncryptionSettings(const QString& filename, bool* encrypted, CipherDialog*& cipherSettings);
};
#endif