From 7f374e0d94230c6742b9ef8bf422f7849e0fc013 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Mon, 15 Jun 2009 17:08:34 +0200 Subject: Fix wrong comparator in QSslCertificatePrivate::QByteArray_from_X509 Because less-than instead of less-or-equal-than was used, the last line of a PEM encoding was not built when the raw length was multiple of 64. Task-number: 256066 Reviewed-by: mariusSO --- src/network/ssl/qsslcertificate.cpp | 2 +- tests/auto/qsslcertificate/tst_qsslcertificate.cpp | 38 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp index ccb3f06..21d5a33 100644 --- a/src/network/ssl/qsslcertificate.cpp +++ b/src/network/ssl/qsslcertificate.cpp @@ -610,7 +610,7 @@ QByteArray QSslCertificatePrivate::QByteArray_from_X509(X509 *x509, QSsl::Encodi // Convert to Base64 - wrap at 64 characters. array = array.toBase64(); QByteArray tmp; - for (int i = 0; i < array.size() - 64; i += 64) { + for (int i = 0; i <= array.size() - 64; i += 64) { tmp += QByteArray::fromRawData(array.data() + i, 64); tmp += "\n"; } diff --git a/tests/auto/qsslcertificate/tst_qsslcertificate.cpp b/tests/auto/qsslcertificate/tst_qsslcertificate.cpp index 6f50fc4..46b8686 100644 --- a/tests/auto/qsslcertificate/tst_qsslcertificate.cpp +++ b/tests/auto/qsslcertificate/tst_qsslcertificate.cpp @@ -99,6 +99,7 @@ private slots: void fromPath_data(); void fromPath(); void certInfo(); + void task256066toPem(); // ### add tests for certificate bundles (multiple certificates concatenated into a single // structure); both PEM and DER formatted #endif @@ -689,6 +690,43 @@ void tst_QSslCertificate::certInfo() QCOMPARE(cert, QSslCertificate(QByteArray::fromHex(der), QSsl::Der)); } +void tst_QSslCertificate::task256066toPem() +{ + // a certificate whose PEM encoding's length is a multiple of 64 + const char *mycert = "-----BEGIN CERTIFICATE-----\n" \ + "MIIEGjCCAwKgAwIBAgIESikYSjANBgkqhkiG9w0BAQUFADB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Df+LcvL6AH0QOiW6rMTtB/0w\n" \ + "CQYDVR0TBAIwADANBgkqhkiG9w0BAQUFAAOCAQEABRyRuUm9zt8V27WuNeXtCDmU\n" \ + "MGzA6g4QXNAd2nxFzT3k+kNzzQTOcgRdmjiEPuK49On+GWnBr/5MSBNhbCJVPWr/\n" \ + "yym1UYTBisaqhRt/N/kwZqd0bHeLJk+ZxSePXRyqkp9H8KPWqz7H+O/FxRS4ffxo\n" \ + "Q9Clem+e0bcjNlL5xXiRGycBeZq8cKj+0+A/UuattznQlvHdlCEsSeu1fPOORqFV\n" \ + "fZur4HC31lQD7xVvETLiL83CtOQC78+29XPD6Zlrrc5OF2yibSVParY19b8Zh6yu\n" \ + "p1dNvN8pBgXGrsyxRonwHooV2ghGNmGILkpdvlQfnxeCUg4erfHjDdSY9vmT7w==\n" \ + "-----END CERTIFICATE-----\n"; + + QByteArray pem1(mycert); + QSslCertificate cert1(pem1); + QVERIFY(!cert1.isNull()); + QByteArray pem2(cert1.toPem()); + QSslCertificate cert2(pem2); + QVERIFY(!cert2.isNull()); + QCOMPARE(pem1, pem2); +} + #endif // QT_NO_OPENSSL QTEST_MAIN(tst_QSslCertificate) -- cgit v0.12