![]() |
Qt 6.x
The Qt SDK
|
#include <qtlskey_openssl_p.h>
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) |
![]() | |
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 |
![]() | |
virtual | ~TlsKey () |
virtual void | decodeDer (KeyType type, KeyAlgorithm algorithm, const QByteArray &der, const QByteArray &passPhrase, bool deepClear)=0 |
virtual void | decodePem (KeyType type, KeyAlgorithm algorithm, const QByteArray &pem, const QByteArray &passPhrase, bool deepClear)=0 |
virtual QByteArray | toPem (const QByteArray &passPhrase) const =0 |
virtual QByteArray | derFromPem (const QByteArray &pem, QMap< QByteArray, QByteArray > *headers) const =0 |
virtual QByteArray | pemFromDer (const QByteArray &der, const QMap< QByteArray, QByteArray > &headers) const =0 |
virtual void | fromHandle (Qt::HANDLE handle, KeyType type)=0 |
virtual Qt::HANDLE | handle () const =0 |
virtual bool | isNull () const =0 |
virtual KeyType | type () const =0 |
virtual KeyAlgorithm | algorithm () const =0 |
virtual int | length () const =0 |
virtual void | clear (bool deepClear)=0 |
virtual bool | isPkcs8 () const =0 |
virtual QByteArray | decrypt (Cipher cipher, const QByteArray &data, const QByteArray &passPhrase, const QByteArray &iv) const =0 |
virtual QByteArray | encrypt (Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv) const =0 |
QByteArray | pemHeader () const |
QByteArray | pemFooter () const |
Static Public Member Functions | |
static TlsKeyOpenSSL * | publicKeyFromX509 (X509 *x) |
Public Attributes | ||
union { | ||
EVP_PKEY * opaque | ||
RSA * rsa | ||
DSA * dsa | ||
DH * dh | ||
EC_KEY * ec | ||
EVP_PKEY * genericKey | ||
}; | ||
Additional Inherited Members | |
![]() | |
using | KeyType = QSsl::KeyType |
using | KeyAlgorithm = QSsl::KeyAlgorithm |
![]() | |
static QByteArray | pkcs8Header (bool encrypted) |
static QByteArray | pkcs8Footer (bool encrypted) |
static bool | isEncryptedPkcs8 (const QByteArray &der) |
![]() | |
bool | keyIsNull = true |
KeyType | keyType = QSsl::PublicKey |
KeyAlgorithm | keyAlgorithm = QSsl::Opaque |
Definition at line 48 of file qtlskey_openssl_p.h.
|
inline |
Definition at line 51 of file qtlskey_openssl_p.h.
References clear().
Referenced by publicKeyFromX509().
|
inline |
Definition at line 56 of file qtlskey_openssl_p.h.
References clear().
|
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).
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.
|
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).
Implements QTlsPrivate::TlsKey.
Definition at line 18 of file qtlskey_openssl.cpp.
References QTlsPrivate::TlsKeyBase::algorithm(), decodePem(), QByteArray::isEmpty(), QTlsPrivate::TlsKeyBase::keyAlgorithm, QTlsPrivate::TlsKeyBase::keyType, QTlsPrivate::TlsKeyBase::pemFromDer(), and QTlsPrivate::TlsKeyBase::type().
|
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).
Implements QTlsPrivate::TlsKey.
Definition at line 33 of file qtlskey_openssl.cpp.
References QTlsPrivate::TlsKeyBase::algorithm(), clear(), QByteArray::data(), QSsl::Dh, dh, QSsl::Dsa, dsa, QSsl::Ec, ec, genericKey, QByteArray::isEmpty(), 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, QByteArray::size(), and QTlsPrivate::TlsKeyBase::type().
Referenced by decodeDer().
|
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.
Implements QTlsPrivate::TlsKey.
Definition at line 479 of file qtlskey_openssl.cpp.
References QTlsPrivate::doCrypt().
|
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.
Implements QTlsPrivate::TlsKey.
Definition at line 96 of file qtlskey_openssl.cpp.
References QByteArray::at(), QByteArray::contains(), QByteArray::fromBase64(), header(), i, QByteArray::indexOf(), QMap< Key, T >::insert(), j, QByteArray::mid(), QTlsPrivate::TlsKey::pemFooter(), QTlsPrivate::TlsKey::pemHeader(), QTlsPrivate::TlsKeyBase::pkcs8Footer(), QTlsPrivate::TlsKeyBase::pkcs8Header(), QSsl::PublicKey, QString::size(), QByteArray::size(), QByteArray::trimmed(), and QTlsPrivate::TlsKeyBase::type().
|
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.
Implements QTlsPrivate::TlsKey.
Definition at line 485 of file qtlskey_openssl.cpp.
References QTlsPrivate::doCrypt().
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().
|
overridevirtual |
Initializes this key using the handle and type, taking the ownership of the 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().
|
overridevirtual |
If a TLS backend supports opaque keys, returns a native handle that this key was initialized with.
Implements QTlsPrivate::TlsKey.
Definition at line 202 of file qtlskey_openssl.cpp.
References QSsl::Dh, dh, QSsl::Dsa, dsa, QSsl::Ec, ec, QTlsPrivate::TlsKeyBase::keyAlgorithm, QSsl::Opaque, opaque, qCWarning, QSsl::Rsa, and rsa.
Referenced by fromHandle().
|
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.
|
static |
Definition at line 491 of file qtlskey_openssl.cpp.
References TlsKeyOpenSSL(), QSsl::Dsa, dsa, QSsl::Ec, ec, get_pubkey, QTlsPrivate::TlsKeyBase::keyAlgorithm, QTlsPrivate::TlsKeyBase::keyIsNull, 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().
|
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).
Implements QTlsPrivate::TlsKey.
Definition at line 255 of file qtlskey_openssl.cpp.
References QTlsPrivate::TlsKeyBase::algorithm(), QByteArray::data(), QSsl::Dh, dh, QSsl::Dsa, dsa, QSsl::Ec, ec, genericKey, QByteArray::isEmpty(), 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(), qScopeGuard(), QSsl::Rsa, rsa, QByteArray::size(), QSslSocket::supportsSsl(), QTlsPrivate::TlsKeyBase::type(), write_privatekey, and write_pubkey.
union { ... } QTlsPrivate::TlsKeyOpenSSL |
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* QTlsPrivate::TlsKeyOpenSSL::dsa |
Definition at line 85 of file qtlskey_openssl_p.h.
Referenced by clear(), decodePem(), fromEVP_PKEY(), handle(), length(), publicKeyFromX509(), and toPem().
EC_KEY* QTlsPrivate::TlsKeyOpenSSL::ec |
Definition at line 88 of file qtlskey_openssl_p.h.
Referenced by clear(), decodePem(), fromEVP_PKEY(), handle(), length(), publicKeyFromX509(), and toPem().
EVP_PKEY* QTlsPrivate::TlsKeyOpenSSL::genericKey |
Definition at line 90 of file qtlskey_openssl_p.h.
Referenced by clear(), decodePem(), length(), and toPem().
EVP_PKEY* QTlsPrivate::TlsKeyOpenSSL::opaque |
Definition at line 83 of file qtlskey_openssl_p.h.
Referenced by clear(), fromHandle(), and handle().
RSA* QTlsPrivate::TlsKeyOpenSSL::rsa |
Definition at line 84 of file qtlskey_openssl_p.h.
Referenced by clear(), decodePem(), fromEVP_PKEY(), handle(), length(), publicKeyFromX509(), and toPem().