summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2023-03-15 18:08:56 +0100
committerMichal Klocek <michal.klocek@qt.io>2023-03-23 12:50:44 +0100
commit9fd30150ba979e0a79ad0b9b48261a9f699735bc (patch)
tree515b3ad52706870f6b9ac9d8e537f73b84902f3a
parentf8264c2f508c241dcc20a028de00753960bd580d (diff)
Revert "Use QSslServer in certificate test"
New ssl server can not be used with 6.2, however httpserver is used by most of the tests, therfore revert the change. This reverts commit 54017760b77fb8359d4ef51c82668acbfd4e86e2. Change-Id: If426a78d92c9b8379cea310ada1104b7bfbc7dfd Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--tests/auto/core/certificateerror/tst_certificateerror.cpp1
-rw-r--r--tests/auto/httpserver/httpserver.cpp3
-rw-r--r--tests/auto/httpserver/httpsserver.h71
3 files changed, 34 insertions, 41 deletions
diff --git a/tests/auto/core/certificateerror/tst_certificateerror.cpp b/tests/auto/core/certificateerror/tst_certificateerror.cpp
index 67e2d8ae4..fd22f5d63 100644
--- a/tests/auto/core/certificateerror/tst_certificateerror.cpp
+++ b/tests/auto/core/certificateerror/tst_certificateerror.cpp
@@ -105,7 +105,6 @@ void tst_CertificateError::handleError()
QTRY_COMPARE_WITH_TIMEOUT(page.loadSpy.size(), 1, 30000);
QCOMPARE(page.loadSpy.takeFirst().value(0).toBool(), acceptCertificate);
QCOMPARE(toPlainTextSync(&page), expectedContent);
- QVERIFY(server.stop());
}
void tst_CertificateError::fatalError()
diff --git a/tests/auto/httpserver/httpserver.cpp b/tests/auto/httpserver/httpserver.cpp
index e08af77e7..c65d68ce7 100644
--- a/tests/auto/httpserver/httpserver.cpp
+++ b/tests/auto/httpserver/httpserver.cpp
@@ -24,8 +24,7 @@ HttpServer::HttpServer(QTcpServer *tcpServer, const QString &protocol,
{
m_url.setHost(hostAddress.toString());
m_url.setScheme(protocol);
- connect(tcpServer, &QTcpServer::pendingConnectionAvailable, this,
- &HttpServer::handleNewConnection);
+ connect(tcpServer, &QTcpServer::newConnection, this, &HttpServer::handleNewConnection);
}
HttpServer::~HttpServer()
diff --git a/tests/auto/httpserver/httpsserver.h b/tests/auto/httpserver/httpsserver.h
index 10deeb322..d064c1416 100644
--- a/tests/auto/httpserver/httpsserver.h
+++ b/tests/auto/httpserver/httpsserver.h
@@ -7,56 +7,51 @@
#include "httpserver.h"
#include <QDebug>
-#include <QtCore/qfile.h>
-#include <QtNetwork/qsslkey.h>
-#include <QtNetwork/qsslsocket.h>
-#include <QtNetwork/qsslconfiguration.h>
-#include <QtNetwork/qsslserver.h>
+#include <QFile>
+#include <QSslKey>
+#include <QSslSocket>
+#include <QSslConfiguration>
+#include <QTcpServer>
-static QSslServer *createServer(const QString &certificateFileName, const QString &keyFileName,
- const QString &ca)
+struct SslTcpServer : QTcpServer
{
- QSslConfiguration configuration(QSslConfiguration::defaultConfiguration());
+ SslTcpServer(const QString &certPath, const QString &keyPath) {
+ sslconf.setLocalCertificateChain(QSslCertificate::fromPath(certPath));
+ sslconf.setPrivateKey(readKey(keyPath));
+ }
+
+ void incomingConnection(qintptr d) override {
+ auto socket = new QSslSocket(this);
+ socket->setSslConfiguration(sslconf);
- QFile keyFile(keyFileName);
- if (keyFile.open(QIODevice::ReadOnly)) {
- QSslKey key(keyFile.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
- if (!key.isNull()) {
- configuration.setPrivateKey(key);
- } else {
- qCritical() << "Could not parse key: " << keyFileName;
+ if (!socket->setSocketDescriptor(d)) {
+ qWarning() << "Failed to setup ssl socket!";
+ delete socket;
+ return;
}
- } else {
- qCritical() << "Could not find key: " << keyFileName;
- }
- QList<QSslCertificate> localCerts = QSslCertificate::fromPath(certificateFileName);
- if (!localCerts.isEmpty()) {
- configuration.setLocalCertificateChain(localCerts);
- } else {
- qCritical() << "Could not find certificate: " << certificateFileName;
+ connect(socket, QOverload<QSslSocket::SocketError>::of(&QSslSocket::errorOccurred),
+ [] (QSslSocket::SocketError e) { qWarning() << "! Socket Error:" << e; });
+ connect(socket, QOverload<const QList<QSslError> &>::of(&QSslSocket::sslErrors),
+ [] (const QList<QSslError> &le) { qWarning() << "! SSL Errors:\n" << le; });
+
+ addPendingConnection(socket);
+ socket->startServerEncryption();
}
- if (!ca.isEmpty()) {
- QList<QSslCertificate> caCerts = QSslCertificate::fromPath(ca);
- if (!caCerts.isEmpty()) {
- configuration.addCaCertificates(caCerts);
- configuration.setPeerVerifyMode(QSslSocket::VerifyPeer);
- } else {
- qCritical() << "Could not find certificate: " << certificateFileName;
- }
+ QSslKey readKey(const QString &path) const {
+ QFile file(path);
+ file.open(QIODevice::ReadOnly);
+ return QSslKey(file.readAll(), QSsl::Rsa, QSsl::Pem);
}
- QSslServer *server = new QSslServer();
- server->setSslConfiguration(configuration);
- return server;
-}
+ QSslConfiguration sslconf;
+};
struct HttpsServer : HttpServer
{
- HttpsServer(const QString &certPath, const QString &keyPath, const QString &ca,
- QObject *parent = nullptr)
- : HttpServer(createServer(certPath, keyPath, ca), "https", QHostAddress::LocalHost, 0,
+ HttpsServer(const QString &certPath, const QString &keyPath, QObject *parent = nullptr)
+ : HttpServer(new SslTcpServer(certPath, keyPath), "https", QHostAddress::LocalHost, 0,
parent)
{
}