com.trolltech.qt.network
Class QSslCertificate

java.lang.Object
  extended by com.trolltech.qt.internal.QSignalEmitterInternal
      extended by com.trolltech.qt.QSignalEmitter
          extended by com.trolltech.qt.QtJambiObject
              extended by com.trolltech.qt.network.QSslCertificate
All Implemented Interfaces:
QtJambiInterface, java.lang.Cloneable

public class QSslCertificate
extends QtJambiObject
implements java.lang.Cloneable

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(), 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.

See also:
QSslSocket, QSslKey, QSslCipher, and QSslError.


Nested Class Summary
static class QSslCertificate.SubjectInfo
          Describes keys that you can pass to QSslCertificate::issuerInfo() or QSslCertificate::subjectInfo() to get information about the certificate issuer or subject.
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.PrivateSignal0, QSignalEmitter.PrivateSignal1, QSignalEmitter.PrivateSignal2, QSignalEmitter.PrivateSignal3, QSignalEmitter.PrivateSignal4, QSignalEmitter.PrivateSignal5, QSignalEmitter.PrivateSignal6, QSignalEmitter.PrivateSignal7, QSignalEmitter.PrivateSignal8, QSignalEmitter.PrivateSignal9, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9
 
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal
 
Field Summary
 
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
currentSender
 
Constructor Summary
QSslCertificate()
          Constructs a QSslCertificate by parsing the format encoded data and using the first available certificate found.
QSslCertificate(QByteArray encoded)
          Constructs a QSslCertificate by parsing the format encoded data and using the first available certificate found.
QSslCertificate(QByteArray encoded, QSsl.EncodingFormat format)
          Constructs a QSslCertificate by parsing the format encoded data and using the first available certificate found.
QSslCertificate(QIODevice device)
          Constructs a QSslCertificate by reading format encoded data from device and using the first certificate found.
QSslCertificate(QIODevice device, QSsl.EncodingFormat format)
          Constructs a QSslCertificate by reading format encoded data from device and using the first certificate found.
QSslCertificate(QSslCertificate other)
          Constructs an identical copy of other.
 
Method Summary
 java.util.SortedMap alternateSubjectNames()
          Returns the list of alternative subject names for this certificate.
 void clear()
          Clears the contents of this certificate, making it a null certificate.
 QSslCertificate clone()
          This method is reimplemented for internal reasons
 QByteArray digest()
          Returns a cryptographic digest of this certificate.
 QByteArray digest(QCryptographicHash.Algorithm algorithm)
          Returns a cryptographic digest of this certificate.
 QDateTime effectiveDate()
          Returns the date-time that the certificate becomes valid, or an empty QDateTime if this is a null certificate.
 QDateTime expiryDate()
          Returns the date-time that the certificate expires, or an empty QDateTime if this is a null certificate.
static java.util.List fromData(QByteArray data)
          Searches for and parses all certificates in data that are encoded in the specified format and returns them in a list of certificates.
static java.util.List fromData(QByteArray data, QSsl.EncodingFormat format)
          Searches for and parses all certificates in data that are encoded in the specified format and returns them in a list of certificates.
static java.util.List fromDevice(QIODevice device)
          Searches for and parses all certificates in device that are encoded in the specified format and returns them in a list of certificates.
static java.util.List fromDevice(QIODevice device, QSsl.EncodingFormat format)
          Searches for and parses all certificates in device that are encoded in the specified format and returns them in a list of certificates.
static java.util.List fromPath(java.lang.String path)
          Searches all files in the path for certificates encoded in the specified format and returns them in a list.
static java.util.List fromPath(java.lang.String path, QSsl.EncodingFormat format)
          Searches all files in the path for certificates encoded in the specified format and returns them in a list.
