keepassxc/src/browser/BrowserAction.h

94 lines
3.2 KiB
C++
Raw Normal View History

2017-12-12 10:15:23 +02:00
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
*
* 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 10:15:23 +02:00
#ifndef BROWSERACTION_H
#define BROWSERACTION_H
#include "BrowserMessageBuilder.h"
#include <QJsonArray>
#include <QJsonObject>
#include <QString>
2017-12-12 10:15:23 +02:00
class QLocalSocket;
2021-07-11 22:10:29 -04: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();
}
inline QString getString(const QString& param) const
{
return decrypted.value(param).toString();
}
};
class BrowserAction
2017-12-12 10:15:23 +02:00
{
public:
explicit BrowserAction() = default;
2017-12-12 10:15:23 +02:00
~BrowserAction() = default;
QJsonObject processClientMessage(QLocalSocket* socket, const QJsonObject& json);
2017-12-12 10:15:23 +02:00
private:
QJsonObject handleAction(QLocalSocket* socket, const QJsonObject& json);
2017-12-12 10:15:23 +02: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 10:24:49 +03:00
QJsonObject handleGetLogins(const QJsonObject& json, const QString& action);
QJsonObject handleGeneratePassword(QLocalSocket* socket, const QJsonObject& json, const QString& action);
2017-12-12 10:15:23 +02:00
QJsonObject handleSetLogin(const QJsonObject& json, const QString& action);
QJsonObject handleLockDatabase(const QJsonObject& json, const QString& action);
QJsonObject handleGetDatabaseGroups(const QJsonObject& json, const QString& action);
QJsonObject handleCreateNewGroup(const QJsonObject& json, const QString& action);
QJsonObject handleGetTotp(const QJsonObject& json, const QString& action);
QJsonObject handleDeleteEntry(const QJsonObject& json, const QString& action);
QJsonObject handleGlobalAutoType(const QJsonObject& json, const QString& action);
2017-12-12 10:15:23 +02:00
private:
QJsonObject buildResponse(const QString& action, const QString& nonce, const Parameters& params = {});
2017-12-12 10:15:23 +02:00
QJsonObject getErrorReply(const QString& action, const int errorCode) const;
QJsonObject decryptMessage(const QString& message, const QString& nonce);
BrowserRequest decodeRequest(const QJsonObject& json);
2017-12-12 10:15:23 +02:00
private:
static const int MaxUrlLength;
2018-03-31 16:01:30 -04:00
QString m_clientPublicKey;
QString m_publicKey;
QString m_secretKey;
bool m_associated = false;
2018-12-10 14:20:58 +02:00
friend class TestBrowser;
2017-12-12 10:15:23 +02:00
};
#endif // BROWSERACTION_H