2017-12-12 08:15:23 +00:00
|
|
|
/*
|
2023-02-18 20:52:31 +00:00
|
|
|
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
|
2018-11-01 03:27:38 +00:00
|
|
|
*
|
|
|
|
|
* 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 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
2017-12-12 08:15:23 +00:00
|
|
|
|
2023-10-25 14:12:55 +00:00
|
|
|
#ifndef KEEPASSXC_BROWSERACTION_H
|
|
|
|
|
#define KEEPASSXC_BROWSERACTION_H
|
2017-12-12 08:15:23 +00:00
|
|
|
|
2023-02-18 20:52:31 +00:00
|
|
|
#include "BrowserMessageBuilder.h"
|
2023-10-25 14:12:55 +00:00
|
|
|
#include "BrowserService.h"
|
2023-02-18 20:52:31 +00:00
|
|
|
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonObject>
|
2020-05-11 01:20:00 +00:00
|
|
|
#include <QString>
|
2017-12-12 08:15:23 +00:00
|
|
|
|
2022-02-22 22:52:51 +00:00
|
|
|
class QLocalSocket;
|
2021-07-12 02:10:29 +00:00
|
|
|
|
2023-02-18 20:52:31 +00:00
|
|
|
struct BrowserRequest
|
|
|
|
|
{
|
|
|
|
|
QString hash;
|
|
|
|
|
QString nonce;
|
|
|
|
|
QString incrementedNonce;
|
|
|
|
|
QJsonObject decrypted;
|
|
|
|
|
|
|
|
|
|
inline bool isEmpty() const
|
|
|
|
|
{
|
|
|
|
|
return decrypted.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline QJsonArray getArray(const QString& param) const
|
|
|
|
|
{
|
|
|
|
|
return decrypted.value(param).toArray();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 12:42:01 +00:00
|
|
|
inline bool getBool(const QString& param) const
|
|
|
|
|
{
|
|
|
|
|
return decrypted.value(param).toBool();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-25 14:12:55 +00:00
|
|
|
inline QJsonObject getObject(const QString& param) const
|
|
|
|
|
{
|
|
|
|
|
return decrypted.value(param).toObject();
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-18 20:52:31 +00:00
|
|
|
inline QString getString(const QString& param) const
|
|
|
|
|
{
|
|
|
|
|
return decrypted.value(param).toString();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-11 01:20:00 +00:00
|
|
|
class BrowserAction
|
2017-12-12 08:15:23 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2022-02-22 22:52:51 +00:00
|
|
|
explicit BrowserAction() = default;
|
2017-12-12 08:15:23 +00:00
|
|
|
~BrowserAction() = default;
|
|
|
|
|
|
2022-02-22 22:52:51 +00:00
|
|
|
QJsonObject processClientMessage(QLocalSocket* socket, const QJsonObject& json);
|
2017-12-12 08:15:23 +00:00
|
|
|
|
|
|
|
|
private:
|
2022-02-22 22:52:51 +00:00
|
|
|
QJsonObject handleAction(QLocalSocket* socket, const QJsonObject& json);
|
2017-12-12 08:15:23 +00:00
|
|
|
QJsonObject handleChangePublicKeys(const QJsonObject& json, const QString& action);
|
|
|
|
|
QJsonObject handleGetDatabaseHash(const QJsonObject& json, const QString& action);
|
|
|
|
|
QJsonObject handleAssociate(const QJsonObject& json, const QString& action);
|
|
|
|
|
QJsonObject handleTestAssociate(const QJsonObject& json, const QString& action);
|
2022-10-26 07:24:49 +00:00
|
|
|
QJsonObject handleGetLogins(const QJsonObject& json, const QString& action);
|
2022-02-22 22:52:51 +00:00
|
|
|
QJsonObject handleGeneratePassword(QLocalSocket* socket, const QJsonObject& json, const QString& action);
|
2017-12-12 08:15:23 +00:00
|
|
|
QJsonObject handleSetLogin(const QJsonObject& json, const QString& action);
|
|
|
|
|
QJsonObject handleLockDatabase(const QJsonObject& json, const QString& action);
|
2019-01-30 14:48:22 +00:00
|
|
|
QJsonObject handleGetDatabaseGroups(const QJsonObject& json, const QString& action);
|
2023-02-25 19:09:36 +00:00
|
|
|
QJsonObject handleGetDatabaseEntries(const QJsonObject& json, const QString& action);
|
2019-03-16 08:34:50 +00:00
|
|
|
QJsonObject handleCreateNewGroup(const QJsonObject& json, const QString& action);
|
2020-08-17 10:17:58 +00:00
|
|
|
QJsonObject handleGetTotp(const QJsonObject& json, const QString& action);
|
2021-09-06 15:38:25 +00:00
|
|
|
QJsonObject handleDeleteEntry(const QJsonObject& json, const QString& action);
|
2021-10-10 11:49:25 +00:00
|
|
|
QJsonObject handleGlobalAutoType(const QJsonObject& json, const QString& action);
|
2023-10-25 14:12:55 +00:00
|
|
|
#ifdef WITH_XC_BROWSER_PASSKEYS
|
|
|
|
|
QJsonObject handlePasskeysGet(const QJsonObject& json, const QString& action);
|
|
|
|
|
QJsonObject handlePasskeysRegister(const QJsonObject& json, const QString& action);
|
|
|
|
|
#endif
|
2017-12-12 08:15:23 +00:00
|
|
|
|
2022-02-22 22:52:51 +00:00
|
|
|
private:
|
2023-02-18 20:52:31 +00:00
|
|
|
QJsonObject buildResponse(const QString& action, const QString& nonce, const Parameters& params = {});
|
2017-12-12 08:15:23 +00:00
|
|
|
QJsonObject getErrorReply(const QString& action, const int errorCode) const;
|
2019-01-25 03:45:30 +00:00
|
|
|
QJsonObject decryptMessage(const QString& message, const QString& nonce);
|
2023-02-18 20:52:31 +00:00
|
|
|
BrowserRequest decodeRequest(const QJsonObject& json);
|
2023-10-25 14:12:55 +00:00
|
|
|
StringPairList getConnectionKeys(const BrowserRequest& browserRequest);
|
2017-12-12 08:15:23 +00:00
|
|
|
|
|
|
|
|
private:
|
2021-10-10 11:49:25 +00:00
|
|
|
static const int MaxUrlLength;
|
|
|
|
|
|
2018-03-31 20:01:30 +00:00
|
|
|
QString m_clientPublicKey;
|
|
|
|
|
QString m_publicKey;
|
|
|
|
|
QString m_secretKey;
|
2020-05-11 01:20:00 +00:00
|
|
|
bool m_associated = false;
|
2018-12-10 12:20:58 +00:00
|
|
|
|
|
|
|
|
friend class TestBrowser;
|
2017-12-12 08:15:23 +00:00
|
|
|
};
|
|
|
|
|
|
2023-10-25 14:12:55 +00:00
|
|
|
#endif // KEEPASSXC_BROWSERACTION_H
|