⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qsslcertificate.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtNetwork module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************//******************************************************************************** In addition, as a special exception, Trolltech gives permission to link** the code of its release of Qt with the OpenSSL project's "OpenSSL" library** (or modified versions of the "OpenSSL" library that use the same license** as the original version), and distribute the linked executables.**** You must comply with the GNU General Public License version 2 in all** respects for all of the code used other than the "OpenSSL" code.  If you** modify this file, you may extend this exception to your version of the file,** but you are not obligated to do so.  If you do not wish to do so, delete** this exception statement from your version of this file.******************************************************************************//*!    \class QSslCertificate    \brief The QSslCertificate class provides a convenient API for an X509 certificate.    \since 4.3    \reentrant    \ingroup io    \module network    QSslCertificate stores an X509 certificate, and is commonly used    to verify the identity and store information about the local host,    a remotely connected peer, or a trusted third party Certificate    Authority.    There are many ways to construct a QSslCertificate. The most    common way is to call QSslSocket::peerCertificate(), which returns    a QSslCertificate object, or QSslSocket::peerCertificateChain(),    which returns a list of them. You can also load certificates from    a DER (binary) or PEM (Base64) encoded bundle, typically stored as    one or more local files, or in a Qt Resource.    You can call isNull() to check if your certificate is null. By    default, QSslCertificate constructs a null certificate. To check    if the certificate is valid, call isValid(). A null certificate is    invalid, but an invalid certificate is not necessarily null. If    you want to reset all contents in a certificate, call clear().    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    subject's public key as a QSslKey. You can call issuerInfo() or    subjectInfo() to get detailed information about the certificate    issuer and its subject.    Internally, QSslCertificate is stored as an X509 structure. You    can access this handle by calling handle(), but the results are    likely to not be portable.    \sa QSslSocket, QSslKey, QSslCipher, QSslError*//*!    \enum QSslCertificate::SubjectInfo    Describes keys that you can pass to QSslCertificate::issuerInfo() or    QSslCertificate::subjectInfo() to get information about the certificate    issuer or subject.    \value Organization "O" The name of the organization.    \value CommonName "CN" The common name; most often this is used to store    the host name.    \value LocalityName "L" The locality.    \value OrganizationalUnitName "OU" The organizational unit name.    \value CountryName "C" The country.    \value StateOrProvinceName "ST" The state or province.*/#include "qsslsocket_openssl_symbols_p.h"#include "qsslcertificate.h"#include "qsslcertificate_p.h"#include "qsslkey.h"#include "qsslkey_p.h"#include <QtCore/qatomic.h>#include <QtCore/qdatetime.h>#include <QtCore/qdebug.h>#include <QtCore/qdir.h>#include <QtCore/qdiriterator.h>#include <QtCore/qfile.h>#include <QtCore/qfileinfo.h>#include <QtCore/qmap.h>#include <QtCore/qstring.h>#include <QtCore/qstringlist.h>/*!    Constructs a QSslCertificate by reading \a format encoded data    from \a device and using the first certificate found. You can    later call isNull() to see if \a device contained a certificate,    and if this certificate was loaded successfully.*/QSslCertificate::QSslCertificate(QIODevice *device, QSsl::EncodingFormat format)    : d(new QSslCertificatePrivate){    QSslSocketPrivate::ensureInitialized();    if (device)        d->init(device->readAll(), format);}/*!    Constructs a QSslCertificate by parsing the \a format encoded    \a data and using the first available certificate found. You can    later call isNull() to see if \a data contained a certificate,    and if this certificate was loaded successfully.*/QSslCertificate::QSslCertificate(const QByteArray &data, QSsl::EncodingFormat format)    : d(new QSslCertificatePrivate){    QSslSocketPrivate::ensureInitialized();    d->init(data, format);}/*!    Constructs an identical copy of \a other.*/QSslCertificate::QSslCertificate(const QSslCertificate &other) : d(other.d){    d->ref.ref();}/*!    Destroys the QSslCertificate.*/QSslCertificate::~QSslCertificate(){    if (!d->ref.deref())        delete d;}/*!    Copies the contents of \a other into this certificate, making the two    certificates identical.*/QSslCertificate &QSslCertificate::operator=(const QSslCertificate &other){    qAtomicAssign(d, other.d);    return *this;}/*!    Returns true if this certificate is the same as \a other; otherwise    returns false.*/bool QSslCertificate::operator==(const QSslCertificate &other) const{    if (d == other.d)        return true;    if (d->null && other.d->null)        return true;    if (d->x509 && other.d->x509)        return q_X509_cmp(d->x509, other.d->x509) == 0;    return false;}/*!    \fn bool QSslCertificate::operator!=(const QSslCertificate &other) const    Returns true if this certificate is not the same as \a other; otherwise    returns false.*//*!    Returns true if this is a null certificate (i.e., a certificate    with no contents); otherwise returns false.    By default, QSslCertificate constructs a null certificate.    \sa isValid(), clear()*/bool QSslCertificate::isNull() const{    return d->null;}/*!    Returns true if this certificate is valid; otherwise returns    false.    Note: Currently, this function only checks that the current    data-time is within the date-time range during which the    certificate is considered valid. No other checks are    currently performed.    \sa isNull()*/bool QSslCertificate::isValid() const{    const QDateTime currentTime = QDateTime::currentDateTime();    return currentTime >= d->notValidBefore && currentTime <= d->notValidAfter;}/*!    Clears the contents of this certificate, making it a null    certificate.    \sa isNull()*/void QSslCertificate::clear(){    if (!d->ref.deref()) {        delete d;        d = new QSslCertificatePrivate;    }}/*!    Returns the certificate's version string.*/QByteArray QSslCertificate::version() const{    return d->versionString;}/*!    Returns the certificate's serial number string.*/QByteArray QSslCertificate::serialNumber() const{    return d->serialNumberString;}/*!    Returns a cryptographic digest of this certificate. By default,    and MD5 digest will be generated, but you can also specify a    custom \a algorithm.*/QByteArray QSslCertificate::digest(QCryptographicHash::Algorithm algorithm) const{    return QCryptographicHash::hash(toDer(), algorithm);}static QString _q_SubjectInfoToString(QSslCertificate::SubjectInfo info){    QString str;    switch (info) {    case QSslCertificate::Organization: str = QLatin1String("O"); break;    case QSslCertificate::CommonName: str = QLatin1String("CN"); break;    case QSslCertificate::LocalityName: str = QLatin1String("L"); break;    case QSslCertificate::OrganizationalUnitName: str = QLatin1String("OU"); break;    case QSslCertificate::CountryName: str = QLatin1String("C"); break;    case QSslCertificate::StateOrProvinceName: str = QLatin1String("ST"); break;    }    return str;}/*!  \fn QString QSslCertificate::issuerInfo(SubjectInfo subject) const    Returns the issuer information for the \a subject from the  certificate, or an empty string if there is no information for  \a subject in the certificate.  \sa subjectInfo()*/QString QSslCertificate::issuerInfo(SubjectInfo info) const{    return d->issuerInfo.value(_q_SubjectInfoToString(info));}/*!  Returns the issuer information for \a tag from the certificate,  or an empty string if there is no information for \a tag in the  certificate.  \sa subjectInfo()*/QString QSslCertificate::issuerInfo(const QByteArray &tag) const{    // ### Use a QByteArray for the keys in the map    return d->issuerInfo.value(QString::fromLatin1(tag));}/*!  \fn QString QSslCertificate::subjectInfo(SubjectInfo subject) const  Returns the information for the \a subject, or an empty string if  there is no information for \a subject in the certificate.    \sa issuerInfo()*/QString QSslCertificate::subjectInfo(SubjectInfo info) const{    return d->subjectInfo.value(_q_SubjectInfoToString(info));}/*!    Returns the subject information for \a tag, or an empty string if    there is no information for \a tag in the certificate.    \sa issuerInfo()*/QString QSslCertificate::subjectInfo(const QByteArray &tag) const{    // ### Use a QByteArray for the keys in the map    return d->subjectInfo.value(QString::fromLatin1(tag));}/*!  Returns the list of alternative subject names for this  certificate. The alternate subject names typically contain host  names, optionally with wildcards, that are valid for this  certificate.    These names are tested against the connected peer's host name, if  either the subject information for \l CommonName doesn't define a  valid host name, or the subject info name doesn't match the peer's  host name.    \sa subjectInfo()*/QMultiMap<QSsl::AlternateNameEntryType, QString> QSslCertificate::alternateSubjectNames() const{    QMultiMap<QSsl::AlternateNameEntryType, QString> result;    STACK *altNames = (STACK *)q_X509_get_ext_d2i(d->x509, NID_subject_alt_name, 0, 0);    if (altNames) {        for (int i = 0; i < q_sk_GENERAL_NAME_num(altNames); ++i) {            const GENERAL_NAME *genName = q_sk_GENERAL_NAME_value(altNames, i);            const QString altName = QLatin1String(QByteArray(reinterpret_cast<const char *>(q_ASN1_STRING_data(genName->d.ia5)),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -