8#include <QtNetwork/private/qsslsocket_p.h>
10#include <QtCore/qscopeguard.h>
11#include <QtCore/qbytearray.h>
12#include <QtCore/qiodevice.h>
13#include <QtCore/qdebug.h>
15#include <openssl/bn.h>
16#include <openssl/dh.h>
20#ifndef OPENSSL_NO_DEPRECATED_3_0
31 QSslSocketPrivate::ensureInitialized();
51 const BIGNUM *p =
nullptr;
52 const BIGNUM *q =
nullptr;
53 const BIGNUM *g =
nullptr;
58 if (residue == 11 || residue == 23)
59 status &= ~DH_NOT_SUITABLE_GENERATOR;
62 bad |= DH_CHECK_P_NOT_PRIME;
63 bad |= DH_CHECK_P_NOT_SAFE_PRIME;
64 bad |= DH_NOT_SUITABLE_GENERATOR;
66 return !(status & bad);
75#ifndef OPENSSL_NO_DEPRECATED_3_0
79 return DHParams::InvalidInputDataError;
81 const unsigned char *data =
reinterpret_cast<
const unsigned char *>(der.data());
82 const int len = der.size();
86 QSslSocketPrivate::ensureInitialized();
90 const auto dhRaii = qScopeGuard([dh] {
q_DH_free(dh
);});
95 return DHParams::UnsafeParametersError;
97 return DHParams::InvalidInputDataError;
102 qCWarning(lcTlsBackend,
"Diffie-Hellman parameters are not supported, because OpenSSL v3 was built with deprecated API removed");
104 return DHParams::NoError;
109#ifndef OPENSSL_NO_DEPRECATED_3_0
113 return DHParams::InvalidInputDataError;
117 QSslSocketPrivate::ensureInitialized();
119 BIO *bio = q_BIO_new_mem_buf(
const_cast<
char *>(pem.data()), pem.size());
121 return DHParams::InvalidInputDataError;
123 const auto bioRaii = qScopeGuard([bio]
132 const auto dhGuard = qScopeGuard([dh]
142 data->assign({buf, len});
144 return DHParams::InvalidInputDataError;
146 return DHParams::UnsafeParametersError;
149 return DHParams::InvalidInputDataError;
154 qCWarning(lcTlsBackend,
"Diffie-Hellman parameters are not supported, because OpenSSL v3 was built with deprecated API removed");
156 return DHParams::NoError;
int dhParametersFromDer(const QByteArray &derData, QByteArray *data) const override
int dhParametersFromPem(const QByteArray &pemData, QByteArray *data) const override
static QString getErrorsFromOpenSsl()
DH * q_d2i_DHparams(DH **a, const unsigned char **pp, long length)
int q_DH_check(DH *dh, int *codes)
BN_ULONG q_BN_mod_word(const BIGNUM *a, BN_ULONG w)
int q_i2d_DHparams(DH *a, unsigned char **p)
int q_BN_is_word(BIGNUM *a, BN_ULONG w)
DH * q_PEM_read_bio_DHparams(BIO *a, DH **b, pem_password_cb *c, void *d)
void q_DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
#define q_OPENSSL_free(addr)