Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QSslCertificate Class

TheQSslCertificate class provides a convenient API for an X509 certificate.More...

Header:#include <QSslCertificate>
Since: Qt 4.3

Note: All functions in this class arereentrant.

Public Types

enumSubjectInfo { Organization, CommonName, LocalityName, OrganizationalUnitName, CountryName, StateOrProvinceName }

Public Functions

QSslCertificate(QIODevice * device, QSsl::EncodingFormat format = QSsl::Pem)
QSslCertificate(const QByteArray & data = QByteArray(), QSsl::EncodingFormat format = QSsl::Pem)
QSslCertificate(const QSslCertificate & other)
~QSslCertificate()
QMultiMap<QSsl::AlternateNameEntryType, QString>alternateSubjectNames() const
voidclear()
QByteArraydigest(QCryptographicHash::Algorithm algorithm = QCryptographicHash::Md5) const
QDateTimeeffectiveDate() const
QDateTimeexpiryDate() const
Qt::HANDLEhandle() const
boolisNull() const
boolisValid() const
QStringissuerInfo(SubjectInfo subject) const
QStringissuerInfo(const QByteArray & tag) const
QSslKeypublicKey() const
QByteArrayserialNumber() const
QStringsubjectInfo(SubjectInfo subject) const
QStringsubjectInfo(const QByteArray & tag) const
QByteArraytoDer() const
QByteArraytoPem() const
QByteArrayversion() const
booloperator!=(const QSslCertificate & other) const
QSslCertificate &operator=(const QSslCertificate & other)
booloperator==(const QSslCertificate & other) const

Static Public Members

QList<QSslCertificate>fromData(const QByteArray & data, QSsl::EncodingFormat format = QSsl::Pem)
QList<QSslCertificate>fromDevice(QIODevice * device, QSsl::EncodingFormat format = QSsl::Pem)
QList<QSslCertificate>fromPath(const QString & path, QSsl::EncodingFormat format = QSsl::Pem, QRegExp::PatternSyntax syntax = QRegExp::FixedString)

Detailed Description

TheQSslCertificate class provides a convenient API for an X509 certificate.

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 aQSslCertificate. The most common way is to callQSslSocket::peerCertificate(), which returns aQSslCertificate object, orQSslSocket::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 callisNull() to check if your certificate is null. By default,QSslCertificate constructs a null certificate. To check if the certificate is valid, callisValid(). A null certificate is invalid, but an invalid certificate is not necessarily null. If you want to reset all contents in a certificate, callclear().

After loading a certificate, you can find information about the certificate, its subject, and its issuer, by calling one of the many accessor functions, includingversion(),serialNumber(),issuerInfo() andsubjectInfo(). You can calleffectiveDate() andexpiryDate() to check when the certificate starts being effective and when it expires. ThepublicKey() function returns the certificate subject's public key as aQSslKey. You can callissuerInfo() orsubjectInfo() 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 callinghandle(), but the results are likely to not be portable.

See alsoQSslSocket,QSslKey,QSslCipher, andQSslError.

Member Type Documentation

enum QSslCertificate::SubjectInfo

Describes keys that you can pass toQSslCertificate::issuerInfo() orQSslCertificate::subjectInfo() to get information about the certificate issuer or subject.

ConstantValueDescription
QSslCertificate::Organization0"O" The name of the organization.
QSslCertificate::CommonName1"CN" The common name; most often this is used to store the host name.
QSslCertificate::LocalityName2"L" The locality.
QSslCertificate::OrganizationalUnitName3"OU" The organizational unit name.
QSslCertificate::CountryName4"C" The country.
QSslCertificate::StateOrProvinceName5"ST" The state or province.

Member Function Documentation

QSslCertificate::QSslCertificate(QIODevice * device,QSsl::EncodingFormat format = QSsl::Pem)

Constructs aQSslCertificate by readingformat encoded data fromdevice and using the first certificate found. You can later callisNull() to see ifdevice contained a certificate, and if this certificate was loaded successfully.

QSslCertificate::QSslCertificate(constQByteArray & data = QByteArray(),QSsl::EncodingFormat format = QSsl::Pem)

Constructs aQSslCertificate by parsing theformat encodeddata and using the first available certificate found. You can later callisNull() to see ifdata contained a certificate, and if this certificate was loaded successfully.

QSslCertificate::QSslCertificate(constQSslCertificate & other)

Constructs an identical copy ofother.

QSslCertificate::~QSslCertificate()

Destroys theQSslCertificate.

