8#include <QtNetwork/private/qsslkey_p.h>
10#include <QtNetwork/qsslsocket.h>
12#include <QtCore/qscopeguard.h>
27 QMap<QByteArray, QByteArray> headers;
50 void *phrase =
const_cast<char *
>(passPhrase.data());
52#ifdef OPENSSL_NO_DEPRECATED_3_0
103 int headerIndex = der.indexOf(
header);
104 int footerIndex = der.indexOf(footer, headerIndex +
header.size());
106 if (headerIndex == -1 || footerIndex == -1) {
109 headerIndex = der.indexOf(
header);
110 footerIndex = der.indexOf(footer, headerIndex +
header.size());
112 if (headerIndex == -1 || footerIndex == -1) {
115 headerIndex = der.indexOf(
header);
116 footerIndex = der.indexOf(footer, headerIndex +
header.size());
119 if (headerIndex == -1 || footerIndex == -1)
122 der = der.mid(headerIndex +
header.size(), footerIndex - (headerIndex +
header.size()));
124 if (der.contains(
"Proc-Type:")) {
127 while (
i < der.size()) {
128 int j = der.indexOf(
':',
i);
136 i = der.indexOf(
'\n',
j);
139 if (!
value.isEmpty())
142 bool hasCR = (
i && der[
i-1] ==
'\r');
146 }
while (
i < der.size() && (der.at(
i) ==
' ' || der.at(
i) ==
'\t'));
150 headers->insert(field,
value);
162#ifndef OPENSSL_NO_DEPRECATED_3_0
207#ifndef OPENSSL_NO_DEPRECATED_3_0
224 "This version of OpenSSL disabled direct manipulation with RSA/DSA/DH/EC_KEY structures, consider using QSsl::Opaque instead.");
234#ifndef OPENSSL_NO_DEPRECATED_3_0
260 const EVP_CIPHER *cipher =
nullptr;
262#ifndef OPENSSL_NO_DES
275#ifndef OPENSSL_NO_DEPRECATED_3_0
277#define write_pubkey(alg, key) q_PEM_write_bio_##alg##_PUBKEY(bio, key)
278#define write_privatekey(alg, key) \
279 q_PEM_write_bio_##alg##PrivateKey(bio, key, cipher, (uchar *)passPhrase.data(), \
280 passPhrase.size(), nullptr, nullptr)
284#define write_pubkey(alg, key) q_PEM_write_bio_PUBKEY(bio, genericKey)
285#define write_privatekey(alg, key) \
286 q_PEM_write_bio_PrivateKey_traditional(bio, genericKey, cipher, (uchar *)passPhrase.data(), passPhrase.size(), nullptr, nullptr)
306#ifdef OPENSSL_NO_DEPRECATED_3_0
319 passPhrase.size(),
nullptr,
nullptr)) {
338 char *
data =
nullptr;
351 EVP_PKEY *evpKey =
reinterpret_cast<EVP_PKEY *
>(
handle);
368#ifndef OPENSSL_NO_DEPRECATED_3_0
369#define get_key(key, alg) key = q_EVP_PKEY_get1_##alg(pkey)
371#define get_key(key, alg) q_EVP_PKEY_up_ref(pkey); genericKey = pkey;
414 const EVP_CIPHER *
type =
nullptr;
419#ifndef OPENSSL_NO_DES
424#ifndef OPENSSL_NO_DES
429#ifndef OPENSSL_NO_RC2
448 output.resize(
data.size() + EVP_MAX_BLOCK_LENGTH);
463 reinterpret_cast<const unsigned char *
>(
key.constData()),
464 reinterpret_cast<const unsigned char *
>(iv.constData()),
467 reinterpret_cast<unsigned char *
>(
output.data()), &
len,
468 reinterpret_cast<const unsigned char *
>(
data.constData()),
data.size());
470 reinterpret_cast<unsigned char *
>(
output.data()) +
len, &
i);
494 std::unique_ptr<TlsKeyOpenSSL> keyRaii(tlsKey);
498#ifndef OPENSSL_NO_DEPRECATED_3_0
500#define get_pubkey(keyName, alg) tlsKey->keyName = q_EVP_PKEY_get1_##alg(pkey)
504#define get_pubkey(a, b) tlsKey->genericKey = pkey
515 tlsKey->keyIsNull =
false;
516 }
else if (
keyType == EVP_PKEY_DSA) {
519 tlsKey->keyIsNull =
false;
521 }
else if (
keyType == EVP_PKEY_EC) {
524 tlsKey->keyIsNull =
false;
526 }
else if (
keyType == EVP_PKEY_DH) {
532#ifndef OPENSSL_NO_DEPRECATED_3_0
536 return keyRaii.release();
QByteArray trimmed() const &
static QByteArray fromBase64(const QByteArray &base64, Base64Options options=Base64Encoding)
QByteArray mid(qsizetype index, qsizetype len=-1) const &
static bool supportsSsl()
Returns true if this platform supports SSL; otherwise, returns false.
static void logAndClearErrorQueue()
KeyType type() const override
QByteArray pemFromDer(const QByteArray &der, const QMap< QByteArray, QByteArray > &headers) const override
KeyAlgorithm algorithm() const override
static QByteArray pkcs8Footer(bool encrypted)
static QByteArray pkcs8Header(bool encrypted)
bool isNull() const override
KeyAlgorithm keyAlgorithm
void decodePem(KeyType type, KeyAlgorithm algorithm, const QByteArray &pem, const QByteArray &passPhrase, bool deepClear) override
void fromHandle(Qt::HANDLE opaque, KeyType expectedType) override
void clear(bool deep) override
bool fromEVP_PKEY(EVP_PKEY *pkey)
QByteArray derFromPem(const QByteArray &pem, QMap< QByteArray, QByteArray > *headers) const override
void decodeDer(KeyType type, KeyAlgorithm algorithm, const QByteArray &der, const QByteArray &passPhrase, bool deepClear) override
QByteArray decrypt(Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv) const override
QByteArray toPem(const QByteArray &passPhrase) const override
int length() const override
Qt::HANDLE handle() const override
QByteArray encrypt(Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv) const override
static TlsKeyOpenSSL * publicKeyFromX509(X509 *x)
QByteArray pemHeader() const
QByteArray pemFooter() const
KeyType
Describes the two types of keys QSslKey supports.
KeyAlgorithm
Describes the different key algorithms supported by QSslKey.
Combined button and popup list for selecting options.
Namespace containing onternal types that TLS backends implement.
QByteArray doCrypt(QSslKeyPrivate::Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv, bool enc)
static QString header(const QString &name)
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qCWarning(category,...)
GLuint64 GLenum void * handle
GLint GLint GLint GLint GLint x
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
int q_EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *c)
const EVP_CIPHER * q_EVP_des_cbc()
const EVP_CIPHER * q_EVP_aes_192_cbc()
const EVP_CIPHER * q_EVP_aes_256_cbc()
int q_EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, const unsigned char *key, const unsigned char *iv, int enc)
int q_EVP_PKEY_base_id(EVP_PKEY *a)
DSA * q_PEM_read_bio_DSAPrivateKey(BIO *a, DSA **b, pem_password_cb *c, void *d)
int q_EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl)
EC_KEY * q_PEM_read_bio_EC_PUBKEY(BIO *a, EC_KEY **b, pem_password_cb *c, void *d)
const EVP_CIPHER * q_EVP_rc2_cbc()
RSA * q_PEM_read_bio_RSAPrivateKey(BIO *a, RSA **b, pem_password_cb *c, void *d)
#define q_BIO_get_mem_data(b, pp)
void q_EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *a)
int q_EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen)
DSA * q_PEM_read_bio_DSA_PUBKEY(BIO *a, DSA **b, pem_password_cb *c, void *d)
EVP_PKEY * q_PEM_read_bio_PrivateKey(BIO *a, EVP_PKEY **b, pem_password_cb *c, void *d)
EVP_PKEY * q_EVP_PKEY_new()
RSA * q_PEM_read_bio_RSA_PUBKEY(BIO *a, RSA **b, pem_password_cb *c, void *d)
void q_EVP_PKEY_free(EVP_PKEY *a)
void q_EC_KEY_free(EC_KEY *ecdh)
BIO * q_BIO_new(const BIO_METHOD *a)
const EVP_CIPHER * q_EVP_des_ede3_cbc()
EVP_PKEY * q_PEM_read_bio_PUBKEY(BIO *a, EVP_PKEY **b, pem_password_cb *c, void *d)
EVP_PKEY * q_X509_get_pubkey(X509 *a)
int q_EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
int q_EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, const unsigned char *key, const unsigned char *iv, int enc)
const BIO_METHOD * q_BIO_s_mem()
int q_PEM_write_bio_PUBKEY(BIO *a, EVP_PKEY *b)
int q_EVP_PKEY_set1_DH(EVP_PKEY *a, DH *b)
int q_EC_GROUP_get_degree(const EC_GROUP *g)
DH * q_EVP_PKEY_get1_DH(EVP_PKEY *a)
int q_PEM_write_bio_PrivateKey(BIO *a, EVP_PKEY *b, const EVP_CIPHER *c, unsigned char *d, int e, pem_password_cb *f, void *g)
const EVP_CIPHER * q_EVP_aes_128_cbc()
BIO * q_BIO_new_mem_buf(void *a, int b)
EVP_CIPHER_CTX * q_EVP_CIPHER_CTX_new()
int q_EVP_PKEY_type(int a)
const EC_GROUP * q_EC_KEY_get0_group(const EC_KEY *k)
int q_EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
EC_KEY * q_PEM_read_bio_ECPrivateKey(BIO *a, EC_KEY **b, pem_password_cb *c, void *d)
#define write_pubkey(alg, key)
#define write_privatekey(alg, key)
#define get_key(key, alg)
#define get_pubkey(keyName, alg)
QT_BEGIN_NAMESPACE typedef uchar * output