Enable validation according to WebSocket resource and origin.

This commit is contained in:
lotodore
2013-10-05 16:42:05 +02:00
parent 2c5dcc2ba0
commit a6f3536290
8 changed files with 33 additions and 13 deletions
+3 -1
View File
@@ -64,7 +64,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
myConfigState = OK;
// !!!! Revisionsnummer der Configdefaults !!!!!
configRev = 101;
configRev = 102;
//standard defaults
logOnOffDefault = "1";
@@ -223,6 +223,8 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
configList.push_back(ConfigInfo("ServerUseWebSocket", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("ServerPort", CONFIG_TYPE_INT, "7234"));
configList.push_back(ConfigInfo("ServerWebSocketPort", CONFIG_TYPE_INT, "7233"));
configList.push_back(ConfigInfo("ServerWebSocketResource", CONFIG_TYPE_STRING, ""));
configList.push_back(ConfigInfo("ServerWebSocketOrigin", CONFIG_TYPE_STRING, ""));
configList.push_back(ConfigInfo("ServerUsePutAvatars", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("ServerPutAvatarsAddress", CONFIG_TYPE_STRING, ""));
configList.push_back(ConfigInfo("ServerPutAvatarsUser", CONFIG_TYPE_STRING, ""));
+12 -4
View File
@@ -36,8 +36,10 @@
using namespace std;
ServerAcceptWebHelper::ServerAcceptWebHelper(ServerCallback &serverCallback, boost::shared_ptr<boost::asio::io_service> ioService)
: m_ioService(ioService), m_serverCallback(serverCallback)
ServerAcceptWebHelper::ServerAcceptWebHelper(ServerCallback &serverCallback, boost::shared_ptr<boost::asio::io_service> ioService,
const string &webSocketResource, const string &webSocketOrigin)
: m_ioService(ioService), m_serverCallback(serverCallback),
m_webSocketResource(webSocketResource), m_webSocketOrigin(webSocketOrigin)
{
m_webSocketServer.reset(new server);
}
@@ -71,9 +73,15 @@ ServerAcceptWebHelper::Close()
}
bool
ServerAcceptWebHelper::validate(websocketpp::connection_hdl /*hdl*/)
ServerAcceptWebHelper::validate(websocketpp::connection_hdl hdl)
{
return true;
bool retVal = false;
server::connection_ptr con = m_webSocketServer->get_con_from_hdl(hdl);
if ((m_webSocketResource.empty() || con->get_resource() == m_webSocketResource)
&& (m_webSocketOrigin.empty() || (con->get_origin() != "null" && con->get_origin() == m_webSocketOrigin))) {
retVal = true;
}
return retVal;
}
void
+4 -2
View File
@@ -78,7 +78,8 @@ ServerManager::~ServerManager()
}
void
ServerManager::Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const string &logDir)
ServerManager::Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const string &logDir,
const string &webSocketResource, const string &webSocketOrigin)
{
GetLobbyThread().Init(logDir);
@@ -95,7 +96,8 @@ ServerManager::Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int
}*/
if (proto & TRANSPORT_PROTOCOL_WEBSOCKET)
{
boost::shared_ptr<ServerAcceptInterface> webAcceptHelper(new ServerAcceptWebHelper(GetGui(), m_ioService));
boost::shared_ptr<ServerAcceptInterface> webAcceptHelper(
new ServerAcceptWebHelper(GetGui(), m_ioService, webSocketResource, webSocketOrigin));
webAcceptHelper->Listen(websocketPort, ipv6, logDir, m_lobbyThread);
m_acceptHelperPool.push_back(webAcceptHelper);
}
+3 -2
View File
@@ -52,7 +52,8 @@ ServerManagerIrc::~ServerManagerIrc()
}
void
ServerManagerIrc::Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const string &logDir)
ServerManagerIrc::Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const string &logDir,
const std::string &webSocketResource, const std::string &webSocketOrigin)
{
boost::shared_ptr<IrcThread> tmpIrcAdminThread;
boost::shared_ptr<IrcThread> tmpIrcLobbyThread;
@@ -83,7 +84,7 @@ ServerManagerIrc::Init(unsigned serverPort, unsigned websocketPort, bool ipv6, i
m_adminBot->Init(m_lobbyThread, tmpIrcAdminThread, myConfig.readConfigString("CacheDir"));
m_lobbyBot->Init(m_lobbyThread, tmpIrcLobbyThread);
ServerManager::Init(serverPort, websocketPort, ipv6, proto, logDir);
ServerManager::Init(serverPort, websocketPort, ipv6, proto, logDir, webSocketResource, webSocketOrigin);
}
void
+4 -1
View File
@@ -40,7 +40,8 @@
class ServerAcceptWebHelper : public ServerAcceptInterface
{
public:
ServerAcceptWebHelper(ServerCallback &serverCallback, boost::shared_ptr<boost::asio::io_service> ioService);
ServerAcceptWebHelper(ServerCallback &serverCallback, boost::shared_ptr<boost::asio::io_service> ioService,
const std::string &webSocketResource, const std::string &webSocketOrigin);
virtual void Listen(unsigned serverPort, bool ipv6, const std::string &logDir,
boost::shared_ptr<ServerLobbyThread> lobbyThread);
@@ -61,6 +62,8 @@ private:
ServerCallback &m_serverCallback;
boost::shared_ptr<server> m_webSocketServer;
SessionMap m_sessionMap;
std::string m_webSocketResource;
std::string m_webSocketOrigin;
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
};
+2 -1
View File
@@ -54,7 +54,8 @@ public:
virtual ~ServerManager();
// Set the parameters.
virtual void Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const std::string &logDir);
virtual void Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const std::string &logDir,
const std::string &webSocketResource, const std::string &webSocketOrigin);
// Main start function.
virtual void RunAll();
+2 -1
View File
@@ -45,7 +45,8 @@ public:
virtual ~ServerManagerIrc();
// Set the parameters.
virtual void Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const std::string &logDir);
virtual void Init(unsigned serverPort, unsigned websocketPort, bool ipv6, int proto, const std::string &logDir,
const std::string &webSocketResource, const std::string &webSocketOrigin);
// Main start function.
virtual void RunAll();
+3 -1
View File
@@ -342,7 +342,9 @@ void Session::startNetworkServer(bool dedicated)
myConfig->readConfigInt("ServerWebSocketPort"),
myConfig->readConfigInt("ServerUseIpv6") == 1,
protocol,
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("LogDir"))
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("LogDir")),
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("ServerWebSocketResource")),
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("ServerWebSocketOrigin"))
);
myNetServer->RunAll();