Skip to content

Commit

Permalink
Add support for gzip compressed databases.
Browse files Browse the repository at this point in the history
  • Loading branch information
debfx committed Sep 23, 2010
1 parent f0e711a commit b8dfb9c
Show file tree
Hide file tree
Showing 13 changed files with 1,290 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ find_package(Automoc4 REQUIRED)

find_package(Libgcrypt REQUIRED)

find_package(ZLIB REQUIRED)

add_subdirectory(src)
if( WITH_TESTS )
add_subdirectory(tests)
Expand Down
4 changes: 4 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Files: share/icons/entries/*.png
Copyright: 2003-2004, David Vignoni <[email protected]>
License: LGPL-2.1

Files: src/streams/qtiocompressor.*, src/streams/QtIOCompressor
Copyright: 2009, Nokia Corporation and/or its subsidiary(-ies)
License: LGPL-2.1 or GPL-3

Files: tests/modeltest.*
Copyright: 2007, Trolltech ASA
License: GPL-2
502 changes: 502 additions & 0 deletions LICENSE.LGPL

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions LICENSE.NOKIA-LGPL-EXCEPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Nokia Qt LGPL Exception version 1.1

As an additional permission to the GNU Lesser General Public License
version 2.1, the object code form of a "work that uses the Library"
may incorporate material from a header file that is part of the
Library. You may distribute such object code under terms of your
choice, provided that:
(i) the header files of the Library have not been modified; and
(ii) the incorporated material is limited to numerical parameters,
data structure layouts, accessors, macros, inline functions and
templates; and
(iii) you comply with the terms of Section 6 of the GNU
Lesser General Public License version 2.1.

Moreover, you may apply this exception to a modified version of the
Library, provided that such modification does not involve copying
material from the Library into the modified Library?s header files
unless such material is limited to (i) numerical parameters; (ii) data
structure layouts; (iii) accessors; and (iv) small macros, templates
and inline functions of five lines or less in length.

Furthermore, you are not required to apply this additional permission
to a modified version of the Library.
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set(keepassx_SOURCES
keys/PasswordKey.cpp
streams/HashedBlockStream.cpp
streams/LayeredStream.cpp
streams/qtiocompressor.cpp
streams/SymmetricCipherStream.cpp
)

Expand All @@ -55,4 +56,4 @@ qt4_wrap_ui(keepassx_SOURCES ${keepassx_FORMS})
automoc4_add_library( keepassx_core STATIC ${keepassx_SOURCES} )

automoc4_add_executable( ${PROGNAME} WIN32 MACOSX_BUNDLE main.cpp )
target_link_libraries( ${PROGNAME} keepassx_core ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${LIBGCRYPT_LIBS} )
target_link_libraries( ${PROGNAME} keepassx_core ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${LIBGCRYPT_LIBS} ${ZLIB_LIBRARIES} )
20 changes: 17 additions & 3 deletions src/format/KeePass2Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#include <QtCore/QFile>
#include <QtCore/QIODevice>

#include "KeePass2.h"
#include "KeePass2XmlReader.h"
#include "crypto/CryptoHash.h"
#include "streams/HashedBlockStream.h"
#include "streams/QtIOCompressor"
#include "streams/SymmetricCipherStream.h"

const QSysInfo::Endian KeePass2Reader::BYTEORDER = QSysInfo::LittleEndian;
Expand Down Expand Up @@ -80,8 +80,22 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke
HashedBlockStream hashedStream(&cipherStream);
hashedStream.open(QIODevice::ReadOnly);

QIODevice* xmlDevice;
QScopedPointer<QtIOCompressor> ioCompressor;

if (m_compression == KeePass2::CompressionNone) {
xmlDevice = &hashedStream;
}
else {
ioCompressor.reset(new QtIOCompressor(&hashedStream));
ioCompressor->setStreamFormat(QtIOCompressor::GzipFormat);
ioCompressor->open(QIODevice::ReadOnly);
xmlDevice = ioCompressor.data();
}

KeePass2XmlReader xmlReader;
Database* db = xmlReader.readDatabase(&hashedStream);
Database* db = xmlReader.readDatabase(xmlDevice);
// TODO forward error messages from xmlReader
return db;
}

Expand Down Expand Up @@ -208,7 +222,7 @@ void KeePass2Reader::setCompressionFlags(const QByteArray& data)
raiseError("");
}
else {
m_compression = id;
m_compression = static_cast<KeePass2::CompressionAlgorithm>(id);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/format/KeePass2Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "core/Endian.h"
#include "core/Uuid.h"
#include "keys/CompositeKey.h"
#include "format/KeePass2.h"

class Database;

Expand Down Expand Up @@ -59,7 +60,7 @@ class KeePass2Reader
bool m_headerEnd;

Uuid m_cipher;
int m_compression;
KeePass2::CompressionAlgorithm m_compression;
QByteArray m_masterSeed;
QByteArray m_transformSeed;
quint64 m_transformRounds;
Expand Down
1 change: 1 addition & 0 deletions src/streams/QtIOCompressor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "qtiocompressor.h"
Loading

0 comments on commit b8dfb9c

Please sign in to comment.