Home · All Classes · Main Classes · Grouped Classes · Modules · Functions

QSslCertificate Class Reference
[
QtNetwork module]

The QSslCertificate class provides a convenient API for an X509 certificate. More...

 #include <QSslCertificate>

Note: All the functions in this class are reentrant.

This class was introduced in Qt 4.3.

Public Types

Public Functions

Static Public Members


Detailed Description

The QSslCertificate 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 a QSslCertificate. The most common way is to call QSslSocket::peerCertificate() or QSslSocket::peerCertificateChain(), which both return QSslCertificate objects. You can also create load certificates from a binary or PEM 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 or not; by default, QSslCertificate constructs a null certificate. To check if the certificate is valid, call isValid(). Null certificates are always also invalid. 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.

See also QSslSocket, QSslKey, QSslCipher, and QSslError.


Member Type Documentation

enum QSslCertificate::SubjectInfo

Describes keys that you can pass to QSslCertificate::issuerInfo() or QSslCertificate::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 )

Constructs a QSslCertificate, and reads from device to find the first available certificate. You can later call isNull() to see if device contains a certificate, and this certificate was loaded successfully.

QSslCertificate::QSslCertificate ( const QByteArray & data = QByteArray() )

Constructs a QSslCertificate, and parses data to find the first available certificate. You can later call isNull() to see if data contains a certificate, and this certificate was loaded successfully.

QSslCertificate::QSslCertificate ( const QSslCertificate & other )

Constructs an identical copy of other.

QSslCertificate::~QSslCertificate ()

Destroys the QSslCertificate.

QStringList QSslCertificate::alternateSubjectNames () const

Returns the list of alternative subject names for this certificate. The alternate subject names typically contain hostnames, optionally with wildcards, that are valid for this certificate.

These names are tested against the connected peer's host name if the subject info for CommonName either does not define a valid host name, or if the subject info name doesn't match the peer's host name.

See also subjectInfo().

void QSslCertificate::clear ()

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

See also isNull().

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

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

QList<QSslCertificate> QSslCertificate::fromData ( const QByteArray & data )   [static]

Searches for and parses all certificates in data, and returns the list of certificates.

See also fromDevice().

QList<QSslCertificate> QSslCertificate::fromDevice ( QIODevice * device )   [static]

Searches for and parses all certificates in device, and returns the list of certificates.

See also fromData().

Qt::HANDLE QSslCertificate::handle () const

Returns a pointer to the native certificate handle, if this is available; otherwise a null pointer is returned.

You can use this handle together with 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 between platforms, and between minor Qt releases.

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 also isValid() and clear().

bool QSslCertificate::isValid () const

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

Note: Currently, this function always returns false.

See also isNull().

QString QSslCertificate::issuerInfo ( SubjectInfo info ) const

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

See also subjectInfo().

QString QSslCertificate::issuerInfo ( const QByteArray & tag ) const

This is an overloaded member function, provided for convenience.

Returns the issuer info for tag, or an empty string if there is no information for tag in the certificate.

See also subjectInfo().

QDateTime QSslCertificate::notValidAfter () const

Returns the date that the certificate expires, or an empty QDateTime if this is a null certificate.

See also notValidBefore().

QDateTime QSslCertificate::notValidBefore () const

Returns the date that the certificate becomes valid, or an empty QDateTime if this is a null certificate.

See also notValidAfter().

QSslKey QSslCertificate::publicKey () const

Returns the certificate subject's public key.

QByteArray QSslCertificate::serialNumber () const

Returns the certificate's serial number string.

QString QSslCertificate::subjectInfo ( SubjectInfo info ) const

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

See also issuerInfo().

QString QSslCertificate::subjectInfo ( const QByteArray & tag ) const

This is an overloaded member function, provided for convenience.

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

See also issuerInfo().

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!= ( const QSslCertificate & other ) const

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

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

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

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

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


Copyright © 2007 Trolltech Trademarks
Qt 4.3.0beta