Contents

CertificateBuilder Class Reference

The CertificateBuilder class is a tool for creating X.509 certificates. More...

    #include <CertificateBuilder>

Public Types

enum KeyPurpose { PurposeWebServer, PurposeWebClient, PurposeCodeSigning, PurposeEmailProtection, ..., PurposeAny }
enum KeyUsageFlag { UsageEncipherOnly, UsageCrlSign, UsageKeyCertSign, UsageKeyAgreement, ..., UsageDecipherOnly }
flags KeyUsageFlags

Public Functions

CertificateBuilder ()
~CertificateBuilder ()
bool addAuthorityKeyIdentifier ( const QSslCertificate & qcacert )
bool addKeyPurpose ( KeyPurpose purpose, bool critical = false )
bool addKeyPurpose ( const QByteArray & oid, bool critical = false )
bool addSubjectKeyIdentifier ()
bool copyRequestExtensions ( const CertificateRequest & crq )
int error () const
QString errorString () const
bool setActivationTime ( const QDateTime & date )
bool setBasicConstraints ( bool ca = false, int pathLength = -1 )
bool setExpirationTime ( const QDateTime & date )
bool setKeyUsage ( KeyUsageFlags usages )
bool setRequest ( const CertificateRequest & crq )
bool setSerial ( const QByteArray & serial )
bool setVersion ( int version = 3 )
QSslCertificate signedCertificate ( const QSslKey & qkey )
QSslCertificate signedCertificate ( const QSslCertificate & qcacert, const QSslKey & qcakey )

Detailed Description

The CertificateBuilder class is a tool for creating X.509 certificates.

Member Type Documentation

enum CertificateBuilder::KeyPurpose

enum CertificateBuilder::KeyUsageFlag
flags CertificateBuilder::KeyUsageFlags

The KeyUsageFlags type is a typedef for QFlags<KeyUsageFlag>. It stores an OR combination of KeyUsageFlag values.

Member Function Documentation

CertificateBuilder::CertificateBuilder ()

CertificateBuilder::~CertificateBuilder ()

bool CertificateBuilder::addAuthorityKeyIdentifier ( const QSslCertificate & qcacert )

Adds the authority key identifier extension to the certificate. The key is extracted the specified certificate which must be the one later used to sign the certificate.

bool CertificateBuilder::addKeyPurpose ( KeyPurpose purpose, bool critical = false )

Adds the specified purpose to the list of those this certificate may be used for. This method may be called multiple times to add a series of different purposes.

bool CertificateBuilder::addKeyPurpose ( const QByteArray & oid, bool critical = false )

Adds the specified purpose to the list of those this certificate may be used for. This method may be called multiple times to add a series of different purposes. This method differs from the one above by allowing arbitrary OIDs to be used, not just those for which there is built in support.

bool CertificateBuilder::addSubjectKeyIdentifier ()

Adds the subject key identifier extension to the certificate. The key is extracted automatically from the certificate being created.

bool CertificateBuilder::copyRequestExtensions ( const CertificateRequest & crq )

Copies the extensions from the request to the certificate being created. This should only be done after checking that the request is safe, since otherwise you could potentially copy extensions that grant the generated certificate facilities you did not intend.

int CertificateBuilder::error () const

Returns the last error that occurred when using this object. The values used are those of gnutls. If there has not been an error then it is guaranteed to be 0.

QString CertificateBuilder::errorString () const

Returns a string describing the last error that occurred when using this object.

bool CertificateBuilder::setActivationTime ( const QDateTime & date )

Set the time at which the certificate will become valid.

bool CertificateBuilder::setBasicConstraints ( bool ca = false, int pathLength = -1 )

Add the basic constraints extension. This allows you to specify if the certificate being created is a CA (ie. may sign certificates), and the maximum length of the chain that is allowed if you grant it that permission. By default the pathLength is unlimited.

bool CertificateBuilder::setExpirationTime ( const QDateTime & date )

Set the time after which the certificate is no longer valid.

bool CertificateBuilder::setKeyUsage ( KeyUsageFlags usages )

Sets the key usage flags for the certificate. If you call this method more than once then only the last value will be used by the created certificate.

bool CertificateBuilder::setRequest ( const CertificateRequest & crq )

Set the request that the certificate will be generated from.

bool CertificateBuilder::setSerial ( const QByteArray & serial )

Set the serial number of the certificate. This should be a random value containing a large amount of entropy.

bool CertificateBuilder::setVersion ( int version = 3 )

Set the version of the X.509 certificate. In general the version will be 3.

QSslCertificate CertificateBuilder::signedCertificate ( const QSslKey & qkey )

Creates a self-signed certificate by signing the certificate with the specified key.

QSslCertificate CertificateBuilder::signedCertificate ( const QSslCertificate & qcacert, const QSslKey & qcakey )

Creates a certificate signed by the specified CA certificate using the CA key.