Skip to content

Commit

Permalink
Merge pull request #1770 from pasdam/feature/useQuuid
Browse files Browse the repository at this point in the history
Replaced Uuid with QUuid
  • Loading branch information
droidmonkey authored Jul 9, 2018
2 parents 0142e07 + c47882b commit 470a74e
Show file tree
Hide file tree
Showing 53 changed files with 440 additions and 647 deletions.
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ set(keepassx_SOURCES
core/TimeInfo.cpp
core/Tools.cpp
core/Translator.cpp
core/Uuid.cpp
core/Base32.h
core/Base32.cpp
cli/Utils.cpp
Expand Down
30 changes: 13 additions & 17 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <QJsonArray>
#include <QInputDialog>
#include <QProgressDialog>
#include <QMessageBox>
#include <QUuid>

#include "BrowserService.h"
#include "BrowserAccessControlDialog.h"
#include "BrowserEntryConfig.h"
Expand All @@ -26,19 +32,9 @@
#include "core/Group.h"
#include "core/Metadata.h"
#include "core/PasswordGenerator.h"
#include "core/Uuid.h"
#include "gui/MainWindow.h"
#include <QInputDialog>
#include <QJsonArray>
#include <QMessageBox>
#include <QProgressDialog>

// de887cc3-0363-43b8-974b-5911b8816224
static const unsigned char KEEPASSXCBROWSER_UUID_DATA[] =
{0xde, 0x88, 0x7c, 0xc3, 0x03, 0x63, 0x43, 0xb8, 0x97, 0x4b, 0x59, 0x11, 0xb8, 0x81, 0x62, 0x24};
static const Uuid KEEPASSXCBROWSER_UUID =
Uuid(QByteArray::fromRawData(reinterpret_cast<const char*>(KEEPASSXCBROWSER_UUID_DATA),
sizeof(KEEPASSXCBROWSER_UUID_DATA)));
static const QUuid KEEPASSXCBROWSER_UUID = QUuid::fromRfc4122(QByteArray::fromHex("de887cc3036343b8974b5911b8816224"));
static const char KEEPASSXCBROWSER_NAME[] = "KeePassXC-Browser Settings";
static const char ASSOCIATE_KEY_PREFIX[] = "Public Key: ";
static const char KEEPASSXCBROWSER_GROUP_NAME[] = "KeePassXC-Browser Passwords";
Expand Down Expand Up @@ -118,7 +114,7 @@ QString BrowserService::getDatabaseRootUuid()
return QString();
}

return rootGroup->uuid().toHex();
return QString::fromLatin1(rootGroup->uuid().toRfc4122().toHex());
}

QString BrowserService::getDatabaseRecycleBinUuid()
Expand All @@ -132,7 +128,7 @@ QString BrowserService::getDatabaseRecycleBinUuid()
if (!recycleBin) {
return QString();
}
return recycleBin->uuid().toHex();
return QString::fromLatin1(recycleBin->uuid().toRfc4122().toHex());
}

Entry* BrowserService::getConfigEntry(bool create)
Expand Down Expand Up @@ -306,7 +302,7 @@ void BrowserService::addEntry(const QString&,
}

Entry* entry = new Entry();
entry->setUuid(Uuid::random());
entry->setUuid(QUuid::createUuid());
entry->setTitle(QUrl(url).host());
entry->setUrl(url);
entry->setIcon(KEEPASSXCBROWSER_DEFAULT_ICON);
Expand Down Expand Up @@ -350,7 +346,7 @@ void BrowserService::updateEntry(const QString& id,
return;
}

Entry* entry = db->resolveEntry(Uuid::fromHex(uuid));
Entry* entry = db->resolveEntry(QUuid::fromRfc4122(QByteArray::fromHex(uuid.toLatin1())));
if (!entry) {
return;
}
Expand Down Expand Up @@ -631,7 +627,7 @@ QJsonObject BrowserService::prepareEntry(const Entry* entry)
res["login"] = entry->resolveMultiplePlaceholders(entry->username());
res["password"] = entry->resolveMultiplePlaceholders(entry->password());
res["name"] = entry->resolveMultiplePlaceholders(entry->title());
res["uuid"] = entry->resolveMultiplePlaceholders(entry->uuid().toHex());
res["uuid"] = entry->resolveMultiplePlaceholders(QString::fromLatin1(entry->uuid().toRfc4122().toHex()));

