Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QTlsPrivate::TlsKeyOpenSSL Class Referencefinal

#include <qtlskey_openssl_p.h>

Inheritance diagram for QTlsPrivate::TlsKeyOpenSSL:
Collaboration diagram for QTlsPrivate::TlsKeyOpenSSL:

Public Member Functions

 TlsKeyOpenSSL ()
 ~TlsKeyOpenSSL ()
void decodeDer (KeyType type, KeyAlgorithm algorithm, const QByteArray &der, const QByteArray &passPhrase, bool deepClear) override
void decodePem (KeyType type, KeyAlgorithm algorithm, const QByteArray &pem, const QByteArray &passPhrase, bool deepClear) override
QByteArray toPem (const QByteArray &passPhrase) const override
QByteArray derFromPem (const QByteArray &pem, QMap< QByteArray, QByteArray > *headers) const override
void fromHandle (Qt::HANDLE opaque, KeyType expectedType) override
void clear (bool deep) override
Qt::HANDLE handle () const override
int length () const override
QByteArray decrypt (Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv) const override
QByteArray encrypt (Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv) const override
bool fromEVP_PKEY (EVP_PKEY *pkey)
Public Member Functions inherited from QTlsPrivate::TlsKeyBase
 TlsKeyBase (KeyType type=QSsl::PublicKey, KeyAlgorithm algorithm=QSsl::Opaque)
bool isNull () const override
KeyType type () const override
KeyAlgorithm algorithm () const override
bool isPkcs8 () const override
QByteArray pemFromDer (const QByteArray &der, const QMap< QByteArray, QByteArray > &headers) const override
Public Member Functions inherited from QTlsPrivate::TlsKey
 TlsKey ()=default
virtual ~TlsKey ()
QByteArray pemHeader () const
QByteArray pemFooter () const

Static Public Member Functions

static TlsKeyOpenSSLpublicKeyFromX509 (X509 *x)

Public Attributes

union { 
   EVP_PKEY *   opaque 
   RSA *   rsa 
   DSA *   dsa 
   DH *   dh 
   EC_KEY *   ec 
   EVP_PKEY *   genericKey 
}; 

Additional Inherited Members

Public Types inherited from QTlsPrivate::TlsKey
using KeyType = QSsl::KeyType
using KeyAlgorithm = QSsl::KeyAlgorithm
Static Protected Member Functions inherited from QTlsPrivate::TlsKeyBase
static QByteArray pkcs8Header (bool encrypted)
static QByteArray pkcs8Footer (bool encrypted)
static bool isEncryptedPkcs8 (const QByteArray &der)
Protected Attributes inherited from QTlsPrivate::TlsKeyBase
bool keyIsNull = true
KeyType keyType = QSsl::PublicKey
KeyAlgorithm keyAlgorithm = QSsl::Opaque

Detailed Description

Definition at line 49 of file qtlskey_openssl_p.h.

Constructor & Destructor Documentation

◆ TlsKeyOpenSSL()

QTlsPrivate::TlsKeyOpenSSL::TlsKeyOpenSSL ( )
inline

Definition at line 52 of file qtlskey_openssl_p.h.

References clear(), and opaque.

Here is the call graph for this function:

◆ ~TlsKeyOpenSSL()

QTlsPrivate::TlsKeyOpenSSL::~TlsKeyOpenSSL ( )
inline

Definition at line 57 of file qtlskey_openssl_p.h.

References clear().

Here is the call graph for this function:

Member Function Documentation

◆ clear()

void QTlsPrivate::TlsKeyOpenSSL::clear ( bool deep)
overridevirtual

Clears the contents of this key, making it a null key. The meaning of deep is implementation-specific (e.g. if some internal objects representing a key can be shared using reference counting, deep equal to true would imply decrementing a reference count).

See also
isNull()

Implements QTlsPrivate::TlsKey.

Definition at line 166 of file qtlskey_openssl.cpp.

References QTlsPrivate::TlsKeyBase::keyIsNull, q_DH_free(), q_DSA_free(), q_EC_KEY_free(), q_EVP_PKEY_free(), and q_RSA_free().

Referenced by TlsKeyOpenSSL(), ~TlsKeyOpenSSL(), and decodePem().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decodeDer()

void QTlsPrivate::TlsKeyOpenSSL::decodeDer ( QSsl::KeyType type,
QSsl::KeyAlgorithm algorithm,
const QByteArray & der,
const QByteArray & passPhrase,
bool deepClear )
overridevirtual

If a support of public and private keys in DER format is required, this function must be overridden and should initialize this key using the type, algorithm, der and passPhrase. If this key was initialized previously, deepClear has an implementation-specific meaning (e.g., if an implementation is using reference-counting and can share internally some data structures, a value true may trigger decrementing a reference counter on some implementation-specific object).

Note
An empty overrider is sufficient, but then reading keys in QSsl::Der format will not be supported.
See also
isNull(), QSsl::KeyType, QSsl::EncodingFormat, QSsl::KeyAlgorithm

Implements QTlsPrivate::TlsKey.

Definition at line 19 of file qtlskey_openssl.cpp.

◆ decodePem()

void QTlsPrivate::TlsKeyOpenSSL::decodePem ( KeyType type,
KeyAlgorithm algorithm,
const QByteArray & pem,
const QByteArray & passPhrase,
bool deepClear )
overridevirtual

If a support of public and private keys in PEM format is required, this function must be overridden and should initialize this key using the type, algorithm, pem and passPhrase. If this key was initialized previously, deepClear has an implementation-specific meaning (e.g., in an implementation using reference-counting, a value true may trigger decrementing a reference counter on some implementation-specific object).

Note
An empty overrider is sufficient, but then reading keys in QSsl::Pem format will not be supported.
See also
isNull(), QSsl::KeyType, QSsl::EncodingFormat, QSsl::KeyAlgorithm

Implements QTlsPrivate::TlsKey.

Definition at line 45 of file qtlskey_openssl.cpp.

References clear(), QTlsPrivate::TlsKeyBase::keyIsNull, q_BIO_free(), q_EVP_PKEY_free(), and q_EVP_PKEY_get1_DH().

Here is the call graph for this function:

◆ decrypt()

QByteArray QTlsPrivate::TlsKeyOpenSSL::decrypt ( Cipher cipher,
const QByteArray & data,
const QByteArray & passPhrase,
const QByteArray & iv ) const
overridevirtual

This function allows to decrypt data (for example, a private key read from a file), using passPhrase, initialization vector iv. cipher is describing a block cipher and its mode (for example, AES256 + CBC). decrypt() is needed to implement QSslKey's constructor.

Note
A TLS backend may provide an empty implementation, but as a result QSslKey will not be able to work with private encrypted keys.
See also
QSslKey

Implements QTlsPrivate::TlsKey.

Definition at line 517 of file qtlskey_openssl.cpp.

◆ derFromPem()

QByteArray QTlsPrivate::TlsKeyOpenSSL::derFromPem ( const QByteArray & pem,
QMap< QByteArray, QByteArray > * headers ) const
overridevirtual

Converts pem to DER format, using this key's type and algorithm. The parameter headers must be a valid, non-null pointer. When parsing pem, the headers found there will be saved into headers.

Note
An overrider returning an empty QByteArray is sufficient, if QSslKey::toDer() is not needed.
This function is very implementation-specific. A backend, that already has this key's non-empty DER data, may simply return this data.
See also
QSslKey::toDer()

Implements QTlsPrivate::TlsKey.

Definition at line 104 of file qtlskey_openssl.cpp.

◆ encrypt()

QByteArray QTlsPrivate::TlsKeyOpenSSL::encrypt ( Cipher cipher,
const QByteArray & data,
const QByteArray & passPhrase,
const QByteArray & iv ) const
overridevirtual

This function is needed to implement QSslKey::toPem() with encryption (for a private key). cipher names a block cipher to use to encrypt data, using passPhrase and initialization vector iv.

Note
An empty implementation is sufficient, but QSslKey::toPem() will fail for a private key and non-empty passphrase.
See also
QSslKey

Implements QTlsPrivate::TlsKey.

Definition at line 523 of file qtlskey_openssl.cpp.

◆ fromEVP_PKEY()

bool QTlsPrivate::TlsKeyOpenSSL::fromEVP_PKEY ( EVP_PKEY * pkey)

Definition at line 387 of file qtlskey_openssl.cpp.

References QTlsPrivate::TlsKeyBase::keyIsNull, q_EVP_PKEY_get1_DH(), q_EVP_PKEY_get1_DSA(), q_EVP_PKEY_get1_EC_KEY(), q_EVP_PKEY_get1_RSA(), q_EVP_PKEY_type(), and q_EVP_PKEY_up_ref().

Here is the call graph for this function:

◆ fromHandle()

