mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-10 07:20:23 -04:00
Add a new database settings wizard
This patch implements a new database wizard to guide users through the process of setting up a new database and choosing sane encryption settings. It also reimplements the master key settings to be more user-friendly. Users can now add, change, or remove individual composite key components instead of having to set all components at once. This avoids confusion about a password being reset if the user only wants to add a key file. With these changes comes a major refactor of how database composite keys and key components are handled. Copying of keys is prohibited and each key exists only once in memory and is referenced via shared pointers. GUI components for changing individual keys are encapsulated into separate classes to be more reusable. The password edit and generator widgets have also been refactored to be more reusable.
This commit is contained in:
parent
e4ded388b4
commit
e443cde452
116 changed files with 5054 additions and 1692 deletions
|
@ -48,6 +48,13 @@
|
|||
#include "crypto/Crypto.h"
|
||||
#include "crypto/kdf/AesKdf.h"
|
||||
#include "format/KeePass2Reader.h"
|
||||
#include "keys/PasswordKey.h"
|
||||
#include "keys/FileKey.h"
|
||||
#include "gui/ApplicationSettingsWidget.h"
|
||||
#include "gui/dbsettings/DatabaseSettingsDialog.h"
|
||||
#include "gui/masterkey/PasswordEditWidget.h"
|
||||
#include "gui/masterkey/KeyFileEditWidget.h"
|
||||
#include "gui/CategoryListWidget.h"
|
||||
#include "gui/CloneDialog.h"
|
||||
#include "gui/DatabaseTabWidget.h"
|
||||
#include "gui/DatabaseWidget.h"
|
||||
|
@ -63,6 +70,8 @@
|
|||
#include "gui/group/EditGroupWidget.h"
|
||||
#include "gui/group/GroupModel.h"
|
||||
#include "gui/group/GroupView.h"
|
||||
#include "gui/wizard/NewDatabaseWizard.h"
|
||||
#include "gui/masterkey/KeyComponentWidget.h"
|
||||
#include "keys/PasswordKey.h"
|
||||
|
||||
void TestGui::initTestCase()
|
||||
|
@ -70,9 +79,11 @@ void TestGui::initTestCase()
|
|||
QVERIFY(Crypto::init());
|
||||
Config::createTempFileInstance();
|
||||
// Disable autosave so we can test the modified file indicator
|
||||
Config::instance()->set("AutoSaveAfterEveryChange", false);
|
||||
config()->set("AutoSaveAfterEveryChange", false);
|
||||
// Enable the tray icon so we can test hiding/restoring the window
|
||||
Config::instance()->set("GUI/ShowTrayIcon", true);
|
||||
config()->set("GUI/ShowTrayIcon", true);
|
||||
// Disable advanced settings mode (activate within individual tests to test advanced settings)
|
||||
config()->set("GUI/AdvancedSettings", false);
|
||||
|
||||
m_mainWindow = new MainWindow();
|
||||
m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");
|
||||
|
@ -135,43 +146,114 @@ void TestGui::cleanup()
|
|||
m_dbWidget = nullptr;
|
||||
}
|
||||
|
||||
void TestGui::testSettingsDefaultTabOrder()
|
||||
{
|
||||
// check application settings default tab order
|
||||
triggerAction("actionSettings");
|
||||
auto* settingsWidget = m_mainWindow->findChild<ApplicationSettingsWidget*>();
|
||||
QVERIFY(settingsWidget->isVisible());
|
||||
QCOMPARE(settingsWidget->findChild<CategoryListWidget*>("categoryList")->currentCategory(), 0);
|
||||
for (auto* w: settingsWidget->findChildren<QTabWidget*>()) {
|
||||
if (w->currentIndex() != 0) {
|
||||
QFAIL("Application settings contain QTabWidgets whose default index is not 0");
|
||||
}
|
||||
}
|
||||
QTest::keyClick(settingsWidget, Qt::Key::Key_Escape);
|
||||
|
||||
// check database settings default tab order
|
||||
triggerAction("actionChangeDatabaseSettings");
|
||||
auto* dbSettingsWidget = m_mainWindow->findChild<DatabaseSettingsDialog*>();
|
||||
QVERIFY(dbSettingsWidget->isVisible());
|
||||
QCOMPARE(dbSettingsWidget->findChild<CategoryListWidget*>("categoryList")->currentCategory(), 0);
|
||||
for (auto* w: dbSettingsWidget->findChildren<QTabWidget*>()) {
|
||||
if (w->currentIndex() != 0) {
|
||||
QFAIL("Database settings contain QTabWidgets whose default index is not 0");
|
||||
}
|
||||
}
|
||||
QTest::keyClick(dbSettingsWidget, Qt::Key::Key_Escape);
|
||||
}
|
||||
|
||||
void TestGui::testCreateDatabase()
|
||||
{
|
||||
QTemporaryFile tmpFile;
|
||||
QVERIFY(tmpFile.open());
|
||||
QString tmpFileName = tmpFile.fileName();
|
||||
tmpFile.remove();
|
||||
|
||||
fileDialog()->setNextFileName(tmpFileName);
|
||||
QTimer::singleShot(0, this, SLOT(createDatabaseCallback()));
|
||||
triggerAction("actionDatabaseNew");
|
||||
|
||||
DatabaseWidget* dbWidget = m_tabWidget->currentDatabaseWidget();
|
||||
|
||||
QWidget* databaseNewWidget = dbWidget->findChild<QWidget*>("changeMasterKeyWidget");
|
||||
PasswordEdit* editPassword = databaseNewWidget->findChild<PasswordEdit*>("enterPasswordEdit");
|
||||
QVERIFY(editPassword->isVisible());
|
||||
|
||||
QLineEdit* editPasswordRepeat = databaseNewWidget->findChild<QLineEdit*>("repeatPasswordEdit");
|
||||
QVERIFY(editPasswordRepeat->isVisible());
|
||||
|
||||
m_tabWidget->currentDatabaseWidget()->setCurrentWidget(databaseNewWidget);
|
||||
|
||||
QTest::keyClicks(editPassword, "test");
|
||||
QTest::keyClicks(editPasswordRepeat, "test");
|
||||
QTest::keyClick(editPasswordRepeat, Qt::Key_Enter);
|
||||
|
||||
// Auto-save after every change is enabled by default, ensure the db saves right away
|
||||
QTRY_VERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).contains("*"));
|
||||
|
||||
m_db = m_tabWidget->currentDatabaseWidget()->database();
|
||||
|
||||
// there is a new empty db
|
||||
m_db = m_tabWidget->currentDatabaseWidget()->database();
|
||||
QCOMPARE(m_db->rootGroup()->children().size(), 0);
|
||||
|
||||
// check meta data
|
||||
QCOMPARE(m_db->metadata()->name(), QString("Test Name"));
|
||||
QCOMPARE(m_db->metadata()->description(), QString("Test Description"));
|
||||
|
||||
// check key and encryption
|
||||
QCOMPARE(m_db->key()->keys().size(), 2);
|
||||
QCOMPARE(m_db->kdf()->uuid(), KeePass2::KDF_ARGON2);
|
||||
QCOMPARE(m_db->cipher(), KeePass2::CIPHER_AES);
|
||||
auto compositeKey = QSharedPointer<CompositeKey>::create();
|
||||
compositeKey->addKey(QSharedPointer<PasswordKey>::create("test"));
|
||||
auto fileKey = QSharedPointer<FileKey>::create();
|
||||
fileKey->load(QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed.key"));
|
||||
compositeKey->addKey(fileKey);
|
||||
QCOMPARE(m_db->key()->rawKey(), compositeKey->rawKey());
|
||||
|
||||
// close the new database
|
||||
MessageBox::setNextAnswer(QMessageBox::No);
|
||||
triggerAction("actionDatabaseClose");
|
||||
Tools::wait(100);
|
||||
}
|
||||
|
||||
void TestGui::createDatabaseCallback()
|
||||
{
|
||||
auto* wizard = m_tabWidget->findChild<NewDatabaseWizard*>();
|
||||
QVERIFY(wizard);
|
||||
|
||||
QTest::keyClicks(wizard->currentPage()->findChild<QLineEdit*>("databaseName"), "Test Name");
|
||||
QTest::keyClicks(wizard->currentPage()->findChild<QLineEdit*>("databaseDescription"), "Test Description");
|
||||
QCOMPARE(wizard->currentId(), 0);
|
||||
|
||||
QTest::keyClick(wizard, Qt::Key_Enter);
|
||||
QCOMPARE(wizard->currentId(), 1);
|
||||
|
||||
QTest::keyClick(wizard, Qt::Key_Enter);
|
||||
QCOMPARE(wizard->currentId(), 2);
|
||||
|
||||
// enter password
|
||||
auto* passwordWidget = wizard->currentPage()->findChild<PasswordEditWidget*>();
|
||||
QCOMPARE(passwordWidget->visiblePage(), KeyFileEditWidget::Page::Edit);
|
||||
auto* passwordEdit = passwordWidget->findChild<QLineEdit*>("enterPasswordEdit");
|
||||
auto* passwordRepeatEdit = passwordWidget->findChild<QLineEdit*>("repeatPasswordEdit");
|
||||
QTRY_VERIFY(passwordEdit->isVisible());
|
||||
QVERIFY(passwordEdit->hasFocus());
|
||||
QTest::keyClicks(passwordEdit, "test");
|
||||
QTest::keyClick(passwordEdit, Qt::Key::Key_Tab);
|
||||
QTest::keyClicks(passwordRepeatEdit, "test");
|
||||
|
||||
// add key file
|
||||
auto* additionalOptionsButton = wizard->currentPage()->findChild<QPushButton*>("additionalKeyOptionsToggle");
|
||||
auto* keyFileWidget = wizard->currentPage()->findChild<KeyFileEditWidget*>();
|
||||
QVERIFY(additionalOptionsButton->isVisible());
|
||||
QTest::mouseClick(additionalOptionsButton, Qt::MouseButton::LeftButton);
|
||||
QTRY_VERIFY(keyFileWidget->isVisible());
|
||||
QTRY_VERIFY(!additionalOptionsButton->isVisible());
|
||||
QCOMPARE(passwordWidget->visiblePage(), KeyFileEditWidget::Page::Edit);
|
||||
QTest::mouseClick(keyFileWidget->findChild<QPushButton*>("addButton"), Qt::MouseButton::LeftButton);
|
||||
auto* fileCombo = keyFileWidget->findChild<QComboBox*>("keyFileCombo");
|
||||
QTRY_VERIFY(fileCombo);
|
||||
QTRY_VERIFY(fileCombo->isVisible());
|
||||
fileDialog()->setNextFileName(QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed.key"));
|
||||
QTest::keyClick(keyFileWidget->findChild<QPushButton*>("addButton"), Qt::Key::Key_Enter);
|
||||
QVERIFY(fileCombo->hasFocus());
|
||||
auto* browseButton = keyFileWidget->findChild<QPushButton*>("browseKeyFileButton");
|
||||
QTest::keyClick(browseButton, Qt::Key::Key_Enter);
|
||||
QCOMPARE(fileCombo->currentText(), QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed.key"));
|
||||
|
||||
// save database to temporary file
|
||||
TemporaryFile tmpFile;
|
||||
QVERIFY(tmpFile.open());
|
||||
tmpFile.close();
|
||||
fileDialog()->setNextFileName(tmpFile.filePath());
|
||||
|
||||
QTest::keyClick(fileCombo, Qt::Key::Key_Enter);
|
||||
}
|
||||
|
||||
void TestGui::testMergeDatabase()
|
||||
|
@ -390,7 +472,7 @@ void TestGui::testSearchEditEntry()
|
|||
|
||||
// Find buttons for group creation
|
||||
EditGroupWidget* editGroupWidget = m_dbWidget->findChild<EditGroupWidget*>("editGroupWidget");
|
||||
QLineEdit* nameEdit = editGroupWidget->findChild<QLineEdit*>("nameEdit");
|
||||
QLineEdit* nameEdit = editGroupWidget->findChild<QLineEdit*>("editName");
|
||||
QDialogButtonBox* editGroupWidgetButtonBox = editGroupWidget->findChild<QDialogButtonBox*>("buttonBox");
|
||||
|
||||
// Add groups "Good" and "Bad"
|
||||
|
@ -965,7 +1047,7 @@ void TestGui::testSaveAs()
|
|||
QFileInfo fileInfo(m_dbFilePath);
|
||||
QDateTime lastModified = fileInfo.lastModified();
|
||||
|
||||
m_db->metadata()->setName("SaveAs");
|
||||
m_db->metadata()->setName("testSaveAs");
|
||||
|
||||
// open temporary file so it creates a filename
|
||||
QTemporaryFile tmpFile;
|
||||
|
@ -977,7 +1059,7 @@ void TestGui::testSaveAs()
|
|||
|
||||
triggerAction("actionDatabaseSaveAs");
|
||||
|
||||
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("SaveAs"));
|
||||
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("testSaveAs"));
|
||||
|
||||
checkDatabase(tmpFileName);
|
||||
|
||||
|
@ -987,31 +1069,40 @@ void TestGui::testSaveAs()
|
|||
|
||||
void TestGui::testSave()
|
||||
{
|
||||
m_db->metadata()->setName("Save");
|
||||
m_db->metadata()->setName("testSave");
|
||||
|
||||
// wait for modified timer
|
||||
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("Save*"));
|
||||
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("testSave*"));
|
||||
|
||||
triggerAction("actionDatabaseSave");
|
||||
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("Save"));
|
||||
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("testSave"));
|
||||
|
||||
checkDatabase();
|
||||
}
|
||||
|
||||
void TestGui::testDatabaseSettings()
|
||||
{
|
||||
m_db->metadata()->setName("Save");
|
||||
m_db->metadata()->setName("testDatabaseSettings");
|
||||
triggerAction("actionChangeDatabaseSettings");
|
||||
QWidget* dbSettingsWidget = m_dbWidget->findChild<QWidget*>("databaseSettingsWidget");
|
||||
QSpinBox* transformRoundsSpinBox = dbSettingsWidget->findChild<QSpinBox*>("transformRoundsSpinBox");
|
||||
auto* dbSettingsDialog = m_dbWidget->findChild<QWidget*>("databaseSettingsDialog");
|
||||
auto* transformRoundsSpinBox = dbSettingsDialog->findChild<QSpinBox*>("transformRoundsSpinBox");
|
||||
auto advancedToggle = dbSettingsDialog->findChild<QCheckBox*>("advancedSettingsToggle");
|
||||
|
||||
advancedToggle->setChecked(true);
|
||||
QApplication::processEvents();
|
||||
|
||||
QVERIFY(transformRoundsSpinBox != nullptr);
|
||||
transformRoundsSpinBox->setValue(123456);
|
||||
QTest::keyClick(transformRoundsSpinBox, Qt::Key_Enter);
|
||||
// wait for modified timer
|
||||
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("Save*"));
|
||||
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("testDatabaseSettings*"));
|
||||
QCOMPARE(m_db->kdf()->rounds(), 123456);
|
||||
|
||||
triggerAction("actionDatabaseSave");
|
||||
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("Save"));
|
||||
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("testDatabaseSettings"));
|
||||
|
||||
advancedToggle->setChecked(false);
|
||||
QApplication::processEvents();
|
||||
|
||||
checkDatabase();
|
||||
}
|
||||
|
@ -1021,8 +1112,8 @@ void TestGui::testKeePass1Import()
|
|||
fileDialog()->setNextFileName(QString(KEEPASSX_TEST_DATA_DIR).append("/basic.kdb"));
|
||||
triggerAction("actionImportKeePass1");
|
||||
|
||||
QWidget* keepass1OpenWidget = m_mainWindow->findChild<QWidget*>("keepass1OpenWidget");
|
||||
QLineEdit* editPassword = keepass1OpenWidget->findChild<QLineEdit*>("editPassword");
|
||||
auto* keepass1OpenWidget = m_mainWindow->findChild<QWidget*>("keepass1OpenWidget");
|
||||
auto* editPassword = keepass1OpenWidget->findChild<QLineEdit*>("editPassword");
|
||||
QVERIFY(editPassword);
|
||||
|
||||
QTest::keyClicks(editPassword, "masterpw");
|
||||
|
@ -1174,8 +1265,8 @@ void TestGui::checkDatabase(QString dbFileName)
|
|||
if (dbFileName.isEmpty())
|
||||
dbFileName = m_dbFilePath;
|
||||
|
||||
CompositeKey key;
|
||||
key.addKey(PasswordKey("a"));
|
||||
auto key = QSharedPointer<CompositeKey>::create();
|
||||
key->addKey(QSharedPointer<PasswordKey>::create("a"));
|
||||
KeePass2Reader reader;
|
||||
QScopedPointer<Database> dbSaved(reader.readDatabase(dbFileName, key));
|
||||
QVERIFY(dbSaved);
|
||||
|
@ -1189,6 +1280,7 @@ void TestGui::triggerAction(const QString& name)
|
|||
QVERIFY(action);
|
||||
QVERIFY(action->isEnabled());
|
||||
action->trigger();
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
void TestGui::dragAndDropGroup(const QModelIndex& sourceIndex,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue