Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/network/ssl/qsslcertificate.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtNetwork module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4747
    4848    \reentrant
    49     \ingroup io
     49    \ingroup network
    5050    \ingroup ssl
    5151    \inmodule QtNetwork
     
    7272    certificate, its subject, and its issuer, by calling one of the
    7373    many accessor functions, including version(), serialNumber(),
    74     issuerInfo() and subjectInfo(). You can call notValidBefore() and
    75     notValidAfter() to check when the certificate was issued, and when
    76     it expires. The publicKey() function returns the certificate
     74    issuerInfo() and subjectInfo(). You can call effectiveDate() and
     75    expiryDate() to check when the certificate starts being
     76    effective and when it expires.
     77    The publicKey() function returns the certificate
    7778    subject's public key as a QSslKey. You can call issuerInfo() or
    7879    subjectInfo() to get detailed information about the certificate
     
    126127QT_BEGIN_NAMESPACE
    127128
     129// forward declaration
     130static QMap<QString, QString> _q_mapFromOnelineName(char *name);
     131
    128132/*!
    129133    Constructs a QSslCertificate by reading \a format encoded data
     
    158162QSslCertificate::QSslCertificate(const QSslCertificate &other) : d(other.d)
    159163{
    160     d->ref.ref();
    161164}
    162165
     
    166169QSslCertificate::~QSslCertificate()
    167170{
    168     if (!d->ref.deref())
    169         delete d;
    170171}
    171172
     
    176177QSslCertificate &QSslCertificate::operator=(const QSslCertificate &other)
    177178{
    178     qAtomicAssign(d, other.d);
     179    d = other.d;
    179180    return *this;
    180181}
     
    242243    if (isNull())
    243244        return;
    244     if (d->ref == 1)
    245         delete d;
    246     else
    247         d->ref.deref();
    248 
    249245    d = new QSslCertificatePrivate;
    250246}
     
    255251QByteArray QSslCertificate::version() const
    256252{
     253    if (d->versionString.isEmpty() && d->x509)
     254        d->versionString =
     255            QByteArray::number(qlonglong(q_ASN1_INTEGER_get(d->x509->cert_info->version)) + 1);
     256
    257257    return d->versionString;
    258258}
    259259
    260260/*!
    261     Returns the certificate's serial number string.
     261    Returns the certificate's serial number string in decimal format.
    262262*/
    263263QByteArray QSslCertificate::serialNumber() const
    264264{
     265    if (d->serialNumberString.isEmpty() && d->x509)
     266        d->serialNumberString =
     267            QByteArray::number(qlonglong(q_ASN1_INTEGER_get(d->x509->cert_info->serialNumber)));
     268
    265269    return d->serialNumberString;
    266270}
     
    268272/*!
    269273    Returns a cryptographic digest of this certificate. By default,
    270     and MD5 digest will be generated, but you can also specify a
     274    an MD5 digest will be generated, but you can also specify a
    271275    custom \a algorithm.
    272276*/
     
    301305QString QSslCertificate::issuerInfo(SubjectInfo info) const
    302306{
     307    if (d->issuerInfo.isEmpty() && d->x509)
     308        d->issuerInfo =
     309                _q_mapFromOnelineName(q_X509_NAME_oneline(q_X509_get_issuer_name(d->x509), 0, 0));
     310
    303311    return d->issuerInfo.value(_q_SubjectInfoToString(info));
    304312}
     
    328336QString QSslCertificate::subjectInfo(SubjectInfo info) const
    329337{
     338    if (d->subjectInfo.isEmpty() && d->x509)
     339        d->subjectInfo =
     340                _q_mapFromOnelineName(q_X509_NAME_oneline(q_X509_get_subject_name(d->x509), 0, 0));
     341
    330342    return d->subjectInfo.value(_q_SubjectInfoToString(info));
    331343}
     
    363375        return result;
    364376
    365     STACK *altNames = (STACK *)q_X509_get_ext_d2i(d->x509, NID_subject_alt_name, 0, 0);
     377    STACK_OF(GENERAL_NAME) *altNames = (STACK_OF(GENERAL_NAME)*)q_X509_get_ext_d2i(d->x509, NID_subject_alt_name, 0, 0);
    366378
    367379    if (altNames) {
     
    378390
    379391            const char *altNameStr = reinterpret_cast<const char *>(q_ASN1_STRING_data(genName->d.ia5));
    380             const QString altName = QLatin1String(QByteArray(altNameStr, len));
     392            const QString altName = QString::fromLatin1(altNameStr, len);
    381393            if (genName->type == GEN_DNS)
    382394                result.insert(QSsl::DnsEntry, altName);
     
    384396                result.insert(QSsl::EmailEntry, altName);
    385397        }
    386         q_sk_free(altNames);
     398        q_sk_pop_free((STACK*)altNames, reinterpret_cast<void(*)(void*)>(q_sk_free));
    387399    }
    388400
     
    611623    array = array.toBase64();
    612624    QByteArray tmp;
    613     for (int i = 0; i < array.size() - 64; i += 64) {
     625    for (int i = 0; i <= array.size() - 64; i += 64) {
    614626        tmp += QByteArray::fromRawData(array.data() + i, 64);
    615627        tmp += "\n";
     
    662674    if (!x509 || !QSslSocket::supportsSsl())
    663675        return certificate;
    664 
    665     certificate.d->issuerInfo =
    666         _q_mapFromOnelineName(q_X509_NAME_oneline(q_X509_get_issuer_name(x509), 0, 0));
    667     certificate.d->subjectInfo =
    668         _q_mapFromOnelineName(q_X509_NAME_oneline(q_X509_get_subject_name(x509), 0, 0));
    669676
    670677    ASN1_TIME *nbef = q_X509_get_notBefore(x509);
     
    687694
    688695    if (ch == '\n') {
    689         *offset++;
     696        *offset += 1;
    690697        return true;
    691698    }
     
    767774    debug << "QSslCertificate("
    768775          << certificate.version()
    769           << "," << certificate.serialNumber()
    770           << "," << certificate.digest().toBase64()
    771           << "," << certificate.issuerInfo(QSslCertificate::Organization)
    772           << "," << certificate.subjectInfo(QSslCertificate::Organization)
    773           << "," << certificate.alternateSubjectNames()
     776          << ',' << certificate.serialNumber()
     777          << ',' << certificate.digest().toBase64()
     778          << ',' << certificate.issuerInfo(QSslCertificate::Organization)
     779          << ',' << certificate.subjectInfo(QSslCertificate::Organization)
     780          << ',' << certificate.alternateSubjectNames()
    774781#ifndef QT_NO_TEXTSTREAM
    775           << "," << certificate.effectiveDate()
    776           << "," << certificate.expiryDate()
     782          << ',' << certificate.effectiveDate()
     783          << ',' << certificate.expiryDate()
    777784#endif
    778           << ")";
     785          << ')';
    779786    return debug;
    780787}
Note: See TracChangeset for help on using the changeset viewer.