if (entry->hasTotp()) {
res["totp"] = entry->totp();
Expand Down Expand Up @@ -693,7 +689,7 @@ Group* BrowserService::findCreateAddEntryGroup()
}

Group* group = new Group();
group->setUuid(Uuid::random());
group->setUuid(QUuid::createUuid());
group->setName(groupName);
group->setIcon(KEEPASSXCBROWSER_DEFAULT_ICON);
group->setParent(rootGroup);
Expand Down
33 changes: 17 additions & 16 deletions src/core/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "Database.h"

#include <QDebug>
#include <QFile>
#include <QSaveFile>
#include <QTemporaryFile>
Expand All @@ -35,13 +36,13 @@
#include "keys/FileKey.h"
#include "keys/PasswordKey.h"

QHash<Uuid, Database*> Database::m_uuidMap;
QHash<QUuid, Database*> Database::m_uuidMap;

Database::Database()
: m_metadata(new Metadata(this))
, m_timer(new QTimer(this))
, m_emitModified(false)
, m_uuid(Uuid::random())
, m_uuid(QUuid::createUuid())
{
m_data.cipher = KeePass2::CIPHER_AES;
m_data.compressionAlgo = CompressionGZip;
Expand All @@ -53,7 +54,7 @@ Database::Database()
m_data.hasKey = false;

setRootGroup(new Group());
rootGroup()->setUuid(Uuid::random());
rootGroup()->setUuid(QUuid::createUuid());
m_timer->setSingleShot(true);

m_uuidMap.insert(m_uuid, this);
Expand Down Expand Up @@ -97,7 +98,7 @@ const Metadata* Database::metadata() const
return m_metadata;
}

Entry* Database::resolveEntry(const Uuid& uuid)
Entry* Database::resolveEntry(const QUuid& uuid)
{
return findEntryRecursive(uuid, m_rootGroup);
}
Expand All @@ -107,7 +108,7 @@ Entry* Database::resolveEntry(const QString& text, EntryReferenceType referenceT
return findEntryRecursive(text, referenceType, m_rootGroup);
}

Entry* Database::findEntryRecursive(const Uuid& uuid, Group* group)
Entry* Database::findEntryRecursive(const QUuid& uuid, Group* group)
{
const QList<Entry*> entryList = group->entries();
for (Entry* entry : entryList) {
Expand Down Expand Up @@ -154,8 +155,8 @@ Entry* Database::findEntryRecursive(const QString& text, EntryReferenceType refe
case EntryReferenceType::Notes:
found = entry->notes() == text;
break;
case EntryReferenceType::Uuid:
found = entry->uuid() == Uuid::fromHex(text);
case EntryReferenceType::QUuid:
found = entry->uuid() == QUuid::fromRfc4122(QByteArray::fromHex(text.toLatin1()));
break;
case EntryReferenceType::CustomAttributes:
found = entry->attributes()->containsValue(text);
Expand All @@ -178,12 +179,12 @@ Entry* Database::findEntryRecursive(const QString& text, EntryReferenceType refe
return nullptr;
}

Group* Database::resolveGroup(const Uuid& uuid)
Group* Database::resolveGroup(const QUuid& uuid)
{
return findGroupRecursive(uuid, m_rootGroup);
}

Group* Database::findGroupRecursive(const Uuid& uuid, Group* group)
Group* Database::findGroupRecursive(const QUuid& uuid, Group* group)
{
if (group->uuid() == uuid) {
return group;
Expand Down Expand Up @@ -211,7 +212,7 @@ void Database::addDeletedObject(const DeletedObject& delObj)
m_deletedObjects.append(delObj);
}

void Database::addDeletedObject(const Uuid& uuid)
void Database::addDeletedObject(const QUuid& uuid)
{
DeletedObject delObj;
delObj.deletionTime = QDateTime::currentDateTimeUtc();
Expand All @@ -220,7 +221,7 @@ void Database::addDeletedObject(const Uuid& uuid)
addDeletedObject(delObj);
}

Uuid Database::cipher() const
const QUuid& Database::cipher() const
{
return m_data.cipher;
}
Expand All @@ -246,7 +247,7 @@ bool Database::challengeMasterSeed(const QByteArray& masterSeed)
return m_data.key.challenge(masterSeed, m_data.challengeResponseKey);
}

void Database::setCipher(const Uuid& cipher)
void Database::setCipher(const QUuid& cipher)
{
Q_ASSERT(!cipher.isNull());

Expand Down Expand Up @@ -387,10 +388,10 @@ void Database::merge(const Database* other)
{
m_rootGroup->merge(other->rootGroup());

for (Uuid customIconId : other->metadata()->customIcons().keys()) {
for (const QUuid& customIconId : other->metadata()->customIcons().keys()) {
QImage customIcon = other->metadata()->customIcon(customIconId);
if (!this->metadata()->containsCustomIcon(customIconId)) {
qDebug("Adding custom icon %s to database.", qPrintable(customIconId.toHex()));
qDebug() << QString("Adding custom icon %1 to database.").arg(customIconId.toString());
this->metadata()->addCustomIcon(customIconId, customIcon);
}
}
Expand All @@ -407,12 +408,12 @@ void Database::setEmitModified(bool value)
m_emitModified = value;
}

Uuid Database::uuid()
const QUuid& Database::uuid()
{
return m_uuid;
}

Database* Database::databaseByUuid(const Uuid& uuid)
Database* Database::databaseByUuid(const QUuid& uuid)
{
return m_uuidMap.value(uuid, 0);
}
Expand Down
27 changes: 13 additions & 14 deletions src/core/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <QHash>
#include <QObject>

#include "core/Uuid.h"
#include "crypto/kdf/Kdf.h"
#include "keys/CompositeKey.h"

Expand All @@ -36,7 +35,7 @@ class QIODevice;

struct DeletedObject
{
Uuid uuid;
QUuid uuid;
QDateTime deletionTime;
};

Expand All @@ -56,7 +55,7 @@ class Database : public QObject

struct DatabaseData
{
Uuid cipher;
QUuid cipher;
CompressionAlgorithm compressionAlgo;
QByteArray transformedMasterKey;
QSharedPointer<Kdf> kdf;
Expand All @@ -83,22 +82,22 @@ class Database : public QObject

Metadata* metadata();
const Metadata* metadata() const;
Entry* resolveEntry(const Uuid& uuid);
Entry* resolveEntry(const QUuid& uuid);
Entry* resolveEntry(const QString& text, EntryReferenceType referenceType);
Group* resolveGroup(const Uuid& uuid);
Group* resolveGroup(const QUuid& uuid);
QList<DeletedObject> deletedObjects();
void addDeletedObject(const DeletedObject& delObj);
void addDeletedObject(const Uuid& uuid);
void addDeletedObject(const QUuid& uuid);

Uuid cipher() const;
const QUuid& cipher() const;
Database::CompressionAlgorithm compressionAlgo() const;
QSharedPointer<Kdf> kdf() const;
QByteArray transformedMasterKey() const;
const CompositeKey& key() const;
QByteArray challengeResponseKey() const;
bool challengeMasterSeed(const QByteArray& masterSeed);

void setCipher(const Uuid& cipher);
void setCipher(const QUuid& cipher);
void setCompressionAlgo(Database::CompressionAlgorithm algo);
void setKdf(QSharedPointer<Kdf> kdf);
bool setKey(const CompositeKey& key, bool updateChangedTime = true, bool updateTransformSalt = false);
Expand All @@ -117,10 +116,10 @@ class Database : public QObject
/**
* Returns a unique id that is only valid as long as the Database exists.
*/
Uuid uuid();
const QUuid& uuid();
bool changeKdf(QSharedPointer<Kdf> kdf);

static Database* databaseByUuid(const Uuid& uuid);
static Database* databaseByUuid(const QUuid& uuid);
static Database* openDatabaseFile(QString fileName, CompositeKey key);
static Database* unlockFromStdin(QString databaseFilename, QString keyFilename = QString(""));

Expand All @@ -140,9 +139,9 @@ private slots:
void startModifiedTimer();

private:
Entry* findEntryRecursive(const Uuid& uuid, Group* group);
Entry* findEntryRecursive(const QUuid& uuid, Group* group);
Entry* findEntryRecursive(const QString& text, EntryReferenceType referenceType, Group* group);
Group* findGroupRecursive(const Uuid& uuid, Group* group);
Group* findGroupRecursive(const QUuid& uuid, Group* group);

void createRecycleBin();
QString writeDatabase(QIODevice* device);
Expand All @@ -155,8 +154,8 @@ private slots:
DatabaseData m_data;
bool m_emitModified;

Uuid m_uuid;
static QHash<Uuid, Database*> m_uuidMap;
QUuid m_uuid;
static QHash<QUuid, Database*> m_uuidMap;
};

#endif // KEEPASSX_DATABASE_H
Loading

0 comments on commit 470a74e

Please sign in to comment.