From cb4908dc92ede700e33fee7721bb3d44d0839c4b Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 15 Sep 2017 23:30:22 +0200 Subject: [PATCH] prefer ssl connections rather than plaintext ones in upnp discovery response --- server/webserver.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/server/webserver.cpp b/server/webserver.cpp index 2ce976f2..a20ff0d0 100644 --- a/server/webserver.cpp +++ b/server/webserver.cpp @@ -576,8 +576,13 @@ QByteArray WebServer::createServerXmlDocument(QHostAddress address) bool webSocketServerFound = false; foreach (const ServerConfiguration &config, GuhCore::instance()->configuration()->webSocketServerConfigurations()) { if (config.address == QHostAddress("0.0.0.0") || config.address == address) { - websocketConfiguration = config; - webSocketServerFound = true; + if (!webSocketServerFound) { + websocketConfiguration = config; + webSocketServerFound = true; + } else if (!websocketConfiguration.sslEnabled && config.sslEnabled) { + // If the previous one is plaintext but we also have a secure one, upgrade to that. + websocketConfiguration = config; + } } } if (webSocketServerFound) { @@ -592,8 +597,13 @@ QByteArray WebServer::createServerXmlDocument(QHostAddress address) bool tcpServerFound = false; foreach (const ServerConfiguration &config, GuhCore::instance()->configuration()->tcpServerConfigurations()) { if (config.address == QHostAddress("0.0.0.0") || config.address == address) { - tcpServerConfiguration = config; - tcpServerFound = true; + if (!tcpServerFound) { + tcpServerConfiguration = config; + tcpServerFound = true; + } else if (!tcpServerConfiguration.sslEnabled && config.sslEnabled) { + // If the previous one is plaintext but we also have a secure one, upgrade to that. + tcpServerConfiguration = config; + } } } if (tcpServerFound) {