Adapt the QSsl* tests to use the resource system

This lets the tests run on devices which previously did not have access
to the files used (WinRT, mobile devices).

Change-Id: Ibdd85862eee6ab1a7d4da87ca321ee9bc9880bfa
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Mårten Nordheim 2017-11-14 16:00:16 +01:00
parent a09fc184ac
commit e1600c1a73
9 changed files with 319 additions and 173 deletions

View File

@ -6,4 +6,7 @@ QT = core network testlib
TARGET = tst_qsslcertificate TARGET = tst_qsslcertificate
RESOURCES += \
qsslcertificate.qrc
TESTDATA += certificates/* more-certificates/* verify-certs/* pkcs12/* TESTDATA += certificates/* more-certificates/* verify-certs/* pkcs12/*

View File

@ -0,0 +1,79 @@
<RCC>
<qresource prefix="/">
<file>certificates/ca-cert.pem</file>
<file>certificates/ca-cert.pem.digest-md5</file>
<file>certificates/ca-cert.pem.digest-sha1</file>
<file>certificates/cert-ss-san-utf8.pem</file>
<file>certificates/cert-ss-san-utf8.pem.san</file>
<file>certificates/cert-ss-san.pem</file>
<file>certificates/cert-ss-san.pem.san</file>
<file>certificates/cert-ss.der</file>
<file>certificates/cert-ss.der.pubkey</file>
<file>certificates/cert-ss.pem</file>
<file>certificates/cert-ss.pem.digest-md5</file>
<file>certificates/cert-ss.pem.digest-sha1</file>
<file>certificates/cert-ss.pem.pubkey</file>
<file>certificates/cert.der</file>
<file>certificates/cert.der.pubkey</file>
<file>certificates/cert.pem</file>
<file>certificates/cert.pem.digest-md5</file>
<file>certificates/cert.pem.digest-sha1</file>
<file>certificates/cert.pem.pubkey</file>
<file>certificates/dsa-cert-ss.der.pubkey</file>
<file>certificates/dsa-cert-ss.pem</file>
<file>certificates/dsa-cert-ss.pem.digest-md5</file>
<file>certificates/dsa-cert-ss.pem.digest-sha1</file>
<file>certificates/dsa-cert-ss.pem.pubkey</file>
<file>certificates/ec-cert-ss.der.pubkey</file>
<file>certificates/ec-cert-ss.pem</file>
<file>certificates/ec-cert-ss.pem.digest-md5</file>
<file>certificates/ec-cert-ss.pem.digest-sha1</file>
<file>certificates/ec-cert-ss.pem.pubkey</file>
<file>certificates/gencertificates.sh</file>
<file>certificates/san.cnf</file>
<file>more-certificates/badguy-nul-cn.crt</file>
<file>more-certificates/badguy-nul-san.crt</file>
<file>more-certificates/blacklisted-anssi-tresor.pem</file>
<file>more-certificates/blacklisted-google.com-diginotar.pem</file>
<file>more-certificates/blacklisted-nic-india-2007.pem</file>
<file>more-certificates/blacklisted-nic-india-2011.pem</file>
<file>more-certificates/blacklisted-nic-india-2014.pem</file>
<file>more-certificates/blacklisted-turktrust-e-islem.kktcmerkezbankasi.org.pem</file>
<file>more-certificates/blacklisted-turktrust-ego.gov.tr.pem</file>
<file>more-certificates/blacklisted1.pem</file>
<file>more-certificates/blacklisted2.pem</file>
<file>more-certificates/blacklisted3.pem</file>
<file>more-certificates/blacklisted4.pem</file>
<file>more-certificates/blacklisted5.pem</file>
<file>more-certificates/blacklisted6.pem</file>
<file>more-certificates/blacklisted7.pem</file>
<file>more-certificates/blacklisted8.pem</file>
<file>more-certificates/blacklisted9.pem</file>
<file>more-certificates/cert-large-expiration-date.pem</file>
<file>more-certificates/cert-large-expiration-date.txt.0.9.8</file>
<file>more-certificates/cert-large-expiration-date.txt.1.0.0</file>
<file>more-certificates/cert-large-expiration-date.txt.1.0.1</file>
<file>more-certificates/cert-large-expiration-date.txt.1.0.1c</file>
<file>more-certificates/cert-large-serial-number.pem</file>
<file>more-certificates/malformed-just-begin-no-newline.pem</file>
<file>more-certificates/malformed-just-begin.pem</file>
<file>more-certificates/natwest-banking.pem</file>
<file>more-certificates/no-ending-newline.pem</file>
<file>more-certificates/test-cn-two-cns-cert.pem</file>
<file>more-certificates/test-cn-with-drink-cert.pem</file>
<file>more-certificates/trailing-whitespace.pem</file>
<file>pkcs12/inter.crt</file>
<file>pkcs12/leaf-nokey.p12</file>
<file>pkcs12/leaf.crt</file>
<file>pkcs12/leaf.key</file>
<file>pkcs12/leaf.p12</file>
<file>pkcs12/README</file>
<file>verify-certs/cacert.pem</file>
<file>verify-certs/README</file>
<file>verify-certs/test-addons-mozilla-org-cert.pem</file>
<file>verify-certs/test-intermediate-ca-cert.pem</file>
<file>verify-certs/test-intermediate-is-ca-cert.pem</file>
<file>verify-certs/test-intermediate-not-ca-cert.pem</file>
<file>verify-certs/test-ocsp-good-cert.pem</file>
</qresource>
</RCC>

View File

@ -57,11 +57,8 @@ class tst_QSslCertificate : public QObject
void compareCertificates(const QSslCertificate & cert1, const QSslCertificate & cert2); void compareCertificates(const QSslCertificate & cert1, const QSslCertificate & cert2);
#endif #endif
QString oldCurrentDir;
public slots: public slots:
void initTestCase(); void initTestCase();
void cleanupTestCase();
#ifndef QT_NO_SSL #ifndef QT_NO_SSL
private slots: private slots:
@ -111,23 +108,11 @@ private slots:
// ### add tests for certificate bundles (multiple certificates concatenated into a single // ### add tests for certificate bundles (multiple certificates concatenated into a single
// structure); both PEM and DER formatted // structure); both PEM and DER formatted
#endif #endif
private:
QString testDataDir;
}; };
void tst_QSslCertificate::initTestCase() void tst_QSslCertificate::initTestCase()
{ {
testDataDir = QFileInfo(QFINDTESTDATA("certificates")).absolutePath(); QDir dir(":/certificates");
if (testDataDir.isEmpty())
testDataDir = QCoreApplication::applicationDirPath();
if (QDir::current().absolutePath() != testDataDir) {
oldCurrentDir = QDir::current().absolutePath();
QVERIFY2(QDir::setCurrent(testDataDir),
qPrintable(QString("Cannot change directory to %1").arg(testDataDir)));
}
QDir dir(testDataDir + "/certificates");
QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::Readable); QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::Readable);
QRegExp rxCert(QLatin1String("^.+\\.(pem|der)$")); QRegExp rxCert(QLatin1String("^.+\\.(pem|der)$"));
QRegExp rxSan(QLatin1String("^(.+\\.(?:pem|der))\\.san$")); QRegExp rxSan(QLatin1String("^(.+\\.(?:pem|der))\\.san$"));
@ -151,13 +136,6 @@ void tst_QSslCertificate::initTestCase()
} }
} }
void tst_QSslCertificate::cleanupTestCase()
{
if (!oldCurrentDir.isEmpty()) {
QDir::setCurrent(oldCurrentDir);
}
}
#ifndef QT_NO_SSL #ifndef QT_NO_SSL
void tst_QSslCertificate::hash() void tst_QSslCertificate::hash()
@ -232,7 +210,7 @@ void tst_QSslCertificate::constructor_device()
if (!QSslSocket::supportsSsl()) if (!QSslSocket::supportsSsl())
return; return;
QFile f(testDataDir + "/verify-certs/test-ocsp-good-cert.pem"); QFile f(":/verify-certs/test-ocsp-good-cert.pem");
bool ok = f.open(QIODevice::ReadOnly); bool ok = f.open(QIODevice::ReadOnly);
QVERIFY(ok); QVERIFY(ok);
@ -241,7 +219,7 @@ void tst_QSslCertificate::constructor_device()
f.close(); f.close();
// Check opening a DER as a PEM fails // Check opening a DER as a PEM fails
QFile f2(testDataDir + "/certificates/cert.der"); QFile f2(":/certificates/cert.der");
ok = f2.open(QIODevice::ReadOnly); ok = f2.open(QIODevice::ReadOnly);
QVERIFY(ok); QVERIFY(ok);
@ -250,7 +228,7 @@ void tst_QSslCertificate::constructor_device()
f2.close(); f2.close();
// Check opening a DER as a DER works // Check opening a DER as a DER works
QFile f3(testDataDir + "/certificates/cert.der"); QFile f3(":/certificates/cert.der");
ok = f3.open(QIODevice::ReadOnly); ok = f3.open(QIODevice::ReadOnly);
QVERIFY(ok); QVERIFY(ok);
@ -259,7 +237,7 @@ void tst_QSslCertificate::constructor_device()
f3.close(); f3.close();
// Check opening a PEM as a DER fails // Check opening a PEM as a DER fails
QFile f4(testDataDir + "/verify-certs/test-ocsp-good-cert.pem"); QFile f4(":/verify-certs/test-ocsp-good-cert.pem");
ok = f4.open(QIODevice::ReadOnly); ok = f4.open(QIODevice::ReadOnly);
QVERIFY(ok); QVERIFY(ok);
@ -445,7 +423,7 @@ void tst_QSslCertificate::subjectAlternativeNames()
void tst_QSslCertificate::utf8SubjectNames() void tst_QSslCertificate::utf8SubjectNames()
{ {
QSslCertificate cert = QSslCertificate::fromPath("certificates/cert-ss-san-utf8.pem", QSsl::Pem, QSslCertificate cert = QSslCertificate::fromPath(":/certificates/cert-ss-san-utf8.pem", QSsl::Pem,
QRegExp::FixedString).first(); QRegExp::FixedString).first();
QVERIFY(!cert.isNull()); QVERIFY(!cert.isNull());
@ -568,60 +546,60 @@ void tst_QSslCertificate::fromPath_data()
QTest::newRow("empty regexp der") << QString() << int(QRegExp::RegExp) << false << 0; QTest::newRow("empty regexp der") << QString() << int(QRegExp::RegExp) << false << 0;
QTest::newRow("empty wildcard pem") << QString() << int(QRegExp::Wildcard) << true << 0; QTest::newRow("empty wildcard pem") << QString() << int(QRegExp::Wildcard) << true << 0;
QTest::newRow("empty wildcard der") << QString() << int(QRegExp::Wildcard) << false << 0; QTest::newRow("empty wildcard der") << QString() << int(QRegExp::Wildcard) << false << 0;
QTest::newRow("\"certificates\" fixed pem") << QString("certificates") << int(QRegExp::FixedString) << true << 0; QTest::newRow("\"certificates\" fixed pem") << QString(":/certificates") << int(QRegExp::FixedString) << true << 0;
QTest::newRow("\"certificates\" fixed der") << QString("certificates") << int(QRegExp::FixedString) << false << 0; QTest::newRow("\"certificates\" fixed der") << QString(":/certificates") << int(QRegExp::FixedString) << false << 0;
QTest::newRow("\"certificates\" regexp pem") << QString("certificates") << int(QRegExp::RegExp) << true << 0; QTest::newRow("\"certificates\" regexp pem") << QString(":/certificates") << int(QRegExp::RegExp) << true << 0;
QTest::newRow("\"certificates\" regexp der") << QString("certificates") << int(QRegExp::RegExp) << false << 0; QTest::newRow("\"certificates\" regexp der") << QString(":/certificates") << int(QRegExp::RegExp) << false << 0;
QTest::newRow("\"certificates\" wildcard pem") << QString("certificates") << int(QRegExp::Wildcard) << true << 0; QTest::newRow("\"certificates\" wildcard pem") << QString(":/certificates") << int(QRegExp::Wildcard) << true << 0;
QTest::newRow("\"certificates\" wildcard der") << QString("certificates") << int(QRegExp::Wildcard) << false << 0; QTest::newRow("\"certificates\" wildcard der") << QString(":/certificates") << int(QRegExp::Wildcard) << false << 0;
QTest::newRow("\"certificates/cert.pem\" fixed pem") << QString("certificates/cert.pem") << int(QRegExp::FixedString) << true << 1; QTest::newRow("\"certificates/cert.pem\" fixed pem") << QString(":/certificates/cert.pem") << int(QRegExp::FixedString) << true << 1;
QTest::newRow("\"certificates/cert.pem\" fixed der") << QString("certificates/cert.pem") << int(QRegExp::FixedString) << false << 0; QTest::newRow("\"certificates/cert.pem\" fixed der") << QString(":/certificates/cert.pem") << int(QRegExp::FixedString) << false << 0;
QTest::newRow("\"certificates/cert.pem\" regexp pem") << QString("certificates/cert.pem") << int(QRegExp::RegExp) << true << 1; QTest::newRow("\"certificates/cert.pem\" regexp pem") << QString(":/certificates/cert.pem") << int(QRegExp::RegExp) << true << 1;
QTest::newRow("\"certificates/cert.pem\" regexp der") << QString("certificates/cert.pem") << int(QRegExp::RegExp) << false << 0; QTest::newRow("\"certificates/cert.pem\" regexp der") << QString(":/certificates/cert.pem") << int(QRegExp::RegExp) << false << 0;
QTest::newRow("\"certificates/cert.pem\" wildcard pem") << QString("certificates/cert.pem") << int(QRegExp::Wildcard) << true << 1; QTest::newRow("\"certificates/cert.pem\" wildcard pem") << QString(":/certificates/cert.pem") << int(QRegExp::Wildcard) << true << 1;
QTest::newRow("\"certificates/cert.pem\" wildcard der") << QString("certificates/cert.pem") << int(QRegExp::Wildcard) << false << 0; QTest::newRow("\"certificates/cert.pem\" wildcard der") << QString(":/certificates/cert.pem") << int(QRegExp::Wildcard) << false << 0;
QTest::newRow("\"certificates/*\" fixed pem") << QString("certificates/*") << int(QRegExp::FixedString) << true << 0; QTest::newRow("\"certificates/*\" fixed pem") << QString(":/certificates/*") << int(QRegExp::FixedString) << true << 0;
QTest::newRow("\"certificates/*\" fixed der") << QString("certificates/*") << int(QRegExp::FixedString) << false << 0; QTest::newRow("\"certificates/*\" fixed der") << QString(":/certificates/*") << int(QRegExp::FixedString) << false << 0;
QTest::newRow("\"certificates/*\" regexp pem") << QString("certificates/*") << int(QRegExp::RegExp) << true << 0; QTest::newRow("\"certificates/*\" regexp pem") << QString(":/certificates/*") << int(QRegExp::RegExp) << true << 0;
QTest::newRow("\"certificates/*\" regexp der") << QString("certificates/*") << int(QRegExp::RegExp) << false << 0; QTest::newRow("\"certificates/*\" regexp der") << QString(":/certificates/*") << int(QRegExp::RegExp) << false << 0;
QTest::newRow("\"certificates/*\" wildcard pem") << QString("certificates/*") << int(QRegExp::Wildcard) << true << 7; QTest::newRow("\"certificates/*\" wildcard pem") << QString(":/certificates/*") << int(QRegExp::Wildcard) << true << 7;
QTest::newRow("\"certificates/ca*\" wildcard pem") << QString("certificates/ca*") << int(QRegExp::Wildcard) << true << 1; QTest::newRow("\"certificates/ca*\" wildcard pem") << QString(":/certificates/ca*") << int(QRegExp::Wildcard) << true << 1;
QTest::newRow("\"certificates/cert*\" wildcard pem") << QString("certificates/cert*") << int(QRegExp::Wildcard) << true << 4; QTest::newRow("\"certificates/cert*\" wildcard pem") << QString(":/certificates/cert*") << int(QRegExp::Wildcard) << true << 4;
QTest::newRow("\"certificates/cert-[sure]*\" wildcard pem") << QString("certificates/cert-[sure]*") << int(QRegExp::Wildcard) << true << 3; QTest::newRow("\"certificates/cert-[sure]*\" wildcard pem") << QString(":/certificates/cert-[sure]*") << int(QRegExp::Wildcard) << true << 3;
QTest::newRow("\"certificates/cert-[not]*\" wildcard pem") << QString("certificates/cert-[not]*") << int(QRegExp::Wildcard) << true << 0; QTest::newRow("\"certificates/cert-[not]*\" wildcard pem") << QString(":/certificates/cert-[not]*") << int(QRegExp::Wildcard) << true << 0;
QTest::newRow("\"certificates/*\" wildcard der") << QString("certificates/*") << int(QRegExp::Wildcard) << false << 2; QTest::newRow("\"certificates/*\" wildcard der") << QString(":/certificates/*") << int(QRegExp::Wildcard) << false << 2;
QTest::newRow("\"c*/c*.pem\" fixed pem") << QString("c*/c*.pem") << int(QRegExp::FixedString) << true << 0; QTest::newRow("\"c*/c*.pem\" fixed pem") << QString(":/c*/c*.pem") << int(QRegExp::FixedString) << true << 0;
QTest::newRow("\"c*/c*.pem\" fixed der") << QString("c*/c*.pem") << int(QRegExp::FixedString) << false << 0; QTest::newRow("\"c*/c*.pem\" fixed der") << QString(":/c*/c*.pem") << int(QRegExp::FixedString) << false << 0;
QTest::newRow("\"c*/c*.pem\" regexp pem") << QString("c*/c*.pem") << int(QRegExp::RegExp) << true << 0; QTest::newRow("\"c*/c*.pem\" regexp pem") << QString(":/c*/c*.pem") << int(QRegExp::RegExp) << true << 0;
QTest::newRow("\"c*/c*.pem\" regexp der") << QString("c*/c*.pem") << int(QRegExp::RegExp) << false << 0; QTest::newRow("\"c*/c*.pem\" regexp der") << QString(":/c*/c*.pem") << int(QRegExp::RegExp) << false << 0;
QTest::newRow("\"c*/c*.pem\" wildcard pem") << QString("c*/c*.pem") << int(QRegExp::Wildcard) << true << 5; QTest::newRow("\"c*/c*.pem\" wildcard pem") << QString(":/c*/c*.pem") << int(QRegExp::Wildcard) << true << 5;
QTest::newRow("\"c*/c*.pem\" wildcard der") << QString("c*/c*.pem") << int(QRegExp::Wildcard) << false << 0; QTest::newRow("\"c*/c*.pem\" wildcard der") << QString(":/c*/c*.pem") << int(QRegExp::Wildcard) << false << 0;
QTest::newRow("\"d*/c*.pem\" fixed pem") << QString("d*/c*.pem") << int(QRegExp::FixedString) << true << 0; QTest::newRow("\"d*/c*.pem\" fixed pem") << QString(":/d*/c*.pem") << int(QRegExp::FixedString) << true << 0;
QTest::newRow("\"d*/c*.pem\" fixed der") << QString("d*/c*.pem") << int(QRegExp::FixedString) << false << 0; QTest::newRow("\"d*/c*.pem\" fixed der") << QString(":/d*/c*.pem") << int(QRegExp::FixedString) << false << 0;
QTest::newRow("\"d*/c*.pem\" regexp pem") << QString("d*/c*.pem") << int(QRegExp::RegExp) << true << 0; QTest::newRow("\"d*/c*.pem\" regexp pem") << QString(":/d*/c*.pem") << int(QRegExp::RegExp) << true << 0;
QTest::newRow("\"d*/c*.pem\" regexp der") << QString("d*/c*.pem") << int(QRegExp::RegExp) << false << 0; QTest::newRow("\"d*/c*.pem\" regexp der") << QString(":/d*/c*.pem") << int(QRegExp::RegExp) << false << 0;
QTest::newRow("\"d*/c*.pem\" wildcard pem") << QString("d*/c*.pem") << int(QRegExp::Wildcard) << true << 0; QTest::newRow("\"d*/c*.pem\" wildcard pem") << QString(":/d*/c*.pem") << int(QRegExp::Wildcard) << true << 0;
QTest::newRow("\"d*/c*.pem\" wildcard der") << QString("d*/c*.pem") << int(QRegExp::Wildcard) << false << 0; QTest::newRow("\"d*/c*.pem\" wildcard der") << QString(":/d*/c*.pem") << int(QRegExp::Wildcard) << false << 0;
QTest::newRow("\"c.*/c.*.pem\" fixed pem") << QString("c.*/c.*.pem") << int(QRegExp::FixedString) << true << 0; QTest::newRow("\"c.*/c.*.pem\" fixed pem") << QString(":/c.*/c.*.pem") << int(QRegExp::FixedString) << true << 0;
QTest::newRow("\"c.*/c.*.pem\" fixed der") << QString("c.*/c.*.pem") << int(QRegExp::FixedString) << false << 0; QTest::newRow("\"c.*/c.*.pem\" fixed der") << QString(":/c.*/c.*.pem") << int(QRegExp::FixedString) << false << 0;
QTest::newRow("\"c.*/c.*.pem\" regexp pem") << QString("c.*/c.*.pem") << int(QRegExp::RegExp) << true << 5; QTest::newRow("\"c.*/c.*.pem\" regexp pem") << QString(":/c.*/c.*.pem") << int(QRegExp::RegExp) << true << 5;
QTest::newRow("\"c.*/c.*.pem\" regexp der") << QString("c.*/c.*.pem") << int(QRegExp::RegExp) << false << 0; QTest::newRow("\"c.*/c.*.pem\" regexp der") << QString(":/c.*/c.*.pem") << int(QRegExp::RegExp) << false << 0;
QTest::newRow("\"c.*/c.*.pem\" wildcard pem") << QString("c.*/c.*.pem") << int(QRegExp::Wildcard) << true << 0; QTest::newRow("\"c.*/c.*.pem\" wildcard pem") << QString(":/c.*/c.*.pem") << int(QRegExp::Wildcard) << true << 0;
QTest::newRow("\"c.*/c.*.pem\" wildcard der") << QString("c.*/c.*.pem") << int(QRegExp::Wildcard) << false << 0; QTest::newRow("\"c.*/c.*.pem\" wildcard der") << QString(":/c.*/c.*.pem") << int(QRegExp::Wildcard) << false << 0;
QTest::newRow("\"d.*/c.*.pem\" fixed pem") << QString("d.*/c.*.pem") << int(QRegExp::FixedString) << true << 0; QTest::newRow("\"d.*/c.*.pem\" fixed pem") << QString(":/d.*/c.*.pem") << int(QRegExp::FixedString) << true << 0;
QTest::newRow("\"d.*/c.*.pem\" fixed der") << QString("d.*/c.*.pem") << int(QRegExp::FixedString) << false << 0; QTest::newRow("\"d.*/c.*.pem\" fixed der") << QString(":/d.*/c.*.pem") << int(QRegExp::FixedString) << false << 0;
QTest::newRow("\"d.*/c.*.pem\" regexp pem") << QString("d.*/c.*.pem") << int(QRegExp::RegExp) << true << 0; QTest::newRow("\"d.*/c.*.pem\" regexp pem") << QString(":/d.*/c.*.pem") << int(QRegExp::RegExp) << true << 0;
QTest::newRow("\"d.*/c.*.pem\" regexp der") << QString("d.*/c.*.pem") << int(QRegExp::RegExp) << false << 0; QTest::newRow("\"d.*/c.*.pem\" regexp der") << QString(":/d.*/c.*.pem") << int(QRegExp::RegExp) << false << 0;
QTest::newRow("\"d.*/c.*.pem\" wildcard pem") << QString("d.*/c.*.pem") << int(QRegExp::Wildcard) << true << 0; QTest::newRow("\"d.*/c.*.pem\" wildcard pem") << QString(":/d.*/c.*.pem") << int(QRegExp::Wildcard) << true << 0;
QTest::newRow("\"d.*/c.*.pem\" wildcard der") << QString("d.*/c.*.pem") << int(QRegExp::Wildcard) << false << 0; QTest::newRow("\"d.*/c.*.pem\" wildcard der") << QString(":/d.*/c.*.pem") << int(QRegExp::Wildcard) << false << 0;
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
QTest::newRow("absolute path wildcard pem") << (testDataDir + "/certificates/*.pem") << int(QRegExp::Wildcard) << true << 7; QTest::newRow("absolute path wildcard pem") << (":/certificates/*.pem") << int(QRegExp::Wildcard) << true << 7;
#endif #endif
QTest::newRow("trailing-whitespace") << QString("more-certificates/trailing-whitespace.pem") << int(QRegExp::FixedString) << true << 1; QTest::newRow("trailing-whitespace") << QString(":/more-certificates/trailing-whitespace.pem") << int(QRegExp::FixedString) << true << 1;
QTest::newRow("no-ending-newline") << QString("more-certificates/no-ending-newline.pem") << int(QRegExp::FixedString) << true << 1; QTest::newRow("no-ending-newline") << QString(":/more-certificates/no-ending-newline.pem") << int(QRegExp::FixedString) << true << 1;
QTest::newRow("malformed-just-begin") << QString("more-certificates/malformed-just-begin.pem") << int(QRegExp::FixedString) << true << 0; QTest::newRow("malformed-just-begin") << QString(":/more-certificates/malformed-just-begin.pem") << int(QRegExp::FixedString) << true << 0;
QTest::newRow("malformed-just-begin-no-newline") << QString("more-certificates/malformed-just-begin-no-newline.pem") << int(QRegExp::FixedString) << true << 0; QTest::newRow("malformed-just-begin-no-newline") << QString(":/more-certificates/malformed-just-begin-no-newline.pem") << int(QRegExp::FixedString) << true << 0;
} }
void tst_QSslCertificate::fromPath() void tst_QSslCertificate::fromPath()
@ -722,7 +700,7 @@ void tst_QSslCertificate::certInfo()
"dc:c2:eb:b7:bb:50:18:05:ba:ad:af:08:49:fe:98:63" "dc:c2:eb:b7:bb:50:18:05:ba:ad:af:08:49:fe:98:63"
"55:ba:e7:fb:95:5d:91"; "55:ba:e7:fb:95:5d:91";
QSslCertificate cert = QSslCertificate::fromPath("certificates/cert.pem", QSsl::Pem, QSslCertificate cert = QSslCertificate::fromPath(":/certificates/cert.pem", QSsl::Pem,
QRegExp::FixedString).first(); QRegExp::FixedString).first();
QVERIFY(!cert.isNull()); QVERIFY(!cert.isNull());
@ -779,7 +757,7 @@ void tst_QSslCertificate::certInfo()
void tst_QSslCertificate::certInfoQByteArray() void tst_QSslCertificate::certInfoQByteArray()
{ {
QSslCertificate cert = QSslCertificate::fromPath("certificates/cert.pem", QSsl::Pem, QSslCertificate cert = QSslCertificate::fromPath(":/certificates/cert.pem", QSsl::Pem,
QRegExp::FixedString).first(); QRegExp::FixedString).first();
QVERIFY(!cert.isNull()); QVERIFY(!cert.isNull());
@ -832,7 +810,7 @@ void tst_QSslCertificate::nulInCN()
QSKIP("Generic QSslCertificatePrivate fails this test"); QSKIP("Generic QSslCertificatePrivate fails this test");
#endif #endif
QList<QSslCertificate> certList = QList<QSslCertificate> certList =
QSslCertificate::fromPath(testDataDir + "/more-certificates/badguy-nul-cn.crt"); QSslCertificate::fromPath(":/more-certificates/badguy-nul-cn.crt");
QCOMPARE(certList.size(), 1); QCOMPARE(certList.size(), 1);
const QSslCertificate &cert = certList.at(0); const QSslCertificate &cert = certList.at(0);
@ -851,7 +829,7 @@ void tst_QSslCertificate::nulInSan()
QSKIP("Generic QSslCertificatePrivate fails this test"); QSKIP("Generic QSslCertificatePrivate fails this test");
#endif #endif
QList<QSslCertificate> certList = QList<QSslCertificate> certList =
QSslCertificate::fromPath(testDataDir + "/more-certificates/badguy-nul-san.crt"); QSslCertificate::fromPath(":/more-certificates/badguy-nul-san.crt");
QCOMPARE(certList.size(), 1); QCOMPARE(certList.size(), 1);
const QSslCertificate &cert = certList.at(0); const QSslCertificate &cert = certList.at(0);
@ -871,7 +849,7 @@ void tst_QSslCertificate::nulInSan()
void tst_QSslCertificate::largeSerialNumber() void tst_QSslCertificate::largeSerialNumber()
{ {
QList<QSslCertificate> certList = QList<QSslCertificate> certList =
QSslCertificate::fromPath(testDataDir + "/more-certificates/cert-large-serial-number.pem"); QSslCertificate::fromPath(":/more-certificates/cert-large-serial-number.pem");
QCOMPARE(certList.size(), 1); QCOMPARE(certList.size(), 1);
@ -883,7 +861,7 @@ void tst_QSslCertificate::largeSerialNumber()
void tst_QSslCertificate::largeExpirationDate() // QTBUG-12489 void tst_QSslCertificate::largeExpirationDate() // QTBUG-12489
{ {
QList<QSslCertificate> certList = QList<QSslCertificate> certList =
QSslCertificate::fromPath(testDataDir + "/more-certificates/cert-large-expiration-date.pem"); QSslCertificate::fromPath(":/more-certificates/cert-large-expiration-date.pem");
QCOMPARE(certList.size(), 1); QCOMPARE(certList.size(), 1);
@ -896,8 +874,8 @@ void tst_QSslCertificate::largeExpirationDate() // QTBUG-12489
void tst_QSslCertificate::blacklistedCertificates() void tst_QSslCertificate::blacklistedCertificates()
{ {
QList<QSslCertificate> blacklistedCerts = QSslCertificate::fromPath("more-certificates/blacklisted*.pem", QSsl::Pem, QRegExp::Wildcard); QList<QSslCertificate> blacklistedCerts = QSslCertificate::fromPath(":/more-certificates/blacklisted*.pem", QSsl::Pem, QRegExp::Wildcard);
QVERIFY2(blacklistedCerts.count() > 0, "Please run this test from the source directory"); QVERIFY(blacklistedCerts.count() > 0);
for (int a = 0; a < blacklistedCerts.count(); a++) { for (int a = 0; a < blacklistedCerts.count(); a++) {
QVERIFY(blacklistedCerts.at(a).isBlacklisted()); QVERIFY(blacklistedCerts.at(a).isBlacklisted());
} }
@ -905,34 +883,34 @@ void tst_QSslCertificate::blacklistedCertificates()
void tst_QSslCertificate::selfsignedCertificates() void tst_QSslCertificate::selfsignedCertificates()
{ {
QVERIFY(QSslCertificate::fromPath(testDataDir + "/certificates/cert-ss.pem").first().isSelfSigned()); QVERIFY(QSslCertificate::fromPath(":/certificates/cert-ss.pem").first().isSelfSigned());
QVERIFY(!QSslCertificate::fromPath(testDataDir + "/certificates/cert.pem").first().isSelfSigned()); QVERIFY(!QSslCertificate::fromPath(":/certificates/cert.pem").first().isSelfSigned());
QVERIFY(!QSslCertificate().isSelfSigned()); QVERIFY(!QSslCertificate().isSelfSigned());
} }
void tst_QSslCertificate::toText() void tst_QSslCertificate::toText()
{ {
QList<QSslCertificate> certList = QList<QSslCertificate> certList =
QSslCertificate::fromPath(testDataDir + "/more-certificates/cert-large-expiration-date.pem"); QSslCertificate::fromPath(":/more-certificates/cert-large-expiration-date.pem");
QCOMPARE(certList.size(), 1); QCOMPARE(certList.size(), 1);
const QSslCertificate &cert = certList.at(0); const QSslCertificate &cert = certList.at(0);
// Openssl's cert dump method changed slightly between 0.9.8, 1.0.0 and 1.01 versions, so we want it to match any output // Openssl's cert dump method changed slightly between 0.9.8, 1.0.0 and 1.01 versions, so we want it to match any output
QFile f098(testDataDir + "/more-certificates/cert-large-expiration-date.txt.0.9.8"); QFile f098(":/more-certificates/cert-large-expiration-date.txt.0.9.8");
QVERIFY(f098.open(QIODevice::ReadOnly | QFile::Text)); QVERIFY(f098.open(QIODevice::ReadOnly | QFile::Text));
QByteArray txt098 = f098.readAll(); QByteArray txt098 = f098.readAll();
QFile f100(testDataDir + "/more-certificates/cert-large-expiration-date.txt.1.0.0"); QFile f100(":/more-certificates/cert-large-expiration-date.txt.1.0.0");
QVERIFY(f100.open(QIODevice::ReadOnly | QFile::Text)); QVERIFY(f100.open(QIODevice::ReadOnly | QFile::Text));
QByteArray txt100 = f100.readAll(); QByteArray txt100 = f100.readAll();
QFile f101(testDataDir + "/more-certificates/cert-large-expiration-date.txt.1.0.1"); QFile f101(":/more-certificates/cert-large-expiration-date.txt.1.0.1");
QVERIFY(f101.open(QIODevice::ReadOnly | QFile::Text)); QVERIFY(f101.open(QIODevice::ReadOnly | QFile::Text));
QByteArray txt101 = f101.readAll(); QByteArray txt101 = f101.readAll();
QFile f101c(testDataDir + "/more-certificates/cert-large-expiration-date.txt.1.0.1c"); QFile f101c(":/more-certificates/cert-large-expiration-date.txt.1.0.1c");
QVERIFY(f101c.open(QIODevice::ReadOnly | QFile::Text)); QVERIFY(f101c.open(QIODevice::ReadOnly | QFile::Text));
QByteArray txt101c = f101c.readAll(); QByteArray txt101c = f101c.readAll();
@ -950,8 +928,8 @@ void tst_QSslCertificate::toText()
void tst_QSslCertificate::multipleCommonNames() void tst_QSslCertificate::multipleCommonNames()
{ {
QList<QSslCertificate> certList = QList<QSslCertificate> certList =
QSslCertificate::fromPath(testDataDir + "/more-certificates/test-cn-two-cns-cert.pem"); QSslCertificate::fromPath(":/more-certificates/test-cn-two-cns-cert.pem");
QVERIFY2(certList.count() > 0, "Please run this test from the source directory"); QVERIFY(certList.count() > 0);
QStringList commonNames = certList[0].subjectInfo(QSslCertificate::CommonName); QStringList commonNames = certList[0].subjectInfo(QSslCertificate::CommonName);
QVERIFY(commonNames.contains(QString("www.example.com"))); QVERIFY(commonNames.contains(QString("www.example.com")));
@ -961,15 +939,15 @@ void tst_QSslCertificate::multipleCommonNames()
void tst_QSslCertificate::subjectAndIssuerAttributes() void tst_QSslCertificate::subjectAndIssuerAttributes()
{ {
QList<QSslCertificate> certList = QList<QSslCertificate> certList =
QSslCertificate::fromPath(testDataDir + "/more-certificates/test-cn-with-drink-cert.pem"); QSslCertificate::fromPath(":/more-certificates/test-cn-with-drink-cert.pem");
QVERIFY2(certList.count() > 0, "Please run this test from the source directory"); QVERIFY(certList.count() > 0);
QList<QByteArray> attributes = certList[0].subjectInfoAttributes(); QList<QByteArray> attributes = certList[0].subjectInfoAttributes();
QVERIFY(attributes.contains(QByteArray("favouriteDrink"))); QVERIFY(attributes.contains(QByteArray("favouriteDrink")));
attributes.clear(); attributes.clear();
certList = QSslCertificate::fromPath(testDataDir + "/more-certificates/natwest-banking.pem"); certList = QSslCertificate::fromPath(":/more-certificates/natwest-banking.pem");
QVERIFY2(certList.count() > 0, "Please run this test from the source directory"); QVERIFY(certList.count() > 0);
attributes = certList[0].subjectInfoAttributes(); attributes = certList[0].subjectInfoAttributes();
QVERIFY(attributes.contains(QByteArray("1.3.6.1.4.1.311.60.2.1.3"))); QVERIFY(attributes.contains(QByteArray("1.3.6.1.4.1.311.60.2.1.3")));
@ -999,17 +977,17 @@ void tst_QSslCertificate::verify()
errors.clear(); errors.clear();
// Verify a valid cert signed by a CA // Verify a valid cert signed by a CA
QList<QSslCertificate> caCerts = QSslCertificate::fromPath(testDataDir + "/verify-certs/cacert.pem"); QList<QSslCertificate> caCerts = QSslCertificate::fromPath(":/verify-certs/cacert.pem");
QSslSocket::addDefaultCaCertificate(caCerts.first()); QSslSocket::addDefaultCaCertificate(caCerts.first());
toVerify = QSslCertificate::fromPath(testDataDir + "/verify-certs/test-ocsp-good-cert.pem"); toVerify = QSslCertificate::fromPath(":/verify-certs/test-ocsp-good-cert.pem");
errors = QSslCertificate::verify(toVerify); errors = QSslCertificate::verify(toVerify);
VERIFY_VERBOSE(errors.count() == 0); VERIFY_VERBOSE(errors.count() == 0);
errors.clear(); errors.clear();
// Test a blacklisted certificate // Test a blacklisted certificate
toVerify = QSslCertificate::fromPath(testDataDir + "/verify-certs/test-addons-mozilla-org-cert.pem"); toVerify = QSslCertificate::fromPath(":/verify-certs/test-addons-mozilla-org-cert.pem");
errors = QSslCertificate::verify(toVerify); errors = QSslCertificate::verify(toVerify);
bool foundBlack = false; bool foundBlack = false;
foreach (const QSslError &error, errors) { foreach (const QSslError &error, errors) {
@ -1022,7 +1000,7 @@ void tst_QSslCertificate::verify()
errors.clear(); errors.clear();
// This one is expired and untrusted // This one is expired and untrusted
toVerify = QSslCertificate::fromPath(testDataDir + "/more-certificates/cert-large-serial-number.pem"); toVerify = QSslCertificate::fromPath(":/more-certificates/cert-large-serial-number.pem");
errors = QSslCertificate::verify(toVerify); errors = QSslCertificate::verify(toVerify);
VERIFY_VERBOSE(errors.contains(QSslError(QSslError::SelfSignedCertificate, toVerify[0]))); VERIFY_VERBOSE(errors.contains(QSslError(QSslError::SelfSignedCertificate, toVerify[0])));
VERIFY_VERBOSE(errors.contains(QSslError(QSslError::CertificateExpired, toVerify[0]))); VERIFY_VERBOSE(errors.contains(QSslError(QSslError::CertificateExpired, toVerify[0])));
@ -1030,15 +1008,15 @@ void tst_QSslCertificate::verify()
toVerify.clear(); toVerify.clear();
// This one is signed by a valid cert, but the signer is not a valid CA // This one is signed by a valid cert, but the signer is not a valid CA
toVerify << QSslCertificate::fromPath(testDataDir + "/verify-certs/test-intermediate-not-ca-cert.pem").first(); toVerify << QSslCertificate::fromPath(":/verify-certs/test-intermediate-not-ca-cert.pem").first();
toVerify << QSslCertificate::fromPath(testDataDir + "/verify-certs/test-ocsp-good-cert.pem").first(); toVerify << QSslCertificate::fromPath(":/verify-certs/test-ocsp-good-cert.pem").first();
errors = QSslCertificate::verify(toVerify); errors = QSslCertificate::verify(toVerify);
VERIFY_VERBOSE(errors.contains(QSslError(QSslError::InvalidCaCertificate, toVerify[1]))); VERIFY_VERBOSE(errors.contains(QSslError(QSslError::InvalidCaCertificate, toVerify[1])));
toVerify.clear(); toVerify.clear();
// This one is signed by a valid cert, and the signer is a valid CA // This one is signed by a valid cert, and the signer is a valid CA
toVerify << QSslCertificate::fromPath(testDataDir + "/verify-certs/test-intermediate-is-ca-cert.pem").first(); toVerify << QSslCertificate::fromPath(":/verify-certs/test-intermediate-is-ca-cert.pem").first();
toVerify << QSslCertificate::fromPath(testDataDir + "/verify-certs/test-intermediate-ca-cert.pem").first(); toVerify << QSslCertificate::fromPath(":/verify-certs/test-intermediate-ca-cert.pem").first();
errors = QSslCertificate::verify(toVerify); errors = QSslCertificate::verify(toVerify);
VERIFY_VERBOSE(errors.count() == 0); VERIFY_VERBOSE(errors.count() == 0);
@ -1068,8 +1046,8 @@ QString tst_QSslCertificate::toString(const QList<QSslError>& errors)
void tst_QSslCertificate::extensions() void tst_QSslCertificate::extensions()
{ {
QList<QSslCertificate> certList = QList<QSslCertificate> certList =
QSslCertificate::fromPath(testDataDir + "/more-certificates/natwest-banking.pem"); QSslCertificate::fromPath(":/more-certificates/natwest-banking.pem");
QVERIFY2(certList.count() > 0, "Please run this test from the source directory"); QVERIFY(certList.count() > 0);
QSslCertificate cert = certList[0]; QSslCertificate cert = certList[0];
QList<QSslCertificateExtension> extensions = cert.extensions(); QList<QSslCertificateExtension> extensions = cert.extensions();
@ -1166,8 +1144,8 @@ void tst_QSslCertificate::extensions()
void tst_QSslCertificate::extensionsCritical() void tst_QSslCertificate::extensionsCritical()
{ {
QList<QSslCertificate> certList = QList<QSslCertificate> certList =
QSslCertificate::fromPath(testDataDir + "/verify-certs/test-addons-mozilla-org-cert.pem"); QSslCertificate::fromPath(":/verify-certs/test-addons-mozilla-org-cert.pem");
QVERIFY2(certList.count() > 0, "Please run this test from the source directory"); QVERIFY(certList.count() > 0);
QSslCertificate cert = certList[0]; QSslCertificate cert = certList[0];
QList<QSslCertificateExtension> extensions = cert.extensions(); QList<QSslCertificateExtension> extensions = cert.extensions();
@ -1249,7 +1227,7 @@ void tst_QSslCertificate::threadSafeConstMethods()
if (!QSslSocket::supportsSsl()) if (!QSslSocket::supportsSsl())
return; return;
QByteArray encoded = readFile(testDataDir + "/certificates/cert.pem"); QByteArray encoded = readFile(":/certificates/cert.pem");
QSslCertificate certificate(encoded); QSslCertificate certificate(encoded);
QVERIFY(!certificate.isNull()); QVERIFY(!certificate.isNull());
@ -1287,12 +1265,12 @@ void tst_QSslCertificate::version_data()
QTest::newRow("null certificate") << QSslCertificate() << QByteArray(); QTest::newRow("null certificate") << QSslCertificate() << QByteArray();
QList<QSslCertificate> certs; QList<QSslCertificate> certs;
certs << QSslCertificate::fromPath(testDataDir + "/verify-certs/test-ocsp-good-cert.pem"); certs << QSslCertificate::fromPath(":/verify-certs/test-ocsp-good-cert.pem");
QTest::newRow("v3 certificate") << certs.first() << QByteArrayLiteral("3"); QTest::newRow("v3 certificate") << certs.first() << QByteArrayLiteral("3");
certs.clear(); certs.clear();
certs << QSslCertificate::fromPath(testDataDir + "/certificates/cert.pem"); certs << QSslCertificate::fromPath(":/certificates/cert.pem");
QTest::newRow("v1 certificate") << certs.first() << QByteArrayLiteral("1"); QTest::newRow("v1 certificate") << certs.first() << QByteArrayLiteral("1");
} }
@ -1314,7 +1292,7 @@ void tst_QSslCertificate::pkcs12()
return; return;
} }
QFile f(testDataDir + QLatin1String("/pkcs12/leaf.p12")); QFile f(QLatin1String(":/pkcs12/leaf.p12"));
bool ok = f.open(QIODevice::ReadOnly); bool ok = f.open(QIODevice::ReadOnly);
QVERIFY(ok); QVERIFY(ok);
@ -1329,12 +1307,12 @@ void tst_QSslCertificate::pkcs12()
QVERIFY(ok); QVERIFY(ok);
f.close(); f.close();
QList<QSslCertificate> leafCert = QSslCertificate::fromPath(testDataDir + QLatin1String("/pkcs12/leaf.crt")); QList<QSslCertificate> leafCert = QSslCertificate::fromPath(QLatin1String(":/pkcs12/leaf.crt"));
QVERIFY(!leafCert.isEmpty()); QVERIFY(!leafCert.isEmpty());
QCOMPARE(cert, leafCert.first()); QCOMPARE(cert, leafCert.first());
QFile f2(testDataDir + QLatin1String("/pkcs12/leaf.key")); QFile f2(QLatin1String(":/pkcs12/leaf.key"));
ok = f2.open(QIODevice::ReadOnly); ok = f2.open(QIODevice::ReadOnly);
QVERIFY(ok); QVERIFY(ok);
@ -1344,7 +1322,7 @@ void tst_QSslCertificate::pkcs12()
QVERIFY(!leafKey.isNull()); QVERIFY(!leafKey.isNull());
QCOMPARE(key, leafKey); QCOMPARE(key, leafKey);
QList<QSslCertificate> caCert = QSslCertificate::fromPath(testDataDir + QLatin1String("/pkcs12/inter.crt")); QList<QSslCertificate> caCert = QSslCertificate::fromPath(QLatin1String(":/pkcs12/inter.crt"));
QVERIFY(!caCert.isEmpty()); QVERIFY(!caCert.isEmpty());
QVERIFY(!caCerts.isEmpty()); QVERIFY(!caCerts.isEmpty());
@ -1352,7 +1330,7 @@ void tst_QSslCertificate::pkcs12()
QCOMPARE(caCerts, caCert); QCOMPARE(caCerts, caCert);
// QTBUG-62335 - Fail (found no private key) but don't crash: // QTBUG-62335 - Fail (found no private key) but don't crash:
QFile nocert(testDataDir + QLatin1String("/pkcs12/leaf-nokey.p12")); QFile nocert(QLatin1String(":/pkcs12/leaf-nokey.p12"));
ok = nocert.open(QIODevice::ReadOnly); ok = nocert.open(QIODevice::ReadOnly);
QVERIFY(ok); QVERIFY(ok);
QTest::ignoreMessage(QtWarningMsg, "Unable to convert private key"); QTest::ignoreMessage(QtWarningMsg, "Unable to convert private key");

View File

@ -9,4 +9,7 @@ qtConfig(private_tests) {
TARGET = tst_qsslkey TARGET = tst_qsslkey
RESOURCES += \
qsslkey.qrc
TESTDATA += keys/* rsa-without-passphrase.pem rsa-with-passphrase.pem TESTDATA += keys/* rsa-without-passphrase.pem rsa-with-passphrase.pem

View File

@ -0,0 +1,65 @@
<RCC>
<qresource prefix="/">
<file>rsa-without-passphrase.pem</file>
<file>rsa-with-passphrase-3des.pem</file>
<file>rsa-with-passphrase-des.pem</file>
<file>rsa-with-passphrase-rc2.pem</file>
<file>keys/dsa-pri-1024.der</file>
<file>keys/dsa-pri-1024.pem</file>
<file>keys/dsa-pri-512.der</file>
<file>keys/dsa-pri-512.pem</file>
<file>keys/dsa-pri-576.der</file>
<file>keys/dsa-pri-576.pem</file>
<file>keys/dsa-pri-960.der</file>
<file>keys/dsa-pri-960.pem</file>
<file>keys/dsa-pub-1024.der</file>
<file>keys/dsa-pub-1024.pem</file>
<file>keys/dsa-pub-512.der</file>
<file>keys/dsa-pub-512.pem</file>
<file>keys/dsa-pub-576.der</file>
<file>keys/dsa-pub-576.pem</file>
<file>keys/dsa-pub-960.der</file>
<file>keys/dsa-pub-960.pem</file>
<file>keys/ec-pri-224-secp224r1.der</file>
<file>keys/ec-pri-224-secp224r1.pem</file>
<file>keys/ec-pri-256-prime256v1.der</file>
<file>keys/ec-pri-256-prime256v1.pem</file>
<file>keys/ec-pri-384-secp384r1.der</file>
<file>keys/ec-pri-384-secp384r1.pem</file>
<file>keys/ec-pub-224-secp224r1.der</file>
<file>keys/ec-pub-224-secp224r1.pem</file>
<file>keys/ec-pub-256-prime256v1.der</file>
<file>keys/ec-pub-256-prime256v1.pem</file>
<file>keys/ec-pub-384-secp384r1.der</file>
<file>keys/ec-pub-384-secp384r1.pem</file>
<file>keys/genkeys.sh</file>
<file>keys/rsa-pri-1023.der</file>
<file>keys/rsa-pri-1023.pem</file>
<file>keys/rsa-pri-1024.der</file>
<file>keys/rsa-pri-1024.pem</file>
<file>keys/rsa-pri-2048.der</file>
<file>keys/rsa-pri-2048.pem</file>
<file>keys/rsa-pri-40.der</file>
<file>keys/rsa-pri-40.pem</file>
<file>keys/rsa-pri-511.der</file>
<file>keys/rsa-pri-511.pem</file>
<file>keys/rsa-pri-512.der</file>
<file>keys/rsa-pri-512.pem</file>
<file>keys/rsa-pri-999.der</file>
<file>keys/rsa-pri-999.pem</file>
<file>keys/rsa-pub-1023.der</file>
<file>keys/rsa-pub-1023.pem</file>
<file>keys/rsa-pub-1024.der</file>
<file>keys/rsa-pub-1024.pem</file>
<file>keys/rsa-pub-2048.der</file>
<file>keys/rsa-pub-2048.pem</file>
<file>keys/rsa-pub-40.der</file>
<file>keys/rsa-pub-40.pem</file>
<file>keys/rsa-pub-511.der</file>
<file>keys/rsa-pub-511.pem</file>
<file>keys/rsa-pub-512.der</file>
<file>keys/rsa-pub-512.pem</file>
<file>keys/rsa-pub-999.der</file>
<file>keys/rsa-pub-999.pem</file>
</qresource>
</RCC>

View File

@ -97,17 +97,11 @@ private slots:
#endif #endif
#endif #endif
private:
QString testDataDir;
}; };
void tst_QSslKey::initTestCase() void tst_QSslKey::initTestCase()
{ {
testDataDir = QFileInfo(QFINDTESTDATA("rsa-without-passphrase.pem")).absolutePath(); QDir dir(":/keys");
if (testDataDir.isEmpty())
testDataDir = QCoreApplication::applicationDirPath();
QDir dir(testDataDir + "/keys");
QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::Readable); QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::Readable);
QRegExp rx(QLatin1String("^(rsa|dsa|ec)-(pub|pri)-(\\d+)-?\\w*\\.(pem|der)$")); QRegExp rx(QLatin1String("^(rsa|dsa|ec)-(pub|pri)-(\\d+)-?\\w*\\.(pem|der)$"));
foreach (QFileInfo fileInfo, fileInfoList) { foreach (QFileInfo fileInfo, fileInfoList) {
@ -392,9 +386,9 @@ void tst_QSslKey::passphraseChecks_data()
{ {
QTest::addColumn<QString>("fileName"); QTest::addColumn<QString>("fileName");
QTest::newRow("DES") << QString(testDataDir + "/rsa-with-passphrase-des.pem"); QTest::newRow("DES") << QString(":/rsa-with-passphrase-des.pem");
QTest::newRow("3DES") << QString(testDataDir + "/rsa-with-passphrase-3des.pem"); QTest::newRow("3DES") << QString(":/rsa-with-passphrase-3des.pem");
QTest::newRow("RC2") << QString(testDataDir + "/rsa-with-passphrase-rc2.pem"); QTest::newRow("RC2") << QString(":/rsa-with-passphrase-rc2.pem");
} }
void tst_QSslKey::passphraseChecks() void tst_QSslKey::passphraseChecks()
@ -440,7 +434,7 @@ void tst_QSslKey::passphraseChecks()
void tst_QSslKey::noPassphraseChecks() void tst_QSslKey::noPassphraseChecks()
{ {
// be sure and check a key without passphrase too // be sure and check a key without passphrase too
QString fileName(testDataDir + "/rsa-without-passphrase.pem"); QString fileName(":/rsa-without-passphrase.pem");
QFile keyFile(fileName); QFile keyFile(fileName);
{ {
if (!keyFile.isOpen()) if (!keyFile.isOpen())

View File

@ -14,6 +14,9 @@ win32 {
} }
} }
RESOURCES += \
qsslsocket.qrc
DEFINES += SRCDIR=\\\"$$PWD/\\\" DEFINES += SRCDIR=\\\"$$PWD/\\\"
requires(qtConfig(private_tests)) requires(qtConfig(private_tests))

View File

@ -0,0 +1,21 @@
<RCC>
<qresource prefix="/">
<file>certs/aspiriniks.ca.crt</file>
<file>certs/bogus-ca.crt</file>
<file>certs/bogus-ca.key</file>
<file>certs/bogus-client.crt</file>
<file>certs/bogus-client.key</file>
<file>certs/bogus-server.crt</file>
<file>certs/bogus-server.key</file>
<file>certs/ca.crt</file>
<file>certs/fake-login.live.com.key</file>
<file>certs/fake-login.live.com.pem</file>
<file>certs/fluke.cert</file>
<file>certs/fluke.key</file>
<file>certs/inter.crt</file>
<file>certs/leaf.crt</file>
<file>certs/leaf.key</file>
<file>certs/qt-test-server-cacert.pem</file>
<file>certs/xn--schufele-2za.crt</file>
</qresource>
</RCC>

View File

@ -705,7 +705,7 @@ void tst_QSslSocket::connectToHostEncrypted()
QSslSocketPtr socket = newSocket(); QSslSocketPtr socket = newSocket();
this->socket = socket.data(); this->socket = socket.data();
QVERIFY(socket->addCaCertificates(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem"))); QVERIFY(socket->addCaCertificates(QLatin1String(":/certs/qt-test-server-cacert.pem")));
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND #ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND
connect(socket.data(), SIGNAL(sslErrors(QList<QSslError>)), connect(socket.data(), SIGNAL(sslErrors(QList<QSslError>)),
this, SLOT(untrustedWorkaroundSlot(QList<QSslError>))); this, SLOT(untrustedWorkaroundSlot(QList<QSslError>)));
@ -739,7 +739,7 @@ void tst_QSslSocket::connectToHostEncryptedWithVerificationPeerName()
QSslSocketPtr socket = newSocket(); QSslSocketPtr socket = newSocket();
this->socket = socket.data(); this->socket = socket.data();
socket->addCaCertificates(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem")); socket->addCaCertificates(QLatin1String(":/certs/qt-test-server-cacert.pem"));
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND #ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND
connect(socket.data(), SIGNAL(sslErrors(QList<QSslError>)), connect(socket.data(), SIGNAL(sslErrors(QList<QSslError>)),
this, SLOT(untrustedWorkaroundSlot(QList<QSslError>))); this, SLOT(untrustedWorkaroundSlot(QList<QSslError>)));
@ -803,10 +803,10 @@ void tst_QSslSocket::localCertificate()
// values. This test should just run the codepath inside qsslsocket_openssl.cpp // values. This test should just run the codepath inside qsslsocket_openssl.cpp
QSslSocketPtr socket = newSocket(); QSslSocketPtr socket = newSocket();
QList<QSslCertificate> localCert = QSslCertificate::fromPath(SRCDIR "certs/qt-test-server-cacert.pem"); QList<QSslCertificate> localCert = QSslCertificate::fromPath(":/certs/qt-test-server-cacert.pem");
socket->setCaCertificates(localCert); socket->setCaCertificates(localCert);
socket->setLocalCertificate(QLatin1String(SRCDIR "certs/fluke.cert")); socket->setLocalCertificate(QLatin1String(":/certs/fluke.cert"));
socket->setPrivateKey(QLatin1String(SRCDIR "certs/fluke.key")); socket->setPrivateKey(QLatin1String(":/certs/fluke.key"));
socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443);
QFETCH_GLOBAL(bool, setProxy); QFETCH_GLOBAL(bool, setProxy);
@ -832,7 +832,7 @@ void tst_QSslSocket::peerCertificateChain()
QSslSocketPtr socket = newSocket(); QSslSocketPtr socket = newSocket();
this->socket = socket.data(); this->socket = socket.data();
QList<QSslCertificate> caCertificates = QSslCertificate::fromPath(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem")); QList<QSslCertificate> caCertificates = QSslCertificate::fromPath(QLatin1String(":/certs/qt-test-server-cacert.pem"));
QCOMPARE(caCertificates.count(), 1); QCOMPARE(caCertificates.count(), 1);
socket->addCaCertificates(caCertificates); socket->addCaCertificates(caCertificates);
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND #ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND
@ -895,7 +895,7 @@ void tst_QSslSocket::privateKeyOpaque()
if (!QSslSocket::supportsSsl()) if (!QSslSocket::supportsSsl())
return; return;
QFile file(SRCDIR "certs/fluke.key"); QFile file(":/certs/fluke.key");
QVERIFY(file.open(QIODevice::ReadOnly)); QVERIFY(file.open(QIODevice::ReadOnly));
QSslKey key(file.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey); QSslKey key(file.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
QVERIFY(!key.isNull()); QVERIFY(!key.isNull());
@ -908,9 +908,9 @@ void tst_QSslSocket::privateKeyOpaque()
// values. This test should just run the codepath inside qsslsocket_openssl.cpp // values. This test should just run the codepath inside qsslsocket_openssl.cpp
QSslSocketPtr socket = newSocket(); QSslSocketPtr socket = newSocket();
QList<QSslCertificate> localCert = QSslCertificate::fromPath(SRCDIR "certs/qt-test-server-cacert.pem"); QList<QSslCertificate> localCert = QSslCertificate::fromPath(":/certs/qt-test-server-cacert.pem");
socket->setCaCertificates(localCert); socket->setCaCertificates(localCert);
socket->setLocalCertificate(QLatin1String(SRCDIR "certs/fluke.cert")); socket->setLocalCertificate(QLatin1String(":/certs/fluke.cert"));
socket->setPrivateKey(QSslKey(reinterpret_cast<Qt::HANDLE>(pkey))); socket->setPrivateKey(QSslKey(reinterpret_cast<Qt::HANDLE>(pkey)));
socket->setPeerVerifyMode(QSslSocket::QueryPeer); socket->setPeerVerifyMode(QSslSocket::QueryPeer);
@ -928,7 +928,7 @@ void tst_QSslSocket::protocol()
QSslSocketPtr socket = newSocket(); QSslSocketPtr socket = newSocket();
this->socket = socket.data(); this->socket = socket.data();
QList<QSslCertificate> certs = QSslCertificate::fromPath(SRCDIR "certs/qt-test-server-cacert.pem"); QList<QSslCertificate> certs = QSslCertificate::fromPath(":/certs/qt-test-server-cacert.pem");
socket->setCaCertificates(certs); socket->setCaCertificates(certs);
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND #ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND
@ -1075,8 +1075,8 @@ class SslServer : public QTcpServer
{ {
Q_OBJECT Q_OBJECT
public: public:
SslServer(const QString &keyFile = SRCDIR "certs/fluke.key", SslServer(const QString &keyFile = ":/certs/fluke.key",
const QString &certFile = SRCDIR "certs/fluke.cert", const QString &certFile = ":/certs/fluke.cert",
const QString &interFile = QString()) const QString &interFile = QString())
: socket(0), : socket(0),
config(QSslConfiguration::defaultConfiguration()), config(QSslConfiguration::defaultConfiguration()),
@ -1422,7 +1422,7 @@ void tst_QSslSocket::setCaCertificates()
QSslSocket socket; QSslSocket socket;
QCOMPARE(socket.caCertificates(), QSslSocket::defaultCaCertificates()); QCOMPARE(socket.caCertificates(), QSslSocket::defaultCaCertificates());
socket.setCaCertificates(QSslCertificate::fromPath(SRCDIR "certs/qt-test-server-cacert.pem")); socket.setCaCertificates(QSslCertificate::fromPath(":/certs/qt-test-server-cacert.pem"));
QCOMPARE(socket.caCertificates().size(), 1); QCOMPARE(socket.caCertificates().size(), 1);
socket.setCaCertificates(socket.defaultCaCertificates()); socket.setCaCertificates(socket.defaultCaCertificates());
QCOMPARE(socket.caCertificates(), QSslSocket::defaultCaCertificates()); QCOMPARE(socket.caCertificates(), QSslSocket::defaultCaCertificates());
@ -1438,7 +1438,7 @@ void tst_QSslSocket::localCertificateChain()
return; return;
QSslSocket socket; QSslSocket socket;
socket.setLocalCertificate(QLatin1String(SRCDIR "certs/fluke.cert")); socket.setLocalCertificate(QLatin1String(":/certs/fluke.cert"));
QSslConfiguration conf = socket.sslConfiguration(); QSslConfiguration conf = socket.sslConfiguration();
QList<QSslCertificate> chain = conf.localCertificateChain(); QList<QSslCertificate> chain = conf.localCertificateChain();
@ -1456,9 +1456,9 @@ void tst_QSslSocket::setLocalCertificateChain()
if (setProxy) if (setProxy)
return; return;
SslServer server(QLatin1String(SRCDIR "certs/leaf.key"), SslServer server(QLatin1String(":/certs/leaf.key"),
QLatin1String(SRCDIR "certs/leaf.crt"), QLatin1String(":/certs/leaf.crt"),
QLatin1String(SRCDIR "certs/inter.crt")); QLatin1String(":/certs/inter.crt"));
QVERIFY(server.listen()); QVERIFY(server.listen());
@ -1524,7 +1524,7 @@ void tst_QSslSocket::setSslConfiguration_data()
QTest::newRow("empty") << QSslConfiguration() << false; QTest::newRow("empty") << QSslConfiguration() << false;
QSslConfiguration conf = QSslConfiguration::defaultConfiguration(); QSslConfiguration conf = QSslConfiguration::defaultConfiguration();
QTest::newRow("default") << conf << false; // does not contain test server cert QTest::newRow("default") << conf << false; // does not contain test server cert
QList<QSslCertificate> testServerCert = QSslCertificate::fromPath(SRCDIR "certs/qt-test-server-cacert.pem"); QList<QSslCertificate> testServerCert = QSslCertificate::fromPath(":/certs/qt-test-server-cacert.pem");
conf.setCaCertificates(testServerCert); conf.setCaCertificates(testServerCert);
QTest::newRow("set-root-cert") << conf << true; QTest::newRow("set-root-cert") << conf << true;
conf.setProtocol(QSsl::SecureProtocols); conf.setProtocol(QSsl::SecureProtocols);
@ -1622,7 +1622,7 @@ void tst_QSslSocket::addDefaultCaCertificate()
// Reset the global CA chain // Reset the global CA chain
QSslSocket::setDefaultCaCertificates(QSslSocket::systemCaCertificates()); QSslSocket::setDefaultCaCertificates(QSslSocket::systemCaCertificates());
QList<QSslCertificate> flukeCerts = QSslCertificate::fromPath(SRCDIR "certs/qt-test-server-cacert.pem"); QList<QSslCertificate> flukeCerts = QSslCertificate::fromPath(":/certs/qt-test-server-cacert.pem");
QCOMPARE(flukeCerts.size(), 1); QCOMPARE(flukeCerts.size(), 1);
QList<QSslCertificate> globalCerts = QSslSocket::defaultCaCertificates(); QList<QSslCertificate> globalCerts = QSslSocket::defaultCaCertificates();
QVERIFY(!globalCerts.contains(flukeCerts.first())); QVERIFY(!globalCerts.contains(flukeCerts.first()));
@ -1734,7 +1734,7 @@ void tst_QSslSocket::isMatchingHostname()
{ {
// with normalization: (the certificate has *.SCHÄUFELE.DE as a CN) // with normalization: (the certificate has *.SCHÄUFELE.DE as a CN)
// openssl req -x509 -nodes -subj "/CN=*.SCHÄUFELE.DE" -newkey rsa:512 -keyout /dev/null -out xn--schufele-2za.crt // openssl req -x509 -nodes -subj "/CN=*.SCHÄUFELE.DE" -newkey rsa:512 -keyout /dev/null -out xn--schufele-2za.crt
QList<QSslCertificate> certs = QSslCertificate::fromPath(SRCDIR "certs/xn--schufele-2za.crt"); QList<QSslCertificate> certs = QSslCertificate::fromPath(":/certs/xn--schufele-2za.crt");
QVERIFY(!certs.isEmpty()); QVERIFY(!certs.isEmpty());
QSslCertificate cert = certs.first(); QSslCertificate cert = certs.first();
@ -1790,7 +1790,7 @@ protected:
socket->ignoreSslErrors(); socket->ignoreSslErrors();
// Only set the certificate // Only set the certificate
QList<QSslCertificate> localCert = QSslCertificate::fromPath(SRCDIR "certs/fluke.cert"); QList<QSslCertificate> localCert = QSslCertificate::fromPath(":/certs/fluke.cert");
QVERIFY(!localCert.isEmpty()); QVERIFY(!localCert.isEmpty());
QVERIFY(!localCert.first().isNull()); QVERIFY(!localCert.first().isNull());
socket->setLocalCertificate(localCert.first()); socket->setLocalCertificate(localCert.first());
@ -2019,13 +2019,13 @@ protected:
socket = new QSslSocket(this); socket = new QSslSocket(this);
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(ignoreErrorSlot())); connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(ignoreErrorSlot()));
QFile file(SRCDIR "certs/fluke.key"); QFile file(":/certs/fluke.key");
QVERIFY(file.open(QIODevice::ReadOnly)); QVERIFY(file.open(QIODevice::ReadOnly));
QSslKey key(file.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey); QSslKey key(file.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
QVERIFY(!key.isNull()); QVERIFY(!key.isNull());
socket->setPrivateKey(key); socket->setPrivateKey(key);
QList<QSslCertificate> localCert = QSslCertificate::fromPath(SRCDIR "certs/fluke.cert"); QList<QSslCertificate> localCert = QSslCertificate::fromPath(":/certs/fluke.cert");
QVERIFY(!localCert.isEmpty()); QVERIFY(!localCert.isEmpty());
QVERIFY(!localCert.first().isNull()); QVERIFY(!localCert.first().isNull());
socket->setLocalCertificate(localCert.first()); socket->setLocalCertificate(localCert.first());
@ -2198,8 +2198,8 @@ protected:
{ {
socket = new QSslSocket(this); socket = new QSslSocket(this);
socket->setPrivateKey(SRCDIR "certs/fluke.key"); socket->setPrivateKey(":/certs/fluke.key");
socket->setLocalCertificate(SRCDIR "certs/fluke.cert"); socket->setLocalCertificate(":/certs/fluke.cert");
socket->setSocketDescriptor(socketDescriptor); socket->setSocketDescriptor(socketDescriptor);
socket->startServerEncryption(); socket->startServerEncryption();
} }
@ -2314,7 +2314,7 @@ void tst_QSslSocket::resetProxy()
// make sure the connection works, and then set a nonsense proxy, and then // make sure the connection works, and then set a nonsense proxy, and then
// make sure it does not work anymore // make sure it does not work anymore
QSslSocket socket; QSslSocket socket;
socket.addCaCertificates(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem")); socket.addCaCertificates(QLatin1String(":/certs/qt-test-server-cacert.pem"));
socket.setProxy(goodProxy); socket.setProxy(goodProxy);
socket.connectToHostEncrypted(QtNetworkSettings::serverName(), 443); socket.connectToHostEncrypted(QtNetworkSettings::serverName(), 443);
QVERIFY2(socket.waitForConnected(10000), qPrintable(socket.errorString())); QVERIFY2(socket.waitForConnected(10000), qPrintable(socket.errorString()));
@ -2333,7 +2333,7 @@ void tst_QSslSocket::resetProxy()
// set the nonsense proxy and make sure the connection does not work, // set the nonsense proxy and make sure the connection does not work,
// and then set the right proxy and make sure it works // and then set the right proxy and make sure it works
QSslSocket socket2; QSslSocket socket2;
socket2.addCaCertificates(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem")); socket2.addCaCertificates(QLatin1String(":/certs/qt-test-server-cacert.pem"));
socket2.setProxy(badProxy); socket2.setProxy(badProxy);
socket2.connectToHostEncrypted(QtNetworkSettings::serverName(), 443); socket2.connectToHostEncrypted(QtNetworkSettings::serverName(), 443);
QVERIFY(! socket2.waitForConnected(10000)); QVERIFY(! socket2.waitForConnected(10000));
@ -2352,7 +2352,7 @@ void tst_QSslSocket::ignoreSslErrorsList_data()
// construct the list of errors that we will get with the SSL handshake and that we will ignore // construct the list of errors that we will get with the SSL handshake and that we will ignore
QList<QSslError> expectedSslErrors; QList<QSslError> expectedSslErrors;
// fromPath gives us a list of certs, but it actually only contains one // fromPath gives us a list of certs, but it actually only contains one
QList<QSslCertificate> certs = QSslCertificate::fromPath(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem")); QList<QSslCertificate> certs = QSslCertificate::fromPath(QLatin1String(":/certs/qt-test-server-cacert.pem"));
QSslError rightError(FLUKE_CERTIFICATE_ERROR, certs.at(0)); QSslError rightError(FLUKE_CERTIFICATE_ERROR, certs.at(0));
QSslError wrongError(FLUKE_CERTIFICATE_ERROR); QSslError wrongError(FLUKE_CERTIFICATE_ERROR);
@ -2525,7 +2525,7 @@ void tst_QSslSocket::blacklistedCertificates()
if (setProxy) if (setProxy)
return; return;
SslServer server(SRCDIR "certs/fake-login.live.com.key", SRCDIR "certs/fake-login.live.com.pem"); SslServer server(":/certs/fake-login.live.com.key", ":/certs/fake-login.live.com.pem");
QSslSocket *receiver = new QSslSocket(this); QSslSocket *receiver = new QSslSocket(this);
connect(receiver, SIGNAL(readyRead()), SLOT(exitLoop())); connect(receiver, SIGNAL(readyRead()), SLOT(exitLoop()));
@ -2637,7 +2637,7 @@ void tst_QSslSocket::resume_data()
QTest::newRow("DoNotIgnoreErrors") << false << QList<QSslError>() << false; QTest::newRow("DoNotIgnoreErrors") << false << QList<QSslError>() << false;
QTest::newRow("ignoreAllErrors") << true << QList<QSslError>() << true; QTest::newRow("ignoreAllErrors") << true << QList<QSslError>() << true;
QList<QSslCertificate> certs = QSslCertificate::fromPath(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem")); QList<QSslCertificate> certs = QSslCertificate::fromPath(QLatin1String(":/certs/qt-test-server-cacert.pem"));
QSslError rightError(FLUKE_CERTIFICATE_ERROR, certs.at(0)); QSslError rightError(FLUKE_CERTIFICATE_ERROR, certs.at(0));
QSslError wrongError(FLUKE_CERTIFICATE_ERROR); QSslError wrongError(FLUKE_CERTIFICATE_ERROR);
errorsList.append(wrongError); errorsList.append(wrongError);
@ -2707,8 +2707,8 @@ class WebSocket : public QSslSocket
Q_OBJECT Q_OBJECT
public: public:
explicit WebSocket(qintptr socketDescriptor, explicit WebSocket(qintptr socketDescriptor,
const QString &keyFile = SRCDIR "certs/fluke.key", const QString &keyFile = ":/certs/fluke.key",
const QString &certFile = SRCDIR "certs/fluke.cert"); const QString &certFile = ":/certs/fluke.cert");
protected slots: protected slots:
void onReadyReadFirstBytes(void); void onReadyReadFirstBytes(void);
@ -2913,13 +2913,13 @@ void tst_QSslSocket::qtbug18498_peek2()
QCOMPARE(a[2], 'S'); QCOMPARE(a[2], 'S');
QCOMPARE(server->readAll(), QByteArray("TLS\r\n")); QCOMPARE(server->readAll(), QByteArray("TLS\r\n"));
QFile file(SRCDIR "certs/fluke.key"); QFile file(":/certs/fluke.key");
QVERIFY(file.open(QIODevice::ReadOnly)); QVERIFY(file.open(QIODevice::ReadOnly));
QSslKey key(file.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey); QSslKey key(file.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
QVERIFY(!key.isNull()); QVERIFY(!key.isNull());
server->setPrivateKey(key); server->setPrivateKey(key);
QList<QSslCertificate> localCert = QSslCertificate::fromPath(SRCDIR "certs/fluke.cert"); QList<QSslCertificate> localCert = QSslCertificate::fromPath(":/certs/fluke.cert");
QVERIFY(!localCert.isEmpty()); QVERIFY(!localCert.isEmpty());
QVERIFY(!localCert.first().isNull()); QVERIFY(!localCert.first().isNull());
server->setLocalCertificate(localCert.first()); server->setLocalCertificate(localCert.first());
@ -3113,10 +3113,10 @@ void tst_QSslSocket::verifyClientCertificate_data()
QTest::newRow("NoCert:VerifyPeer") << QSslSocket::VerifyPeer << noCerts << noKey << false; QTest::newRow("NoCert:VerifyPeer") << QSslSocket::VerifyPeer << noCerts << noKey << false;
// self-signed certificate // self-signed certificate
QList<QSslCertificate> flukeCerts = QSslCertificate::fromPath(SRCDIR "certs/fluke.cert"); QList<QSslCertificate> flukeCerts = QSslCertificate::fromPath(":/certs/fluke.cert");
QCOMPARE(flukeCerts.size(), 1); QCOMPARE(flukeCerts.size(), 1);
QFile flukeFile(SRCDIR "certs/fluke.key"); QFile flukeFile(":/certs/fluke.key");
QVERIFY(flukeFile.open(QIODevice::ReadOnly)); QVERIFY(flukeFile.open(QIODevice::ReadOnly));
QSslKey flukeKey(flukeFile.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey); QSslKey flukeKey(flukeFile.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
QVERIFY(!flukeKey.isNull()); QVERIFY(!flukeKey.isNull());
@ -3127,10 +3127,10 @@ void tst_QSslSocket::verifyClientCertificate_data()
QTest::newRow("SelfSignedCert:VerifyPeer") << QSslSocket::VerifyPeer << flukeCerts << flukeKey << false; QTest::newRow("SelfSignedCert:VerifyPeer") << QSslSocket::VerifyPeer << flukeCerts << flukeKey << false;
// valid certificate, but wrong usage (server certificate) // valid certificate, but wrong usage (server certificate)
QList<QSslCertificate> serverCerts = QSslCertificate::fromPath(SRCDIR "certs/bogus-server.crt"); QList<QSslCertificate> serverCerts = QSslCertificate::fromPath(":/certs/bogus-server.crt");
QCOMPARE(serverCerts.size(), 1); QCOMPARE(serverCerts.size(), 1);
QFile serverFile(SRCDIR "certs/bogus-server.key"); QFile serverFile(":/certs/bogus-server.key");
QVERIFY(serverFile.open(QIODevice::ReadOnly)); QVERIFY(serverFile.open(QIODevice::ReadOnly));
QSslKey serverKey(serverFile.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey); QSslKey serverKey(serverFile.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
QVERIFY(!serverKey.isNull()); QVERIFY(!serverKey.isNull());
@ -3141,10 +3141,10 @@ void tst_QSslSocket::verifyClientCertificate_data()
QTest::newRow("ValidServerCert:VerifyPeer") << QSslSocket::VerifyPeer << serverCerts << serverKey << false; QTest::newRow("ValidServerCert:VerifyPeer") << QSslSocket::VerifyPeer << serverCerts << serverKey << false;
// valid certificate, correct usage (client certificate) // valid certificate, correct usage (client certificate)
QList<QSslCertificate> validCerts = QSslCertificate::fromPath(SRCDIR "certs/bogus-client.crt"); QList<QSslCertificate> validCerts = QSslCertificate::fromPath(":/certs/bogus-client.crt");
QCOMPARE(validCerts.size(), 1); QCOMPARE(validCerts.size(), 1);
QFile validFile(SRCDIR "certs/bogus-client.key"); QFile validFile(":/certs/bogus-client.key");
QVERIFY(validFile.open(QIODevice::ReadOnly)); QVERIFY(validFile.open(QIODevice::ReadOnly));
QSslKey validKey(validFile.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey); QSslKey validKey(validFile.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
QVERIFY(!validKey.isNull()); QVERIFY(!validKey.isNull());
@ -3155,7 +3155,7 @@ void tst_QSslSocket::verifyClientCertificate_data()
QTest::newRow("ValidClientCert:VerifyPeer") << QSslSocket::VerifyPeer << validCerts << validKey << true; QTest::newRow("ValidClientCert:VerifyPeer") << QSslSocket::VerifyPeer << validCerts << validKey << true;
// valid certificate, correct usage (client certificate), with chain // valid certificate, correct usage (client certificate), with chain
validCerts += QSslCertificate::fromPath(SRCDIR "certs/bogus-ca.crt"); validCerts += QSslCertificate::fromPath(":/certs/bogus-ca.crt");
QCOMPARE(validCerts.size(), 2); QCOMPARE(validCerts.size(), 2);
QTest::newRow("ValidClientCert:AutoVerifyPeer") << QSslSocket::AutoVerifyPeer << validCerts << validKey << true; QTest::newRow("ValidClientCert:AutoVerifyPeer") << QSslSocket::AutoVerifyPeer << validCerts << validKey << true;
@ -3185,7 +3185,7 @@ void tst_QSslSocket::verifyClientCertificate()
QFETCH(QSslSocket::PeerVerifyMode, peerVerifyMode); QFETCH(QSslSocket::PeerVerifyMode, peerVerifyMode);
SslServer server; SslServer server;
server.addCaCertificates = QLatin1String(SRCDIR "certs/bogus-ca.crt"); server.addCaCertificates = QLatin1String(":/certs/bogus-ca.crt");
server.ignoreSslErrors = false; server.ignoreSslErrors = false;
server.peerVerifyMode = peerVerifyMode; server.peerVerifyMode = peerVerifyMode;
QVERIFY(server.listen()); QVERIFY(server.listen());