ssl support
This commit is contained in:
parent
341d9a57b2
commit
83ecf9491f
@ -78,13 +78,27 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Secure Port:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="secure_port">
|
||||
<property name="maximum">
|
||||
<number>65535</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Description:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QPlainTextEdit" name="description">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
@ -106,7 +120,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QDialogButtonBox" name="button_box">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Save</set>
|
||||
|
@ -9,6 +9,7 @@ public:
|
||||
QString description;
|
||||
QString address;
|
||||
quint16 port = 0;
|
||||
quint16 secure_port = 0;
|
||||
bool legacy = false;
|
||||
|
||||
QString toString() const;
|
||||
|
@ -2,8 +2,9 @@
|
||||
|
||||
#include "aoapplication.h"
|
||||
|
||||
#include <QNetworkRequest>
|
||||
#include <QUrl>
|
||||
#include <QSslConfiguration>
|
||||
#include <QWebSocket>
|
||||
|
||||
WebSocketConnection::WebSocketConnection(AOApplication *ao_app, QObject *parent)
|
||||
: QObject(parent)
|
||||
@ -31,15 +32,28 @@ void WebSocketConnection::connectToServer(const ServerInfo &server)
|
||||
{
|
||||
disconnectFromServer();
|
||||
|
||||
bool useWss = server.secure_port != 0;
|
||||
QString scheme = useWss ? "wss" : "ws";
|
||||
int port = useWss ? server.secure_port : server.port;
|
||||
|
||||
QUrl url;
|
||||
url.setScheme("ws");
|
||||
url.setScheme(scheme);
|
||||
url.setHost(server.address);
|
||||
url.setPort(server.port);
|
||||
url.setPort(port);
|
||||
|
||||
QNetworkRequest req(url);
|
||||
req.setHeader(QNetworkRequest::UserAgentHeader, QStringLiteral("AttorneyOnline/%1 (Desktop)").arg(ao_app->get_version_string()));
|
||||
|
||||
m_socket->open(req);
|
||||
qInfo().noquote() << "Connecting to WebSocket server at:" << url.toString();
|
||||
|
||||
// Set up SSL configuration if using wss
|
||||
if (scheme == "wss") {
|
||||
QSslConfiguration sslConf = QSslConfiguration::defaultConfiguration();
|
||||
sslConf.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||
m_socket->setSslConfiguration(sslConf);
|
||||
}
|
||||
|
||||
m_socket->open(url);
|
||||
}
|
||||
|
||||
void WebSocketConnection::disconnectFromServer()
|
||||
|
@ -71,6 +71,11 @@ void NetworkManager::ms_request_finished(QNetworkReply *reply)
|
||||
server.legacy = true;
|
||||
}
|
||||
|
||||
if (entry.contains("wss_port"))
|
||||
{
|
||||
server.secure_port = entry["wss_port"].toInt();
|
||||
}
|
||||
|
||||
if (server.port != 0)
|
||||
{
|
||||
server_list.append(server);
|
||||
|
@ -676,6 +676,7 @@ QVector<ServerInfo> Options::favorites()
|
||||
favorite.beginGroup(group);
|
||||
f_server.address = favorite.value("address", "127.0.0.1").toString();
|
||||
f_server.port = favorite.value("port", 27016).toInt();
|
||||
f_server.secure_port = favorite.value("secure_port", 0).toInt();
|
||||
f_server.name = favorite.value("name", "Missing Name").toString();
|
||||
f_server.description = favorite.value("desc", "No description").toString();
|
||||
if (favorite.contains("protocol"))
|
||||
@ -704,6 +705,7 @@ void Options::setFavorites(QVector<ServerInfo> value)
|
||||
favorite.setValue("name", fav_server.name);
|
||||
favorite.setValue("address", fav_server.address);
|
||||
favorite.setValue("port", fav_server.port);
|
||||
favorite.setValue("secure_port", fav_server.secure_port);
|
||||
favorite.setValue("desc", fav_server.description);
|
||||
favorite.setValue("legacy", fav_server.legacy);
|
||||
favorite.endGroup();
|
||||
@ -725,6 +727,7 @@ void Options::addFavorite(ServerInfo server)
|
||||
favorite.setValue("name", server.name);
|
||||
favorite.setValue("address", server.address);
|
||||
favorite.setValue("port", server.port);
|
||||
favorite.setValue("secure_port", server.secure_port);
|
||||
favorite.setValue("desc", server.description);
|
||||
favorite.setValue("legacy", server.legacy);
|
||||
favorite.endGroup();
|
||||
@ -737,6 +740,7 @@ void Options::updateFavorite(ServerInfo server, int index)
|
||||
favorite.setValue("name", server.name);
|
||||
favorite.setValue("address", server.address);
|
||||
favorite.setValue("port", server.port);
|
||||
favorite.setValue("secure_port", server.secure_port);
|
||||
favorite.setValue("desc", server.description);
|
||||
favorite.setValue("legacy", server.legacy);
|
||||
favorite.endGroup();
|
||||
|
@ -61,9 +61,9 @@ void DirectConnectDialog::onConnectPressed()
|
||||
return;
|
||||
}
|
||||
|
||||
if (l_url.scheme() != "ws")
|
||||
if (l_url.scheme() != "ws" && l_url.scheme() != "wss")
|
||||
{
|
||||
call_error(tr("Invalid URL scheme. Only ws:// is supported."));
|
||||
call_error(tr("Invalid URL scheme. Only ws:// and wss:// is supported."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ ServerEditorDialog::ServerEditorDialog(QWidget *parent)
|
||||
FROM_UI(QLineEdit, name);
|
||||
FROM_UI(QLineEdit, hostname);
|
||||
FROM_UI(QSpinBox, port);
|
||||
FROM_UI(QSpinBox, secure_port);
|
||||
FROM_UI(QPlainTextEdit, description);
|
||||
FROM_UI(QDialogButtonBox, button_box);
|
||||
|
||||
@ -49,6 +50,7 @@ ServerEditorDialog::ServerEditorDialog(const ServerInfo &server, QWidget *parent
|
||||
ui_name->setText(server.name);
|
||||
ui_hostname->setText(server.address);
|
||||
ui_port->setValue(server.port);
|
||||
ui_secure_port->setValue(server.secure_port);
|
||||
ui_description->setPlainText(server.description);
|
||||
}
|
||||
|
||||
@ -58,6 +60,7 @@ ServerInfo ServerEditorDialog::currentServerInfo() const
|
||||
server.name = ui_name->text();
|
||||
server.address = ui_hostname->text();
|
||||
server.port = ui_port->value();
|
||||
server.secure_port = ui_secure_port->value();
|
||||
server.description = ui_description->toPlainText();
|
||||
return server;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ private:
|
||||
QLineEdit *ui_name;
|
||||
QLineEdit *ui_hostname;
|
||||
QSpinBox *ui_port;
|
||||
QSpinBox *ui_secure_port;
|
||||
QPlainTextEdit *ui_description;
|
||||
QDialogButtonBox *ui_button_box;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user