improve security

This commit is contained in:
Syping 2020-09-19 09:47:02 +02:00
parent d4a25b8346
commit 2cef92e61f
6 changed files with 827 additions and 824 deletions

View file

@ -88,7 +88,7 @@ void SMSubServer::newConnection()
} }
} }
void SMSubServer::messageReceived(QObject *socket, const QByteArray &message) bool SMSubServer::messageReceived(QObject *socket, const QByteArray &message)
{ {
// Only allow commands being sent if authenticated // Only allow commands being sent if authenticated
bool isAuthenticated = socket->property("Authenticated").toBool(); bool isAuthenticated = socket->property("Authenticated").toBool();
@ -155,16 +155,18 @@ void SMSubServer::messageReceived(QObject *socket, const QByteArray &message)
QObject::disconnect(localSocket, &QLocalSocket::readyRead, this, &SMSubServer::lsReadyRead); QObject::disconnect(localSocket, &QLocalSocket::readyRead, this, &SMSubServer::lsReadyRead);
localSocket->write("Incorrect token!\n"); localSocket->write("Incorrect token!\n");
localSocket->disconnectFromServer(); localSocket->disconnectFromServer();
return false;
} }
else if (type == ServerType::WebSocket) { else if (type == ServerType::WebSocket) {
QWebSocket *webSocket = static_cast<QWebSocket*>(socket); QWebSocket *webSocket = static_cast<QWebSocket*>(socket);
QObject::disconnect(webSocket, &QWebSocket::binaryMessageReceived, this, &SMSubServer::wsMessageReceived); QObject::disconnect(webSocket, &QWebSocket::binaryMessageReceived, this, &SMSubServer::wsMessageReceived);
webSocket->sendBinaryMessage("Incorrect token!\n"); webSocket->sendBinaryMessage("Incorrect token!\n");
webSocket->close(QWebSocketProtocol::CloseCodeNormal); webSocket->close(QWebSocketProtocol::CloseCodeNormal);
} return false;
return;
} }
} }
}
return true;
} }
void SMSubServer::wsMessageReceived(const QByteArray &message) void SMSubServer::wsMessageReceived(const QByteArray &message)
@ -178,7 +180,8 @@ void SMSubServer::lsReadyRead()
QLocalSocket *socket = static_cast<QLocalSocket*>(sender()); QLocalSocket *socket = static_cast<QLocalSocket*>(sender());
while (socket->canReadLine()) { while (socket->canReadLine()) {
const QByteArray message = socket->readLine().trimmed(); const QByteArray message = socket->readLine().trimmed();
messageReceived(socket, message); if (!messageReceived(socket, message))
return;
} }
} }

View file

@ -55,7 +55,7 @@ private slots:
private: private:
inline void debugOutput(QObject *socket, const QByteArray &message); inline void debugOutput(QObject *socket, const QByteArray &message);
inline void sendMessage(QObject *socket, const QByteArray &message); inline void sendMessage(QObject *socket, const QByteArray &message);
void messageReceived(QObject *socket, const QByteArray &message); bool messageReceived(QObject *socket, const QByteArray &message);
SMSubServerSettings *serverSettings; SMSubServerSettings *serverSettings;
QVector<QObject*> sockets; QVector<QObject*> sockets;
QVector<QString> tokens; QVector<QString> tokens;

View file

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