From 225e5dac660b3d0e7fa325c2de654e4278e67de9 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Thu, 10 May 2012 19:34:55 +0200 Subject: [PATCH] Add tests for opening KeePass 1 databases with different keyfiles. --- tests/TestKeePass1Reader.cpp | 57 +++++++++++++++++++++++++++++++++++ tests/TestKeePass1Reader.h | 3 ++ tests/data/CompositeKey.kdb | Bin 0 -> 636 bytes tests/data/FileKeyBinary.kdb | Bin 0 -> 636 bytes tests/data/FileKeyHashed.kdb | Bin 0 -> 636 bytes tests/data/FileKeyHex.kdb | Bin 0 -> 636 bytes 6 files changed, 60 insertions(+) create mode 100644 tests/data/CompositeKey.kdb create mode 100644 tests/data/FileKeyBinary.kdb create mode 100644 tests/data/FileKeyHashed.kdb create mode 100644 tests/data/FileKeyHex.kdb diff --git a/tests/TestKeePass1Reader.cpp b/tests/TestKeePass1Reader.cpp index eff5093fc..cb0332fb8 100644 --- a/tests/TestKeePass1Reader.cpp +++ b/tests/TestKeePass1Reader.cpp @@ -17,6 +17,7 @@ #include "TestKeePass1Reader.h" +#include #include #include "config-keepassx-tests.h" @@ -122,6 +123,62 @@ void TestKeePass1Reader::testGroupExpanded() false); } +void TestKeePass1Reader::testFileKey() +{ + QFETCH(QString, type); + + QString name = QString("FileKey").append(type); + + KeePass1Reader reader; + + QString dbFilename = QString("%1/%2.kdb").arg(QString(KEEPASSX_TEST_DATA_DIR), name); + QString keyFilename = QString("%1/%2.key").arg(QString(KEEPASSX_TEST_DATA_DIR), name); + + QFile file(keyFilename); + QVERIFY(file.open(QIODevice::ReadOnly)); + QByteArray keyData = KeePass1Reader::readKeyfile(&file); + QVERIFY(!keyData.isEmpty()); + + Database* db = reader.readDatabase(dbFilename, QString(), keyData); + QVERIFY(db); + QVERIFY(!reader.hasError()); + QCOMPARE(db->rootGroup()->children().size(), 1); + QCOMPARE(db->rootGroup()->children().at(0)->name(), name); + + delete db; +} + +void TestKeePass1Reader::testFileKey_data() +{ + QTest::addColumn("type"); + QTest::newRow("Binary") << QString("Binary"); + QTest::newRow("Hex") << QString("Hex"); + QTest::newRow("Hashed") << QString("Hashed"); +} + +void TestKeePass1Reader::testCompositeKey() +{ + QString name = "CompositeKey"; + + KeePass1Reader reader; + + QString dbFilename = QString("%1/%2.kdb").arg(QString(KEEPASSX_TEST_DATA_DIR), name); + QString keyFilename = QString("%1/FileKeyHex.key").arg(QString(KEEPASSX_TEST_DATA_DIR)); + + QFile file(keyFilename); + QVERIFY(file.open(QIODevice::ReadOnly)); + QByteArray keyData = KeePass1Reader::readKeyfile(&file); + QVERIFY(!keyData.isEmpty()); + + Database* db = reader.readDatabase(dbFilename, "mypassword", keyData); + QVERIFY(db); + QVERIFY(!reader.hasError()); + QCOMPARE(db->rootGroup()->children().size(), 1); + QCOMPARE(db->rootGroup()->children().at(0)->name(), name); + + delete db; +} + void TestKeePass1Reader::cleanupTestCase() { delete m_db; diff --git a/tests/TestKeePass1Reader.h b/tests/TestKeePass1Reader.h index 194167687..8a8da4e0f 100644 --- a/tests/TestKeePass1Reader.h +++ b/tests/TestKeePass1Reader.h @@ -32,6 +32,9 @@ private Q_SLOTS: void testBasic(); void testCustomIcons(); void testGroupExpanded(); + void testFileKey(); + void testFileKey_data(); + void testCompositeKey(); void cleanupTestCase(); private: diff --git a/tests/data/CompositeKey.kdb b/tests/data/CompositeKey.kdb new file mode 100644 index 0000000000000000000000000000000000000000..70060d8f2251a3db585cef9224b76377d7d78a01 GIT binary patch literal 636 zcmV-?0)zbn*`k_d`%AS00000200RJhLUoW;eviuwp7fvJkJ$wD_l1xPzEASdLC0#Q z#&N#^000020001}icMIGPEPZwYJ#?U*oJ@z`nc8JDFK5B5VkHzS z!=5bjQ6=Yu;Ur_KsjJtr3I z$au7Y15!l%&cd2|(=}FPH1-fJr;0I#Tg1=@M;#<0MuYUcwCP`mcDEX{lG@dSM@Yt> zm}vAM>DJ^PA6(u7V-X4!bML1TG?({cT; z!F!yQebEybDa%$dz1)yAW3}`DGBRjR@LUjs{;ixA#J5liEDewyCOP&L zHuZ5=pwD>^1AJc6(%?TTgEBsF%J@Ry^pH{MvVW!c`VopCw>0C!jTR3!p`5)3*o<~E z+Ncbg+G*krXd=!%i}fTT=1C0h;~iSTS8GYpLs7D5gq^*FKCAEnY=uH6hvH0d+XY|} W)OqW0Kg}p!B#V}eVr)qbskOZQeK_6# literal 0 HcmV?d00001 diff --git a/tests/data/FileKeyBinary.kdb b/tests/data/FileKeyBinary.kdb new file mode 100644 index 0000000000000000000000000000000000000000..0ce9f58b74b76be49a54ed772a68864ecef1a433 GIT binary patch literal 636 zcmV-?0)zbn*`k_d`%AS00000200RJ(yze<+XX3b`xXP)!O~o~(c~_Q~H~jC&k5#67 zY^Ll1000020000$99WkGZHVsdjFzFdLR%>%qTqiMk zHxf_CY=;TgnJ;8&pQ6~2GFEy`Xr?k#4T-5wTzruVj(KN*y#=)Pr)Q4&Gz^FKD=0As zuclKxf$)_X#5&iM^?;M>X)ocm739N!o-%pjUx%WLkc7*p_4d>kwr|lZ)`I(o8iQ#H zJT7un1}$izDvc21V#i3h6kQ;j?p4iimXaQNw2$fX_b%5ejdwZ2Sd2vklz!6AD&k!a zrX(A)a10ksznzdK3_e~lV=2{NB$$@0zczM8p0Oe-0dBGDqcM|gzgkk145O6TXqbIU z2&s#lP{RbB7^i!EG3UCOc;t8x32ELAl6t3giibSi#G{OH0NGNlhu7ALBpoSe1_A=# zII1Kqb(!lBLM&ubb2?KC8(wBLZT@QKUMr1%)r-X|w{TBi+vbMxw@P@#ndW9@lxG2l zt0P%{KR&o#Yo;>XY~sUPjcZzNx>`9JmU?&j( literal 0 HcmV?d00001 diff --git a/tests/data/FileKeyHashed.kdb b/tests/data/FileKeyHashed.kdb new file mode 100644 index 0000000000000000000000000000000000000000..8ef734720375daa95b9f7e0d05201b0ce84b1cbc GIT binary patch literal 636 zcmV-?0)zbn*`k_d`%AS00000200RIH)9)iVH|DpPi8Kk`R@DE+-QF*{ORdlwD*w`4 zi49=^0000200016p*!oHOpa-a)HLivK%%w*a8Y2!0*aCEr%!bKvLS*L4LeBIU?n+K z69KNhR&(fnJjHF0Q~ktZ9ba+D43Fwi!vFx(bR0&(i#`V~MOU-G#sg?Ob}d9v6ljw2 zJ1i#fcs==^Ts_h|^(m6v;ckA?Iw%;-t!H`tno=TF5d!6o;<_ z*Q$MxAyS=duWiD~{zrWkVwU@y#qPvs6^zHlPMq8!Jzg{nkdEbc`YY-+Nkybi-f!I4 z7~@=CQwXsv5zRHY^z0eWVDlhlR0L?6c~7ok1#t2UP?Y?Qkd66g^_f1j>&|H7^bD?S zIHgNt77jf+fkX4sk8T66g_*6!`<&gE%_~~cGH@A`R#r0oL+ozwrIZlt!%)3*ffibS zEkE_v#--h=x#&6h=4Z-85#k(99le5ODe)2%MeD><=0X%drA;gv$k)!J=bIU2jZ+wv zZVBC(1J2Yf8NEFMH_w9Q^tEMhQzqm2eY>gty$Fim8b!vNY;w1N`A_W3Kjug#?JcvR zx?B4U6*AWcvTPagVq<3OTeH$XG86KBHfAcEE9edk%y_ZdkNHqxn literal 0 HcmV?d00001 diff --git a/tests/data/FileKeyHex.kdb b/tests/data/FileKeyHex.kdb new file mode 100644 index 0000000000000000000000000000000000000000..ed872c586e8afdaa5c28e994c7875f2d90d19c1b GIT binary patch literal 636 zcmV-?0)zbn*`k_d`%AS00000200RKWuCopgwAr=x1R_{W2FHxw;f|*J;f2`zXn9zs zzmX^b000020002#buZMWp)Qy-?`(L@h!x2Gz9(p?KQbB_+m5q^Qca~f{2M0k1T&tJ zm9D5@$vOO81RHge95UY|kKmFlPfiF>!vFwSQJut*7uf&lv2kc>Uvnx;q*w|CeR z^Y#=cmBPWwIG#8JR4XLoXvhs7q)H=x*tQ@V@SOy{pX*(3oZ`Cyp6_#v8bcLg znK35JCznB8y}d$j;ETCg=0wed?}e2J{06C;%3cvaZ+L82+bw$AIATp3>{TkoRn(%s z`7M5??StCcuU6ywbaDhk`a4R|v2>6W5v>G$E-AzOdJJd+$~SN1PNYS><}Q$~Iz#)0 zUWNY0J~2S}(x%2{ZSQKd0v0NR2Xqa(I&2$*Qws{!DQORSfr501e2ROCwiS}sXXU^F z758@$g6p!=ArOYA{<1sAj2%0VHyA6?7?I1@h0$12?lz_7Tecg`EiHg5Cdmldkl=zg zME}5PuTK%J7n*s6$dKbyaRTu})K0VoyD7Wuw zCY#%hfE4a*$?CW>@-u~d?Lky+^-(m-zWt;?beRfnyjw*h=wt~(;u(pqXarT4=5y2V W3_(;ct=l?Zdk4@xo-g#QO85H%hBnav literal 0 HcmV?d00001