2022-08-05 14:31:12 +03:00
|
|
|
#ifndef SECUREQSETTINGS_H
|
|
|
|
|
#define SECUREQSETTINGS_H
|
|
|
|
|
|
2022-08-26 00:35:03 +03:00
|
|
|
#include <QMutex>
|
|
|
|
|
#include <QMutexLocker>
|
2023-07-14 22:59:49 +09:00
|
|
|
#include <QObject>
|
|
|
|
|
#include <QSettings>
|
2022-08-26 00:35:03 +03:00
|
|
|
|
2025-05-02 23:54:36 -07:00
|
|
|
#include "../client/3rd/qtkeychain/qtkeychain/keychain.h"
|
2022-08-27 17:35:43 +03:00
|
|
|
|
2022-08-05 14:31:12 +03:00
|
|
|
class SecureQSettings : public QObject
|
|
|
|
|
{
|
2024-01-10 23:05:22 +07:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
2022-08-05 14:31:12 +03:00
|
|
|
public:
|
2023-07-14 22:59:49 +09:00
|
|
|
explicit SecureQSettings(const QString &organization, const QString &application = QString(),
|
|
|
|
|
QObject *parent = nullptr);
|
2022-08-05 14:31:12 +03:00
|
|
|
|
2026-02-26 04:41:08 +01:00
|
|
|
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
|
|
|
|
|
void setValue(const QString &key, const QVariant &value);
|
2022-08-05 18:59:47 +03:00
|
|
|
void remove(const QString &key);
|
|
|
|
|
|
|
|
|
|
QByteArray backupAppConfig() const;
|
2022-08-27 17:35:43 +03:00
|
|
|
bool restoreAppConfig(const QByteArray &json);
|
2022-08-05 14:31:12 +03:00
|
|
|
|
2026-02-26 04:41:08 +01:00
|
|
|
void clearSettings();
|
|
|
|
|
|
|
|
|
|
private:
|
2022-08-06 19:47:29 +03:00
|
|
|
QByteArray encryptText(const QByteArray &value) const;
|
2023-07-14 22:59:49 +09:00
|
|
|
QByteArray decryptText(const QByteArray &ba) const;
|
2022-08-06 19:47:29 +03:00
|
|
|
|
|
|
|
|
bool encryptionRequired() const;
|
|
|
|
|
|
2022-08-24 07:38:13 -07:00
|
|
|
QByteArray getEncKey() const;
|
|
|
|
|
QByteArray getEncIv() const;
|
2022-08-27 17:35:43 +03:00
|
|
|
|
|
|
|
|
static QByteArray getSecTag(const QString &tag);
|
|
|
|
|
static void setSecTag(const QString &tag, const QByteArray &data);
|
|
|
|
|
|
2022-08-23 22:47:23 +03:00
|
|
|
QSettings m_settings;
|
2022-08-05 18:59:47 +03:00
|
|
|
|
2025-01-19 10:12:30 +07:00
|
|
|
mutable QHash<QString, QVariant> m_cache;
|
2022-08-05 18:59:47 +03:00
|
|
|
|
|
|
|
|
QStringList encryptedKeys; // encode only key listed here
|
2024-05-09 00:06:23 +03:00
|
|
|
// only this fields need for backup
|
|
|
|
|
QStringList m_fieldsToBackup = {
|
|
|
|
|
"Conf/", "Servers/",
|
|
|
|
|
};
|
2022-08-06 19:47:29 +03:00
|
|
|
|
2022-08-24 07:38:13 -07:00
|
|
|
mutable QByteArray m_key;
|
|
|
|
|
mutable QByteArray m_iv;
|
2022-08-23 22:47:23 +03:00
|
|
|
|
|
|
|
|
const QByteArray magicString { "EncData" }; // Magic keyword used for mark encrypted QByteArray
|
|
|
|
|
|
2026-02-26 04:41:08 +01:00
|
|
|
mutable QRecursiveMutex m_mutex;
|
2022-08-05 14:31:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // SECUREQSETTINGS_H
|