Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
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 48 of file qtlskey_openssl_p.h.

Constructor & Destructor Documentation

◆ TlsKeyOpenSSL()

QTlsPrivate::TlsKeyOpenSSL::TlsKeyOpenSSL ( )
inline

Definition at line 51 of file qtlskey_openssl_p.h.

References clear().

Referenced by publicKeyFromX509().

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

◆ ~TlsKeyOpenSSL()

QTlsPrivate::TlsKeyOpenSSL::~TlsKeyOpenSSL ( )
inline

Definition at line 56 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 158 of file qtlskey_openssl.cpp.

References QTlsPrivate::TlsKeyBase::algorithm(), QSsl::Dh, dh, QSsl::Dsa, dsa, QSsl::Ec, ec, genericKey, QTlsPrivate::TlsKeyBase::keyIsNull, QSsl::Opaque, opaque, q_DH_free(), q_DSA_free(), q_EC_KEY_free(), q_EVP_PKEY_free(), q_RSA_free(), QSsl::Rsa, and rsa.

+ Here is the call 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 18 of file qtlskey_openssl.cpp.

References QTlsPrivate::TlsKeyBase::algorithm(), decodePem(), QTlsPrivate::TlsKeyBase::keyAlgorithm, QTlsPrivate::TlsKeyBase::keyType, QTlsPrivate::TlsKeyBase::pemFromDer(), and QTlsPrivate::TlsKeyBase::type().

+ Here is the call graph for this function:

◆ 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 33 of file qtlskey_openssl.cpp.

References QTlsPrivate::TlsKeyBase::algorithm(), clear(), QSsl::Dh, dh, QSsl::Dsa, dsa, QSsl::Ec, ec, genericKey, QTlsPrivate::TlsKeyBase::keyAlgorithm, QTlsPrivate::TlsKeyBase::keyIsNull, QTlsPrivate::TlsKeyBase::keyType, QTlsBackendOpenSSL::logAndClearErrorQueue(), QSsl::PublicKey, q_BIO_free(), q_BIO_new_mem_buf(), q_EVP_PKEY_free(), q_EVP_PKEY_get1_DH(), q_PEM_read_bio_DSA_PUBKEY(), q_PEM_read_bio_DSAPrivateKey(), q_PEM_read_bio_EC_PUBKEY(), q_PEM_read_bio_ECPrivateKey(), q_PEM_read_bio_PrivateKey(), q_PEM_read_bio_PUBKEY(), q_PEM_read_bio_RSA_PUBKEY(), q_PEM_read_bio_RSAPrivateKey(), qScopeGuard(), QSsl::Rsa, rsa, and QTlsPrivate::TlsKeyBase::type().

Referenced by decodeDer().

+ Here is the call graph for this function:
+ Here is the caller 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 479 of file qtlskey_openssl.cpp.

References QTlsPrivate::doCrypt().

+ Here is the call graph for this function:

◆ 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 96 of file qtlskey_openssl.cpp.

References QByteArray::fromBase64(), header(), i, j, QByteArray::mid(), QTlsPrivate::TlsKey::pemFooter(), QTlsPrivate::TlsKey::pemHeader(), QTlsPrivate::TlsKeyBase::pkcs8Footer(), QTlsPrivate::TlsKeyBase::pkcs8Header(), QSsl::PublicKey, QByteArray(), QByteArray::trimmed(), and QTlsPrivate::TlsKeyBase::type().

+ Here is the call graph for this function:

◆ 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 485 of file qtlskey_openssl.cpp.

References QTlsPrivate::doCrypt().

+ Here is the call graph for this function:

◆ fromEVP_PKEY()

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

Definition at line 363 of file qtlskey_openssl.cpp.

References QSsl::Dh, dh, QSsl::Dsa, dsa, QSsl::Ec, ec, get_key, QTlsPrivate::TlsKeyBase::keyAlgorithm, QTlsPrivate::TlsKeyBase::keyIsNull, QTlsPrivate::TlsKeyBase::keyType, QSsl::PrivateKey, q_EVP_PKEY_base_id(), q_EVP_PKEY_type(), QSsl::Rsa, and rsa.

