Cockatrice/libcockatrice_settings/libcockatrice/settings/servers_settings.h
Lukas Brübach 709233d977
[Security] Add challenge-response auth with scrypt verifiers and stop storing plaintext passwords
Challenge-response authentication: the client derives a scrypt verifier
(RFC 7914, EVP_PBE_scrypt, N=32768, r=8, p=1) and authenticates with
HMAC-SHA256(key, nonce), so neither the password nor its hash is
transmitted. The stored format becomes
"$scrypt$<n>$<r>$<p>$<salt>$<verifier>" and Response_PasswordSalt
now carries the cost parameters. Strict servers only accept scrypt
verifiers; legacy accounts are migrated after a successful login.

Fix #344 for challenge-response servers: a saved profile stores the
derived verifier under the password key instead of the plaintext password.
The connect dialog loads it without revealing it, autoconnect passes it
through, the change-password dialog no longer prefills the old password
field with it, and the client only persists the verifier when
"Save password" is checked.

Took 3 minutes

Took 1 minute

Took 10 seconds

Took 7 minutes
2026-09-06 16:16:22 +02:00

83 lines
3.3 KiB
C++

/**
* @file servers_settings.h
* @ingroup NetworkSettings
*/
//! \todo Document this file.
#ifndef SERVERSSETTINGS_H
#define SERVERSSETTINGS_H
#include "settings_manager.h"
#include <QLoggingCategory>
#include <QObject>
#define SERVERSETTINGS_DEFAULT_HOST "server.cockatrice.us"
#define SERVERSETTINGS_DEFAULT_PORT "4748"
inline Q_LOGGING_CATEGORY(ServersSettingsLog, "servers_settings");
class ServersSettings : public SettingsManager
{
Q_OBJECT
friend class SettingsCache;
public:
int getPreviousHostLogin() const;
int getPrevioushostindex(const QString &) const;
QStringList getPreviousHostList() const;
QString getPrevioushostName() const;
QString getHostname(QString defaultHost = SERVERSETTINGS_DEFAULT_HOST) const;
QString getPort(QString defaultPort = SERVERSETTINGS_DEFAULT_PORT) const;
QString getPlayerName(QString defaultName = "") const;
QString getFPHostname(QString defaultHost = SERVERSETTINGS_DEFAULT_HOST) const;
QString getFPPort(QString defaultPort = SERVERSETTINGS_DEFAULT_PORT) const;
QString getFPPlayerName(QString defaultName = "") const;
QString getPassword();
QString getSaveName(QString defaultname = "");
QString getSite(QString defaultName = "");
bool getSavePassword() const;
int getAutoConnect() const;
void setPreviousHostLogin(int previous);
void setPrevioushostName(const QString &);
void setPreviousHostList(QStringList list);
void setAutoConnect(int autoconnect);
void setSite(QString site);
void setFPHostName(QString hostname);
void setFPPort(QString port);
void setFPPlayerName(QString playerName);
//! \brief Store a password (or a "$scrypt$..." verifier) for the given saved server.
void setServerPassword(const QString &saveName, const QString &password);
void addNewServer(const QString &saveName,
const QString &serv,
const QString &port,
const QString &username,
const QString &password,
bool savePassword,
const QString &site = QString());
void removeServer(QString servAddr);
bool updateExistingServer(QString saveName,
QString serv,
QString port,
QString username,
QString password,
bool savePassword,
QString site = QString());
int findServerIndex(const QString &host, const QString &port) const;
bool hasUsername(const QString &host, const QString &port) const;
bool hasCredentials(const QString &host, const QString &port) const;
bool hasLoginData(const QString &host, const QString &port) const;
bool updateExistingServerWithoutLoss(QString saveName,
QString serv = QString(),
QString port = QString(),
QString site = QString());
void setClearDebugLogStatus(bool abIsChecked);
bool getClearDebugLogStatus(bool abDefaultValue) const;
private:
explicit ServersSettings(const QString &settingPath, QObject *parent = nullptr);
ServersSettings(const ServersSettings & /*other*/);
};
#endif // SERVERSSETTINGS_H