diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2010-01-18 15:01:14 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2010-01-18 15:27:58 (GMT) |
commit | 102f415e39772086e9066f2e9954c0c22725a23e (patch) | |
tree | e5b3a42fb2bebf48a783543ebf8737eeee41a4b8 | |
parent | 74a3dc292d3e48e74836fb953fe793b65e652c54 (diff) | |
download | Qt-102f415e39772086e9066f2e9954c0c22725a23e.zip Qt-102f415e39772086e9066f2e9954c0c22725a23e.tar.gz Qt-102f415e39772086e9066f2e9954c0c22725a23e.tar.bz2 |
Fix QSslCertificate issues
Thank you Matthew Cattell for the fix!
Task-number: QTBUG-6466
Reviewed-by: joao
-rw-r--r-- | src/network/ssl/qsslcertificate.cpp | 14 | ||||
-rw-r--r-- | tests/auto/qsslcertificate/tst_qsslcertificate.cpp | 13 |
2 files changed, 25 insertions, 2 deletions
diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp index dd50c38..8993e72 100644 --- a/src/network/ssl/qsslcertificate.cpp +++ b/src/network/ssl/qsslcertificate.cpp @@ -304,6 +304,7 @@ static QString _q_SubjectInfoToString(QSslCertificate::SubjectInfo info) */ QString QSslCertificate::issuerInfo(SubjectInfo info) const { + // lazy init if (d->issuerInfo.isEmpty() && d->x509) d->issuerInfo = _q_mapFromOnelineName(q_X509_NAME_oneline(q_X509_get_issuer_name(d->x509), 0, 0)); @@ -320,7 +321,11 @@ QString QSslCertificate::issuerInfo(SubjectInfo info) const */ QString QSslCertificate::issuerInfo(const QByteArray &tag) const { - // ### Use a QByteArray for the keys in the map + // lazy init + if (d->issuerInfo.isEmpty() && d->x509) + d->issuerInfo = + _q_mapFromOnelineName(q_X509_NAME_oneline(q_X509_get_issuer_name(d->x509), 0, 0)); + return d->issuerInfo.value(QString::fromLatin1(tag)); } @@ -335,6 +340,7 @@ QString QSslCertificate::issuerInfo(const QByteArray &tag) const */ QString QSslCertificate::subjectInfo(SubjectInfo info) const { + // lazy init if (d->subjectInfo.isEmpty() && d->x509) d->subjectInfo = _q_mapFromOnelineName(q_X509_NAME_oneline(q_X509_get_subject_name(d->x509), 0, 0)); @@ -350,7 +356,11 @@ QString QSslCertificate::subjectInfo(SubjectInfo info) const */ QString QSslCertificate::subjectInfo(const QByteArray &tag) const { - // ### Use a QByteArray for the keys in the map + // lazy init + if (d->subjectInfo.isEmpty() && d->x509) + d->subjectInfo = + _q_mapFromOnelineName(q_X509_NAME_oneline(q_X509_get_subject_name(d->x509), 0, 0)); + return d->subjectInfo.value(QString::fromLatin1(tag)); } diff --git a/tests/auto/qsslcertificate/tst_qsslcertificate.cpp b/tests/auto/qsslcertificate/tst_qsslcertificate.cpp index 892d745..44f8522 100644 --- a/tests/auto/qsslcertificate/tst_qsslcertificate.cpp +++ b/tests/auto/qsslcertificate/tst_qsslcertificate.cpp @@ -105,6 +105,7 @@ private slots: void fromPath_data(); void fromPath(); void certInfo(); + void certInfoQByteArray(); void task256066toPem(); void nulInCN(); void nulInSan(); @@ -697,6 +698,18 @@ void tst_QSslCertificate::certInfo() QCOMPARE(cert, QSslCertificate(QByteArray::fromHex(der), QSsl::Der)); } +void tst_QSslCertificate::certInfoQByteArray() +{ + QSslCertificate cert = QSslCertificate::fromPath("certificates/cert.pem", QSsl::Pem, + QRegExp::FixedString).first(); + QVERIFY(!cert.isNull()); + + // in this test, check the bytearray variants before the enum variants to see if + // we fixed a bug we had with lazy initialization of the values. + QCOMPARE(cert.issuerInfo("CN"), QString("Test CA (1024 bit)")); + QCOMPARE(cert.subjectInfo("CN"), QString("name/with/slashes")); +} + void tst_QSslCertificate::task256066toPem() { // a certificate whose PEM encoding's length is a multiple of 64 |