2012-05-08 16:03:59 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KEEPASSX_KEEPASS1READER_H
|
|
|
|
#define KEEPASSX_KEEPASS1READER_H
|
|
|
|
|
|
|
|
#include <QtCore/QCoreApplication>
|
2012-05-09 17:14:27 -04:00
|
|
|
#include <QtCore/QDateTime>
|
|
|
|
#include <QtCore/QHash>
|
2012-05-08 16:03:59 -04:00
|
|
|
|
|
|
|
class Database;
|
2012-05-09 17:14:27 -04:00
|
|
|
class Entry;
|
|
|
|
class Group;
|
2012-05-08 16:03:59 -04:00
|
|
|
class SymmetricCipherStream;
|
|
|
|
class QIODevice;
|
|
|
|
|
|
|
|
class KeePass1Reader
|
|
|
|
{
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(KeePass1Reader)
|
|
|
|
|
|
|
|
public:
|
|
|
|
KeePass1Reader();
|
|
|
|
Database* readDatabase(QIODevice* device, const QString& password,
|
2012-05-10 16:46:36 -04:00
|
|
|
QIODevice* keyfileDevice);
|
2012-05-12 04:08:41 -04:00
|
|
|
Database* readDatabase(QIODevice* device, const QString& password,
|
|
|
|
const QString& keyfileName);
|
2012-05-08 16:03:59 -04:00
|
|
|
Database* readDatabase(const QString& filename, const QString& password,
|
2012-05-10 16:46:36 -04:00
|
|
|
const QString& keyfileName);
|
2012-05-08 16:03:59 -04:00
|
|
|
bool hasError();
|
|
|
|
QString errorString();
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum PasswordEncoding
|
|
|
|
{
|
|
|
|
Windows1252,
|
|
|
|
Latin1,
|
|
|
|
UTF8
|
|
|
|
};
|
|
|
|
|
|
|
|
SymmetricCipherStream* testKeys(const QString& password, const QByteArray& keyfileData,
|
|
|
|
qint64 contentPos);
|
|
|
|
QByteArray key(const QByteArray& password, const QByteArray& keyfileData);
|
|
|
|
bool verifyKey(SymmetricCipherStream* cipherStream);
|
2012-05-09 17:14:27 -04:00
|
|
|
Group* readGroup(QIODevice* cipherStream);
|
|
|
|
Entry* readEntry(QIODevice* cipherStream);
|
|
|
|
bool constructGroupTree(const QList<Group*> groups);
|
2012-05-10 05:44:25 -04:00
|
|
|
void parseMetaStream(const Entry* entry);
|
|
|
|
bool parseGroupTreeState(const QByteArray& data);
|
|
|
|
bool parseCustomIcons4(const QByteArray& data);
|
2012-05-08 16:03:59 -04:00
|
|
|
void raiseError(const QString& str);
|
2012-05-10 16:46:36 -04:00
|
|
|
static QByteArray readKeyfile(QIODevice* device);
|
2012-05-09 17:14:27 -04:00
|
|
|
static QDateTime dateFromPackedStruct(const QByteArray& data);
|
|
|
|
static bool isMetaStream(const Entry* entry);
|
2012-05-08 16:03:59 -04:00
|
|
|
|
|
|
|
Database* m_db;
|
2012-05-09 17:14:27 -04:00
|
|
|
Group* m_tmpParent;
|
2012-05-08 16:03:59 -04:00
|
|
|
QIODevice* m_device;
|
|
|
|
quint32 m_encryptionFlags;
|
|
|
|
QByteArray m_masterSeed;
|
|
|
|
QByteArray m_encryptionIV;
|
|
|
|
QByteArray m_contentHashHeader;
|
|
|
|
QByteArray m_transformSeed;
|
|
|
|
quint32 m_transformRounds;
|
2012-05-09 17:14:27 -04:00
|
|
|
QHash<quint32, Group*> m_groupIds;
|
|
|
|
QHash<Group*, quint32> m_groupLevels;
|
|
|
|
QHash<QByteArray, Entry*> m_entryUuids;
|
2012-05-10 16:54:26 -04:00
|
|
|
QHash<Entry*, quint32> m_entryGroupIds;
|
2012-05-08 16:03:59 -04:00
|
|
|
|
|
|
|
bool m_error;
|
|
|
|
QString m_errorStr;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // KEEPASSX_KEEPASS1READER_H
|