mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-25 07:19:42 -05:00
Open a kdbx file in main() and add more SymmetricCipher tests.
This commit is contained in:
parent
9f282928e8
commit
d508c2dd68
18
src/main.cpp
18
src/main.cpp
@ -19,8 +19,12 @@
|
|||||||
#include <QtGui/QTreeView>
|
#include <QtGui/QTreeView>
|
||||||
|
|
||||||
#include "core/Database.h"
|
#include "core/Database.h"
|
||||||
|
#include "crypto/Crypto.h"
|
||||||
|
#include "format/KeePass2Reader.h"
|
||||||
#include "format/KeePass2XmlReader.h"
|
#include "format/KeePass2XmlReader.h"
|
||||||
#include "gui/DatabaseWidget.h"
|
#include "gui/DatabaseWidget.h"
|
||||||
|
#include "keys/CompositeKey.h"
|
||||||
|
#include "keys/PasswordKey.h"
|
||||||
|
|
||||||
#include "../tests/config-keepassx-tests.h"
|
#include "../tests/config-keepassx-tests.h"
|
||||||
|
|
||||||
@ -28,8 +32,18 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
KeePass2XmlReader* reader = new KeePass2XmlReader();
|
Crypto::init();
|
||||||
Database* db = reader->readDatabase(QString(KEEPASSX_TEST_DIR).append("/NewDatabase.xml"));
|
|
||||||
|
CompositeKey key;
|
||||||
|
PasswordKey password;
|
||||||
|
password.setPassword("a");
|
||||||
|
key.addKey(password);
|
||||||
|
|
||||||
|
KeePass2Reader* xreader = new KeePass2Reader();
|
||||||
|
Database* db = xreader->readDatabase(QString(KEEPASSX_TEST_DIR).append("/NewDatabase.kdbx"), key);
|
||||||
|
|
||||||
|
//KeePass2XmlReader* reader = new KeePass2XmlReader();
|
||||||
|
//Database* db = reader->readDatabase(QString(KEEPASSX_TEST_DIR).append("/NewDatabase.xml"));
|
||||||
|
|
||||||
DatabaseWidget dbWidget(db);
|
DatabaseWidget dbWidget(db);
|
||||||
dbWidget.show();
|
dbWidget.show();
|
||||||
|
BIN
tests/NewDatabase.kdbx
Normal file
BIN
tests/NewDatabase.kdbx
Normal file
Binary file not shown.
@ -15,10 +15,12 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QtCore/QBuffer>
|
||||||
#include <QtTest/QTest>
|
#include <QtTest/QTest>
|
||||||
|
|
||||||
#include "crypto/Crypto.h"
|
#include "crypto/Crypto.h"
|
||||||
#include "crypto/SymmetricCipher.h"
|
#include "crypto/SymmetricCipher.h"
|
||||||
|
#include "streams/SymmetricCipherStream.h"
|
||||||
|
|
||||||
class TestSymmetricCipher : public QObject
|
class TestSymmetricCipher : public QObject
|
||||||
{
|
{
|
||||||
@ -27,6 +29,7 @@ class TestSymmetricCipher : public QObject
|
|||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
void testAes256CbcEncryption();
|
void testAes256CbcEncryption();
|
||||||
|
void testAes256CbcDecryption();
|
||||||
};
|
};
|
||||||
|
|
||||||
void TestSymmetricCipher::initTestCase()
|
void TestSymmetricCipher::initTestCase()
|
||||||
@ -40,11 +43,52 @@ void TestSymmetricCipher::testAes256CbcEncryption()
|
|||||||
|
|
||||||
QByteArray key = QByteArray::fromHex("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
|
QByteArray key = QByteArray::fromHex("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
|
||||||
QByteArray iv = QByteArray::fromHex("000102030405060708090a0b0c0d0e0f");
|
QByteArray iv = QByteArray::fromHex("000102030405060708090a0b0c0d0e0f");
|
||||||
QByteArray plain = QByteArray::fromHex("6bc1bee22e409f96e93d7e117393172a");
|
QByteArray plainText = QByteArray::fromHex("6bc1bee22e409f96e93d7e117393172a");
|
||||||
|
plainText.append(QByteArray::fromHex("ae2d8a571e03ac9c9eb76fac45af8e51"));
|
||||||
|
QByteArray cipherText = QByteArray::fromHex("f58c4c04d6e5f1ba779eabfb5f7bfbd6");
|
||||||
|
cipherText.append(QByteArray::fromHex("9cfc4e967edb808d679f777bc6702c7d"));
|
||||||
|
|
||||||
SymmetricCipher encrypt(SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Encrypt, key, iv);
|
SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Encrypt, key, iv);
|
||||||
QCOMPARE(QString(encrypt.process(plain).toHex()),
|
QCOMPARE(cipher.blockSize(), 16);
|
||||||
QString("f58c4c04d6e5f1ba779eabfb5f7bfbd6"));
|
|
||||||
|
QCOMPARE(QString(cipher.process(plainText).toHex()),
|
||||||
|
QString(cipherText.toHex()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestSymmetricCipher::testAes256CbcDecryption()
|
||||||
|
{
|
||||||
|
QByteArray key = QByteArray::fromHex("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
|
||||||
|
QByteArray iv = QByteArray::fromHex("000102030405060708090a0b0c0d0e0f");
|
||||||
|
QByteArray cipherText = QByteArray::fromHex("f58c4c04d6e5f1ba779eabfb5f7bfbd6");
|
||||||
|
cipherText.append(QByteArray::fromHex("9cfc4e967edb808d679f777bc6702c7d"));
|
||||||
|
QByteArray plainText = QByteArray::fromHex("6bc1bee22e409f96e93d7e117393172a");
|
||||||
|
plainText.append(QByteArray::fromHex("ae2d8a571e03ac9c9eb76fac45af8e51"));
|
||||||
|
|
||||||
|
SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Decrypt, key, iv);
|
||||||
|
QCOMPARE(cipher.blockSize(), 16);
|
||||||
|
|
||||||
|
QCOMPARE(QString(cipher.process(cipherText).toHex()),
|
||||||
|
QString(plainText.toHex()));
|
||||||
|
|
||||||
|
QBuffer buffer(&cipherText);
|
||||||
|
SymmetricCipherStream stream(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Decrypt, key, iv);
|
||||||
|
buffer.open(QIODevice::ReadOnly);
|
||||||
|
stream.open(QIODevice::ReadOnly);
|
||||||
|
|
||||||
|
QCOMPARE(QString(stream.read(10).toHex()),
|
||||||
|
QString(plainText.left(10).toHex()));
|
||||||
|
buffer.reset();
|
||||||
|
stream.reset();
|
||||||
|
QCOMPARE(QString(stream.read(20).toHex()),
|
||||||
|
QString(plainText.left(20).toHex()));
|
||||||
|
buffer.reset();
|
||||||
|
stream.reset();
|
||||||
|
QCOMPARE(QString(stream.read(16).toHex()),
|
||||||
|
QString(plainText.left(16).toHex()));
|
||||||
|
buffer.reset();
|
||||||
|
stream.reset();
|
||||||
|
QCOMPARE(QString(stream.read(100).toHex()),
|
||||||
|
QString(plainText.toHex()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(TestSymmetricCipher);
|
QTEST_MAIN(TestSymmetricCipher);
|
||||||
|
Loading…
Reference in New Issue
Block a user