Referenced by fromHandle().

+ Here is the call graph for this function:
+ Here is the caller 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 349 of file qtlskey_openssl.cpp.

References fromEVP_PKEY(), handle(), QTlsPrivate::TlsKeyBase::keyAlgorithm, QTlsPrivate::TlsKeyBase::keyIsNull, QTlsPrivate::TlsKeyBase::keyType, QSsl::Opaque, opaque, and q_EVP_PKEY_free().

+ Here is the call graph for this function:

◆ 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 202 of file qtlskey_openssl.cpp.

References QSsl::Dh, dh, QSsl::Dsa, dsa, QSsl::Ec, ec, genericKey, QTlsPrivate::TlsKeyBase::keyAlgorithm, QSsl::Opaque, opaque, qCWarning, QSsl::Rsa, and rsa.

Referenced by fromHandle().

+ Here is the caller graph for this function:

◆ 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 229 of file qtlskey_openssl.cpp.

References QTlsPrivate::TlsKeyBase::algorithm(), QSsl::Dh, dh, QSsl::Dsa, dsa, QSsl::Ec, ec, genericKey, QTlsPrivate::TlsKeyBase::isNull(), QSsl::Opaque, Q_ASSERT, q_DH_bits(), q_DSA_bits(), q_EC_GROUP_get_degree(), q_EC_KEY_get0_group(), q_RSA_bits(), QSsl::Rsa, and rsa.

+ Here is the call graph for this function:

◆ publicKeyFromX509()

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

Definition at line 491 of file qtlskey_openssl.cpp.

References TlsKeyOpenSSL(), QSsl::Dsa, dsa, QSsl::Ec, ec, get_pubkey, QTlsPrivate::TlsKeyBase::keyType, QSsl::PublicKey, Q_ASSERT, q_EVP_PKEY_base_id(), q_EVP_PKEY_free(), q_EVP_PKEY_type(), q_X509_get_pubkey(), QSsl::Rsa, 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 255 of file qtlskey_openssl.cpp.

References QTlsPrivate::TlsKeyBase::algorithm(), QSsl::Dh, dh, QSsl::Dsa, dsa, QSsl::Ec, ec, genericKey, QTlsPrivate::TlsKeyBase::isNull(), QTlsBackendOpenSSL::logAndClearErrorQueue(), QSsl::Opaque, QSsl::PrivateKey, QSsl::PublicKey, q_BIO_free(), q_BIO_get_mem_data, 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_PrivateKey(), q_PEM_write_bio_PUBKEY(), QByteArray(), qScopeGuard(), QSsl::Rsa, rsa, QSslSocket::supportsSsl(), QTlsPrivate::TlsKeyBase::type(), write_privatekey, and write_pubkey.

+ Here is the call graph for this function:

Member Data Documentation

◆ [union]

◆ dh

DH* QTlsPrivate::TlsKeyOpenSSL::dh

Definition at line 86 of file qtlskey_openssl_p.h.

Referenced by clear(), decodePem(), fromEVP_PKEY(), handle(), length(), and toPem().

◆ dsa

DSA* QTlsPrivate::TlsKeyOpenSSL::dsa

◆ ec

EC_KEY* QTlsPrivate::TlsKeyOpenSSL::ec

◆ genericKey

EVP_PKEY* QTlsPrivate::TlsKeyOpenSSL::genericKey

Definition at line 90 of file qtlskey_openssl_p.h.

Referenced by clear(), decodePem(), handle(), length(), and toPem().

◆ opaque

EVP_PKEY* QTlsPrivate::TlsKeyOpenSSL::opaque

Definition at line 83 of file qtlskey_openssl_p.h.

Referenced by clear(), fromHandle(), and handle().

◆ rsa

RSA* QTlsPrivate::TlsKeyOpenSSL::rsa

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