Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Geyer <debfx@fobos.de>2012-05-10 23:06:33 +0400
committerFelix Geyer <debfx@fobos.de>2012-05-10 23:06:33 +0400
commitcf4e574c50b6cddf10ee40f6b7a1626cc8518a12 (patch)
tree8c2f82ad7898d89a53b32e634c0691271051ec26
parent225e5dac660b3d0e7fa325c2de654e4278e67de9 (diff)
Support Twofish encrypted KeePass 1 databases.
Refs #2
-rw-r--r--src/crypto/SymmetricCipher.cpp1
-rw-r--r--src/crypto/SymmetricCipher.h1
-rw-r--r--src/crypto/SymmetricCipherGcrypt.cpp18
-rw-r--r--src/crypto/SymmetricCipherGcrypt.h1
-rw-r--r--src/format/KeePass1.h2
-rw-r--r--src/format/KeePass1Reader.cpp3
-rw-r--r--tests/TestKeePass1Reader.cpp17
-rw-r--r--tests/TestKeePass1Reader.h1
-rw-r--r--tests/data/Twofish.kdbbin0 -> 620 bytes
9 files changed, 39 insertions, 5 deletions
diff --git a/src/crypto/SymmetricCipher.cpp b/src/crypto/SymmetricCipher.cpp
index 0e50dd4ad..383b3024f 100644
--- a/src/crypto/SymmetricCipher.cpp
+++ b/src/crypto/SymmetricCipher.cpp
@@ -38,6 +38,7 @@ SymmetricCipherBackend* SymmetricCipher::createBackend(SymmetricCipher::Algorith
{
switch (algo) {
case SymmetricCipher::Aes256:
+ case SymmetricCipher::Twofish:
return new SymmetricCipherGcrypt(algo, mode, direction);
case SymmetricCipher::Salsa20:
diff --git a/src/crypto/SymmetricCipher.h b/src/crypto/SymmetricCipher.h
index c5c67543a..2a9d910ae 100644
--- a/src/crypto/SymmetricCipher.h
+++ b/src/crypto/SymmetricCipher.h
@@ -29,6 +29,7 @@ public:
enum Algorithm
{
Aes256,
+ Twofish,
Salsa20
};
diff --git a/src/crypto/SymmetricCipherGcrypt.cpp b/src/crypto/SymmetricCipherGcrypt.cpp
index fabe3c4d9..4324a28a0 100644
--- a/src/crypto/SymmetricCipherGcrypt.cpp
+++ b/src/crypto/SymmetricCipherGcrypt.cpp
@@ -21,12 +21,11 @@
SymmetricCipherGcrypt::SymmetricCipherGcrypt(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
SymmetricCipher::Direction direction)
- : m_algo(GCRY_CIPHER_AES256)
+ : m_algo(gcryptAlgo(algo))
, m_mode(gcryptMode(mode))
, m_direction(direction)
{
Q_ASSERT(Crypto::initalized());
- Q_ASSERT(algo == SymmetricCipher::Aes256);
}
SymmetricCipherGcrypt::~SymmetricCipherGcrypt()
@@ -34,6 +33,21 @@ SymmetricCipherGcrypt::~SymmetricCipherGcrypt()
gcry_cipher_close(m_ctx);
}
+int SymmetricCipherGcrypt::gcryptAlgo(SymmetricCipher::Algorithm algo)
+{
+ switch (algo) {
+ case SymmetricCipher::Aes256:
+ return GCRY_CIPHER_AES256;
+
+ case SymmetricCipher::Twofish:
+ return GCRY_CIPHER_TWOFISH;
+
+ default:
+ Q_ASSERT(false);
+ return -1;
+ }
+}
+
int SymmetricCipherGcrypt::gcryptMode(SymmetricCipher::Mode mode)
{
switch (mode) {
diff --git a/src/crypto/SymmetricCipherGcrypt.h b/src/crypto/SymmetricCipherGcrypt.h
index 3af7c705b..2b255df5d 100644
--- a/src/crypto/SymmetricCipherGcrypt.h
+++ b/src/crypto/SymmetricCipherGcrypt.h
@@ -41,6 +41,7 @@ public:
int blockSize() const;
private:
+ static int gcryptAlgo(SymmetricCipher::Algorithm algo);
static int gcryptMode(SymmetricCipher::Mode mode);
gcry_cipher_hd_t m_ctx;
diff --git a/src/format/KeePass1.h b/src/format/KeePass1.h
index 7e656c0cd..0a1c56e56 100644
--- a/src/format/KeePass1.h
+++ b/src/format/KeePass1.h
@@ -20,8 +20,6 @@
#include <QtCore/QtGlobal>
-#include "core/Uuid.h"
-
namespace KeePass1
{
const quint32 SIGNATURE_1 = 0x9AA2D903;
diff --git a/src/format/KeePass1Reader.cpp b/src/format/KeePass1Reader.cpp
index 6d5b294f4..de219325e 100644
--- a/src/format/KeePass1Reader.cpp
+++ b/src/format/KeePass1Reader.cpp
@@ -272,7 +272,8 @@ SymmetricCipherStream* KeePass1Reader::testKeys(const QString& password, const Q
SymmetricCipher::Cbc, SymmetricCipher::Decrypt, finalKey, m_encryptionIV));
}
else {
- // TODO twofish
+ cipherStream.reset(new SymmetricCipherStream(m_device, SymmetricCipher::Twofish,
+ SymmetricCipher::Cbc, SymmetricCipher::Decrypt, finalKey, m_encryptionIV));
}
cipherStream->open(QIODevice::ReadOnly);
diff --git a/tests/TestKeePass1Reader.cpp b/tests/TestKeePass1Reader.cpp
index cb0332fb8..ea4a7d64a 100644
--- a/tests/TestKeePass1Reader.cpp
+++ b/tests/TestKeePass1Reader.cpp
@@ -179,6 +179,23 @@ void TestKeePass1Reader::testCompositeKey()
delete db;
}
+void TestKeePass1Reader::testTwofish()
+{
+ QString name = "Twofish";
+
+ KeePass1Reader reader;
+
+ QString dbFilename = QString("%1/%2.kdb").arg(QString(KEEPASSX_TEST_DATA_DIR), name);
+
+ Database* db = reader.readDatabase(dbFilename, "masterpw", QByteArray());
+ 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 8a8da4e0f..fe1c435fd 100644
--- a/tests/TestKeePass1Reader.h
+++ b/tests/TestKeePass1Reader.h
@@ -35,6 +35,7 @@ private Q_SLOTS:
void testFileKey();
void testFileKey_data();
void testCompositeKey();
+ void testTwofish();
void cleanupTestCase();
private:
diff --git a/tests/data/Twofish.kdb b/tests/data/Twofish.kdb
new file mode 100644
index 000000000..eb4ae6dc5
--- /dev/null
+++ b/tests/data/Twofish.kdb
Binary files differ