summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp')
-rw-r--r--tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp48
1 files changed, 46 insertions, 2 deletions
diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
index d5035c5266..0d75d4dd33 100644
--- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
+++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
@@ -31,6 +31,7 @@
#include <QtCore/qthread.h>
#include <QtCore/qelapsedtimer.h>
#include <QtCore/qrandom.h>
+#include <QtCore/qscopeguard.h>
#include <QtNetwork/qhostaddress.h>
#include <QtNetwork/qhostinfo.h>
#include <QtNetwork/qnetworkproxy.h>
@@ -51,10 +52,12 @@
#include "../../../network-settings.h"
#ifndef QT_NO_SSL
+
#ifndef QT_NO_OPENSSL
#include "private/qsslsocket_openssl_p.h"
#include "private/qsslsocket_openssl_symbols_p.h"
-#endif
+#endif // QT_NO_OPENSSL
+
#include "private/qsslsocket_p.h"
#include "private/qsslconfiguration_p.h"
@@ -73,7 +76,8 @@ typedef QSharedPointer<QSslSocket> QSslSocketPtr;
#define FLUKE_CERTIFICATE_ERROR QSslError::SelfSignedCertificate
#else
#define FLUKE_CERTIFICATE_ERROR QSslError::CertificateUntrusted
-#endif
+#endif // QT_NO_OPENSSL
+
#endif // QT_NO_OPENSSL
// Detect ALPN (Application-Layer Protocol Negotiation) support
@@ -218,6 +222,9 @@ private slots:
void waitForMinusOne();
void verifyMode();
void verifyDepth();
+#ifndef QT_NO_OPENSSL
+ void verifyAndDefaultConfiguration();
+#endif // QT_NO_OPENSSL
void disconnectFromHostWhenConnecting();
void disconnectFromHostWhenConnected();
#ifndef QT_NO_OPENSSL
@@ -2392,6 +2399,43 @@ void tst_QSslSocket::verifyDepth()
QCOMPARE(socket.peerVerifyDepth(), 1);
}
+#ifndef QT_NO_OPENSSL
+void tst_QSslSocket::verifyAndDefaultConfiguration()
+{
+ QFETCH_GLOBAL(const bool, setProxy);
+ if (setProxy)
+ return;
+ const auto defaultCACertificates = QSslConfiguration::defaultConfiguration().caCertificates();
+ const auto chainGuard = qScopeGuard([&defaultCACertificates]{
+ auto conf = QSslConfiguration::defaultConfiguration();
+ conf.setCaCertificates(defaultCACertificates);
+ QSslConfiguration::setDefaultConfiguration(conf);
+ });
+
+ auto chain = QSslCertificate::fromPath(testDataDir + QStringLiteral("certs/qtiochain.crt"), QSsl::Pem);
+ QCOMPARE(chain.size(), 2);
+ QVERIFY(!chain.at(0).isNull());
+ QVERIFY(!chain.at(1).isNull());
+ auto errors = QSslCertificate::verify(chain);
+ // At least, test that 'verify' did not alter the default configuration:
+ QCOMPARE(defaultCACertificates, QSslConfiguration::defaultConfiguration().caCertificates());
+ if (!errors.isEmpty())
+ QSKIP("The certificate for qt.io could not be trusted, skipping the rest of the test");
+#ifdef Q_OS_WINDOWS
+ const auto fakeCaChain = QSslCertificate::fromPath(testDataDir + QStringLiteral("certs/fluke.cert"));
+ QCOMPARE(fakeCaChain.size(), 1);
+ const auto caCert = fakeCaChain.at(0);
+ QVERIFY(!caCert.isNull());
+ auto conf = QSslConfiguration::defaultConfiguration();
+ conf.setCaCertificates({caCert});
+ QSslConfiguration::setDefaultConfiguration(conf);
+ errors = QSslCertificate::verify(chain);
+ QVERIFY(errors.size() > 0);
+ QCOMPARE(QSslConfiguration::defaultConfiguration().caCertificates(), QList{caCert});
+#endif
+}
+#endif // QT_NO_OPENSSL
+
void tst_QSslSocket::disconnectFromHostWhenConnecting()
{
QSslSocketPtr socket = newSocket();