tst_QSslKey - make OpenSSL v3 detection fully runtime

Otherwise, checks are useles in non-developer build.

Fixes: QTBUG-106036
Change-Id: I41b6d8f250021ff9fa4981f9df9244c269ed2999
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit 8e21844683d46e777db3db74df0bcf76cb9a35c0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Timur Pocheptsov 2022-09-01 13:44:36 +02:00 committed by Qt Cherry-pick Bot
parent 88d06dd980
commit cb61bea591

View File

@ -156,6 +156,7 @@ bool tst_QSslKey::fileContainsUnsupportedEllipticCurve(const QString &fileName)
bool tst_QSslKey::algorithmsSupported(const QString &fileName) const bool tst_QSslKey::algorithmsSupported(const QString &fileName) const
{ {
#if QT_CONFIG(ssl)
if (isSchannel && fileName.contains("RC2-64")) // Schannel treats RC2 as 128 bit if (isSchannel && fileName.contains("RC2-64")) // Schannel treats RC2 as 128 bit
return false; return false;
@ -164,10 +165,9 @@ bool tst_QSslKey::algorithmsSupported(const QString &fileName) const
return !(fileName.contains(QRegularExpression("-aes\\d\\d\\d-")) || fileName.contains("pkcs8-pkcs12")); return !(fileName.contains(QRegularExpression("-aes\\d\\d\\d-")) || fileName.contains("pkcs8-pkcs12"));
} }
#if OPENSSL_VERSION_MAJOR < 3 if (!isOpenSsl || QSslSocket::sslLibraryVersionNumber() >> 28 < 3)
// If it's not built with OpenSSL or it's OpenSSL v < 3. return true;
return true;
#else
// OpenSSL v3 first introduced the notion of 'providers'. Many algorithms // OpenSSL v3 first introduced the notion of 'providers'. Many algorithms
// were moved into the 'legacy' provider. While they are still supported in theory, // were moved into the 'legacy' provider. While they are still supported in theory,
// the 'legacy' provider is NOT loaded by default and we are not loading it either. // the 'legacy' provider is NOT loaded by default and we are not loading it either.
@ -178,7 +178,10 @@ bool tst_QSslKey::algorithmsSupported(const QString &fileName) const
return false; return false;
return !name.contains("-rc2-") && !name.contains("-rc4-"); return !name.contains("-rc2-") && !name.contains("-rc4-");
#endif #else
Q_UNUSED(fileName);
return false;
#endif // QT_CONFIG(ssl)
} }
@ -545,12 +548,12 @@ void tst_QSslKey::passphraseChecks_data()
const QByteArray pass("123"); const QByteArray pass("123");
const QByteArray aesPass("1234"); const QByteArray aesPass("1234");
#if OPENSSL_VERSION_MAJOR < 3 if (!isOpenSsl || QSslSocket::sslLibraryVersionNumber() >> 28 < 3) {
// DES and RC2 are not provided by default in OpenSSL v3. // DES and RC2 are not provided by default in OpenSSL v3.
// This part is for either non-OpenSSL build, or OpenSSL v < 3.x. // This part is for either non-OpenSSL build, or OpenSSL v < 3.x.
QTest::newRow("DES") << QString(testDataDir + "rsa-with-passphrase-des.pem") << pass; QTest::newRow("DES") << QString(testDataDir + "rsa-with-passphrase-des.pem") << pass;
QTest::newRow("RC2") << QString(testDataDir + "rsa-with-passphrase-rc2.pem") << pass; QTest::newRow("RC2") << QString(testDataDir + "rsa-with-passphrase-rc2.pem") << pass;
#endif // OPENSSL_VERSION_MAJOR }
QTest::newRow("3DES") << QString(testDataDir + "rsa-with-passphrase-3des.pem") << pass; QTest::newRow("3DES") << QString(testDataDir + "rsa-with-passphrase-3des.pem") << pass;