static java.util.List fromPath(java.lang.String path, QSsl.EncodingFormat format, QRegExp.PatternSyntax syntax)
          Searches all files in the path for certificates encoded in the specified format and returns them in a list.
 long handle()
          Returns a pointer to the native certificate handle, if there is one, or a null pointer otherwise.
 boolean isNull()
          Returns true if this is a null certificate (i.
 java.lang.String issuerInfo(QByteArray tag)
          Returns the issuer information for tag from the certificate, or an empty string if there is no information for tag in the certificate.
 java.lang.String issuerInfo(QSslCertificate.SubjectInfo info)
          Returns the issuer information for the subject from the certificate, or an empty string if there is no information for subject in the certificate.
 boolean isValid()
          Returns true if this certificate is valid; otherwise returns false.
 QSslKey publicKey()
          Returns the certificate subject's public key.
 QByteArray serialNumber()
          Returns the certificate's serial number string.
 java.lang.String subjectInfo(QByteArray tag)
          Returns the subject information for tag, or an empty string if there is no information for tag in the certificate.
 java.lang.String subjectInfo(QSslCertificate.SubjectInfo info)
          Returns the information for the subject, or an empty string if there is no information for subject in the certificate.
 QByteArray toDer()
          Returns this certificate converted to a DER (binary) encoded representation.
 QByteArray toPem()
          Returns this certificate converted to a PEM (Base64) encoded representation.
 java.lang.String toString()
          Returns a string representation of the this QSslCertificate.
 QByteArray version()
          Returns the certificate's version string.
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
__qt_signalInitialization
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QSslCertificate

public QSslCertificate(QIODevice device)
Constructs a QSslCertificate by reading format encoded data from device and using the first certificate found. You can later call isNull() to see if device contained a certificate, and if this certificate was loaded successfully.


QSslCertificate

public QSslCertificate(QIODevice device,
                       QSsl.EncodingFormat format)
Constructs a QSslCertificate by reading format encoded data from device and using the first certificate found. You can later call isNull() to see if device contained a certificate, and if this certificate was loaded successfully.


QSslCertificate

public QSslCertificate(QByteArray encoded)
Constructs a QSslCertificate by parsing the format encoded data and using the first available certificate found. You can later call isNull() to see if data contained a certificate, and if this certificate was loaded successfully.


QSslCertificate

public QSslCertificate()
Constructs a QSslCertificate by parsing the format encoded data and using the first available certificate found. You can later call isNull() to see if data contained a certificate, and if this certificate was loaded successfully.


QSslCertificate

public QSslCertificate(QByteArray encoded,
                       QSsl.EncodingFormat format)
Constructs a QSslCertificate by parsing the format encoded data and using the first available certificate found. You can later call isNull() to see if data contained a certificate, and if this certificate was loaded successfully.


QSslCertificate

public QSslCertificate(QSslCertificate other)
Constructs an identical copy of other.

Method Detail

alternateSubjectNames

public final java.util.SortedMap alternateSubjectNames()
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 CommonName doesn't define a valid host name, or the subject info name doesn't match the peer's host name.

See also:
subjectInfo().


clear

public final void clear()
Clears the contents of this certificate, making it a null certificate.

See also:
isNull().


digest

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


digest

public final QByteArray digest(QCryptographicHash.Algorithm algorithm)
Returns a cryptographic digest of this certificate. By default, and MD5 digest will be generated, but you can also specify a custom algorithm.


effectiveDate

public final QDateTime effectiveDate()
Returns the date-time that the certificate becomes valid, or an empty QDateTime if this is a null certificate.

See also:
expiryDate().


expiryDate

public final QDateTime expiryDate()
Returns the date-time that the certificate expires, or an empty QDateTime if this is a null certificate.

See also:
effectiveDate().


handle

public final long handle()
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.


isNull

public final boolean isNull()
Returns true if this is a null certificate (i. ., a certificate with no contents); otherwise returns false.

By default, QSslCertificate constructs a null certificate.

See also:
isValid(), and clear().


isValid

public final boolean isValid()
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.

See also:
isNull().


issuerInfo

public final java.lang.String issuerInfo(QSslCertificate.SubjectInfo info)
Returns the issuer information for the subject from the certificate, or an empty string if there is no information for subject in the certificate.

See also:
subjectInfo().


issuerInfo

public final java.lang.String issuerInfo(QByteArray tag)
Returns the issuer information for tag from the certificate, or an empty string if there is no information for tag in the certificate.

See also:
subjectInfo().


publicKey

public final QSslKey publicKey()
Returns the certificate subject's public key.


serialNumber

public final QByteArray serialNumber()
Returns the certificate's serial number string.


subjectInfo

public final java.lang.String subjectInfo(QSslCertificate.SubjectInfo info)
Returns the information for the subject, or an empty string if there is no information for subject in the certificate.

See also:
issuerInfo().


subjectInfo

public final java.lang.String subjectInfo(QByteArray tag)
Returns the subject information for tag, or an empty string if there is no information for tag in the certificate.

See also:
issuerInfo().


toDer

public final QByteArray toDer()
Returns this certificate converted to a DER (binary) encoded representation.


toPem

public final QByteArray toPem()
Returns this certificate converted to a PEM (Base64) encoded representation.


version

public final QByteArray version()
Returns the certificate's version string.


fromData

public static java.util.List fromData(QByteArray data)
Searches for and parses all certificates in data that are encoded in the specified format and returns them in a list of certificates.

See also:
fromDevice().


fromData

public static java.util.List fromData(QByteArray data,
                                      QSsl.EncodingFormat format)
Searches for and parses all certificates in data that are encoded in the specified format and returns them in a list of certificates.

See also:
fromDevice().


fromDevice

public static java.util.List fromDevice(QIODevice device)
Searches for and parses all certificates in device that are encoded in the specified format and returns them in a list of certificates.

See also:
fromData().


fromDevice

public static java.util.List fromDevice(QIODevice device,
                                        QSsl.EncodingFormat format)
Searches for and parses all certificates in device that are encoded in the specified format and returns them in a list of certificates.

See also:
fromData().


fromPath

public static java.util.List fromPath(java.lang.String path,
                                      QSsl.EncodingFormat format)
Searches all files in the path for certificates encoded in the specified format and returns them in a list. must be a file or a pattern matching one or more files, as specified by syntax.

Example:

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

See also:
fromData().


fromPath

public static java.util.List fromPath(java.lang.String path)
Searches all files in the path for certificates encoded in the specified format and returns them in a list. must be a file or a pattern matching one or more files, as specified by syntax.

Example:

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

See also:
fromData().


fromPath

public static java.util.List fromPath(java.lang.String path,
                                      QSsl.EncodingFormat format,
                                      QRegExp.PatternSyntax syntax)
Searches all files in the path for certificates encoded in the specified format and returns them in a list. must be a file or a pattern matching one or more files, as specified by syntax.

Example:

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

See also:
fromData().


toString

public java.lang.String toString()
Returns a string representation of the this QSslCertificate.

Overrides:
toString in class java.lang.Object

clone

public QSslCertificate clone()
This method is reimplemented for internal reasons

Overrides:
clone in class java.lang.Object