diff --git a/src/http/Protocol.cpp b/src/http/Protocol.cpp index e150d9af1..efe06299b 100644 --- a/src/http/Protocol.cpp +++ b/src/http/Protocol.cpp @@ -33,7 +33,8 @@ static const char * const STR_SET_LOGIN = "set-login"; static const char * const STR_ASSOCIATE = "associate"; static const char * const STR_TEST_ASSOCIATE = "test-associate"; static const char * const STR_GENERATE_PASSWORD = "generate-password"; -static const char * const STR_VERSION = "1.5.0.0"; +static const char * const STR_VERSION = "1.6.0.0"; + }/*namespace KeepassHttpProtocol*/ using namespace KeepassHttpProtocol; @@ -340,7 +341,7 @@ QVariant Response::getEntries() const QList res; res.reserve(m_entries.size()); - Q_FOREACH(const Entry &entry, m_entries) + Q_FOREACH (const Entry &entry, m_entries) res.append(QJson::QObjectHelper::qobject2qvariant(&entry, QJson::QObjectHelper::Flag_None)); return res; } @@ -353,11 +354,15 @@ void Response::setEntries(const QList &entries) QList encryptedEntries; encryptedEntries.reserve(m_count); - Q_FOREACH(const Entry &entry, entries) { - encryptedEntries << Entry(encrypt(entry.name(), m_cipher), - encrypt(entry.login(), m_cipher), - entry.password().isNull() ? QString() : encrypt(entry.password(), m_cipher), - encrypt(entry.uuid(), m_cipher)); + Q_FOREACH (const Entry &entry, entries) { + Entry encryptedEntry(encrypt(entry.name(), m_cipher), + encrypt(entry.login(), m_cipher), + entry.password().isNull() ? QString() : encrypt(entry.password(), m_cipher), + encrypt(entry.uuid(), m_cipher)); + Q_FOREACH (const StringField & field, entry.stringFields()) + encryptedEntry.addStringField(encrypt(field.key(), m_cipher), + encrypt(field.value(), m_cipher)); + encryptedEntries << encryptedEntry; } m_entries = encryptedEntries; } @@ -405,7 +410,7 @@ void Response::setError(const QString &error) //////////////////////////////////////////////////////////////////////////////////////////////////// -/// ResponseEntry +/// Entry //////////////////////////////////////////////////////////////////////////////////////////////////// Entry::Entry() @@ -423,7 +428,8 @@ Entry::Entry(const Entry & other): m_login(other.m_login), m_password(other.m_password), m_uuid(other.m_uuid), - m_name(other.m_name) + m_name(other.m_name), + m_stringFields(other.m_stringFields) {} Entry & Entry::operator=(const Entry & other) @@ -432,6 +438,7 @@ Entry & Entry::operator=(const Entry & other) m_password = other.m_password; m_uuid = other.m_uuid; m_name = other.m_name; + m_stringFields = other.m_stringFields; return *this; } @@ -454,3 +461,58 @@ QString Entry::password() const { return m_password; } + +QList Entry::stringFields() const +{ + return m_stringFields; +} + +void Entry::addStringField(const QString &key, const QString &value) +{ + m_stringFields.append(StringField(key, value)); +} + +QVariant Entry::getStringFields() const +{ + if (m_stringFields.isEmpty()) + return QVariant(); + + QList res; + res.reserve(m_stringFields.size()); + Q_FOREACH (const StringField &stringfield, m_stringFields) + res.append(QJson::QObjectHelper::qobject2qvariant(&stringfield, QJson::QObjectHelper::Flag_None)); + return res; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// StringField +//////////////////////////////////////////////////////////////////////////////////////////////////// + +StringField::StringField() +{} + +StringField::StringField(const QString &key, const QString &value): + m_key(key), m_value(value) +{} + +StringField::StringField(const StringField &other): + m_key(other.m_key), m_value(other.m_value) +{} + +StringField &StringField::operator =(const StringField &other) +{ + m_key = m_key; + m_value = m_value; + return *this; +} + +QString StringField::key() const +{ + return m_key; +} + +QString StringField::value() const +{ + return m_value; +} diff --git a/src/http/Protocol.h b/src/http/Protocol.h index b0438d554..19edb68db 100644 --- a/src/http/Protocol.h +++ b/src/http/Protocol.h @@ -99,13 +99,34 @@ private: mutable SymmetricCipher m_cipher; }; +class StringField : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString Key READ key ) + Q_PROPERTY(QString Value READ value) + +public: + StringField(); + StringField(const QString& key, const QString& value); + StringField(const StringField & other); + StringField &operator =(const StringField &other); + + QString key() const; + QString value() const; + +private: + QString m_key; + QString m_value; +}; + class Entry : public QObject { Q_OBJECT - Q_PROPERTY(QString Login READ login ) - Q_PROPERTY(QString Password READ password) - Q_PROPERTY(QString Uuid READ uuid ) - Q_PROPERTY(QString Name READ name ) + Q_PROPERTY(QString Login READ login ) + Q_PROPERTY(QString Password READ password ) + Q_PROPERTY(QString Uuid READ uuid ) + Q_PROPERTY(QString Name READ name ) + Q_PROPERTY(QVariant StringFields READ getStringFields) public: Entry(); @@ -117,12 +138,17 @@ public: QString password() const; QString uuid() const; QString name() const; + QList stringFields() const; + void addStringField(const QString& key, const QString& value); private: + QVariant getStringFields() const; + QString m_login; QString m_password; QString m_uuid; QString m_name; + QList m_stringFields; }; class Response : public QObject diff --git a/src/http/Service.cpp b/src/http/Service.cpp index 2e85932bc..6f654ac37 100644 --- a/src/http/Service.cpp +++ b/src/http/Service.cpp @@ -34,11 +34,11 @@ Service::Service(DatabaseTabWidget *parent) : { } -static const char KEEPASSHTTP_UUID_DATA[] = { +static const unsigned char KEEPASSHTTP_UUID_DATA[] = { 0x34, 0x69, 0x7a, 0x40, 0x8a, 0x5b, 0x41, 0xc0, 0x9f, 0x36, 0x89, 0x7d, 0x62, 0x3e, 0xcb, 0x31 }; -static const Uuid KEEPASSHTTP_UUID = Uuid(QByteArray::fromRawData(KEEPASSHTTP_UUID_DATA, sizeof(KEEPASSHTTP_UUID_DATA))); +static const Uuid KEEPASSHTTP_UUID = Uuid(QByteArray::fromRawData(reinterpret_cast(KEEPASSHTTP_UUID_DATA), sizeof(KEEPASSHTTP_UUID_DATA))); static const char KEEPASSHTTP_NAME[] = "KeePassHttp Settings"; static const char ASSOCIATE_KEY_PREFIX[] = "AES Key: "; static const char KEEPASSHTTP_GROUP_NAME[] = "KeePassHttp Passwords"; //Group where new KeePassHttp password are stored @@ -201,6 +201,20 @@ Service::Access Service::checkAccess(const Entry *entry, const QString & host, c return Unknown; //not configured for this host } +KeepassHttpProtocol::Entry Service::prepareEntry(const Entry* entry) +{ + bool returnStringFields = true; //TODO: setting! + KeepassHttpProtocol::Entry res(entry->title(), entry->username(), entry->password(), entry->uuid().toHex()); + if (returnStringFields) + { + const EntryAttributes * attr = entry->attributes(); + Q_FOREACH (const QString& key, attr->keys()) + if (key.startsWith(QLatin1String("KPH: "))) + res.addStringField(key, attr->value(key)); + } + return res; +} + QList Service::findMatchingEntries(const QString &id, const QString &url, const QString &submitUrl, const QString &realm) { QList result; @@ -224,7 +238,7 @@ QList Service::findMatchingEntries(const QString &id } //fall through case Allowed: - result << KeepassHttpProtocol::Entry(entry->title(), entry->username(), entry->password(), entry->uuid().toHex()); + result << prepareEntry(entry); break; } } @@ -259,7 +273,7 @@ QList Service::findMatchingEntries(const QString &id } if (res == QDialog::Accepted) { Q_FOREACH (Entry * entry, pwEntries) - result << KeepassHttpProtocol::Entry(entry->title(), entry->username(), entry->password(), entry->uuid().toHex()); + result << prepareEntry(entry); } } diff --git a/src/http/Service.h b/src/http/Service.h index 871a49904..18c9ef235 100644 --- a/src/http/Service.h +++ b/src/http/Service.h @@ -45,6 +45,7 @@ private: Access checkAccess(const Entry *entry, const QString & host, const QString & submitHost, const QString & realm); bool removeFirstDomain(QString &hostname); Group *findCreateAddEntryGroup(); + KeepassHttpProtocol::Entry prepareEntry(const Entry *entry); QList searchEntries(const QString &text); DatabaseTabWidget * const m_dbTabWidget;