mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-05-02 06:36:07 -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
|
@ -43,13 +43,13 @@ void TestKeys::initTestCase()
|
|||
|
||||
void TestKeys::testComposite()
|
||||
{
|
||||
QScopedPointer<CompositeKey> compositeKey1(new CompositeKey());
|
||||
QScopedPointer<PasswordKey> passwordKey1(new PasswordKey());
|
||||
QScopedPointer<PasswordKey> passwordKey2(new PasswordKey("test"));
|
||||
auto compositeKey1 = QSharedPointer<CompositeKey>::create();
|
||||
auto passwordKey1 = QSharedPointer<PasswordKey>::create();
|
||||
auto passwordKey2 = QSharedPointer<PasswordKey>::create("test");
|
||||
|
||||
// make sure that addKey() creates a copy of the keys
|
||||
compositeKey1->addKey(*passwordKey1);
|
||||
compositeKey1->addKey(*passwordKey2);
|
||||
compositeKey1->addKey(passwordKey1);
|
||||
compositeKey1->addKey(passwordKey2);
|
||||
|
||||
AesKdf kdf;
|
||||
kdf.setRounds(1);
|
||||
|
@ -57,29 +57,13 @@ void TestKeys::testComposite()
|
|||
QVERIFY(compositeKey1->transform(kdf, transformed1));
|
||||
QCOMPARE(transformed1.size(), 32);
|
||||
|
||||
// make sure the subkeys are copied
|
||||
QScopedPointer<CompositeKey> compositeKey2(compositeKey1->clone());
|
||||
QByteArray transformed2;
|
||||
QVERIFY(compositeKey2->transform(kdf, transformed2));
|
||||
QCOMPARE(transformed2.size(), 32);
|
||||
QCOMPARE(transformed1, transformed2);
|
||||
|
||||
QScopedPointer<CompositeKey> compositeKey3(new CompositeKey());
|
||||
QScopedPointer<CompositeKey> compositeKey4(new CompositeKey());
|
||||
|
||||
// test clear()
|
||||
compositeKey3->addKey(PasswordKey("test"));
|
||||
compositeKey3->addKey(QSharedPointer<PasswordKey>::create("test"));
|
||||
compositeKey3->clear();
|
||||
QCOMPARE(compositeKey3->rawKey(), compositeKey4->rawKey());
|
||||
|
||||
// test assignment operator
|
||||
compositeKey3->addKey(PasswordKey("123"));
|
||||
*compositeKey4 = *compositeKey3;
|
||||
QCOMPARE(compositeKey3->rawKey(), compositeKey4->rawKey());
|
||||
|
||||
// test self-assignment
|
||||
*compositeKey3 = *compositeKey3;
|
||||
QCOMPARE(compositeKey3->rawKey(), compositeKey4->rawKey());
|
||||
}
|
||||
|
||||
void TestKeys::testFileKey()
|
||||
|
@ -94,14 +78,14 @@ void TestKeys::testFileKey()
|
|||
QString dbFilename = QString("%1/%2.kdbx").arg(QString(KEEPASSX_TEST_DATA_DIR), name);
|
||||
QString keyFilename = QString("%1/%2.key").arg(QString(KEEPASSX_TEST_DATA_DIR), name);
|
||||
|
||||
CompositeKey compositeKey;
|
||||
FileKey fileKey;
|
||||
QVERIFY(fileKey.load(keyFilename));
|
||||
QCOMPARE(fileKey.rawKey().size(), 32);
|
||||
auto compositeKey = QSharedPointer<CompositeKey>::create();
|
||||
auto fileKey = QSharedPointer<FileKey>::create();
|
||||
QVERIFY(fileKey->load(keyFilename));
|
||||
QCOMPARE(fileKey->rawKey().size(), 32);
|
||||
|
||||
QCOMPARE(fileKey.type(), type);
|
||||
QCOMPARE(fileKey->type(), type);
|
||||
|
||||
compositeKey.addKey(fileKey);
|
||||
compositeKey->addKey(fileKey);
|
||||
|
||||
QScopedPointer<Database> db(reader.readDatabase(dbFilename, compositeKey));
|
||||
QVERIFY(db);
|
||||
|
@ -146,10 +130,10 @@ void TestKeys::testCreateAndOpenFileKey()
|
|||
FileKey::create(&keyBuffer);
|
||||
keyBuffer.reset();
|
||||
|
||||
FileKey fileKey;
|
||||
QVERIFY(fileKey.load(&keyBuffer));
|
||||
CompositeKey compositeKey;
|
||||
compositeKey.addKey(fileKey);
|
||||
auto fileKey = QSharedPointer<FileKey>::create();
|
||||
QVERIFY(fileKey->load(&keyBuffer));
|
||||
auto compositeKey = QSharedPointer<CompositeKey>::create();
|
||||
compositeKey->addKey(fileKey);
|
||||
|
||||
QScopedPointer<Database> dbOrg(new Database());
|
||||
QVERIFY(dbOrg->setKey(compositeKey));
|
||||
|
@ -218,10 +202,10 @@ void TestKeys::benchmarkTransformKey()
|
|||
QSKIP("Benchmark skipped. Set env variable BENCHMARK=1 to enable.");
|
||||
}
|
||||
|
||||
PasswordKey pwKey;
|
||||
pwKey.setPassword("password");
|
||||
CompositeKey compositeKey;
|
||||
compositeKey.addKey(pwKey);
|
||||
auto pwKey = QSharedPointer<PasswordKey>::create();
|
||||
pwKey->setPassword("password");
|
||||
auto compositeKey = QSharedPointer<CompositeKey>::create();
|
||||
compositeKey->addKey(pwKey);
|
||||
|
||||
QByteArray seed(32, '\x4B');
|
||||
|
||||
|
@ -232,25 +216,25 @@ void TestKeys::benchmarkTransformKey()
|
|||
|
||||
QBENCHMARK
|
||||
{
|
||||
Q_UNUSED(compositeKey.transform(kdf, result));
|
||||
Q_UNUSED(compositeKey->transform(kdf, result));
|
||||
};
|
||||
}
|
||||
|
||||
void TestKeys::testCompositeKeyComponents()
|
||||
{
|
||||
PasswordKey passwordKeyEnc("password");
|
||||
FileKey fileKeyEnc;
|
||||
auto passwordKeyEnc = QSharedPointer<PasswordKey>::create("password");
|
||||
auto fileKeyEnc = QSharedPointer<FileKey>::create();
|
||||
QString error;
|
||||
fileKeyEnc.load(QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed.key"), &error);
|
||||
fileKeyEnc->load(QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed.key"), &error);
|
||||
if (!error.isNull()) {
|
||||
QFAIL(qPrintable(error));
|
||||
}
|
||||
auto challengeResponseKeyEnc = QSharedPointer<MockChallengeResponseKey>::create(QByteArray(16, 0x10));
|
||||
|
||||
CompositeKey compositeKeyEnc;
|
||||
compositeKeyEnc.addKey(passwordKeyEnc);
|
||||
compositeKeyEnc.addKey(fileKeyEnc);
|
||||
compositeKeyEnc.addChallengeResponseKey(challengeResponseKeyEnc);
|
||||
auto compositeKeyEnc = QSharedPointer<CompositeKey>::create();
|
||||
compositeKeyEnc->addKey(passwordKeyEnc);
|
||||
compositeKeyEnc->addKey(fileKeyEnc);
|
||||
compositeKeyEnc->addChallengeResponseKey(challengeResponseKeyEnc);
|
||||
|
||||
QScopedPointer<Database> db1(new Database());
|
||||
db1->setKey(compositeKeyEnc);
|
||||
|
@ -263,23 +247,23 @@ void TestKeys::testCompositeKeyComponents()
|
|||
buffer.seek(0);
|
||||
QScopedPointer<Database> db2;
|
||||
KeePass2Reader reader;
|
||||
CompositeKey compositeKeyDec1;
|
||||
auto compositeKeyDec1 = QSharedPointer<CompositeKey>::create();
|
||||
|
||||
// try decryption and subsequently add key components until decryption is successful
|
||||
db2.reset(reader.readDatabase(&buffer, compositeKeyDec1));
|
||||
QVERIFY(reader.hasError());
|
||||
|
||||
compositeKeyDec1.addKey(passwordKeyEnc);
|
||||
compositeKeyDec1->addKey(passwordKeyEnc);
|
||||
buffer.seek(0);
|
||||
db2.reset(reader.readDatabase(&buffer, compositeKeyDec1));
|
||||
QVERIFY(reader.hasError());
|
||||
|
||||
compositeKeyDec1.addKey(fileKeyEnc);
|
||||
compositeKeyDec1->addKey(fileKeyEnc);
|
||||
buffer.seek(0);
|
||||
db2.reset(reader.readDatabase(&buffer, compositeKeyDec1));
|
||||
QVERIFY(reader.hasError());
|
||||
|
||||
compositeKeyDec1.addChallengeResponseKey(challengeResponseKeyEnc);
|
||||
compositeKeyDec1->addChallengeResponseKey(challengeResponseKeyEnc);
|
||||
buffer.seek(0);
|
||||
db2.reset(reader.readDatabase(&buffer, compositeKeyDec1));
|
||||
// now we should be able to open the database
|
||||
|
@ -288,31 +272,31 @@ void TestKeys::testCompositeKeyComponents()
|
|||
}
|
||||
|
||||
// try the same again, but this time with one wrong key component each time
|
||||
CompositeKey compositeKeyDec2;
|
||||
compositeKeyDec2.addKey(PasswordKey("wrong password"));
|
||||
compositeKeyDec2.addKey(fileKeyEnc);
|
||||
compositeKeyDec2.addChallengeResponseKey(challengeResponseKeyEnc);
|
||||
auto compositeKeyDec2 = QSharedPointer<CompositeKey>::create();
|
||||
compositeKeyDec2->addKey(QSharedPointer<PasswordKey>::create("wrong password"));
|
||||
compositeKeyDec2->addKey(fileKeyEnc);
|
||||
compositeKeyDec2->addChallengeResponseKey(challengeResponseKeyEnc);
|
||||
buffer.seek(0);
|
||||
db2.reset(reader.readDatabase(&buffer, compositeKeyDec2));
|
||||
QVERIFY(reader.hasError());
|
||||
|
||||
CompositeKey compositeKeyDec3;
|
||||
compositeKeyDec3.addKey(passwordKeyEnc);
|
||||
FileKey fileKeyWrong;
|
||||
fileKeyWrong.load(QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed2.key"), &error);
|
||||
auto compositeKeyDec3 = QSharedPointer<CompositeKey>::create();
|
||||
compositeKeyDec3->addKey(passwordKeyEnc);
|
||||
auto fileKeyWrong = QSharedPointer<FileKey>::create();
|
||||
fileKeyWrong->load(QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed2.key"), &error);
|
||||
if (!error.isNull()) {
|
||||
QFAIL(qPrintable(error));
|
||||
}
|
||||
compositeKeyDec3.addKey(fileKeyWrong);
|
||||
compositeKeyDec3.addChallengeResponseKey(challengeResponseKeyEnc);
|
||||
compositeKeyDec3->addKey(fileKeyWrong);
|
||||
compositeKeyDec3->addChallengeResponseKey(challengeResponseKeyEnc);
|
||||
buffer.seek(0);
|
||||
db2.reset(reader.readDatabase(&buffer, compositeKeyDec3));
|
||||
QVERIFY(reader.hasError());
|
||||
|
||||
CompositeKey compositeKeyDec4;
|
||||
compositeKeyDec4.addKey(passwordKeyEnc);
|
||||
compositeKeyDec4.addKey(fileKeyEnc);
|
||||
compositeKeyDec4.addChallengeResponseKey(QSharedPointer<MockChallengeResponseKey>::create(QByteArray(16, 0x20)));
|
||||
auto compositeKeyDec4 = QSharedPointer<CompositeKey>::create();
|
||||
compositeKeyDec4->addKey(passwordKeyEnc);
|
||||
compositeKeyDec4->addKey(fileKeyEnc);
|
||||
compositeKeyDec4->addChallengeResponseKey(QSharedPointer<MockChallengeResponseKey>::create(QByteArray(16, 0x20)));
|
||||
buffer.seek(0);
|
||||
db2.reset(reader.readDatabase(&buffer, compositeKeyDec4));
|
||||
QVERIFY(reader.hasError());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue