Support KeePass format 3.00 (used by KeePass2 >= 2.15).

Closes #6

Attachments are now stored in a pool under Metadata instead of in entries.
The protected flag of attachments isn't supported anymore.
New metadata attributes: color, historyMaxItems and historyMaxSize.
Dropped metadata attribute: autoEnableVisualHiding.
This commit is contained in:
Felix Geyer
2012-04-21 16:45:46 +02:00
parent e8ac70120b
commit 8acd6f74d8
23 changed files with 376 additions and 81 deletions

View File

@@ -82,8 +82,6 @@ void TestKeePass2Reader::testProtectedStrings()
QCOMPARE(entry->attributes()->value("TestProtected"), QString("ABC"));
QCOMPARE(entry->attributes()->value("TestUnprotected"), QString("DEF"));
QVERIFY(!db->metadata()->protectTitle());
QVERIFY(db->metadata()->protectUsername());
QVERIFY(db->metadata()->protectPassword());
QVERIFY(entry->attributes()->isProtected("TestProtected"));
QVERIFY(!entry->attributes()->isProtected("TestUnprotected"));
@@ -92,4 +90,36 @@ void TestKeePass2Reader::testProtectedStrings()
delete reader;
}
void TestKeePass2Reader::testFormat200()
{
QString filename = QString(KEEPASSX_TEST_DATA_DIR).append("/Format200.kdbx");
CompositeKey key;
key.addKey(PasswordKey("a"));
KeePass2Reader* reader = new KeePass2Reader();
Database* db = reader->readDatabase(filename, key);
QVERIFY(db);
QVERIFY(!reader->hasError());
QCOMPARE(db->rootGroup()->name(), QString("Format200"));
QVERIFY(!db->metadata()->protectTitle());
QVERIFY(db->metadata()->protectUsername());
QVERIFY(!db->metadata()->protectPassword());
QVERIFY(db->metadata()->protectUrl());
QVERIFY(!db->metadata()->protectNotes());
QCOMPARE(db->rootGroup()->entries().size(), 1);
Entry* entry = db->rootGroup()->entries().at(0);
QCOMPARE(entry->title(), QString("Sample Entry"));
QCOMPARE(entry->username(), QString("User Name"));
QCOMPARE(entry->attachments()->keys().size(), 2);
QCOMPARE(entry->attachments()->value("myattach.txt"), QByteArray("abcdefghijk"));
QCOMPARE(entry->attachments()->value("test.txt"), QByteArray("this is a test"));
QCOMPARE(entry->historyItems().size(), 2);
QCOMPARE(entry->historyItems().at(0)->attachments()->keys().size(), 0);
QCOMPARE(entry->historyItems().at(1)->attachments()->keys().size(), 1);
QCOMPARE(entry->historyItems().at(1)->attachments()->value("myattach.txt"), QByteArray("abcdefghijk"));
}
KEEPASSX_QTEST_CORE_MAIN(TestKeePass2Reader)

View File

@@ -29,6 +29,7 @@ private Q_SLOTS:
void testNonAscii();
void testCompressed();
void testProtectedStrings();
void testFormat200();
};
#endif // KEEPASSX_TESTKEEPASS2READER_H

View File

@@ -46,6 +46,8 @@ void TestKeePass2Writer::initTestCase()
entry->setUuid(Uuid::random());
entry->attributes()->set("test", "protectedTest", true);
QVERIFY(entry->attributes()->isProtected("test"));
entry->attachments()->set("myattach.txt", QByteArray("this is an attachment"));
entry->attachments()->set("aaa.txt", QByteArray("also an attachment"));
entry->setGroup(group);
Group* groupNew = new Group();
groupNew->setUuid(Uuid::random());
@@ -83,4 +85,12 @@ void TestKeePass2Writer::testProtectedAttributes()
QCOMPARE(entry->attributes()->isProtected("test"), true);
}
void TestKeePass2Writer::testAttachments()
{
Entry* entry = m_dbTest->rootGroup()->entries().at(0);
QCOMPARE(entry->attachments()->keys().size(), 2);
QCOMPARE(entry->attachments()->value("myattach.txt"), QByteArray("this is an attachment"));
QCOMPARE(entry->attachments()->value("aaa.txt"), QByteArray("also an attachment"));
}
KEEPASSX_QTEST_CORE_MAIN(TestKeePass2Writer)

View File

@@ -30,6 +30,7 @@ private Q_SLOTS:
void initTestCase();
void testBasic();
void testProtectedAttributes();
void testAttachments();
private:
Database* m_dbOrg;

View File

@@ -84,12 +84,15 @@ void TestKeePass2XmlReader::testMetadata()
QCOMPARE(m_db->metadata()->defaultUserName(), QString("DEFUSERNAME"));
QCOMPARE(m_db->metadata()->defaultUserNameChanged(), genDT(2010, 8, 8, 17, 27, 45));
QCOMPARE(m_db->metadata()->maintenanceHistoryDays(), 127);
QCOMPARE(m_db->metadata()->color(), QColor(0xff, 0xef, 0x00));
QCOMPARE(m_db->metadata()->masterKeyChanged(), genDT(2012, 4, 5, 17, 9, 34));
QCOMPARE(m_db->metadata()->masterKeyChangeRec(), 101);
QCOMPARE(m_db->metadata()->masterKeyChangeForce(), -1);
QCOMPARE(m_db->metadata()->protectTitle(), false);
QCOMPARE(m_db->metadata()->protectUsername(), true);
QCOMPARE(m_db->metadata()->protectPassword(), false);
QCOMPARE(m_db->metadata()->protectUrl(), true);
QCOMPARE(m_db->metadata()->protectNotes(), false);
QCOMPARE(m_db->metadata()->autoEnableVisualHiding(), false);
QCOMPARE(m_db->metadata()->recycleBinEnabled(), true);
QVERIFY(m_db->metadata()->recycleBin() != 0);
QCOMPARE(m_db->metadata()->recycleBin()->name(), QString("Recycle Bin"));
@@ -99,6 +102,8 @@ void TestKeePass2XmlReader::testMetadata()
QVERIFY(m_db->metadata()->lastSelectedGroup() != 0);
QCOMPARE(m_db->metadata()->lastSelectedGroup()->name(), QString("NewDatabase"));
QVERIFY(m_db->metadata()->lastTopVisibleGroup() == m_db->metadata()->lastSelectedGroup());
QCOMPARE(m_db->metadata()->historyMaxItems(), -1);
QCOMPARE(m_db->metadata()->historyMaxSize(), 5242880);
}
void TestKeePass2XmlReader::testCustomIcons()
@@ -199,11 +204,13 @@ void TestKeePass2XmlReader::testEntry1()
const Entry* entry = m_db->rootGroup()->entries().at(0);
QCOMPARE(entry->uuid().toBase64(), QString("+wSUOv6qf0OzW8/ZHAs2sA=="));
QCOMPARE(entry->historyItems().size(), 2);
QCOMPARE(entry->iconNumber(), 0);
QCOMPARE(entry->iconUuid(), Uuid());
QVERIFY(!entry->foregroundColor().isValid());
QVERIFY(!entry->backgroundColor().isValid());
QCOMPARE(entry->overrideUrl(), QString(""));
QCOMPARE(entry->tags(), QString("a b c"));
const TimeInfo ti = entry->timeInfo();
QCOMPARE(ti.lastModificationTime(), genDT(2010, 8, 25, 16, 19, 25));
@@ -216,14 +223,19 @@ void TestKeePass2XmlReader::testEntry1()
QList<QString> attrs = entry->attributes()->keys();
QCOMPARE(entry->attributes()->value("Notes"), QString("Notes"));
QVERIFY(!entry->attributes()->isProtected("Notes"));
QVERIFY(attrs.removeOne("Notes"));
QCOMPARE(entry->attributes()->value("Password"), QString("Password"));
QVERIFY(!entry->attributes()->isProtected("Password"));
QVERIFY(attrs.removeOne("Password"));
QCOMPARE(entry->attributes()->value("Title"), QString("Sample Entry 1"));
QVERIFY(!entry->attributes()->isProtected("Title"));
QVERIFY(attrs.removeOne("Title"));
QCOMPARE(entry->attributes()->value("URL"), QString(""));
QVERIFY(entry->attributes()->isProtected("URL"));
QVERIFY(attrs.removeOne("URL"));
QCOMPARE(entry->attributes()->value("UserName"), QString("User Name"));
QVERIFY(entry->attributes()->isProtected("UserName"));
QVERIFY(attrs.removeOne("UserName"));
QVERIFY(attrs.isEmpty());
@@ -233,7 +245,13 @@ void TestKeePass2XmlReader::testEntry1()
QCOMPARE(entry->password(), entry->attributes()->value("Password"));
QCOMPARE(entry->notes(), entry->attributes()->value("Notes"));
QCOMPARE(entry->attachments()->keys().size(), 0);
QCOMPARE(entry->attachments()->keys().size(), 1);
QCOMPARE(entry->attachments()->value("myattach.txt"), QByteArray("abcdefghijk"));
QCOMPARE(entry->historyItems().at(0)->attachments()->keys().size(), 1);
QCOMPARE(entry->historyItems().at(0)->attachments()->value("myattach.txt"), QByteArray("0123456789"));
QCOMPARE(entry->historyItems().at(1)->attachments()->keys().size(), 1);
QCOMPARE(entry->historyItems().at(1)->attachments()->value("myattach.txt"), QByteArray("abcdefghijk"));
QCOMPARE(entry->autoTypeEnabled(), false);
QCOMPARE(entry->autoTypeObfuscation(), 0);
QCOMPARE(entry->defaultAutoTypeSequence(), QString(""));
@@ -254,6 +272,7 @@ void TestKeePass2XmlReader::testEntry2()
QCOMPARE(entry->foregroundColor(), QColor(255, 0, 0));
QCOMPARE(entry->backgroundColor(), QColor(255, 255, 0));
QCOMPARE(entry->overrideUrl(), QString("http://override.net/"));
QCOMPARE(entry->tags(), QString(""));
const TimeInfo ti = entry->timeInfo();
QCOMPARE(ti.usageCount(), 7);
@@ -276,7 +295,7 @@ void TestKeePass2XmlReader::testEntry2()
QVERIFY(attrs.isEmpty());
QCOMPARE(entry->attachments()->keys().size(), 1);
QCOMPARE(QString(entry->attachments()->value("testattach.txt")), QString("42"));
QCOMPARE(QString(entry->attachments()->value("myattach.txt")), QString("abcdefghijk"));
QCOMPARE(entry->autoTypeEnabled(), true);
QCOMPARE(entry->autoTypeObfuscation(), 1);

Binary file not shown.

BIN
tests/data/Format200.kdbx Normal file

Binary file not shown.

View File

@@ -9,13 +9,16 @@
<DefaultUserName>DEFUSERNAME</DefaultUserName>
<DefaultUserNameChanged>2010-08-08T17:27:45Z</DefaultUserNameChanged>
<MaintenanceHistoryDays>127</MaintenanceHistoryDays>
<Color>#FFEF00</Color>
<MasterKeyChanged>2012-04-05T17:09:34Z</MasterKeyChanged>
<MasterKeyChangeRec>101</MasterKeyChangeRec>
<MasterKeyChangeForce>-1</MasterKeyChangeForce>
<MemoryProtection>
<ProtectTitle>False</ProtectTitle>
<ProtectUserName>True</ProtectUserName>
<ProtectPassword>False</ProtectPassword>
<ProtectURL>True</ProtectURL>
<ProtectNotes>False</ProtectNotes>
<AutoEnableVisualHiding>False</AutoEnableVisualHiding>
</MemoryProtection>
<CustomIcons>
<Icon>
@@ -30,6 +33,12 @@
<EntryTemplatesGroupChanged>2010-08-08T17:24:19Z</EntryTemplatesGroupChanged>
<LastSelectedGroup>lmU+9n0aeESKZvcEze+bRg==</LastSelectedGroup>
<LastTopVisibleGroup>lmU+9n0aeESKZvcEze+bRg==</LastTopVisibleGroup>
<HistoryMaxItems>-1</HistoryMaxItems>
<HistoryMaxSize>5242880</HistoryMaxSize>
<Binaries>
<Binary ID="0" Compressed="True">H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/InZ29+7t3//0wcHD/wfGx4SmCgAAAA==</Binary>
<Binary ID="1" Compressed="True">H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/IrLJdJafX8yLn377/wCfD1fOCwAAAA==</Binary>
</Binaries>
<CustomData>
<Item>
<Key>A Sample Test Key</Key>
@@ -67,6 +76,7 @@
<ForegroundColor />
<BackgroundColor />
<OverrideURL />
<Tags>a b c</Tags>
<Times>
<LastModificationTime>2010-08-25T16:19:25Z</LastModificationTime>
<CreationTime>2010-08-25T16:13:54Z</CreationTime>
@@ -90,12 +100,16 @@
</String>
<String>
<Key>URL</Key>
<Value />
<Value ProtectInMemory="True" />
</String>
<String>
<Key>UserName</Key>
<Value>User Name</Value>
<Value ProtectInMemory="True">User Name</Value>
</String>
<Binary>
<Key>myattach.txt</Key>
<Value Ref="1" />
</Binary>
<AutoType>
<Enabled>False</Enabled>
<DataTransferObfuscation>0</DataTransferObfuscation>
@@ -111,6 +125,7 @@
<ForegroundColor />
<BackgroundColor />
<OverrideURL />
<Tags />
<Times>
<LastModificationTime>2010-08-25T16:13:54Z</LastModificationTime>
<CreationTime>2010-08-25T16:13:54Z</CreationTime>
@@ -140,6 +155,10 @@
<Key>UserName</Key>
<Value>User Name</Value>
</String>
<Binary>
<Key>myattach.txt</Key>
<Value Ref="0" />
</Binary>
<AutoType>
<Enabled>True</Enabled>
<DataTransferObfuscation>0</DataTransferObfuscation>
@@ -155,6 +174,7 @@
<ForegroundColor />
<BackgroundColor />
<OverrideURL />
<Tags />
<Times>
<LastModificationTime>2010-08-25T16:15:43Z</LastModificationTime>
<CreationTime>2010-08-25T16:13:54Z</CreationTime>
@@ -184,6 +204,10 @@
<Key>UserName</Key>
<Value>User Name</Value>
</String>
<Binary>
<Key>myattach.txt</Key>
<Value Ref="1" />
</Binary>
<AutoType>
<Enabled>True</Enabled>
<DataTransferObfuscation>0</DataTransferObfuscation>
@@ -202,6 +226,7 @@
<ForegroundColor>#FF0000</ForegroundColor>
<BackgroundColor>#FFFF00</BackgroundColor>
<OverrideURL>http://override.net/</OverrideURL>
<Tags />
<Times>
<LastModificationTime>2010-08-25T16:20:24Z</LastModificationTime>
<CreationTime>2010-08-25T16:15:45Z</CreationTime>
@@ -233,15 +258,15 @@
</String>
<String>
<Key>URL</Key>
<Value>http://www.keepassx.org/</Value>
<Value ProtectInMemory="True">http://www.keepassx.org/</Value>
</String>
<String>
<Key>UserName</Key>
<Value>notDEFUSERNAME</Value>
<Value ProtectInMemory="True">notDEFUSERNAME</Value>
</String>
<Binary>
<Key>testattach.txt</Key>
<Value>NDI=</Value>
<Key>myattach.txt</Key>
<Value Ref="1" />
</Binary>
<AutoType>
<Enabled>True</Enabled>
@@ -322,6 +347,7 @@
<ForegroundColor />
<BackgroundColor />
<OverrideURL />
<Tags />
<Times>
<LastModificationTime>2010-08-25T16:21:15Z</LastModificationTime>
<CreationTime>2010-08-25T16:20:45Z</CreationTime>
@@ -384,6 +410,7 @@
<ForegroundColor />
<BackgroundColor />
<OverrideURL />
<Tags />
<Times>
<LastModificationTime>2010-08-25T16:20:32Z</LastModificationTime>
<CreationTime>2010-08-25T16:20:27Z</CreationTime>

Binary file not shown.

View File

@@ -0,0 +1 @@
Δöض

Binary file not shown.