void QTlsPrivate::TlsKeyOpenSSL::fromHandle ( Qt::HANDLE handle,
QSsl::KeyType type )
overridevirtual

Initializes this key using the handle and type, taking the ownership of the handle.

Note
The meaning of the handle is implementation-specific.
If a TLS backend does not support such keys, it must provide an empty implementation.
See also
handle(), QSslKey::QSslKey(), QSslKet::handle()

Implements QTlsPrivate::TlsKey.

Definition at line 373 of file qtlskey_openssl.cpp.

◆ handle()

Qt::HANDLE QTlsPrivate::TlsKeyOpenSSL::handle ( ) const
overridevirtual

If a TLS backend supports opaque keys, returns a native handle that this key was initialized with.

See also
fromHandle(), QSslKey::handle()

Implements QTlsPrivate::TlsKey.

Definition at line 210 of file qtlskey_openssl.cpp.

◆ length()

int QTlsPrivate::TlsKeyOpenSSL::length ( ) const
overridevirtual

Returns the length of the key in bits, or -1 if the key is null.

Implements QTlsPrivate::TlsKey.

Definition at line 237 of file qtlskey_openssl.cpp.

References q_DH_bits(), q_DSA_bits(), q_EC_GROUP_get_degree(), q_EC_KEY_get0_group(), and q_RSA_bits().

Here is the call graph for this function:

◆ publicKeyFromX509()

TlsKeyOpenSSL * QTlsPrivate::TlsKeyOpenSSL::publicKeyFromX509 ( X509 * x)
static

Definition at line 529 of file qtlskey_openssl.cpp.

References dsa, ec, genericKey, QTlsPrivate::TlsKeyBase::keyIsNull, q_EVP_PKEY_free(), q_EVP_PKEY_get1_DSA(), q_EVP_PKEY_get1_EC_KEY(), q_EVP_PKEY_get1_RSA(), q_EVP_PKEY_type(), q_X509_get_pubkey(), and rsa.

Referenced by QTlsPrivate::X509CertificateOpenSSL::publicKey().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toPem()

QByteArray QTlsPrivate::TlsKeyOpenSSL::toPem ( const QByteArray & passPhrase) const
overridevirtual

This function must be overridden, if converting a key to PEM format, potentially with encryption, is needed (e.g. to save a QSslKey into a file). If this key is private and passPhrase is not empty, the key's data is expected to be encrypted using some conventional encryption algorithm (e.g. DES or AES - the one that different tools or even the class QSslKey can understand later).

Note
If this particular functionality is not needed, an overrider returning an empty QByteArray is sufficient.
See also
QSslKey::toPem()

Implements QTlsPrivate::TlsKey.

Definition at line 270 of file qtlskey_openssl.cpp.

References QTlsBackendOpenSSL::logAndClearErrorQueue(), q_BIO_free(), q_BIO_new(), q_BIO_s_mem(), q_EVP_des_ede3_cbc(), q_EVP_PKEY_free(), q_EVP_PKEY_new(), q_EVP_PKEY_set1_DH(), q_PEM_write_bio_DSA_PUBKEY(), q_PEM_write_bio_EC_PUBKEY(), q_PEM_write_bio_PUBKEY(), and q_PEM_write_bio_RSA_PUBKEY().

Here is the call graph for this function:

Member Data Documentation

◆ [union]

◆ dh

DH* QTlsPrivate::TlsKeyOpenSSL::dh

Definition at line 87 of file qtlskey_openssl_p.h.

◆ dsa

DSA* QTlsPrivate::TlsKeyOpenSSL::dsa

Definition at line 86 of file qtlskey_openssl_p.h.

Referenced by publicKeyFromX509().

◆ ec

EC_KEY* QTlsPrivate::TlsKeyOpenSSL::ec

Definition at line 89 of file qtlskey_openssl_p.h.

Referenced by publicKeyFromX509().

◆ genericKey

EVP_PKEY* QTlsPrivate::TlsKeyOpenSSL::genericKey

Definition at line 91 of file qtlskey_openssl_p.h.

Referenced by publicKeyFromX509().

◆ opaque

EVP_PKEY* QTlsPrivate::TlsKeyOpenSSL::opaque

Definition at line 84 of file qtlskey_openssl_p.h.

Referenced by TlsKeyOpenSSL().

◆ rsa

RSA* QTlsPrivate::TlsKeyOpenSSL::rsa

Definition at line 85 of file qtlskey_openssl_p.h.

Referenced by publicKeyFromX509().


The documentation for this class was generated from the following files: