diff options
author | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2020-09-09 15:11:29 +0200 |
---|---|---|
committer | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2020-09-11 20:38:50 +0200 |
commit | 2b56244866c5a7c124d084e6b38b025cb1c53edc (patch) | |
tree | 27d1827e7d0fbb5b43f6cbc092e6da966bc9c4ad /tests | |
parent | 80d3b30a054e55f627ba6a88a4969251691a7a60 (diff) |
Fix a rather sloppy test case in tst_QSslKey
It's not guaranteed that all curves we want to use are supported
by a specific build of OpenSSL library we have to link with. Filter
out files that contain EC, which is not among the curves, reported
by QSslConfiguration::supportedEllipticCurves.
Fixes: QTBUG-46203
Change-Id: I70d7e6fcacb3d81f8c771e4a8d6cca06295e7474
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit 4f658d04da03953358959c0a0921e564cf67ecb2)
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/network/ssl/qsslkey/tst_qsslkey.cpp | 58 |
1 files changed, 52 insertions, 6 deletions
diff --git a/tests/auto/network/ssl/qsslkey/tst_qsslkey.cpp b/tests/auto/network/ssl/qsslkey/tst_qsslkey.cpp index f94756ed73..8ff6d35ba2 100644 --- a/tests/auto/network/ssl/qsslkey/tst_qsslkey.cpp +++ b/tests/auto/network/ssl/qsslkey/tst_qsslkey.cpp @@ -31,10 +31,16 @@ #include <qsslkey.h> #include <qsslsocket.h> #include <QScopeGuard> +#include <qsslconfiguration.h> +#include <qsslellipticcurve.h> #include <QtNetwork/qhostaddress.h> #include <QtNetwork/qnetworkproxy.h> +#include <QtCore/qstring.h> +#include <QtCore/qdebug.h> +#include <QtCore/qlist.h> + #ifdef QT_BUILD_INTERNAL #ifndef QT_NO_SSL #include "private/qsslkey_p.h" @@ -45,6 +51,8 @@ #endif #endif +#include <algorithm> + class tst_QSslKey : public QObject { Q_OBJECT @@ -65,6 +73,8 @@ class tst_QSslKey : public QObject QList<KeyInfo> keyInfoList; void createPlainTestRows(bool pemOnly = false); +public: + tst_QSslKey(); public slots: void initTestCase(); @@ -100,8 +110,46 @@ private slots: #endif private: QString testDataDir; + + bool fileContainsUnsupportedEllipticCurve(const QString &fileName) const; + QVector<QString> unsupportedCurves; }; +tst_QSslKey::tst_QSslKey() +{ + const QString expectedCurves[] = { + // See how we generate them in keys/genkey.sh. + QStringLiteral("secp224r1"), + QStringLiteral("prime256v1"), + QStringLiteral("secp384r1"), + QStringLiteral("brainpoolP256r1"), + QStringLiteral("brainpoolP384r1"), + QStringLiteral("brainpoolP512r1") + }; + const auto supportedCurves = QSslConfiguration::supportedEllipticCurves(); + + for (const auto &requestedEc : expectedCurves) { + auto pos = std::find_if(supportedCurves.begin(), supportedCurves.end(), + [&requestedEc](const QSslEllipticCurve &supported) { + return requestedEc == supported.shortName(); + }); + if (pos == supportedCurves.end()) { + qWarning() << "EC with the name:" << requestedEc + << "is not supported by your build of OpenSSL and will not be tested."; + unsupportedCurves.push_back(requestedEc); + } + } +} + +bool tst_QSslKey::fileContainsUnsupportedEllipticCurve(const QString &fileName) const +{ + for (const auto &name : unsupportedCurves) { + if (fileName.contains(name)) + return true; + } + return false; +} + void tst_QSslKey::initTestCase() { testDataDir = QFileInfo(QFINDTESTDATA("rsa-without-passphrase.pem")).absolutePath(); @@ -114,6 +162,9 @@ void tst_QSslKey::initTestCase() const QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::Readable); QRegExp rx(QLatin1String("^(rsa|dsa|dh|ec)-(pub|pri)-(\\d+)-?[\\w-]*\\.(pem|der)$")); for (const QFileInfo &fileInfo : fileInfoList) { + if (fileContainsUnsupportedEllipticCurve(fileInfo.fileName())) + continue; + if (rx.indexIn(fileInfo.fileName()) >= 0) { keyInfoList << KeyInfo( fileInfo, @@ -238,14 +289,9 @@ void tst_QSslKey::constructorHandle() BIO* bio = q_BIO_new(q_BIO_s_mem()); q_BIO_write(bio, pem.constData(), pem.length()); EVP_PKEY *origin = func(bio, nullptr, nullptr, static_cast<void *>(passphrase.data())); -#if QT_CONFIG(opensslv11) + Q_ASSERT(origin); q_EVP_PKEY_up_ref(origin); -#endif QSslKey key(origin, type); -#if !QT_CONFIG(opensslv11) - q_BIO_write(bio, pem.constData(), pem.length()); - origin = func(bio, nullptr, nullptr, static_cast<void *>(passphrase.data())); -#endif q_BIO_free(bio); EVP_PKEY *handle = q_EVP_PKEY_new(); |