summaryrefslogtreecommitdiffstats
path: root/src/network/ssl/qsslcertificate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/ssl/qsslcertificate.cpp')
-rw-r--r--src/network/ssl/qsslcertificate.cpp73
1 files changed, 40 insertions, 33 deletions
diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp
index 07047bc..3793b1e 100644
--- a/src/network/ssl/qsslcertificate.cpp
+++ b/src/network/ssl/qsslcertificate.cpp
@@ -1,7 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtNetwork module of the Qt Toolkit.
@@ -21,9 +20,10 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
+** package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
@@ -46,7 +46,7 @@
\since 4.3
\reentrant
- \ingroup io
+ \ingroup network
\ingroup ssl
\inmodule QtNetwork
@@ -71,9 +71,10 @@
After loading a certificate, you can find information about the
certificate, its subject, and its issuer, by calling one of the
many accessor functions, including version(), serialNumber(),
- issuerInfo() and subjectInfo(). You can call notValidBefore() and
- notValidAfter() to check when the certificate was issued, and when
- it expires. The publicKey() function returns the certificate
+ issuerInfo() and subjectInfo(). You can call effectiveDate() and
+ expiryDate() to check when the certificate starts being
+ effective and when it expires.
+ The publicKey() function returns the certificate
subject's public key as a QSslKey. You can call issuerInfo() or
subjectInfo() to get detailed information about the certificate
issuer and its subject.
@@ -125,6 +126,9 @@
QT_BEGIN_NAMESPACE
+// forward declaration
+static QMap<QString, QString> _q_mapFromOnelineName(char *name);
+
/*!
Constructs a QSslCertificate by reading \a format encoded data
from \a device and using the first certificate found. You can
@@ -157,7 +161,6 @@ QSslCertificate::QSslCertificate(const QByteArray &data, QSsl::EncodingFormat fo
*/
QSslCertificate::QSslCertificate(const QSslCertificate &other) : d(other.d)
{
- d->ref.ref();
}
/*!
@@ -165,8 +168,6 @@ QSslCertificate::QSslCertificate(const QSslCertificate &other) : d(other.d)
*/
QSslCertificate::~QSslCertificate()
{
- if (!d->ref.deref())
- delete d;
}
/*!
@@ -175,7 +176,7 @@ QSslCertificate::~QSslCertificate()
*/
QSslCertificate &QSslCertificate::operator=(const QSslCertificate &other)
{
- qAtomicAssign(d, other.d);
+ d = other.d;
return *this;
}
@@ -241,11 +242,6 @@ void QSslCertificate::clear()
{
if (isNull())
return;
- if (d->ref == 1)
- delete d;
- else
- d->ref.deref();
-
d = new QSslCertificatePrivate;
}
@@ -254,14 +250,22 @@ void QSslCertificate::clear()
*/
QByteArray QSslCertificate::version() const
{
+ if (d->versionString.isEmpty() && d->x509)
+ d->versionString =
+ QByteArray::number(qlonglong(q_ASN1_INTEGER_get(d->x509->cert_info->version)) + 1);
+
return d->versionString;
}
/*!
- Returns the certificate's serial number string.
+ Returns the certificate's serial number string in decimal format.
*/
QByteArray QSslCertificate::serialNumber() const
{
+ if (d->serialNumberString.isEmpty() && d->x509)
+ d->serialNumberString =
+ QByteArray::number(qlonglong(q_ASN1_INTEGER_get(d->x509->cert_info->serialNumber)));
+
return d->serialNumberString;
}
@@ -300,6 +304,10 @@ static QString _q_SubjectInfoToString(QSslCertificate::SubjectInfo info)
*/
QString QSslCertificate::issuerInfo(SubjectInfo info) const
{
+ 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(_q_SubjectInfoToString(info));
}
@@ -327,6 +335,10 @@ QString QSslCertificate::issuerInfo(const QByteArray &tag) const
*/
QString QSslCertificate::subjectInfo(SubjectInfo info) const
{
+ 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(_q_SubjectInfoToString(info));
}
@@ -383,7 +395,7 @@ QMultiMap<QSsl::AlternateNameEntryType, QString> QSslCertificate::alternateSubje
else if (genName->type == GEN_EMAIL)
result.insert(QSsl::EmailEntry, altName);
}
- q_sk_free((STACK*)altNames);
+ q_sk_pop_free((STACK*)altNames, q_sk_free);
}
return result;
@@ -662,11 +674,6 @@ QSslCertificate QSslCertificatePrivate::QSslCertificate_from_X509(X509 *x509)
if (!x509 || !QSslSocket::supportsSsl())
return certificate;
- certificate.d->issuerInfo =
- _q_mapFromOnelineName(q_X509_NAME_oneline(q_X509_get_issuer_name(x509), 0, 0));
- certificate.d->subjectInfo =
- _q_mapFromOnelineName(q_X509_NAME_oneline(q_X509_get_subject_name(x509), 0, 0));
-
ASN1_TIME *nbef = q_X509_get_notBefore(x509);
ASN1_TIME *naft = q_X509_get_notAfter(x509);
certificate.d->notValidBefore = q_getTimeFromASN1(nbef);
@@ -686,7 +693,7 @@ static bool matchLineFeed(const QByteArray &pem, int *offset)
ch = pem.at(++*offset);
if (ch == '\n') {
- *offset++;
+ *offset += 1;
return true;
}
if (ch == '\r' && pem.size() > (*offset + 1) && pem.at(*offset + 1) == '\n') {
@@ -766,16 +773,16 @@ QDebug operator<<(QDebug debug, const QSslCertificate &certificate)
{
debug << "QSslCertificate("
<< certificate.version()
- << "," << certificate.serialNumber()
- << "," << certificate.digest().toBase64()
- << "," << certificate.issuerInfo(QSslCertificate::Organization)
- << "," << certificate.subjectInfo(QSslCertificate::Organization)
- << "," << certificate.alternateSubjectNames()
+ << ',' << certificate.serialNumber()
+ << ',' << certificate.digest().toBase64()
+ << ',' << certificate.issuerInfo(QSslCertificate::Organization)
+ << ',' << certificate.subjectInfo(QSslCertificate::Organization)
+ << ',' << certificate.alternateSubjectNames()
#ifndef QT_NO_TEXTSTREAM
- << "," << certificate.effectiveDate()
- << "," << certificate.expiryDate()
+ << ',' << certificate.effectiveDate()
+ << ',' << certificate.expiryDate()
#endif
- << ")";
+ << ')';
return debug;
}
QDebug operator<<(QDebug debug, QSslCertificate::SubjectInfo info)