store tokens in QByteArray, minor fixes

This commit is contained in:
Syping 2024-05-18 05:06:56 +02:00
parent 0198da6595
commit fd57796114
4 changed files with 11 additions and 11 deletions

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)
project(smsub LANGUAGES CXX VERSION 0.10)
project(smsub LANGUAGES CXX VERSION 0.10.1)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

View file

@ -113,15 +113,15 @@ void SMSubServer::newConnection()
bool SMSubServer::messageReceived(QObject *socket, const QByteArray &message)
{
// Only allow commands being sent if authenticated
const bool isAuthenticated = socket->property("Authenticated").toBool();
const bool isAuthenticated = isVariantTrue(socket->property("Authenticated"));
if (isAuthenticated) {
if (message == "+dbg") {
socket->setProperty("ReceiveDbgMsg", true);
sendMessage(socket, "Debug messages enabled!\n");
debugOutput(socket, "Debug messages enabled!");
}
else if (message == "-dbg") {
debugOutput(socket, "Debug messages disabled!");
socket->setProperty("ReceiveDbgMsg", false);
sendMessage(socket, "Debug messages disabled!\n");
}
else if (message == "+json") {
socket->setProperty("ReceiveJson", true);
@ -152,7 +152,7 @@ bool SMSubServer::messageReceived(QObject *socket, const QByteArray &message)
QByteArray authUuid = QUuid::createUuid().toByteArray(QUuid::Id128) +
QUuid::createUuid().toByteArray(QUuid::Id128);
authUuid = QByteArray::fromHex(authUuid).toBase64(QByteArray::OmitTrailingEquals);
emit tokenRegistered(QString::fromUtf8(authUuid));
emit tokenRegistered(authUuid);
sendMessage(socket, "Token: " + authUuid + '\n');
}
else {
@ -215,7 +215,7 @@ bool SMSubServer::messageReceived(QObject *socket, const QByteArray &message)
}
else {
// Authenticate when token is valid, otherwise disconnect
if (tokens.contains(QString::fromUtf8(message))) {
if (tokens.contains(message)) {
// Set client as authenticated and add it to vector
socket->setProperty("Authenticated", true);
sendMessage(socket, "Login successful!\n");
@ -349,7 +349,7 @@ void SMSubServer::sendMessage(QObject *socket, const QByteArray &message)
}
}
void SMSubServer::registerToken(const QString &token)
void SMSubServer::registerToken(const QByteArray &token)
{
// Register temporary token for a secure remote connection
tokens << token;

View file

@ -44,7 +44,7 @@ public:
public slots:
void writeOutput(const QByteArray &output);
void registerToken(const QString &token);
void registerToken(const QByteArray &token);
void statusUpdated(const bool status, const qint64 time);
private slots:
@ -60,7 +60,7 @@ private:
inline bool isVariantTrue(const QVariant &variant);
SMSubServerSettings *serverSettings;
QVector<QObject*> sockets;
QVector<QString> tokens;
QVector<QByteArray> tokens;
qint64 startTime;
qint64 stopTime;
ServerType type;
@ -68,7 +68,7 @@ private:
bool status;
signals:
void tokenRegistered(const QString &password);
void tokenRegistered(const QByteArray &token);
void inputWritten(const QByteArray &input);
void startRequested();
void stopRequested();

View file

@ -134,7 +134,7 @@ int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
a.setApplicationName("Server Manager Subprocess");
a.setApplicationVersion("0.10");
a.setApplicationVersion("0.10.1");
#ifdef Q_OS_UNIX
catchUnixSignals({SIGINT, SIGHUP, SIGQUIT, SIGTERM});