mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-08 14:33:23 +00:00
Compare commits
4 Commits
4.8.14.1
...
bugfix/sec
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4911aa5eaa | ||
|
|
f18dbc1e15 | ||
|
|
9753c3feb6 | ||
|
|
67f29ac483 |
@@ -211,8 +211,14 @@ ErrorCode ServerController::uploadFileToHost(const ServerCredentials &credential
|
||||
localFile.write(data);
|
||||
localFile.close();
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
error = m_sshClient.sftpFileCopy(overwriteMode, localFile.fileName().toLocal8Bit().toStdString(), remotePath.toStdString(),
|
||||
"non_desc");
|
||||
#else
|
||||
error = m_sshClient.sftpFileCopy(overwriteMode, localFile.fileName().toStdString(), remotePath.toStdString(),
|
||||
"non_desc");
|
||||
#endif
|
||||
|
||||
if (error != ErrorCode::NoError) {
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ SecureQSettings::SecureQSettings(const QString &organization, const QString &app
|
||||
if (encryptionRequired() && !encrypted) {
|
||||
for (const QString &key : m_settings.allKeys()) {
|
||||
if (encryptedKeys.contains(key)) {
|
||||
const QVariant &val = value(key);
|
||||
QVariant val;
|
||||
value(key, val);
|
||||
setValue(key, val);
|
||||
}
|
||||
}
|
||||
@@ -34,16 +35,18 @@ SecureQSettings::SecureQSettings(const QString &organization, const QString &app
|
||||
}
|
||||
}
|
||||
|
||||
QVariant SecureQSettings::value(const QString &key, const QVariant &defaultValue) const
|
||||
void SecureQSettings::value(const QString &key, QVariant &returnValue, const QVariant &defaultValue) const
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
|
||||
if (m_cache.contains(key)) {
|
||||
return m_cache.value(key);
|
||||
returnValue = m_cache.value(key);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_settings.contains(key)) {
|
||||
returnValue = defaultValue;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_settings.contains(key))
|
||||
return defaultValue;
|
||||
|
||||
QVariant retVal;
|
||||
|
||||
@@ -54,7 +57,7 @@ QVariant SecureQSettings::value(const QString &key, const QVariant &defaultValue
|
||||
|
||||
if (getEncKey().isEmpty() || getEncIv().isEmpty()) {
|
||||
qCritical() << "SecureQSettings::setValue Decryption requested, but key is empty";
|
||||
return {};
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray encryptedValue = retVal.toByteArray().mid(magicString.size());
|
||||
@@ -75,13 +78,11 @@ QVariant SecureQSettings::value(const QString &key, const QVariant &defaultValue
|
||||
}
|
||||
|
||||
m_cache.insert(key, retVal);
|
||||
return retVal;
|
||||
returnValue = retVal;
|
||||
}
|
||||
|
||||
void SecureQSettings::setValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
|
||||
if (encryptionRequired() && encryptedKeys.contains(key)) {
|
||||
if (!getEncKey().isEmpty() && !getEncIv().isEmpty()) {
|
||||
QByteArray decryptedValue;
|
||||
@@ -107,8 +108,6 @@ void SecureQSettings::setValue(const QString &key, const QVariant &value)
|
||||
|
||||
void SecureQSettings::remove(const QString &key)
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
|
||||
m_settings.remove(key);
|
||||
m_cache.remove(key);
|
||||
|
||||
@@ -125,7 +124,9 @@ QByteArray SecureQSettings::backupAppConfig() const
|
||||
QJsonObject cfg;
|
||||
|
||||
for (const QString &key : m_settings.allKeys()) {
|
||||
cfg.insert(key, QJsonValue::fromVariant(value(key)));
|
||||
QVariant v;
|
||||
value(key, v);
|
||||
cfg.insert(key, QJsonValue::fromVariant(v));
|
||||
}
|
||||
|
||||
return QJsonDocument(cfg).toJson();
|
||||
@@ -253,7 +254,6 @@ void SecureQSettings::setSecTag(const QString &tag, const QByteArray &data)
|
||||
|
||||
void SecureQSettings::clearSettings()
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
m_settings.clear();
|
||||
m_cache.clear();
|
||||
sync();
|
||||
|
||||
@@ -14,12 +14,15 @@ constexpr const char *keyChainName = "AmneziaVPN-Keychain";
|
||||
|
||||
class SecureQSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SecureQSettings(const QString &organization, const QString &application = QString(),
|
||||
QObject *parent = nullptr);
|
||||
|
||||
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
|
||||
void setValue(const QString &key, const QVariant &value);
|
||||
Q_INVOKABLE void value(const QString &key, QVariant &eturnValue, const QVariant &defaultValue = QVariant()) const;
|
||||
Q_INVOKABLE void setValue(const QString &key, const QVariant &value);
|
||||
|
||||
void remove(const QString &key);
|
||||
void sync();
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
#include "settings.h"
|
||||
|
||||
#include "QThread"
|
||||
#include "QCoreApplication"
|
||||
|
||||
#include "utilities.h"
|
||||
#include "version.h"
|
||||
|
||||
@@ -12,10 +16,10 @@ Settings::Settings(QObject *parent) : QObject(parent), m_settings(ORGANIZATION_N
|
||||
{
|
||||
// Import old settings
|
||||
if (serversCount() == 0) {
|
||||
QString user = m_settings.value("Server/userName").toString();
|
||||
QString password = m_settings.value("Server/password").toString();
|
||||
QString serverName = m_settings.value("Server/serverName").toString();
|
||||
int port = m_settings.value("Server/serverPort").toInt();
|
||||
QString user = value("Server/userName").toString();
|
||||
QString password = value("Server/password").toString();
|
||||
QString serverName = value("Server/serverName").toString();
|
||||
int port = value("Server/serverPort").toInt();
|
||||
|
||||
if (!user.isEmpty() && !password.isEmpty() && !serverName.isEmpty()) {
|
||||
QJsonObject server;
|
||||
@@ -35,12 +39,12 @@ Settings::Settings(QObject *parent) : QObject(parent), m_settings(ORGANIZATION_N
|
||||
}
|
||||
}
|
||||
|
||||
int Settings::serversCount() const
|
||||
int Settings::serversCount()
|
||||
{
|
||||
return serversArray().size();
|
||||
}
|
||||
|
||||
QJsonObject Settings::server(int index) const
|
||||
QJsonObject Settings::server(int index)
|
||||
{
|
||||
const QJsonArray &servers = serversArray();
|
||||
if (index >= servers.size())
|
||||
@@ -84,12 +88,12 @@ void Settings::setDefaultContainer(int serverIndex, DockerContainer container)
|
||||
editServer(serverIndex, s);
|
||||
}
|
||||
|
||||
DockerContainer Settings::defaultContainer(int serverIndex) const
|
||||
DockerContainer Settings::defaultContainer(int serverIndex)
|
||||
{
|
||||
return ContainerProps::containerFromString(defaultContainerName(serverIndex));
|
||||
}
|
||||
|
||||
QString Settings::defaultContainerName(int serverIndex) const
|
||||
QString Settings::defaultContainerName(int serverIndex)
|
||||
{
|
||||
QString name = server(serverIndex).value(config_key::defaultContainer).toString();
|
||||
if (name.isEmpty()) {
|
||||
@@ -98,7 +102,7 @@ QString Settings::defaultContainerName(int serverIndex) const
|
||||
return name;
|
||||
}
|
||||
|
||||
QMap<DockerContainer, QJsonObject> Settings::containers(int serverIndex) const
|
||||
QMap<DockerContainer, QJsonObject> Settings::containers(int serverIndex)
|
||||
{
|
||||
const QJsonArray &containers = server(serverIndex).value(config_key::containers).toArray();
|
||||
|
||||
@@ -182,7 +186,7 @@ void Settings::clearLastConnectionConfig(int serverIndex, DockerContainer contai
|
||||
setProtocolConfig(serverIndex, container, proto, c);
|
||||
}
|
||||
|
||||
bool Settings::haveAuthData(int serverIndex) const
|
||||
bool Settings::haveAuthData(int serverIndex)
|
||||
{
|
||||
if (serverIndex < 0)
|
||||
return false;
|
||||
@@ -190,7 +194,7 @@ bool Settings::haveAuthData(int serverIndex) const
|
||||
return (!cred.hostName.isEmpty() && !cred.userName.isEmpty() && !cred.secretData.isEmpty());
|
||||
}
|
||||
|
||||
QString Settings::nextAvailableServerName() const
|
||||
QString Settings::nextAvailableServerName()
|
||||
{
|
||||
int i = 0;
|
||||
bool nameExist = false;
|
||||
@@ -211,7 +215,7 @@ QString Settings::nextAvailableServerName() const
|
||||
|
||||
void Settings::setSaveLogs(bool enabled)
|
||||
{
|
||||
m_settings.setValue("Conf/saveLogs", enabled);
|
||||
setValue("Conf/saveLogs", enabled);
|
||||
if (!isSaveLogs()) {
|
||||
Logger::deInit();
|
||||
} else {
|
||||
@@ -222,7 +226,7 @@ void Settings::setSaveLogs(bool enabled)
|
||||
emit saveLogsChanged();
|
||||
}
|
||||
|
||||
QString Settings::routeModeString(RouteMode mode) const
|
||||
QString Settings::routeModeString(RouteMode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case VpnAllSites: return "AllSites";
|
||||
@@ -231,9 +235,9 @@ QString Settings::routeModeString(RouteMode mode) const
|
||||
}
|
||||
}
|
||||
|
||||
Settings::RouteMode Settings::routeMode() const
|
||||
Settings::RouteMode Settings::routeMode()
|
||||
{
|
||||
return static_cast<RouteMode>(m_settings.value("Conf/routeMode", 0).toInt());
|
||||
return static_cast<RouteMode>(value("Conf/routeMode", 0).toInt());
|
||||
}
|
||||
|
||||
bool Settings::addVpnSite(RouteMode mode, const QString &site, const QString &ip)
|
||||
@@ -263,7 +267,7 @@ void Settings::addVpnSites(RouteMode mode, const QMap<QString, QString> &sites)
|
||||
setVpnSites(mode, allSites);
|
||||
}
|
||||
|
||||
QStringList Settings::getVpnIps(RouteMode mode) const
|
||||
QStringList Settings::getVpnIps(RouteMode mode)
|
||||
{
|
||||
QStringList ips;
|
||||
const QVariantMap &m = vpnSites(mode);
|
||||
@@ -319,14 +323,14 @@ void Settings::removeAllVpnSites(RouteMode mode)
|
||||
setVpnSites(mode, QVariantMap());
|
||||
}
|
||||
|
||||
QString Settings::primaryDns() const
|
||||
QString Settings::primaryDns()
|
||||
{
|
||||
return m_settings.value("Conf/primaryDns", cloudFlareNs1).toString();
|
||||
return value("Conf/primaryDns", cloudFlareNs1).toString();
|
||||
}
|
||||
|
||||
QString Settings::secondaryDns() const
|
||||
QString Settings::secondaryDns()
|
||||
{
|
||||
return m_settings.value("Conf/secondaryDns", cloudFlareNs2).toString();
|
||||
return value("Conf/secondaryDns", cloudFlareNs2).toString();
|
||||
}
|
||||
|
||||
void Settings::clearSettings()
|
||||
@@ -334,12 +338,12 @@ void Settings::clearSettings()
|
||||
m_settings.clearSettings();
|
||||
}
|
||||
|
||||
ServerCredentials Settings::defaultServerCredentials() const
|
||||
ServerCredentials Settings::defaultServerCredentials()
|
||||
{
|
||||
return serverCredentials(defaultServerIndex());
|
||||
}
|
||||
|
||||
ServerCredentials Settings::serverCredentials(int index) const
|
||||
ServerCredentials Settings::serverCredentials(int index)
|
||||
{
|
||||
const QJsonObject &s = server(index);
|
||||
|
||||
@@ -351,3 +355,38 @@ ServerCredentials Settings::serverCredentials(int index) const
|
||||
|
||||
return credentials;
|
||||
}
|
||||
|
||||
QVariant Settings::value(const QString &key, const QVariant &defaultValue)
|
||||
{
|
||||
QVariant returnValue;
|
||||
// if (defaultValue.isNull() || !defaultValue.isValid()) {
|
||||
// QMetaObject::invokeMethod(&m_settings, "value",
|
||||
// Qt::QueuedConnection,
|
||||
// Q_ARG(const QString&, key),
|
||||
// Q_ARG(QVariant, returnValue));
|
||||
// } else {
|
||||
|
||||
if (QThread::currentThread() == QCoreApplication::instance()->thread()) {
|
||||
m_settings.value(key, returnValue, defaultValue);
|
||||
} else {
|
||||
QMetaObject::invokeMethod(&m_settings, "value",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_ARG(const QString&, key),
|
||||
Q_ARG(QVariant&, returnValue),
|
||||
Q_ARG(const QVariant&, defaultValue));
|
||||
}
|
||||
// }
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
void Settings::setValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
if (QThread::currentThread() == QCoreApplication::instance()->thread()) {
|
||||
m_settings.setValue(key, value);
|
||||
} else {
|
||||
QMetaObject::invokeMethod(&m_settings, "setValue",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_ARG(const QString&, key),
|
||||
Q_ARG(const QVariant&, value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,43 +24,43 @@ class Settings : public QObject
|
||||
public:
|
||||
explicit Settings(QObject *parent = nullptr);
|
||||
|
||||
ServerCredentials defaultServerCredentials() const;
|
||||
ServerCredentials serverCredentials(int index) const;
|
||||
ServerCredentials defaultServerCredentials();
|
||||
ServerCredentials serverCredentials(int index);
|
||||
|
||||
QJsonArray serversArray() const
|
||||
QJsonArray serversArray()
|
||||
{
|
||||
return QJsonDocument::fromJson(m_settings.value("Servers/serversList").toByteArray()).array();
|
||||
return QJsonDocument::fromJson(value("Servers/serversList").toByteArray()).array();
|
||||
}
|
||||
void setServersArray(const QJsonArray &servers)
|
||||
{
|
||||
m_settings.setValue("Servers/serversList", QJsonDocument(servers).toJson());
|
||||
setValue("Servers/serversList", QJsonDocument(servers).toJson());
|
||||
}
|
||||
|
||||
// Servers section
|
||||
int serversCount() const;
|
||||
QJsonObject server(int index) const;
|
||||
int serversCount();
|
||||
QJsonObject server(int index);
|
||||
void addServer(const QJsonObject &server);
|
||||
void removeServer(int index);
|
||||
bool editServer(int index, const QJsonObject &server);
|
||||
|
||||
int defaultServerIndex() const
|
||||
int defaultServerIndex()
|
||||
{
|
||||
return m_settings.value("Servers/defaultServerIndex", 0).toInt();
|
||||
return value("Servers/defaultServerIndex", 0).toInt();
|
||||
}
|
||||
void setDefaultServer(int index)
|
||||
{
|
||||
m_settings.setValue("Servers/defaultServerIndex", index);
|
||||
setValue("Servers/defaultServerIndex", index);
|
||||
}
|
||||
QJsonObject defaultServer() const
|
||||
QJsonObject defaultServer()
|
||||
{
|
||||
return server(defaultServerIndex());
|
||||
}
|
||||
|
||||
void setDefaultContainer(int serverIndex, DockerContainer container);
|
||||
DockerContainer defaultContainer(int serverIndex) const;
|
||||
QString defaultContainerName(int serverIndex) const;
|
||||
DockerContainer defaultContainer(int serverIndex);
|
||||
QString defaultContainerName(int serverIndex);
|
||||
|
||||
QMap<DockerContainer, QJsonObject> containers(int serverIndex) const;
|
||||
QMap<DockerContainer, QJsonObject> containers(int serverIndex);
|
||||
void setContainers(int serverIndex, const QMap<DockerContainer, QJsonObject> &containers);
|
||||
|
||||
QJsonObject containerConfig(int serverIndex, DockerContainer container);
|
||||
@@ -72,31 +72,31 @@ public:
|
||||
|
||||
void clearLastConnectionConfig(int serverIndex, DockerContainer container, Proto proto = Proto::Any);
|
||||
|
||||
bool haveAuthData(int serverIndex) const;
|
||||
QString nextAvailableServerName() const;
|
||||
bool haveAuthData(int serverIndex);
|
||||
QString nextAvailableServerName();
|
||||
|
||||
// App settings section
|
||||
bool isAutoConnect() const
|
||||
bool isAutoConnect()
|
||||
{
|
||||
return m_settings.value("Conf/autoConnect", false).toBool();
|
||||
return value("Conf/autoConnect", false).toBool();
|
||||
}
|
||||
void setAutoConnect(bool enabled)
|
||||
{
|
||||
m_settings.setValue("Conf/autoConnect", enabled);
|
||||
setValue("Conf/autoConnect", enabled);
|
||||
}
|
||||
|
||||
bool isStartMinimized() const
|
||||
bool isStartMinimized()
|
||||
{
|
||||
return m_settings.value("Conf/startMinimized", false).toBool();
|
||||
return value("Conf/startMinimized", false).toBool();
|
||||
}
|
||||
void setStartMinimized(bool enabled)
|
||||
{
|
||||
m_settings.setValue("Conf/startMinimized", enabled);
|
||||
setValue("Conf/startMinimized", enabled);
|
||||
}
|
||||
|
||||
bool isSaveLogs() const
|
||||
bool isSaveLogs()
|
||||
{
|
||||
return m_settings.value("Conf/saveLogs", false).toBool();
|
||||
return value("Conf/saveLogs", false).toBool();
|
||||
}
|
||||
void setSaveLogs(bool enabled);
|
||||
|
||||
@@ -107,51 +107,51 @@ public:
|
||||
};
|
||||
Q_ENUM(RouteMode)
|
||||
|
||||
QString routeModeString(RouteMode mode) const;
|
||||
QString routeModeString(RouteMode mode);
|
||||
|
||||
RouteMode routeMode() const;
|
||||
void setRouteMode(RouteMode mode) { m_settings.setValue("Conf/routeMode", mode); }
|
||||
RouteMode routeMode();
|
||||
void setRouteMode(RouteMode mode) { setValue("Conf/routeMode", mode); }
|
||||
|
||||
QVariantMap vpnSites(RouteMode mode) const
|
||||
QVariantMap vpnSites(RouteMode mode)
|
||||
{
|
||||
return m_settings.value("Conf/" + routeModeString(mode)).toMap();
|
||||
return value("Conf/" + routeModeString(mode)).toMap();
|
||||
}
|
||||
void setVpnSites(RouteMode mode, const QVariantMap &sites)
|
||||
{
|
||||
m_settings.setValue("Conf/" + routeModeString(mode), sites);
|
||||
setValue("Conf/" + routeModeString(mode), sites);
|
||||
m_settings.sync();
|
||||
}
|
||||
bool addVpnSite(RouteMode mode, const QString &site, const QString &ip = "");
|
||||
void addVpnSites(RouteMode mode, const QMap<QString, QString> &sites); // map <site, ip>
|
||||
QStringList getVpnIps(RouteMode mode) const;
|
||||
QStringList getVpnIps(RouteMode mode);
|
||||
void removeVpnSite(RouteMode mode, const QString &site);
|
||||
|
||||
void addVpnIps(RouteMode mode, const QStringList &ip);
|
||||
void removeVpnSites(RouteMode mode, const QStringList &sites);
|
||||
void removeAllVpnSites(RouteMode mode);
|
||||
|
||||
bool useAmneziaDns() const
|
||||
bool useAmneziaDns()
|
||||
{
|
||||
return m_settings.value("Conf/useAmneziaDns", true).toBool();
|
||||
return value("Conf/useAmneziaDns", true).toBool();
|
||||
}
|
||||
void setUseAmneziaDns(bool enabled)
|
||||
{
|
||||
m_settings.setValue("Conf/useAmneziaDns", enabled);
|
||||
setValue("Conf/useAmneziaDns", enabled);
|
||||
}
|
||||
|
||||
QString primaryDns() const;
|
||||
QString secondaryDns() const;
|
||||
QString primaryDns();
|
||||
QString secondaryDns();
|
||||
|
||||
// QString primaryDns() const { return m_primaryDns; }
|
||||
// QString primaryDns() { return m_primaryDns; }
|
||||
void setPrimaryDns(const QString &primaryDns)
|
||||
{
|
||||
m_settings.setValue("Conf/primaryDns", primaryDns);
|
||||
setValue("Conf/primaryDns", primaryDns);
|
||||
}
|
||||
|
||||
// QString secondaryDns() const { return m_secondaryDns; }
|
||||
// QString secondaryDns() { return m_secondaryDns; }
|
||||
void setSecondaryDns(const QString &secondaryDns)
|
||||
{
|
||||
m_settings.setValue("Conf/secondaryDns", secondaryDns);
|
||||
setValue("Conf/secondaryDns", secondaryDns);
|
||||
}
|
||||
|
||||
static const char cloudFlareNs1[];
|
||||
@@ -160,7 +160,7 @@ public:
|
||||
// static constexpr char openNicNs5[] = "94.103.153.176";
|
||||
// static constexpr char openNicNs13[] = "144.76.103.143";
|
||||
|
||||
QByteArray backupAppConfig() const
|
||||
QByteArray backupAppConfig()
|
||||
{
|
||||
return m_settings.backupAppConfig();
|
||||
}
|
||||
@@ -171,20 +171,20 @@ public:
|
||||
|
||||
QLocale getAppLanguage()
|
||||
{
|
||||
return m_settings.value("Conf/appLanguage", QLocale()).toLocale();
|
||||
return value("Conf/appLanguage", QLocale()).toLocale();
|
||||
};
|
||||
void setAppLanguage(QLocale locale)
|
||||
{
|
||||
m_settings.setValue("Conf/appLanguage", locale);
|
||||
setValue("Conf/appLanguage", locale);
|
||||
};
|
||||
|
||||
bool isScreenshotsEnabled() const
|
||||
bool isScreenshotsEnabled()
|
||||
{
|
||||
return m_settings.value("Conf/screenshotsEnabled", false).toBool();
|
||||
return value("Conf/screenshotsEnabled", false).toBool();
|
||||
}
|
||||
void setScreenshotsEnabled(bool enabled)
|
||||
{
|
||||
m_settings.setValue("Conf/screenshotsEnabled", enabled);
|
||||
setValue("Conf/screenshotsEnabled", enabled);
|
||||
}
|
||||
|
||||
void clearSettings();
|
||||
@@ -194,6 +194,9 @@ signals:
|
||||
|
||||
private:
|
||||
SecureQSettings m_settings;
|
||||
|
||||
QVariant value(const QString &key, const QVariant &defaultValue = QVariant());
|
||||
void setValue(const QString &key, const QVariant &value);
|
||||
};
|
||||
|
||||
#endif // SETTINGS_H
|
||||
|
||||
Reference in New Issue
Block a user