QMultiMap<QSsl::AlternateNameEntryType,QString> QSslCertificate::alternateSubjectNames() const

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 forCommonName doesn't define a valid host name, or the subject info name doesn't match the peer's host name.

See alsosubjectInfo().

void QSslCertificate::clear()

Clears the contents of this certificate, making it a null certificate.

See alsoisNull().

QByteArray QSslCertificate::digest(QCryptographicHash::Algorithm algorithm = QCryptographicHash::Md5) const

Returns a cryptographic digest of this certificate. By default, an MD5 digest will be generated, but you can also specify a customalgorithm.

QDateTime QSslCertificate::effectiveDate() const

Returns the date-time that the certificate becomes valid, or an emptyQDateTime if this is a null certificate.

See alsoexpiryDate().

QDateTime QSslCertificate::expiryDate() const

Returns the date-time that the certificate expires, or an emptyQDateTime if this is a null certificate.

See alsoeffectiveDate().

[static]QList<QSslCertificate> QSslCertificate::fromData(constQByteArray & data,QSsl::EncodingFormat format = QSsl::Pem)

Searches for and parses all certificates indata that are encoded in the specifiedformat and returns them in a list of certificates.

See alsofromDevice().

[static]QList<QSslCertificate> QSslCertificate::fromDevice(QIODevice * device,QSsl::EncodingFormat format = QSsl::Pem)

Searches for and parses all certificates indevice that are encoded in the specifiedformat and returns them in a list of certificates.

See alsofromData().

[static]QList<QSslCertificate> QSslCertificate::fromPath(constQString & path,QSsl::EncodingFormat format = QSsl::Pem,QRegExp::PatternSyntax syntax = QRegExp::FixedString)

Searches all files in thepath for certificates encoded in the specifiedformat and returns them in a list.must be a file or a pattern matching one or more files, as specified bysyntax.

Example:

foreach (constQSslCertificate&cert,QSslCertificate::fromPath("C:/ssl/certificate.*.pem",QSsl::Pem,QRegExp::Wildcard)) {qDebug()<< cert.issuerInfo(QSslCertificate::Organization);}

See alsofromData().

Qt::HANDLE QSslCertificate::handle() const

Returns a pointer to the native certificate handle, if there is one, or a null pointer otherwise.

You can use this handle, together with the native API, to access extended information about the certificate.

Warning: Use of this function has a high probability of being non-portable, and its return value may vary from platform to platform or change from minor release to minor release.

bool QSslCertificate::isNull() const

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.

See alsoisValid() andclear().

bool QSslCertificate::isValid() const

Returns true if this certificate is valid; otherwise returns false.

Note: Currently, this function checks that the current data-time is within the date-time range during which the certificate is considered valid, and checks that the certificate is not in a blacklist of fraudulent certificates.

See alsoisNull().

QString QSslCertificate::issuerInfo(SubjectInfo subject) const

Returns the issuer information for thesubject from the certificate, or an empty string if there is no information forsubject in the certificate.

See alsosubjectInfo().

QString QSslCertificate::issuerInfo(constQByteArray & tag) const

Returns the issuer information fortag from the certificate, or an empty string if there is no information fortag in the certificate.

See alsosubjectInfo().

QSslKey QSslCertificate::publicKey() const

Returns the certificate subject's public key.

QByteArray QSslCertificate::serialNumber() const

Returns the certificate's serial number string in decimal format. In case the serial number cannot be converted to decimal format (i.e. if it is bigger than 4294967295, which means it does not fit into 4 bytes), its hexadecimal version is returned.

QString QSslCertificate::subjectInfo(SubjectInfo subject) const

Returns the information for thesubject, or an empty string if there is no information forsubject in the certificate.

See alsoissuerInfo().

QString QSslCertificate::subjectInfo(constQByteArray & tag) const

Returns the subject information fortag, or an empty string if there is no information fortag in the certificate.

See alsoissuerInfo().

QByteArray QSslCertificate::toDer() const

Returns this certificate converted to a DER (binary) encoded representation.

QByteArray QSslCertificate::toPem() const

Returns this certificate converted to a PEM (Base64) encoded representation.

QByteArray QSslCertificate::version() const

Returns the certificate's version string.

bool QSslCertificate::operator!=(constQSslCertificate & other) const

Returns true if this certificate is not the same asother; otherwise returns false.

QSslCertificate & QSslCertificate::operator=(constQSslCertificate & other)

Copies the contents ofother into this certificate, making the two certificates identical.

bool QSslCertificate::operator==(constQSslCertificate & other) const

Returns true if this certificate is the same asother; otherwise returns false.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp