@@ -1,3985 +0,0 @@
1−commit 2d88fc0ce4ac76924a65ffd797183de9422ba672
2−Author: Andreas Rammhold <andreas@rammhold.de>
3−Date: Wed Mar 6 00:18:51 2019 +0100
4−
5− openssl1.1 compat
6−
7−diff --git a/config.tests/openssl/openssl.cpp b/config.tests/openssl/openssl.cpp
8−index 6c8a9e8f19..d33b62389c 100644
9−--- a/config.tests/openssl/openssl.cpp
10−+++ b/config.tests/openssl/openssl.cpp
11−@@ -39,8 +39,8 @@
12−
13− #include <openssl/opensslv.h>
14−
15−-#if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER-0 < 0x0090700fL || OPENSSL_VERSION_NUMBER-0 >= 0x10100000L
16−-# error "OpenSSL >= 0.9.7, and < 1.1.0 is required"
17−+#if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER-0 < 0x0090700fL
18−+# error "OpenSSL >= 0.9.7 is required"
19− #endif
20−
21− #include <openssl/ssl.h>
22−diff --git a/config.tests/openssl11/openssl.cpp b/config.tests/openssl11/openssl.cpp
23−new file mode 100644
24−index 0000000000..c20cc59deb
25−--- /dev/null
26−+++ b/config.tests/openssl11/openssl.cpp
27−@@ -0,0 +1,48 @@
28−+/****************************************************************************
29−+**
30−+** Copyright (C) 2017 The Qt Company Ltd.
31−+** Contact: https://www.qt.io/licensing/
32−+**
33−+** This file is part of the config.tests of the Qt Toolkit.
34−+**
35−+** $QT_BEGIN_LICENSE:LGPL$
36−+** Commercial License Usage
37−+** Licensees holding valid commercial Qt licenses may use this file in
38−+** accordance with the commercial license agreement provided with the
39−+** Software or, alternatively, in accordance with the terms contained in
40−+** a written agreement between you and The Qt Company. For licensing terms
41−+** and conditions see https://www.qt.io/terms-conditions. For further
42−+** information use the contact form at https://www.qt.io/contact-us.
43−+**
44−+** GNU Lesser General Public License Usage
45−+** Alternatively, this file may be used under the terms of the GNU Lesser
46−+** General Public License version 3 as published by the Free Software
47−+** Foundation and appearing in the file LICENSE.LGPL3 included in the
48−+** packaging of this file. Please review the following information to
49−+** ensure the GNU Lesser General Public License version 3 requirements
50−+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
51−+**
52−+** GNU General Public License Usage
53−+** Alternatively, this file may be used under the terms of the GNU
54−+** General Public License version 2.0 or (at your option) the GNU General
55−+** Public license version 3 or any later version approved by the KDE Free
56−+** Qt Foundation. The licenses are as published by the Free Software
57−+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
58−+** included in the packaging of this file. Please review the following
59−+** information to ensure the GNU General Public License requirements will
60−+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
61−+** https://www.gnu.org/licenses/gpl-3.0.html.
62−+**
63−+** $QT_END_LICENSE$
64−+**
65−+****************************************************************************/
66−+
67−+#include <openssl/opensslv.h>
68−+
69−+#if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER-0 < 0x10100000L
70−+# error "OpenSSL >= 1.1 is required"
71−+#endif
72−+
73−+int main()
74−+{
75−+}
76−diff --git a/config.tests/openssl11/openssl11.pro b/config.tests/openssl11/openssl11.pro
77−new file mode 100644
78−index 0000000000..a023aee4aa
79−--- /dev/null
80−+++ b/config.tests/openssl11/openssl11.pro
81−@@ -0,0 +1,2 @@
82−+SOURCES = openssl.cpp
83−+CONFIG -= x11 qt
84−diff --git a/src/network/configure.json b/src/network/configure.json
85−index 2cf90ed94b..a021c0734b 100644
86−--- a/src/network/configure.json
87−+++ b/src/network/configure.json
88−@@ -77,6 +77,17 @@
89− },
90− { "libs": "-lssl -lcrypto", "condition": "!config.win32" }
91− ]
92−+ },
93−+ "openssl11": {
94−+ "label": "OpenSSL v. 1.1 support",
95−+ "type": "compile",
96−+ "test": "openssl11",
97−+ "sources": [
98−+ {
99−+ "comment": "placeholder for OPENSSL_PATH",
100−+ "libs": ""
101−+ }
102−+ ]
103− }
104− },
105−
106−@@ -182,7 +193,7 @@
107− "enable": "input.openssl == 'yes' || input.openssl == 'linked' || input.openssl == 'runtime'",
108− "disable": "input.openssl == 'no' || input.ssl == 'no'",
109− "autoDetect": "!config.winrt",
110−- "condition": "!features.securetransport && (features.openssl-linked || libs.openssl_headers)",
111−+ "condition": "!features.securetransport && (features.openssl-linked || libs.openssl_headers || feature.opensslv11)",
112− "output": [
113− "privateFeature",
114− { "type": "publicQtConfig", "condition": "!features.openssl-linked" },
115−@@ -193,7 +204,7 @@
116− "label": " Qt directly linked to OpenSSL",
117− "enable": "input.openssl == 'linked'",
118− "disable": "input.openssl != 'linked'",
119−- "condition": "!features.securetransport && libs.openssl",
120−+ "condition": "!features.securetransport && (libs.openssl || feature.opensslv11)",
121− "output": [
122− "privateFeature",
123− { "type": "define", "name": "QT_LINKED_OPENSSL" }
124−@@ -213,6 +224,11 @@
125− "condition": "config.winrt || features.securetransport || features.openssl",
126− "output": [ "publicFeature", "feature" ]
127− },
128−+ "opensslv11": {
129−+ "label": "OpenSSL v. 1.1",
130−+ "condition": "libs.openssl11",
131−+ "output": ["publicFeature", "feature"]
132−+ },
133− "sctp": {
134− "label": "SCTP",
135− "autoDetect": false,
136−diff --git a/src/network/ssl/qsslcertificate_openssl.cpp b/src/network/ssl/qsslcertificate_openssl.cpp
137−index 28b7eda54a..71e514a025 100644
138−--- a/src/network/ssl/qsslcertificate_openssl.cpp
139−+++ b/src/network/ssl/qsslcertificate_openssl.cpp
140−@@ -1,6 +1,7 @@
141− /****************************************************************************
142− **
143−-** Copyright (C) 2016 The Qt Company Ltd.
144−+** Copyright (C) 2017 The Qt Company Ltd.
145−+** Copyright (C) 2016 Richard J. Moore <rich@kde.org>
146− ** Contact: https://www.qt.io/licensing/
147− **
148− ** This file is part of the QtNetwork module of the Qt Toolkit.
149−@@ -64,12 +65,14 @@ bool QSslCertificate::operator==(const QSslCertificate &other) const
150− uint qHash(const QSslCertificate &key, uint seed) Q_DECL_NOTHROW
151− {
152− if (X509 * const x509 = key.d->x509) {
153−- (void)q_X509_cmp(x509, x509); // populate x509->sha1_hash
154−- // (if someone knows a better way...)
155−- return qHashBits(x509->sha1_hash, SHA_DIGEST_LENGTH, seed);
156−- } else {
157−- return seed;
158−+ const EVP_MD *sha1 = q_EVP_sha1();
159−+ unsigned int len = 0;
160−+ unsigned char md[EVP_MAX_MD_SIZE];
161−+ q_X509_digest(x509, sha1, md, &len);
162−+ return qHashBits(md, len, seed);
163− }
164−+
165−+ return seed;
166− }
167−
168− bool QSslCertificate::isNull() const
169−@@ -89,8 +92,7 @@ QByteArray QSslCertificate::version() const
170− {
171− QMutexLocker lock(QMutexPool::globalInstanceGet(d.data()));
172− if (d->versionString.isEmpty() && d->x509)
173−- d->versionString =
174−- QByteArray::number(qlonglong(q_ASN1_INTEGER_get(d->x509->cert_info->version)) + 1);
175−+ d->versionString = QByteArray::number(qlonglong(q_X509_get_version(d->x509)) + 1);
176−
177− return d->versionString;
178− }
179−@@ -99,7 +101,7 @@ QByteArray QSslCertificate::serialNumber() const
180− {
181− QMutexLocker lock(QMutexPool::globalInstanceGet(d.data()));
182− if (d->serialNumberString.isEmpty() && d->x509) {
183−- ASN1_INTEGER *serialNumber = d->x509->cert_info->serialNumber;
184−+ ASN1_INTEGER *serialNumber = q_X509_get_serialNumber(d->x509);
185− QByteArray hexString;
186− hexString.reserve(serialNumber->length * 3);
187− for (int a = 0; a < serialNumber->length; ++a) {
188−@@ -199,14 +201,15 @@ QMultiMap<QSsl::AlternativeNameEntryType, QString> QSslCertificate::subjectAlter
189− continue;
190− }
191−
192−- const char *altNameStr = reinterpret_cast<const char *>(q_ASN1_STRING_data(genName->d.ia5));
193−+ const char *altNameStr = reinterpret_cast<const char *>(q_ASN1_STRING_get0_data(genName->d.ia5));
194− const QString altName = QString::fromLatin1(altNameStr, len);
195− if (genName->type == GEN_DNS)
196− result.insert(QSsl::DnsEntry, altName);
197− else if (genName->type == GEN_EMAIL)
198− result.insert(QSsl::EmailEntry, altName);
199− }
200−- q_sk_pop_free((STACK*)altNames, reinterpret_cast<void(*)(void*)>(q_sk_free));
201−+
202−+ q_OPENSSL_sk_pop_free((OPENSSL_STACK*)altNames, reinterpret_cast<void(*)(void*)>(q_OPENSSL_sk_free));
203− }
204−
205− return result;
206−@@ -235,25 +238,26 @@ QSslKey QSslCertificate::publicKey() const
207− QSslKey key;
208−
209− key.d->type = QSsl::PublicKey;
210−- X509_PUBKEY *xkey = d->x509->cert_info->key;
211−- EVP_PKEY *pkey = q_X509_PUBKEY_get(xkey);
212−+
213−+ EVP_PKEY *pkey = q_X509_get_pubkey(d->x509);
214− Q_ASSERT(pkey);
215−+ const int keyType = q_EVP_PKEY_type(q_EVP_PKEY_base_id(pkey));
216−
217−- if (q_EVP_PKEY_type(pkey->type) == EVP_PKEY_RSA) {
218−+ if (keyType == EVP_PKEY_RSA) {
219− key.d->rsa = q_EVP_PKEY_get1_RSA(pkey);
220− key.d->algorithm = QSsl::Rsa;
221− key.d->isNull = false;
222−- } else if (q_EVP_PKEY_type(pkey->type) == EVP_PKEY_DSA) {
223−+ } else if (keyType == EVP_PKEY_DSA) {
224− key.d->dsa = q_EVP_PKEY_get1_DSA(pkey);
225− key.d->algorithm = QSsl::Dsa;
226− key.d->isNull = false;
227− #ifndef OPENSSL_NO_EC
228−- } else if (q_EVP_PKEY_type(pkey->type) == EVP_PKEY_EC) {
229−+ } else if (keyType == EVP_PKEY_EC) {
230− key.d->ec = q_EVP_PKEY_get1_EC_KEY(pkey);
231− key.d->algorithm = QSsl::Ec;
232− key.d->isNull = false;
233− #endif
234−- } else if (q_EVP_PKEY_type(pkey->type) == EVP_PKEY_DH) {
235−+ } else if (keyType == EVP_PKEY_DH) {
236− // DH unsupported
237− } else {
238− // error?
239−@@ -275,7 +279,7 @@ static QVariant x509UnknownExtensionToValue(X509_EXTENSION *ext)
240− X509V3_EXT_METHOD *meth = const_cast<X509V3_EXT_METHOD *>(q_X509V3_EXT_get(ext));
241− if (!meth) {
242− ASN1_OCTET_STRING *value = q_X509_EXTENSION_get_data(ext);
243−- QByteArray result( reinterpret_cast<const char *>(q_ASN1_STRING_data(value)),
244−+ QByteArray result( reinterpret_cast<const char *>(q_ASN1_STRING_get0_data(value)),
245− q_ASN1_STRING_length(value));
246− return result;
247− }
248−@@ -371,7 +375,7 @@ static QVariant x509ExtensionToValue(X509_EXTENSION *ext)
249− continue;
250− }
251−
252−- const char *uriStr = reinterpret_cast<const char *>(q_ASN1_STRING_data(name->d.uniformResourceIdentifier));
253−+ const char *uriStr = reinterpret_cast<const char *>(q_ASN1_STRING_get0_data(name->d.uniformResourceIdentifier));
254− const QString uri = QString::fromUtf8(uriStr, len);
255−
256− result[QString::fromUtf8(QSslCertificatePrivate::asn1ObjectName(ad->method))] = uri;
257−@@ -380,11 +384,7 @@ static QVariant x509ExtensionToValue(X509_EXTENSION *ext)
258− }
259− }
260−
261−-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
262−- q_sk_pop_free((_STACK*)info, reinterpret_cast<void(*)(void*)>(q_sk_free));
263−-#else
264−- q_sk_pop_free((STACK*)info, reinterpret_cast<void(*)(void*)>(q_sk_free));
265−-#endif
266−+ q_OPENSSL_sk_pop_free((OPENSSL_STACK*)info, reinterpret_cast<void(*)(void *)>(q_OPENSSL_sk_free));
267− return result;
268− }
269− break;
270−@@ -607,7 +607,11 @@ static QMap<QByteArray, QString> _q_mapFromX509Name(X509_NAME *name)
271− unsigned char *data = 0;
272− int size = q_ASN1_STRING_to_UTF8(&data, q_X509_NAME_ENTRY_get_data(e));
273− info.insertMulti(name, QString::fromUtf8((char*)data, size));
274−+#if QT_CONFIG(opensslv11)
275−+ q_CRYPTO_free(data, 0, 0);
276−+#else
277− q_CRYPTO_free(data);
278−+#endif
279− }
280−
281− return info;
282−@@ -619,8 +623,9 @@ QSslCertificate QSslCertificatePrivate::QSslCertificate_from_X509(X509 *x509)
283− if (!x509 || !QSslSocket::supportsSsl())
284− return certificate;
285−
286−- ASN1_TIME *nbef = q_X509_get_notBefore(x509);
287−- ASN1_TIME *naft = q_X509_get_notAfter(x509);
288−+ ASN1_TIME *nbef = q_X509_getm_notBefore(x509);
289−+ ASN1_TIME *naft = q_X509_getm_notAfter(x509);
290−+
291− certificate.d->notValidBefore = q_getTimeFromASN1(nbef);
292− certificate.d->notValidAfter = q_getTimeFromASN1(naft);
293− certificate.d->null = false;
294−diff --git a/src/network/ssl/qsslcontext_openssl.cpp b/src/network/ssl/qsslcontext_openssl.cpp
295−index c92d8fc3f8..cef503710c 100644
296−--- a/src/network/ssl/qsslcontext_openssl.cpp
297−+++ b/src/network/ssl/qsslcontext_openssl.cpp
298−@@ -1,6 +1,6 @@
299− /****************************************************************************
300− **
301−-** Copyright (C) 2016 The Qt Company Ltd.
302−+** Copyright (C) 2017 The Qt Company Ltd.
303− ** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
304− ** Copyright (C) 2014 Governikus GmbH & Co. KG.
305− ** Contact: https://www.qt.io/licensing/
306−@@ -41,22 +41,14 @@
307−
308−
309− #include <QtNetwork/qsslsocket.h>
310−-#include <QtNetwork/qssldiffiehellmanparameters.h>
311−-#include <QtCore/qmutex.h>
312−
313− #include "private/qssl_p.h"
314− #include "private/qsslcontext_openssl_p.h"
315−-#include "private/qsslsocket_p.h"
316− #include "private/qsslsocket_openssl_p.h"
317− #include "private/qsslsocket_openssl_symbols_p.h"
318−-#include "private/qssldiffiehellmanparameters_p.h"
319−
320− QT_BEGIN_NAMESPACE
321−
322−-// defined in qsslsocket_openssl.cpp:
323−-extern int q_X509Callback(int ok, X509_STORE_CTX *ctx);
324−-extern QString getErrorsFromOpenSsl();
325−-
326− QSslContext::QSslContext()
327− : ctx(0),
328− pkey(0),
329−@@ -78,301 +70,6 @@ QSslContext::~QSslContext()
330− q_SSL_SESSION_free(session);
331− }
332−
333−-static inline QString msgErrorSettingEllipticCurves(const QString &why)
334−-{
335−- return QSslSocket::tr("Error when setting the elliptic curves (%1)").arg(why);
336−-}
337−-
338−-// static
339−-void QSslContext::initSslContext(QSslContext *sslContext, QSslSocket::SslMode mode, const QSslConfiguration &configuration, bool allowRootCertOnDemandLoading)
340−-{
341−- sslContext->sslConfiguration = configuration;
342−- sslContext->errorCode = QSslError::NoError;
343−-
344−- bool client = (mode == QSslSocket::SslClientMode);
345−-
346−- bool reinitialized = false;
347−- bool unsupportedProtocol = false;
348−-init_context:
349−- switch (sslContext->sslConfiguration.protocol()) {
350−- case QSsl::SslV2:
351−-#ifndef OPENSSL_NO_SSL2
352−- sslContext->ctx = q_SSL_CTX_new(client ? q_SSLv2_client_method() : q_SSLv2_server_method());
353−-#else
354−- // SSL 2 not supported by the system, but chosen deliberately -> error
355−- sslContext->ctx = 0;
356−- unsupportedProtocol = true;
357−-#endif
358−- break;
359−- case QSsl::SslV3:
360−-#ifndef OPENSSL_NO_SSL3_METHOD
361−- sslContext->ctx = q_SSL_CTX_new(client ? q_SSLv3_client_method() : q_SSLv3_server_method());
362−-#else
363−- // SSL 3 not supported by the system, but chosen deliberately -> error
364−- sslContext->ctx = 0;
365−- unsupportedProtocol = true;
366−-#endif
367−- break;
368−- case QSsl::SecureProtocols:
369−- // SSLv2 and SSLv3 will be disabled by SSL options
370−- // But we need q_SSLv23_server_method() otherwise AnyProtocol will be unable to connect on Win32.
371−- case QSsl::TlsV1SslV3:
372−- // SSLv2 will will be disabled by SSL options
373−- case QSsl::AnyProtocol:
374−- default:
375−- sslContext->ctx = q_SSL_CTX_new(client ? q_SSLv23_client_method() : q_SSLv23_server_method());
376−- break;
377−- case QSsl::TlsV1_0:
378−- sslContext->ctx = q_SSL_CTX_new(client ? q_TLSv1_client_method() : q_TLSv1_server_method());
379−- break;
380−- case QSsl::TlsV1_1:
381−-#if OPENSSL_VERSION_NUMBER >= 0x10001000L
382−- sslContext->ctx = q_SSL_CTX_new(client ? q_TLSv1_1_client_method() : q_TLSv1_1_server_method());
383−-#else
384−- // TLS 1.1 not supported by the system, but chosen deliberately -> error
385−- sslContext->ctx = 0;
386−- unsupportedProtocol = true;
387−-#endif
388−- break;
389−- case QSsl::TlsV1_2:
390−-#if OPENSSL_VERSION_NUMBER >= 0x10001000L
391−- sslContext->ctx = q_SSL_CTX_new(client ? q_TLSv1_2_client_method() : q_TLSv1_2_server_method());
392−-#else
393−- // TLS 1.2 not supported by the system, but chosen deliberately -> error
394−- sslContext->ctx = 0;
395−- unsupportedProtocol = true;
396−-#endif
397−- break;
398−- case QSsl::TlsV1_0OrLater:
399−- // Specific protocols will be specified via SSL options.
400−- sslContext->ctx = q_SSL_CTX_new(client ? q_SSLv23_client_method() : q_SSLv23_server_method());
401−- break;
402−- case QSsl::TlsV1_1OrLater:
403−- case QSsl::TlsV1_2OrLater:
404−-#if OPENSSL_VERSION_NUMBER >= 0x10001000L
405−- // Specific protocols will be specified via SSL options.
406−- sslContext->ctx = q_SSL_CTX_new(client ? q_SSLv23_client_method() : q_SSLv23_server_method());
407−-#else
408−- // TLS 1.1/1.2 not supported by the system, but chosen deliberately -> error
409−- sslContext->ctx = 0;
410−- unsupportedProtocol = true;
411−-#endif
412−- break;
413−- }
414−-
415−- if (!sslContext->ctx) {
416−- // After stopping Flash 10 the SSL library looses its ciphers. Try re-adding them
417−- // by re-initializing the library.
418−- if (!reinitialized) {
419−- reinitialized = true;
420−- if (q_SSL_library_init() == 1)
421−- goto init_context;
422−- }
423−-
424−- sslContext->errorStr = QSslSocket::tr("Error creating SSL context (%1)").arg(
425−- unsupportedProtocol ? QSslSocket::tr("unsupported protocol") : QSslSocketBackendPrivate::getErrorsFromOpenSsl()
426−- );
427−- sslContext->errorCode = QSslError::UnspecifiedError;
428−- return;
429−- }
430−-
431−- // Enable bug workarounds.
432−- long options = QSslSocketBackendPrivate::setupOpenSslOptions(configuration.protocol(), configuration.d->sslOptions);
433−- q_SSL_CTX_set_options(sslContext->ctx, options);
434−-
435−-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
436−- // Tell OpenSSL to release memory early
437−- // http://www.openssl.org/docs/ssl/SSL_CTX_set_mode.html
438−- if (q_SSLeay() >= 0x10000000L)
439−- q_SSL_CTX_set_mode(sslContext->ctx, SSL_MODE_RELEASE_BUFFERS);
440−-#endif
441−-
442−- // Initialize ciphers
443−- QByteArray cipherString;
444−- bool first = true;
445−- QList<QSslCipher> ciphers = sslContext->sslConfiguration.ciphers();
446−- if (ciphers.isEmpty())
447−- ciphers = QSslSocketPrivate::defaultCiphers();
448−- for (const QSslCipher &cipher : qAsConst(ciphers)) {
449−- if (first)
450−- first = false;
451−- else
452−- cipherString.append(':');
453−- cipherString.append(cipher.name().toLatin1());
454−- }
455−-
456−- if (!q_SSL_CTX_set_cipher_list(sslContext->ctx, cipherString.data())) {
457−- sslContext->errorStr = QSslSocket::tr("Invalid or empty cipher list (%1)").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
458−- sslContext->errorCode = QSslError::UnspecifiedError;
459−- return;
460−- }
461−-
462−- const QDateTime now = QDateTime::currentDateTimeUtc();
463−-
464−- // Add all our CAs to this store.
465−- const auto caCertificates = sslContext->sslConfiguration.caCertificates();
466−- for (const QSslCertificate &caCertificate : caCertificates) {
467−- // From https://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html:
468−- //
469−- // If several CA certificates matching the name, key identifier, and
470−- // serial number condition are available, only the first one will be
471−- // examined. This may lead to unexpected results if the same CA
472−- // certificate is available with different expiration dates. If a
473−- // ``certificate expired'' verification error occurs, no other
474−- // certificate will be searched. Make sure to not have expired
475−- // certificates mixed with valid ones.
476−- //
477−- // See also: QSslSocketBackendPrivate::verify()
478−- if (caCertificate.expiryDate() >= now) {
479−- q_X509_STORE_add_cert(q_SSL_CTX_get_cert_store(sslContext->ctx), (X509 *)caCertificate.handle());
480−- }
481−- }
482−-
483−- if (QSslSocketPrivate::s_loadRootCertsOnDemand && allowRootCertOnDemandLoading) {
484−- // tell OpenSSL the directories where to look up the root certs on demand
485−- const QList<QByteArray> unixDirs = QSslSocketPrivate::unixRootCertDirectories();
486−- for (const QByteArray &unixDir : unixDirs)
487−- q_SSL_CTX_load_verify_locations(sslContext->ctx, 0, unixDir.constData());
488−- }
489−-
490−- if (!sslContext->sslConfiguration.localCertificate().isNull()) {
491−- // Require a private key as well.
492−- if (sslContext->sslConfiguration.privateKey().isNull()) {
493−- sslContext->errorStr = QSslSocket::tr("Cannot provide a certificate with no key, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
494−- sslContext->errorCode = QSslError::UnspecifiedError;
495−- return;
496−- }
497−-
498−- // Load certificate
499−- if (!q_SSL_CTX_use_certificate(sslContext->ctx, (X509 *)sslContext->sslConfiguration.localCertificate().handle())) {
500−- sslContext->errorStr = QSslSocket::tr("Error loading local certificate, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
501−- sslContext->errorCode = QSslError::UnspecifiedError;
502−- return;
503−- }
504−-
505−- if (configuration.d->privateKey.algorithm() == QSsl::Opaque) {
506−- sslContext->pkey = reinterpret_cast<EVP_PKEY *>(configuration.d->privateKey.handle());
507−- } else {
508−- // Load private key
509−- sslContext->pkey = q_EVP_PKEY_new();
510−- // before we were using EVP_PKEY_assign_R* functions and did not use EVP_PKEY_free.
511−- // this lead to a memory leak. Now we use the *_set1_* functions which do not
512−- // take ownership of the RSA/DSA key instance because the QSslKey already has ownership.
513−- if (configuration.d->privateKey.algorithm() == QSsl::Rsa)
514−- q_EVP_PKEY_set1_RSA(sslContext->pkey, reinterpret_cast<RSA *>(configuration.d->privateKey.handle()));
515−- else if (configuration.d->privateKey.algorithm() == QSsl::Dsa)
516−- q_EVP_PKEY_set1_DSA(sslContext->pkey, reinterpret_cast<DSA *>(configuration.d->privateKey.handle()));
517−-#ifndef OPENSSL_NO_EC
518−- else if (configuration.d->privateKey.algorithm() == QSsl::Ec)
519−- q_EVP_PKEY_set1_EC_KEY(sslContext->pkey, reinterpret_cast<EC_KEY *>(configuration.d->privateKey.handle()));
520−-#endif
521−- }
522−-
523−- if (!q_SSL_CTX_use_PrivateKey(sslContext->ctx, sslContext->pkey)) {
524−- sslContext->errorStr = QSslSocket::tr("Error loading private key, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
525−- sslContext->errorCode = QSslError::UnspecifiedError;
526−- return;
527−- }
528−- if (configuration.d->privateKey.algorithm() == QSsl::Opaque)
529−- sslContext->pkey = 0; // Don't free the private key, it belongs to QSslKey
530−-
531−- // Check if the certificate matches the private key.
532−- if (!q_SSL_CTX_check_private_key(sslContext->ctx)) {
533−- sslContext->errorStr = QSslSocket::tr("Private key does not certify public key, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
534−- sslContext->errorCode = QSslError::UnspecifiedError;
535−- return;
536−- }
537−-
538−- // If we have any intermediate certificates then we need to add them to our chain
539−- bool first = true;
540−- for (const QSslCertificate &cert : qAsConst(configuration.d->localCertificateChain)) {
541−- if (first) {
542−- first = false;
543−- continue;
544−- }
545−- q_SSL_CTX_ctrl(sslContext->ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0,
546−- q_X509_dup(reinterpret_cast<X509 *>(cert.handle())));
547−- }
548−- }
549−-
550−- // Initialize peer verification.
551−- if (sslContext->sslConfiguration.peerVerifyMode() == QSslSocket::VerifyNone) {
552−- q_SSL_CTX_set_verify(sslContext->ctx, SSL_VERIFY_NONE, 0);
553−- } else {
554−- q_SSL_CTX_set_verify(sslContext->ctx, SSL_VERIFY_PEER, q_X509Callback);
555−- }
556−-
557−- // Set verification depth.
558−- if (sslContext->sslConfiguration.peerVerifyDepth() != 0)
559−- q_SSL_CTX_set_verify_depth(sslContext->ctx, sslContext->sslConfiguration.peerVerifyDepth());
560−-
561−- // set persisted session if the user set it
562−- if (!configuration.sessionTicket().isEmpty())
563−- sslContext->setSessionASN1(configuration.sessionTicket());
564−-
565−- // Set temp DH params
566−- QSslDiffieHellmanParameters dhparams = configuration.diffieHellmanParameters();
567−-
568−- if (!dhparams.isValid()) {
569−- sslContext->errorStr = QSslSocket::tr("Diffie-Hellman parameters are not valid");
570−- sslContext->errorCode = QSslError::UnspecifiedError;
571−- return;
572−- }
573−-
574−- if (!dhparams.isEmpty()) {
575−- const QByteArray ¶ms = dhparams.d->derData;
576−- const char *ptr = params.constData();
577−- DH *dh = q_d2i_DHparams(NULL, reinterpret_cast<const unsigned char **>(&ptr), params.length());
578−- if (dh == NULL)
579−- qFatal("q_d2i_DHparams failed to convert QSslDiffieHellmanParameters to DER form");
580−- q_SSL_CTX_set_tmp_dh(sslContext->ctx, dh);
581−- q_DH_free(dh);
582−- }
583−-
584−-#ifndef OPENSSL_NO_EC
585−-#if OPENSSL_VERSION_NUMBER >= 0x10002000L
586−- if (q_SSLeay() >= 0x10002000L) {
587−- q_SSL_CTX_ctrl(sslContext->ctx, SSL_CTRL_SET_ECDH_AUTO, 1, NULL);
588−- } else
589−-#endif
590−- {
591−- // Set temp ECDH params
592−- EC_KEY *ecdh = 0;
593−- ecdh = q_EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
594−- q_SSL_CTX_set_tmp_ecdh(sslContext->ctx, ecdh);
595−- q_EC_KEY_free(ecdh);
596−- }
597−-#endif // OPENSSL_NO_EC
598−-
599−-#if OPENSSL_VERSION_NUMBER >= 0x10001000L && !defined(OPENSSL_NO_PSK)
600−- if (!client)
601−- q_SSL_CTX_use_psk_identity_hint(sslContext->ctx, sslContext->sslConfiguration.preSharedKeyIdentityHint().constData());
602−-#endif // OPENSSL_VERSION_NUMBER >= 0x10001000L && !defined(OPENSSL_NO_PSK)
603−-
604−- const QVector<QSslEllipticCurve> qcurves = sslContext->sslConfiguration.ellipticCurves();
605−- if (!qcurves.isEmpty()) {
606−-#if OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(OPENSSL_NO_EC)
607−- // Set the curves to be used
608−- if (q_SSLeay() >= 0x10002000L) {
609−- // SSL_CTX_ctrl wants a non-const pointer as last argument,
610−- // but let's avoid a copy into a temporary array
611−- if (!q_SSL_CTX_ctrl(sslContext->ctx,
612−- SSL_CTRL_SET_CURVES,
613−- qcurves.size(),
614−- const_cast<int *>(reinterpret_cast<const int *>(qcurves.data())))) {
615−- sslContext->errorStr = msgErrorSettingEllipticCurves(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
616−- sslContext->errorCode = QSslError::UnspecifiedError;
617−- }
618−- } else
619−-#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(OPENSSL_NO_EC)
620−- {
621−- // specific curves requested, but not possible to set -> error
622−- sslContext->errorStr = msgErrorSettingEllipticCurves(QSslSocket::tr("OpenSSL version too old, need at least v1.0.2"));
623−- sslContext->errorCode = QSslError::UnspecifiedError;
624−- }
625−- }
626−-}
627−-
628− QSslContext* QSslContext::fromConfiguration(QSslSocket::SslMode mode, const QSslConfiguration &configuration, bool allowRootCertOnDemandLoading)
629− {
630− QSslContext *sslContext = new QSslContext();
631−@@ -463,7 +160,7 @@ SSL* QSslContext::createSsl()
632− m_npnContext.len = m_supportedNPNVersions.count();
633− m_npnContext.status = QSslConfiguration::NextProtocolNegotiationNone;
634− #if OPENSSL_VERSION_NUMBER >= 0x10002000L
635−- if (q_SSLeay() >= 0x10002000L) {
636−+ if (QSslSocket::sslLibraryVersionNumber() >= 0x10002000L) {
637− // Callback's type has a parameter 'const unsigned char ** out'
638− // since it was introduced in 1.0.2. Internally, OpenSSL's own code
639− // (tests/examples) cast it to unsigned char * (since it's 'out').
640−@@ -508,7 +205,7 @@ bool QSslContext::cacheSession(SSL* ssl)
641− unsigned char *data = reinterpret_cast<unsigned char *>(m_sessionASN1.data());
642− if (!q_i2d_SSL_SESSION(session, &data))
643− qCWarning(lcSsl, "could not store persistent version of SSL session");
644−- m_sessionTicketLifeTimeHint = session->tlsext_tick_lifetime_hint;
645−+ m_sessionTicketLifeTimeHint = q_SSL_SESSION_get_ticket_lifetime_hint(session);
646− }
647− }
648−
649−diff --git a/src/network/ssl/qsslcontext_openssl11.cpp b/src/network/ssl/qsslcontext_openssl11.cpp
650−new file mode 100644
651−index 0000000000..787b6ae3f5
652−--- /dev/null
653−+++ b/src/network/ssl/qsslcontext_openssl11.cpp
654−@@ -0,0 +1,277 @@
655−+/****************************************************************************
656−+**
657−+** Copyright (C) 2017 The Qt Company Ltd.
658−+** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
659−+** Copyright (C) 2014 Governikus GmbH & Co. KG.
660−+** Copyright (C) 2016 Richard J. Moore <rich@kde.org>
661−+** Contact: https://www.qt.io/licensing/
662−+**
663−+** This file is part of the QtNetwork module of the Qt Toolkit.
664−+**
665−+** $QT_BEGIN_LICENSE:LGPL$
666−+** Commercial License Usage
667−+** Licensees holding valid commercial Qt licenses may use this file in
668−+** accordance with the commercial license agreement provided with the
669−+** Software or, alternatively, in accordance with the terms contained in
670−+** a written agreement between you and The Qt Company. For licensing terms
671−+** and conditions see https://www.qt.io/terms-conditions. For further
672−+** information use the contact form at https://www.qt.io/contact-us.
673−+**
674−+** GNU Lesser General Public License Usage
675−+** Alternatively, this file may be used under the terms of the GNU Lesser
676−+** General Public License version 3 as published by the Free Software
677−+** Foundation and appearing in the file LICENSE.LGPL3 included in the
678−+** packaging of this file. Please review the following information to
679−+** ensure the GNU Lesser General Public License version 3 requirements
680−+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
681−+**
682−+** GNU General Public License Usage
683−+** Alternatively, this file may be used under the terms of the GNU
684−+** General Public License version 2.0 or (at your option) the GNU General
685−+** Public license version 3 or any later version approved by the KDE Free
686−+** Qt Foundation. The licenses are as published by the Free Software
687−+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
688−+** included in the packaging of this file. Please review the following
689−+** information to ensure the GNU General Public License requirements will
690−+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
691−+** https://www.gnu.org/licenses/gpl-3.0.html.
692−+**
693−+** $QT_END_LICENSE$
694−+**
695−+****************************************************************************/
696−+
697−+
698−+#include <QtNetwork/qsslsocket.h>
699−+#include <QtNetwork/qssldiffiehellmanparameters.h>
700−+
701−+#include "private/qssl_p.h"
702−+#include "private/qsslcontext_openssl_p.h"
703−+#include "private/qsslsocket_p.h"
704−+#include "private/qsslsocket_openssl_p.h"
705−+#include "private/qsslsocket_openssl_symbols_p.h"
706−+#include "private/qssldiffiehellmanparameters_p.h"
707−+
708−+#include <vector>
709−+
710−+QT_BEGIN_NAMESPACE
711−+
712−+// defined in qsslsocket_openssl.cpp:
713−+extern int q_X509Callback(int ok, X509_STORE_CTX *ctx);
714−+extern QString getErrorsFromOpenSsl();
715−+
716−+static inline QString msgErrorSettingEllipticCurves(const QString &why)
717−+{
718−+ return QSslSocket::tr("Error when setting the elliptic curves (%1)").arg(why);
719−+}
720−+
721−+// static
722−+void QSslContext::initSslContext(QSslContext *sslContext, QSslSocket::SslMode mode, const QSslConfiguration &configuration, bool allowRootCertOnDemandLoading)
723−+{
724−+ sslContext->sslConfiguration = configuration;
725−+ sslContext->errorCode = QSslError::NoError;
726−+
727−+ bool client = (mode == QSslSocket::SslClientMode);
728−+
729−+ bool reinitialized = false;
730−+ bool unsupportedProtocol = false;
731−+init_context:
732−+ if (sslContext->sslConfiguration.protocol() == QSsl::SslV2) {
733−+ // SSL 2 is no longer supported, but chosen deliberately -> error
734−+ sslContext->ctx = nullptr;
735−+ unsupportedProtocol = true;
736−+ } else {
737−+ // The ssl options will actually control the supported methods
738−+ sslContext->ctx = q_SSL_CTX_new(client ? q_TLS_client_method() : q_TLS_server_method());
739−+ }
740−+
741−+ if (!sslContext->ctx) {
742−+ // After stopping Flash 10 the SSL library loses its ciphers. Try re-adding them
743−+ // by re-initializing the library.
744−+ if (!reinitialized) {
745−+ reinitialized = true;
746−+ if (q_OPENSSL_init_ssl(0, nullptr) == 1)
747−+ goto init_context;
748−+ }
749−+
750−+ sslContext->errorStr = QSslSocket::tr("Error creating SSL context (%1)").arg(
751−+ unsupportedProtocol ? QSslSocket::tr("unsupported protocol") : QSslSocketBackendPrivate::getErrorsFromOpenSsl()
752−+ );
753−+ sslContext->errorCode = QSslError::UnspecifiedError;
754−+ return;
755−+ }
756−+
757−+ // Enable bug workarounds.
758−+ long options = QSslSocketBackendPrivate::setupOpenSslOptions(configuration.protocol(), configuration.d->sslOptions);
759−+ q_SSL_CTX_set_options(sslContext->ctx, options);
760−+
761−+ // Tell OpenSSL to release memory early
762−+ // http://www.openssl.org/docs/ssl/SSL_CTX_set_mode.html
763−+ q_SSL_CTX_set_mode(sslContext->ctx, SSL_MODE_RELEASE_BUFFERS);
764−+
765−+ // Initialize ciphers
766−+ QByteArray cipherString;
767−+ bool first = true;
768−+ QList<QSslCipher> ciphers = sslContext->sslConfiguration.ciphers();
769−+ if (ciphers.isEmpty())
770−+ ciphers = QSslSocketPrivate::defaultCiphers();
771−+ for (const QSslCipher &cipher : qAsConst(ciphers)) {
772−+ if (first)
773−+ first = false;
774−+ else
775−+ cipherString.append(':');
776−+ cipherString.append(cipher.name().toLatin1());
777−+ }
778−+
779−+ if (!q_SSL_CTX_set_cipher_list(sslContext->ctx, cipherString.data())) {
780−+ sslContext->errorStr = QSslSocket::tr("Invalid or empty cipher list (%1)").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
781−+ sslContext->errorCode = QSslError::UnspecifiedError;
782−+ return;
783−+ }
784−+
785−+ const QDateTime now = QDateTime::currentDateTimeUtc();
786−+
787−+ // Add all our CAs to this store.
788−+ const auto caCertificates = sslContext->sslConfiguration.caCertificates();
789−+ for (const QSslCertificate &caCertificate : caCertificates) {
790−+ // From https://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html:
791−+ //
792−+ // If several CA certificates matching the name, key identifier, and
793−+ // serial number condition are available, only the first one will be
794−+ // examined. This may lead to unexpected results if the same CA
795−+ // certificate is available with different expiration dates. If a
796−+ // ``certificate expired'' verification error occurs, no other
797−+ // certificate will be searched. Make sure to not have expired
798−+ // certificates mixed with valid ones.
799−+ //
800−+ // See also: QSslSocketBackendPrivate::verify()
801−+ if (caCertificate.expiryDate() >= now) {
802−+ q_X509_STORE_add_cert(q_SSL_CTX_get_cert_store(sslContext->ctx), (X509 *)caCertificate.handle());
803−+ }
804−+ }
805−+
806−+ if (QSslSocketPrivate::s_loadRootCertsOnDemand && allowRootCertOnDemandLoading) {
807−+ // tell OpenSSL the directories where to look up the root certs on demand
808−+ const QList<QByteArray> unixDirs = QSslSocketPrivate::unixRootCertDirectories();
809−+ for (const QByteArray &unixDir : unixDirs)
810−+ q_SSL_CTX_load_verify_locations(sslContext->ctx, nullptr, unixDir.constData());
811−+ }
812−+
813−+ if (!sslContext->sslConfiguration.localCertificate().isNull()) {
814−+ // Require a private key as well.
815−+ if (sslContext->sslConfiguration.privateKey().isNull()) {
816−+ sslContext->errorStr = QSslSocket::tr("Cannot provide a certificate with no key, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
817−+ sslContext->errorCode = QSslError::UnspecifiedError;
818−+ return;
819−+ }
820−+
821−+ // Load certificate
822−+ if (!q_SSL_CTX_use_certificate(sslContext->ctx, (X509 *)sslContext->sslConfiguration.localCertificate().handle())) {
823−+ sslContext->errorStr = QSslSocket::tr("Error loading local certificate, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
824−+ sslContext->errorCode = QSslError::UnspecifiedError;
825−+ return;
826−+ }
827−+
828−+ if (configuration.d->privateKey.algorithm() == QSsl::Opaque) {
829−+ sslContext->pkey = reinterpret_cast<EVP_PKEY *>(configuration.d->privateKey.handle());
830−+ } else {
831−+ // Load private key
832−+ sslContext->pkey = q_EVP_PKEY_new();
833−+ // before we were using EVP_PKEY_assign_R* functions and did not use EVP_PKEY_free.
834−+ // this lead to a memory leak. Now we use the *_set1_* functions which do not
835−+ // take ownership of the RSA/DSA key instance because the QSslKey already has ownership.
836−+ if (configuration.d->privateKey.algorithm() == QSsl::Rsa)
837−+ q_EVP_PKEY_set1_RSA(sslContext->pkey, reinterpret_cast<RSA *>(configuration.d->privateKey.handle()));
838−+ else if (configuration.d->privateKey.algorithm() == QSsl::Dsa)
839−+ q_EVP_PKEY_set1_DSA(sslContext->pkey, reinterpret_cast<DSA *>(configuration.d->privateKey.handle()));
840−+#ifndef OPENSSL_NO_EC
841−+ else if (configuration.d->privateKey.algorithm() == QSsl::Ec)
842−+ q_EVP_PKEY_set1_EC_KEY(sslContext->pkey, reinterpret_cast<EC_KEY *>(configuration.d->privateKey.handle()));
843−+#endif
844−+ }
845−+
846−+ if (!q_SSL_CTX_use_PrivateKey(sslContext->ctx, sslContext->pkey)) {
847−+ sslContext->errorStr = QSslSocket::tr("Error loading private key, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
848−+ sslContext->errorCode = QSslError::UnspecifiedError;
849−+ return;
850−+ }
851−+ if (configuration.d->privateKey.algorithm() == QSsl::Opaque)
852−+ sslContext->pkey = nullptr; // Don't free the private key, it belongs to QSslKey
853−+
854−+ // Check if the certificate matches the private key.
855−+ if (!q_SSL_CTX_check_private_key(sslContext->ctx)) {
856−+ sslContext->errorStr = QSslSocket::tr("Private key does not certify public key, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
857−+ sslContext->errorCode = QSslError::UnspecifiedError;
858−+ return;
859−+ }
860−+
861−+ // If we have any intermediate certificates then we need to add them to our chain
862−+ bool first = true;
863−+ for (const QSslCertificate &cert : qAsConst(configuration.d->localCertificateChain)) {
864−+ if (first) {
865−+ first = false;
866−+ continue;
867−+ }
868−+ q_SSL_CTX_ctrl(sslContext->ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0,
869−+ q_X509_dup(reinterpret_cast<X509 *>(cert.handle())));
870−+ }
871−+ }
872−+
873−+ // Initialize peer verification.
874−+ if (sslContext->sslConfiguration.peerVerifyMode() == QSslSocket::VerifyNone) {
875−+ q_SSL_CTX_set_verify(sslContext->ctx, SSL_VERIFY_NONE, nullptr);
876−+ } else {
877−+ q_SSL_CTX_set_verify(sslContext->ctx, SSL_VERIFY_PEER, q_X509Callback);
878−+ }
879−+
880−+ // Set verification depth.
881−+ if (sslContext->sslConfiguration.peerVerifyDepth() != 0)
882−+ q_SSL_CTX_set_verify_depth(sslContext->ctx, sslContext->sslConfiguration.peerVerifyDepth());
883−+
884−+ // set persisted session if the user set it
885−+ if (!configuration.sessionTicket().isEmpty())
886−+ sslContext->setSessionASN1(configuration.sessionTicket());
887−+
888−+ // Set temp DH params
889−+ QSslDiffieHellmanParameters dhparams = configuration.diffieHellmanParameters();
890−+
891−+ if (!dhparams.isValid()) {
892−+ sslContext->errorStr = QSslSocket::tr("Diffie-Hellman parameters are not valid");
893−+ sslContext->errorCode = QSslError::UnspecifiedError;
894−+ return;
895−+ }
896−+
897−+ if (!dhparams.isEmpty()) {
898−+ const QByteArray ¶ms = dhparams.d->derData;
899−+ const char *ptr = params.constData();
900−+ DH *dh = q_d2i_DHparams(NULL, reinterpret_cast<const unsigned char **>(&ptr), params.length());
901−+ if (dh == NULL)
902−+ qFatal("q_d2i_DHparams failed to convert QSslDiffieHellmanParameters to DER form");
903−+ q_SSL_CTX_set_tmp_dh(sslContext->ctx, dh);
904−+ q_DH_free(dh);
905−+ }
906−+
907−+#ifndef OPENSSL_NO_PSK
908−+ if (!client)
909−+ q_SSL_CTX_use_psk_identity_hint(sslContext->ctx, sslContext->sslConfiguration.preSharedKeyIdentityHint().constData());
910−+#endif // !OPENSSL_NO_PSK
911−+
912−+ const QVector<QSslEllipticCurve> qcurves = sslContext->sslConfiguration.ellipticCurves();
913−+ if (!qcurves.isEmpty()) {
914−+#ifdef OPENSSL_NO_EC
915−+ sslContext->errorStr = msgErrorSettingEllipticCurves(QSslSocket::tr("OpenSSL version with disabled elliptic curves"));
916−+ sslContext->errorCode = QSslError::UnspecifiedError;
917−+#else
918−+ // Set the curves to be used.
919−+ std::vector<int> curves;
920−+ curves.reserve(qcurves.size());
921−+ for (const auto &sslCurve : qcurves)
922−+ curves.push_back(sslCurve.id);
923−+ if (!q_SSL_CTX_ctrl(sslContext->ctx, SSL_CTRL_SET_CURVES, long(curves.size()), &curves[0])) {
924−+ sslContext->errorStr = msgErrorSettingEllipticCurves(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
925−+ sslContext->errorCode = QSslError::UnspecifiedError;
926−+ }
927−+#endif
928−+ }
929−+}
930−+
931−+QT_END_NAMESPACE
932−diff --git a/src/network/ssl/qsslcontext_opensslpre11.cpp b/src/network/ssl/qsslcontext_opensslpre11.cpp
933−new file mode 100644
934−index 0000000000..9c01c2f2dc
935−--- /dev/null
936−+++ b/src/network/ssl/qsslcontext_opensslpre11.cpp
937−@@ -0,0 +1,354 @@
938−+/****************************************************************************
939−+**
940−+** Copyright (C) 2017 The Qt Company Ltd.
941−+** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
942−+** Copyright (C) 2014 Governikus GmbH & Co. KG.
943−+** Contact: https://www.qt.io/licensing/
944−+**
945−+** This file is part of the QtNetwork module of the Qt Toolkit.
946−+**
947−+** $QT_BEGIN_LICENSE:LGPL$
948−+** Commercial License Usage
949−+** Licensees holding valid commercial Qt licenses may use this file in
950−+** accordance with the commercial license agreement provided with the
951−+** Software or, alternatively, in accordance with the terms contained in
952−+** a written agreement between you and The Qt Company. For licensing terms
953−+** and conditions see https://www.qt.io/terms-conditions. For further
954−+** information use the contact form at https://www.qt.io/contact-us.
955−+**
956−+** GNU Lesser General Public License Usage
957−+** Alternatively, this file may be used under the terms of the GNU Lesser
958−+** General Public License version 3 as published by the Free Software
959−+** Foundation and appearing in the file LICENSE.LGPL3 included in the
960−+** packaging of this file. Please review the following information to
961−+** ensure the GNU Lesser General Public License version 3 requirements
962−+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
963−+**
964−+** GNU General Public License Usage
965−+** Alternatively, this file may be used under the terms of the GNU
966−+** General Public License version 2.0 or (at your option) the GNU General
967−+** Public license version 3 or any later version approved by the KDE Free
968−+** Qt Foundation. The licenses are as published by the Free Software
969−+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
970−+** included in the packaging of this file. Please review the following
971−+** information to ensure the GNU General Public License requirements will
972−+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
973−+** https://www.gnu.org/licenses/gpl-3.0.html.
974−+**
975−+** $QT_END_LICENSE$
976−+**
977−+****************************************************************************/
978−+
979−+
980−+#include <QtNetwork/qsslsocket.h>
981−+#include <QtNetwork/qssldiffiehellmanparameters.h>
982−+
983−+#include "private/qssl_p.h"
984−+#include "private/qsslcontext_openssl_p.h"
985−+#include "private/qsslsocket_p.h"
986−+#include "private/qsslsocket_openssl_p.h"
987−+#include "private/qsslsocket_openssl_symbols_p.h"
988−+#include "private/qssldiffiehellmanparameters_p.h"
989−+
990−+QT_BEGIN_NAMESPACE
991−+
992−+// defined in qsslsocket_openssl.cpp:
993−+extern int q_X509Callback(int ok, X509_STORE_CTX *ctx);
994−+extern QString getErrorsFromOpenSsl();
995−+
996−+static inline QString msgErrorSettingEllipticCurves(const QString &why)
997−+{
998−+ return QSslSocket::tr("Error when setting the elliptic curves (%1)").arg(why);
999−+}
1000−+
1001−+// static
1002−+void QSslContext::initSslContext(QSslContext *sslContext, QSslSocket::SslMode mode, const QSslConfiguration &configuration, bool allowRootCertOnDemandLoading)
1003−+{
1004−+ sslContext->sslConfiguration = configuration;
1005−+ sslContext->errorCode = QSslError::NoError;
1006−+
1007−+ bool client = (mode == QSslSocket::SslClientMode);
1008−+
1009−+ bool reinitialized = false;
1010−+ bool unsupportedProtocol = false;
1011−+init_context:
1012−+ switch (sslContext->sslConfiguration.protocol()) {
1013−+ case QSsl::SslV2:
1014−+#ifndef OPENSSL_NO_SSL2
1015−+ sslContext->ctx = q_SSL_CTX_new(client ? q_SSLv2_client_method() : q_SSLv2_server_method());
1016−+#else
1017−+ // SSL 2 not supported by the system, but chosen deliberately -> error
1018−+ sslContext->ctx = 0;
1019−+ unsupportedProtocol = true;
1020−+#endif
1021−+ break;
1022−+ case QSsl::SslV3:
1023−+#ifndef OPENSSL_NO_SSL3_METHOD
1024−+ sslContext->ctx = q_SSL_CTX_new(client ? q_SSLv3_client_method() : q_SSLv3_server_method());
1025−+#else
1026−+ // SSL 3 not supported by the system, but chosen deliberately -> error
1027−+ sslContext->ctx = 0;
1028−+ unsupportedProtocol = true;
1029−+#endif
1030−+ break;
1031−+ case QSsl::SecureProtocols:
1032−+ // SSLv2 and SSLv3 will be disabled by SSL options
1033−+ // But we need q_SSLv23_server_method() otherwise AnyProtocol will be unable to connect on Win32.
1034−+ case QSsl::TlsV1SslV3:
1035−+ // SSLv2 will will be disabled by SSL options
1036−+ case QSsl::AnyProtocol:
1037−+ default:
1038−+ sslContext->ctx = q_SSL_CTX_new(client ? q_SSLv23_client_method() : q_SSLv23_server_method());
1039−+ break;
1040−+ case QSsl::TlsV1_0:
1041−+ sslContext->ctx = q_SSL_CTX_new(client ? q_TLSv1_client_method() : q_TLSv1_server_method());
1042−+ break;
1043−+ case QSsl::TlsV1_1:
1044−+#if OPENSSL_VERSION_NUMBER >= 0x10001000L
1045−+ sslContext->ctx = q_SSL_CTX_new(client ? q_TLSv1_1_client_method() : q_TLSv1_1_server_method());
1046−+#else
1047−+ // TLS 1.1 not supported by the system, but chosen deliberately -> error
1048−+ sslContext->ctx = 0;
1049−+ unsupportedProtocol = true;
1050−+#endif
1051−+ break;
1052−+ case QSsl::TlsV1_2:
1053−+#if OPENSSL_VERSION_NUMBER >= 0x10001000L
1054−+ sslContext->ctx = q_SSL_CTX_new(client ? q_TLSv1_2_client_method() : q_TLSv1_2_server_method());
1055−+#else
1056−+ // TLS 1.2 not supported by the system, but chosen deliberately -> error
1057−+ sslContext->ctx = 0;
1058−+ unsupportedProtocol = true;
1059−+#endif
1060−+ break;
1061−+ case QSsl::TlsV1_0OrLater:
1062−+ // Specific protocols will be specified via SSL options.
1063−+ sslContext->ctx = q_SSL_CTX_new(client ? q_SSLv23_client_method() : q_SSLv23_server_method());
1064−+ break;
1065−+ case QSsl::TlsV1_1OrLater:
1066−+ case QSsl::TlsV1_2OrLater:
1067−+#if OPENSSL_VERSION_NUMBER >= 0x10001000L
1068−+ // Specific protocols will be specified via SSL options.
1069−+ sslContext->ctx = q_SSL_CTX_new(client ? q_SSLv23_client_method() : q_SSLv23_server_method());
1070−+#else
1071−+ // TLS 1.1/1.2 not supported by the system, but chosen deliberately -> error
1072−+ sslContext->ctx = 0;
1073−+ unsupportedProtocol = true;
1074−+#endif
1075−+ break;
1076−+ }
1077−+
1078−+ if (!sslContext->ctx) {
1079−+ // After stopping Flash 10 the SSL library loses its ciphers. Try re-adding them
1080−+ // by re-initializing the library.
1081−+ if (!reinitialized) {
1082−+ reinitialized = true;
1083−+ if (q_SSL_library_init() == 1)
1084−+ goto init_context;
1085−+ }
1086−+
1087−+ sslContext->errorStr = QSslSocket::tr("Error creating SSL context (%1)").arg(
1088−+ unsupportedProtocol ? QSslSocket::tr("unsupported protocol") : QSslSocketBackendPrivate::getErrorsFromOpenSsl()
1089−+ );
1090−+ sslContext->errorCode = QSslError::UnspecifiedError;
1091−+ return;
1092−+ }
1093−+
1094−+ // Enable bug workarounds.
1095−+ long options = QSslSocketBackendPrivate::setupOpenSslOptions(configuration.protocol(), configuration.d->sslOptions);
1096−+ q_SSL_CTX_set_options(sslContext->ctx, options);
1097−+
1098−+#if OPENSSL_VERSION_NUMBER >= 0x10000000L
1099−+ // Tell OpenSSL to release memory early
1100−+ // http://www.openssl.org/docs/ssl/SSL_CTX_set_mode.html
1101−+ if (q_SSLeay() >= 0x10000000L)
1102−+ q_SSL_CTX_set_mode(sslContext->ctx, SSL_MODE_RELEASE_BUFFERS);
1103−+#endif
1104−+
1105−+ // Initialize ciphers
1106−+ QByteArray cipherString;
1107−+ bool first = true;
1108−+ QList<QSslCipher> ciphers = sslContext->sslConfiguration.ciphers();
1109−+ if (ciphers.isEmpty())
1110−+ ciphers = QSslSocketPrivate::defaultCiphers();
1111−+ for (const QSslCipher &cipher : qAsConst(ciphers)) {
1112−+ if (first)
1113−+ first = false;
1114−+ else
1115−+ cipherString.append(':');
1116−+ cipherString.append(cipher.name().toLatin1());
1117−+ }
1118−+
1119−+ if (!q_SSL_CTX_set_cipher_list(sslContext->ctx, cipherString.data())) {
1120−+ sslContext->errorStr = QSslSocket::tr("Invalid or empty cipher list (%1)").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
1121−+ sslContext->errorCode = QSslError::UnspecifiedError;
1122−+ return;
1123−+ }
1124−+
1125−+ const QDateTime now = QDateTime::currentDateTimeUtc();
1126−+
1127−+ // Add all our CAs to this store.
1128−+ const auto caCertificates = sslContext->sslConfiguration.caCertificates();
1129−+ for (const QSslCertificate &caCertificate : caCertificates) {
1130−+ // From https://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html:
1131−+ //
1132−+ // If several CA certificates matching the name, key identifier, and
1133−+ // serial number condition are available, only the first one will be
1134−+ // examined. This may lead to unexpected results if the same CA
1135−+ // certificate is available with different expiration dates. If a
1136−+ // ``certificate expired'' verification error occurs, no other
1137−+ // certificate will be searched. Make sure to not have expired
1138−+ // certificates mixed with valid ones.
1139−+ //
1140−+ // See also: QSslSocketBackendPrivate::verify()
1141−+ if (caCertificate.expiryDate() >= now) {
1142−+ q_X509_STORE_add_cert(q_SSL_CTX_get_cert_store(sslContext->ctx), (X509 *)caCertificate.handle());
1143−+ }
1144−+ }
1145−+
1146−+ if (QSslSocketPrivate::s_loadRootCertsOnDemand && allowRootCertOnDemandLoading) {
1147−+ // tell OpenSSL the directories where to look up the root certs on demand
1148−+ const QList<QByteArray> unixDirs = QSslSocketPrivate::unixRootCertDirectories();
1149−+ for (const QByteArray &unixDir : unixDirs)
1150−+ q_SSL_CTX_load_verify_locations(sslContext->ctx, 0, unixDir.constData());
1151−+ }
1152−+
1153−+ if (!sslContext->sslConfiguration.localCertificate().isNull()) {
1154−+ // Require a private key as well.
1155−+ if (sslContext->sslConfiguration.privateKey().isNull()) {
1156−+ sslContext->errorStr = QSslSocket::tr("Cannot provide a certificate with no key, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
1157−+ sslContext->errorCode = QSslError::UnspecifiedError;
1158−+ return;
1159−+ }
1160−+
1161−+ // Load certificate
1162−+ if (!q_SSL_CTX_use_certificate(sslContext->ctx, (X509 *)sslContext->sslConfiguration.localCertificate().handle())) {
1163−+ sslContext->errorStr = QSslSocket::tr("Error loading local certificate, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
1164−+ sslContext->errorCode = QSslError::UnspecifiedError;
1165−+ return;
1166−+ }
1167−+
1168−+ if (configuration.d->privateKey.algorithm() == QSsl::Opaque) {
1169−+ sslContext->pkey = reinterpret_cast<EVP_PKEY *>(configuration.d->privateKey.handle());
1170−+ } else {
1171−+ // Load private key
1172−+ sslContext->pkey = q_EVP_PKEY_new();
1173−+ // before we were using EVP_PKEY_assign_R* functions and did not use EVP_PKEY_free.
1174−+ // this lead to a memory leak. Now we use the *_set1_* functions which do not
1175−+ // take ownership of the RSA/DSA key instance because the QSslKey already has ownership.
1176−+ if (configuration.d->privateKey.algorithm() == QSsl::Rsa)
1177−+ q_EVP_PKEY_set1_RSA(sslContext->pkey, reinterpret_cast<RSA *>(configuration.d->privateKey.handle()));
1178−+ else if (configuration.d->privateKey.algorithm() == QSsl::Dsa)
1179−+ q_EVP_PKEY_set1_DSA(sslContext->pkey, reinterpret_cast<DSA *>(configuration.d->privateKey.handle()));
1180−+#ifndef OPENSSL_NO_EC
1181−+ else if (configuration.d->privateKey.algorithm() == QSsl::Ec)
1182−+ q_EVP_PKEY_set1_EC_KEY(sslContext->pkey, reinterpret_cast<EC_KEY *>(configuration.d->privateKey.handle()));
1183−+#endif
1184−+ }
1185−+
1186−+ if (!q_SSL_CTX_use_PrivateKey(sslContext->ctx, sslContext->pkey)) {
1187−+ sslContext->errorStr = QSslSocket::tr("Error loading private key, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
1188−+ sslContext->errorCode = QSslError::UnspecifiedError;
1189−+ return;
1190−+ }
1191−+ if (configuration.d->privateKey.algorithm() == QSsl::Opaque)
1192−+ sslContext->pkey = 0; // Don't free the private key, it belongs to QSslKey
1193−+
1194−+ // Check if the certificate matches the private key.
1195−+ if (!q_SSL_CTX_check_private_key(sslContext->ctx)) {
1196−+ sslContext->errorStr = QSslSocket::tr("Private key does not certify public key, %1").arg(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
1197−+ sslContext->errorCode = QSslError::UnspecifiedError;
1198−+ return;
1199−+ }
1200−+
1201−+ // If we have any intermediate certificates then we need to add them to our chain
1202−+ bool first = true;
1203−+ for (const QSslCertificate &cert : qAsConst(configuration.d->localCertificateChain)) {
1204−+ if (first) {
1205−+ first = false;
1206−+ continue;
1207−+ }
1208−+ q_SSL_CTX_ctrl(sslContext->ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0,
1209−+ q_X509_dup(reinterpret_cast<X509 *>(cert.handle())));
1210−+ }
1211−+ }
1212−+
1213−+ // Initialize peer verification.
1214−+ if (sslContext->sslConfiguration.peerVerifyMode() == QSslSocket::VerifyNone) {
1215−+ q_SSL_CTX_set_verify(sslContext->ctx, SSL_VERIFY_NONE, 0);
1216−+ } else {
1217−+ q_SSL_CTX_set_verify(sslContext->ctx, SSL_VERIFY_PEER, q_X509Callback);
1218−+ }
1219−+
1220−+ // Set verification depth.
1221−+ if (sslContext->sslConfiguration.peerVerifyDepth() != 0)
1222−+ q_SSL_CTX_set_verify_depth(sslContext->ctx, sslContext->sslConfiguration.peerVerifyDepth());
1223−+
1224−+ // set persisted session if the user set it
1225−+ if (!configuration.sessionTicket().isEmpty())
1226−+ sslContext->setSessionASN1(configuration.sessionTicket());
1227−+
1228−+ // Set temp DH params
1229−+ QSslDiffieHellmanParameters dhparams = configuration.diffieHellmanParameters();
1230−+
1231−+ if (!dhparams.isValid()) {
1232−+ sslContext->errorStr = QSslSocket::tr("Diffie-Hellman parameters are not valid");
1233−+ sslContext->errorCode = QSslError::UnspecifiedError;
1234−+ return;
1235−+ }
1236−+
1237−+ if (!dhparams.isEmpty()) {
1238−+ const QByteArray ¶ms = dhparams.d->derData;
1239−+ const char *ptr = params.constData();
1240−+ DH *dh = q_d2i_DHparams(NULL, reinterpret_cast<const unsigned char **>(&ptr), params.length());
1241−+ if (dh == NULL)
1242−+ qFatal("q_d2i_DHparams failed to convert QSslDiffieHellmanParameters to DER form");
1243−+ q_SSL_CTX_set_tmp_dh(sslContext->ctx, dh);
1244−+ q_DH_free(dh);
1245−+ }
1246−+
1247−+#ifndef OPENSSL_NO_EC
1248−+#if OPENSSL_VERSION_NUMBER >= 0x10002000L
1249−+ if (q_SSLeay() >= 0x10002000L) {
1250−+ q_SSL_CTX_ctrl(sslContext->ctx, SSL_CTRL_SET_ECDH_AUTO, 1, NULL);
1251−+ } else
1252−+#endif
1253−+ {
1254−+ // Set temp ECDH params
1255−+ EC_KEY *ecdh = 0;
1256−+ ecdh = q_EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
1257−+ q_SSL_CTX_set_tmp_ecdh(sslContext->ctx, ecdh);
1258−+ q_EC_KEY_free(ecdh);
1259−+ }
1260−+#endif // OPENSSL_NO_EC
1261−+
1262−+#if OPENSSL_VERSION_NUMBER >= 0x10001000L && !defined(OPENSSL_NO_PSK)
1263−+ if (!client)
1264−+ q_SSL_CTX_use_psk_identity_hint(sslContext->ctx, sslContext->sslConfiguration.preSharedKeyIdentityHint().constData());
1265−+#endif // OPENSSL_VERSION_NUMBER >= 0x10001000L && !defined(OPENSSL_NO_PSK)
1266−+
1267−+ const QVector<QSslEllipticCurve> qcurves = sslContext->sslConfiguration.ellipticCurves();
1268−+ if (!qcurves.isEmpty()) {
1269−+#if OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(OPENSSL_NO_EC)
1270−+ // Set the curves to be used
1271−+ if (q_SSLeay() >= 0x10002000L) {
1272−+ // SSL_CTX_ctrl wants a non-const pointer as last argument,
1273−+ // but let's avoid a copy into a temporary array
1274−+ if (!q_SSL_CTX_ctrl(sslContext->ctx,
1275−+ SSL_CTRL_SET_CURVES,
1276−+ qcurves.size(),
1277−+ const_cast<int *>(reinterpret_cast<const int *>(qcurves.data())))) {
1278−+ sslContext->errorStr = msgErrorSettingEllipticCurves(QSslSocketBackendPrivate::getErrorsFromOpenSsl());
1279−+ sslContext->errorCode = QSslError::UnspecifiedError;
1280−+ }
1281−+ } else
1282−+#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(OPENSSL_NO_EC)
1283−+ {
1284−+ // specific curves requested, but not possible to set -> error
1285−+ sslContext->errorStr = msgErrorSettingEllipticCurves(QSslSocket::tr("OpenSSL version too old, need at least v1.0.2"));
1286−+ sslContext->errorCode = QSslError::UnspecifiedError;
1287−+ }
1288−+ }
1289−+}
1290−+
1291−+QT_END_NAMESPACE
1292−diff --git a/src/network/ssl/qssldiffiehellmanparameters_openssl.cpp b/src/network/ssl/qssldiffiehellmanparameters_openssl.cpp
1293−index 90687b05c5..5ebad822f1 100644
1294−--- a/src/network/ssl/qssldiffiehellmanparameters_openssl.cpp
1295−+++ b/src/network/ssl/qssldiffiehellmanparameters_openssl.cpp
1296−@@ -1,6 +1,7 @@
1297− /****************************************************************************
1298− **
1299− ** Copyright (C) 2015 Mikkel Krautz <mikkel@krautz.dk>
1300−+** Copyright (C) 2016 Richard J. Moore <rich@kde.org>
1301− ** Contact: https://www.qt.io/licensing/
1302− **
1303− ** This file is part of the QtNetwork module of the Qt Toolkit.
1304−@@ -50,8 +51,8 @@
1305− #include <QtCore/qdebug.h>
1306− #endif
1307−
1308−-// For q_BN_is_word.
1309− #include <openssl/bn.h>
1310−+#include <openssl/dh.h>
1311−
1312− QT_BEGIN_NAMESPACE
1313−
1314−@@ -62,13 +63,6 @@ static bool isSafeDH(DH *dh)
1315−
1316− QSslSocketPrivate::ensureInitialized();
1317−
1318−- // Mark p < 1024 bits as unsafe.
1319−- if (q_BN_num_bits(dh->p) < 1024) {
1320−- return false;
1321−- }
1322−-
1323−- if (q_DH_check(dh, &status) != 1)
1324−- return false;
1325−
1326− // From https://wiki.openssl.org/index.php/Diffie-Hellman_parameters:
1327− //
1328−@@ -81,11 +75,39 @@ static bool isSafeDH(DH *dh)
1329− // Without the test, the IETF parameters would
1330− // fail validation. For details, see Diffie-Hellman
1331− // Parameter Check (when g = 2, must p mod 24 == 11?).
1332−+#if QT_CONFIG(opensslv11)
1333−+ // Mark p < 1024 bits as unsafe.
1334−+ if (q_DH_bits(dh) < 1024)
1335−+ return false;
1336−+
1337−+ if (q_DH_check(dh, &status) != 1)
1338−+ return false;
1339−+
1340−+ const BIGNUM *p = nullptr;
1341−+ const BIGNUM *q = nullptr;
1342−+ const BIGNUM *g = nullptr;
1343−+ q_DH_get0_pqg(dh, &p, &q, &g);
1344−+
1345−+ if (q_BN_is_word(const_cast<BIGNUM *>(g), DH_GENERATOR_2)) {
1346−+ long residue = q_BN_mod_word(p, 24);
1347−+ if (residue == 11 || residue == 23)
1348−+ status &= ~DH_NOT_SUITABLE_GENERATOR;
1349−+ }
1350−+
1351−+#else
1352−+ // Mark p < 1024 bits as unsafe.
1353−+ if (q_BN_num_bits(dh->p) < 1024)
1354−+ return false;
1355−+
1356−+ if (q_DH_check(dh, &status) != 1)
1357−+ return false;
1358−+
1359− if (q_BN_is_word(dh->g, DH_GENERATOR_2)) {
1360− long residue = q_BN_mod_word(dh->p, 24);
1361− if (residue == 11 || residue == 23)
1362− status &= ~DH_NOT_SUITABLE_GENERATOR;
1363− }
1364−+#endif
1365−
1366− bad |= DH_CHECK_P_NOT_PRIME;
1367− bad |= DH_CHECK_P_NOT_SAFE_PRIME;
1368−diff --git a/src/network/ssl/qsslellipticcurve.h b/src/network/ssl/qsslellipticcurve.h
1369−index 231566063e..57dda19bad 100644
1370−--- a/src/network/ssl/qsslellipticcurve.h
1371−+++ b/src/network/ssl/qsslellipticcurve.h
1372−@@ -80,6 +80,7 @@ private:
1373− friend Q_DECL_CONSTEXPR bool operator==(QSslEllipticCurve lhs, QSslEllipticCurve rhs) Q_DECL_NOTHROW;
1374− friend Q_DECL_CONSTEXPR uint qHash(QSslEllipticCurve curve, uint seed) Q_DECL_NOTHROW;
1375−
1376−+ friend class QSslContext;
1377− friend class QSslSocketPrivate;
1378− friend class QSslSocketBackendPrivate;
1379− };
1380−diff --git a/src/network/ssl/qsslellipticcurve_openssl.cpp b/src/network/ssl/qsslellipticcurve_openssl.cpp
1381−index e18197b703..8cd14837f0 100644
1382−--- a/src/network/ssl/qsslellipticcurve_openssl.cpp
1383−+++ b/src/network/ssl/qsslellipticcurve_openssl.cpp
1384−@@ -1,6 +1,7 @@
1385− /****************************************************************************
1386− **
1387− ** Copyright (C) 2014 Governikus GmbH & Co. KG.
1388−+** Copyright (C) 2016 Richard J. Moore <rich@kde.org>
1389− ** Contact: https://www.qt.io/licensing/
1390− **
1391− ** This file is part of the QtNetwork module of the Qt Toolkit.
1392−@@ -78,17 +79,18 @@ QSslEllipticCurve QSslEllipticCurve::fromShortName(const QString &name)
1393− QSslEllipticCurve result;
1394−
1395− #ifndef OPENSSL_NO_EC
1396−- const QByteArray curveNameLatin1 = name.toLatin1();
1397−
1398−+ const QByteArray curveNameLatin1 = name.toLatin1();
1399− int nid = q_OBJ_sn2nid(curveNameLatin1.data());
1400−
1401− #if OPENSSL_VERSION_NUMBER >= 0x10002000L
1402−- if (nid == 0 && q_SSLeay() >= 0x10002000L)
1403−+ if (nid == 0 && QSslSocket::sslLibraryVersionNumber() >= 0x10002000L)
1404− nid = q_EC_curve_nist2nid(curveNameLatin1.data());
1405− #endif // OPENSSL_VERSION_NUMBER >= 0x10002000L
1406−
1407− result.id = nid;
1408−-#endif
1409−+
1410−+#endif // !OPENSSL_NO_EC
1411−
1412− return result;
1413− }
1414−diff --git a/src/network/ssl/qsslkey_openssl.cpp b/src/network/ssl/qsslkey_openssl.cpp
1415−index 26119023d1..2b03af9441 100644
1416−--- a/src/network/ssl/qsslkey_openssl.cpp
1417−+++ b/src/network/ssl/qsslkey_openssl.cpp
1418−@@ -1,6 +1,7 @@
1419− /****************************************************************************
1420− **
1421−-** Copyright (C) 2016 The Qt Company Ltd.
1422−+** Copyright (C) 2017 The Qt Company Ltd.
1423−+** Copyright (C) 2016 Richard J. Moore <rich@kde.org>
1424− ** Contact: https://www.qt.io/licensing/
1425− **
1426− ** This file is part of the QtNetwork module of the Qt Toolkit.
1427−@@ -87,33 +88,32 @@ bool QSslKeyPrivate::fromEVP_PKEY(EVP_PKEY *pkey)
1428− if (pkey == nullptr)
1429− return false;
1430−
1431−- if (pkey->type == EVP_PKEY_RSA) {
1432−+#if QT_CONFIG(opensslv11)
1433−+ const int keyType = q_EVP_PKEY_type(q_EVP_PKEY_base_id(pkey));
1434−+#else
1435−+ const int keyType = pkey->type;
1436−+#endif
1437−+ if (keyType == EVP_PKEY_RSA) {
1438− isNull = false;
1439− algorithm = QSsl::Rsa;
1440− type = QSsl::PrivateKey;
1441−
1442−- rsa = q_RSA_new();
1443−- memcpy(rsa, q_EVP_PKEY_get1_RSA(pkey), sizeof(RSA));
1444−-
1445−+ rsa = q_EVP_PKEY_get1_RSA(pkey);
1446− return true;
1447−- }
1448−- else if (pkey->type == EVP_PKEY_DSA) {
1449−+ } else if (keyType == EVP_PKEY_DSA) {
1450− isNull = false;
1451− algorithm = QSsl::Dsa;
1452− type = QSsl::PrivateKey;
1453−
1454−- dsa = q_DSA_new();
1455−- memcpy(dsa, q_EVP_PKEY_get1_DSA(pkey), sizeof(DSA));
1456−-
1457−+ dsa = q_EVP_PKEY_get1_DSA(pkey);
1458− return true;
1459− }
1460− #ifndef OPENSSL_NO_EC
1461−- else if (pkey->type == EVP_PKEY_EC) {
1462−+ else if (keyType == EVP_PKEY_EC) {
1463− isNull = false;
1464− algorithm = QSsl::Ec;
1465− type = QSsl::PrivateKey;
1466−- ec = q_EC_KEY_dup(q_EVP_PKEY_get1_EC_KEY(pkey));
1467−-
1468−+ ec = q_EVP_PKEY_get1_EC_KEY(pkey);
1469− return true;
1470− }
1471− #endif
1472−@@ -181,8 +181,8 @@ int QSslKeyPrivate::length() const
1473− return -1;
1474−
1475− switch (algorithm) {
1476−- case QSsl::Rsa: return q_BN_num_bits(rsa->n);
1477−- case QSsl::Dsa: return q_BN_num_bits(dsa->p);
1478−+ case QSsl::Rsa: return q_RSA_bits(rsa);
1479−+ case QSsl::Dsa: return q_DSA_bits(dsa);
1480− #ifndef OPENSSL_NO_EC
1481− case QSsl::Ec: return q_EC_GROUP_get_degree(q_EC_KEY_get0_group(ec));
1482− #endif
1483−@@ -276,7 +276,13 @@ Qt::HANDLE QSslKeyPrivate::handle() const
1484−
1485− static QByteArray doCrypt(QSslKeyPrivate::Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv, int enc)
1486− {
1487−- EVP_CIPHER_CTX ctx;
1488−+#if QT_CONFIG(opensslv11)
1489−+ EVP_CIPHER_CTX *ctx = q_EVP_CIPHER_CTX_new();
1490−+#else
1491−+ EVP_CIPHER_CTX evpCipherContext;
1492−+ EVP_CIPHER_CTX *ctx = &evpCipherContext;
1493−+#endif
1494−+
1495− const EVP_CIPHER* type = 0;
1496− int i = 0, len = 0;
1497−
1498−@@ -294,21 +300,44 @@ static QByteArray doCrypt(QSslKeyPrivate::Cipher cipher, const QByteArray &data,
1499−
1500− QByteArray output;
1501− output.resize(data.size() + EVP_MAX_BLOCK_LENGTH);
1502−- q_EVP_CIPHER_CTX_init(&ctx);
1503−- q_EVP_CipherInit(&ctx, type, NULL, NULL, enc);
1504−- q_EVP_CIPHER_CTX_set_key_length(&ctx, key.size());
1505−+
1506−+#if QT_CONFIG(opensslv11)
1507−+ q_EVP_CIPHER_CTX_reset(ctx);
1508−+#else
1509−+ q_EVP_CIPHER_CTX_init(ctx);
1510−+#endif
1511−+
1512−+ q_EVP_CipherInit(ctx, type, NULL, NULL, enc);
1513−+ q_EVP_CIPHER_CTX_set_key_length(ctx, key.size());
1514− if (cipher == QSslKeyPrivate::Rc2Cbc)
1515−- q_EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_SET_RC2_KEY_BITS, 8 * key.size(), NULL);
1516−- q_EVP_CipherInit(&ctx, NULL,
1517−+ q_EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC2_KEY_BITS, 8 * key.size(), NULL);
1518−+
1519−+#if QT_CONFIG(opensslv11)
1520−+ // EVP_CipherInit in 1.1 resets the context thus making the calls above useless.
1521−+ // We call EVP_CipherInit_ex instead.
1522−+ q_EVP_CipherInit_ex(ctx, nullptr, nullptr,
1523−+ reinterpret_cast<const unsigned char *>(key.constData()),
1524−+ reinterpret_cast<const unsigned char *>(iv.constData()),
1525−+ enc);
1526−+#else
1527−+ q_EVP_CipherInit(ctx, NULL,
1528− reinterpret_cast<const unsigned char *>(key.constData()),
1529− reinterpret_cast<const unsigned char *>(iv.constData()), enc);
1530−- q_EVP_CipherUpdate(&ctx,
1531−+#endif // opensslv11
1532−+
1533−+ q_EVP_CipherUpdate(ctx,
1534− reinterpret_cast<unsigned char *>(output.data()), &len,
1535− reinterpret_cast<const unsigned char *>(data.constData()), data.size());
1536−- q_EVP_CipherFinal(&ctx,
1537−+ q_EVP_CipherFinal(ctx,
1538− reinterpret_cast<unsigned char *>(output.data()) + len, &i);
1539− len += i;
1540−- q_EVP_CIPHER_CTX_cleanup(&ctx);
1541−+
1542−+#if QT_CONFIG(opensslv11)
1543−+ q_EVP_CIPHER_CTX_reset(ctx);
1544−+ q_EVP_CIPHER_CTX_free(ctx);
1545−+#else
1546−+ q_EVP_CIPHER_CTX_cleanup(ctx);
1547−+#endif
1548−
1549− return output.left(len);
1550− }
1551−diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp
1552−index f5b493897e..45cea490fc 100644
1553−--- a/src/network/ssl/qsslsocket_openssl.cpp
1554−+++ b/src/network/ssl/qsslsocket_openssl.cpp
1555−@@ -1,6 +1,6 @@
1556− /****************************************************************************
1557− **
1558−-** Copyright (C) 2016 The Qt Company Ltd.
1559−+** Copyright (C) 2017 The Qt Company Ltd.
1560− ** Copyright (C) 2014 Governikus GmbH & Co. KG
1561− ** Contact: https://www.qt.io/licensing/
1562− **
1563−@@ -97,70 +97,6 @@ bool QSslSocketPrivate::s_loadRootCertsOnDemand = false;
1564− int QSslSocketBackendPrivate::s_indexForSSLExtraData = -1;
1565− #endif
1566−
1567−-/* \internal
1568−-
1569−- From OpenSSL's thread(3) manual page:
1570−-
1571−- OpenSSL can safely be used in multi-threaded applications provided that at
1572−- least two callback functions are set.
1573−-
1574−- locking_function(int mode, int n, const char *file, int line) is needed to
1575−- perform locking on shared data structures. (Note that OpenSSL uses a
1576−- number of global data structures that will be implicitly shared
1577−- whenever multiple threads use OpenSSL.) Multi-threaded
1578−- applications will crash at random if it is not set. ...
1579−- ...
1580−- id_function(void) is a function that returns a thread ID. It is not
1581−- needed on Windows nor on platforms where getpid() returns a different
1582−- ID for each thread (most notably Linux)
1583−-*/
1584−-class QOpenSslLocks
1585−-{
1586−-public:
1587−- inline QOpenSslLocks()
1588−- : initLocker(QMutex::Recursive),
1589−- locksLocker(QMutex::Recursive)
1590−- {
1591−- QMutexLocker locker(&locksLocker);
1592−- int numLocks = q_CRYPTO_num_locks();
1593−- locks = new QMutex *[numLocks];
1594−- memset(locks, 0, numLocks * sizeof(QMutex *));
1595−- }
1596−- inline ~QOpenSslLocks()
1597−- {
1598−- QMutexLocker locker(&locksLocker);
1599−- for (int i = 0; i < q_CRYPTO_num_locks(); ++i)
1600−- delete locks[i];
1601−- delete [] locks;
1602−-
1603−- QSslSocketPrivate::deinitialize();
1604−- }
1605−- inline QMutex *lock(int num)
1606−- {
1607−- QMutexLocker locker(&locksLocker);
1608−- QMutex *tmp = locks[num];
1609−- if (!tmp)
1610−- tmp = locks[num] = new QMutex(QMutex::Recursive);
1611−- return tmp;
1612−- }
1613−-
1614−- QMutex *globalLock()
1615−- {
1616−- return &locksLocker;
1617−- }
1618−-
1619−- QMutex *initLock()
1620−- {
1621−- return &initLocker;
1622−- }
1623−-
1624−-private:
1625−- QMutex initLocker;
1626−- QMutex locksLocker;
1627−- QMutex **locks;
1628−-};
1629−-Q_GLOBAL_STATIC(QOpenSslLocks, openssl_locks)
1630−-
1631− QString QSslSocketBackendPrivate::getErrorsFromOpenSsl()
1632− {
1633− QString errorString;
1634−@@ -175,20 +111,6 @@ QString QSslSocketBackendPrivate::getErrorsFromOpenSsl()
1635− }
1636−
1637− extern "C" {
1638−-static void locking_function(int mode, int lockNumber, const char *, int)
1639−-{
1640−- QMutex *mutex = openssl_locks()->lock(lockNumber);
1641−-
1642−- // Lock or unlock it
1643−- if (mode & CRYPTO_LOCK)
1644−- mutex->lock();
1645−- else
1646−- mutex->unlock();
1647−-}
1648−-static unsigned long id_function()
1649−-{
1650−- return (quintptr)QThread::currentThreadId();
1651−-}
1652−
1653− #if OPENSSL_VERSION_NUMBER >= 0x10001000L && !defined(OPENSSL_NO_PSK)
1654− static unsigned int q_ssl_psk_client_callback(SSL *ssl,
1655−@@ -227,7 +149,7 @@ QSslSocketBackendPrivate::~QSslSocketBackendPrivate()
1656− destroySslContext();
1657− }
1658−
1659−-QSslCipher QSslSocketBackendPrivate::QSslCipher_from_SSL_CIPHER(SSL_CIPHER *cipher)
1660−+QSslCipher QSslSocketBackendPrivate::QSslCipher_from_SSL_CIPHER(const SSL_CIPHER *cipher)
1661− {
1662− QSslCipher ciph;
1663−
1664−@@ -283,6 +205,7 @@ struct QSslErrorList
1665− QMutex mutex;
1666− QVector<QSslErrorEntry> errors;
1667− };
1668−+
1669− Q_GLOBAL_STATIC(QSslErrorList, _q_sslErrorList)
1670−
1671− int q_X509Callback(int ok, X509_STORE_CTX *ctx)
1672−@@ -312,7 +235,7 @@ int q_X509Callback(int ok, X509_STORE_CTX *ctx)
1673− }
1674− #endif
1675− }
1676−- // Always return OK to allow verification to continue. We're handle the
1677−+ // Always return OK to allow verification to continue. We handle the
1678− // errors gracefully after collecting all errors, after verification has
1679− // completed.
1680− return 1;
1681−@@ -397,7 +320,7 @@ bool QSslSocketBackendPrivate::initSslContext()
1682− if (configuration.protocol != QSsl::SslV2 &&
1683− configuration.protocol != QSsl::SslV3 &&
1684− configuration.protocol != QSsl::UnknownProtocol &&
1685−- mode == QSslSocket::SslClientMode && q_SSLeay() >= 0x00090806fL) {
1686−+ mode == QSslSocket::SslClientMode && QSslSocket::sslLibraryVersionNumber() >= 0x00090806fL) {
1687− // Set server hostname on TLS extension. RFC4366 section 3.1 requires it in ACE format.
1688− QString tlsHostName = verificationPeerName.isEmpty() ? q->peerName() : verificationPeerName;
1689− if (tlsHostName.isEmpty())
1690−@@ -438,13 +361,13 @@ bool QSslSocketBackendPrivate::initSslContext()
1691−
1692− #if OPENSSL_VERSION_NUMBER >= 0x10001000L
1693− // Save a pointer to this object into the SSL structure.
1694−- if (q_SSLeay() >= 0x10001000L)
1695−+ if (QSslSocket::sslLibraryVersionNumber() >= 0x10001000L)
1696− q_SSL_set_ex_data(ssl, s_indexForSSLExtraData, this);
1697− #endif
1698−
1699− #if OPENSSL_VERSION_NUMBER >= 0x10001000L && !defined(OPENSSL_NO_PSK)
1700− // Set the client callback for PSK
1701−- if (q_SSLeay() >= 0x10001000L) {
1702−+ if (QSslSocket::sslLibraryVersionNumber() >= 0x10001000L) {
1703− if (mode == QSslSocket::SslClientMode)
1704− q_SSL_set_psk_client_callback(ssl, &q_ssl_psk_client_callback);
1705− else if (mode == QSslSocket::SslServerMode)
1706−@@ -464,16 +387,6 @@ void QSslSocketBackendPrivate::destroySslContext()
1707− sslContextPointer.clear();
1708− }
1709−
1710−-/*!
1711−- \internal
1712−-*/
1713−-void QSslSocketPrivate::deinitialize()
1714−-{
1715−- q_CRYPTO_set_id_callback(0);
1716−- q_CRYPTO_set_locking_callback(0);
1717−- q_ERR_free_strings();
1718−-}
1719−-
1720− /*!
1721− \internal
1722−
1723−@@ -486,91 +399,6 @@ bool QSslSocketPrivate::supportsSsl()
1724− return ensureLibraryLoaded();
1725− }
1726−
1727−-bool QSslSocketPrivate::ensureLibraryLoaded()
1728−-{
1729−- if (!q_resolveOpenSslSymbols())
1730−- return false;
1731−-
1732−- // Check if the library itself needs to be initialized.
1733−- QMutexLocker locker(openssl_locks()->initLock());
1734−-
1735−- if (!s_libraryLoaded) {
1736−- s_libraryLoaded = true;
1737−-
1738−- // Initialize OpenSSL.
1739−- q_CRYPTO_set_id_callback(id_function);
1740−- q_CRYPTO_set_locking_callback(locking_function);
1741−- if (q_SSL_library_init() != 1)
1742−- return false;
1743−- q_SSL_load_error_strings();
1744−- q_OpenSSL_add_all_algorithms();
1745−-
1746−-#if OPENSSL_VERSION_NUMBER >= 0x10001000L
1747−- if (q_SSLeay() >= 0x10001000L)
1748−- QSslSocketBackendPrivate::s_indexForSSLExtraData = q_SSL_get_ex_new_index(0L, NULL, NULL, NULL, NULL);
1749−-#endif
1750−-
1751−- // Initialize OpenSSL's random seed.
1752−- if (!q_RAND_status()) {
1753−- qWarning("Random number generator not seeded, disabling SSL support");
1754−- return false;
1755−- }
1756−- }
1757−- return true;
1758−-}
1759−-
1760−-void QSslSocketPrivate::ensureCiphersAndCertsLoaded()
1761−-{
1762−- QMutexLocker locker(openssl_locks()->initLock());
1763−- if (s_loadedCiphersAndCerts)
1764−- return;
1765−- s_loadedCiphersAndCerts = true;
1766−-
1767−- resetDefaultCiphers();
1768−- resetDefaultEllipticCurves();
1769−-
1770−-#if QT_CONFIG(library)
1771−- //load symbols needed to receive certificates from system store
1772−-#if defined(Q_OS_WIN)
1773−- HINSTANCE hLib = LoadLibraryW(L"Crypt32");
1774−- if (hLib) {
1775−- ptrCertOpenSystemStoreW = (PtrCertOpenSystemStoreW)GetProcAddress(hLib, "CertOpenSystemStoreW");
1776−- ptrCertFindCertificateInStore = (PtrCertFindCertificateInStore)GetProcAddress(hLib, "CertFindCertificateInStore");
1777−- ptrCertCloseStore = (PtrCertCloseStore)GetProcAddress(hLib, "CertCloseStore");
1778−- if (!ptrCertOpenSystemStoreW || !ptrCertFindCertificateInStore || !ptrCertCloseStore)
1779−- qCWarning(lcSsl, "could not resolve symbols in crypt32 library"); // should never happen
1780−- } else {
1781−- qCWarning(lcSsl, "could not load crypt32 library"); // should never happen
1782−- }
1783−-#elif defined(Q_OS_QNX)
1784−- s_loadRootCertsOnDemand = true;
1785−-#elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
1786−- // check whether we can enable on-demand root-cert loading (i.e. check whether the sym links are there)
1787−- QList<QByteArray> dirs = unixRootCertDirectories();
1788−- QStringList symLinkFilter;
1789−- symLinkFilter << QLatin1String("[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9]");
1790−- for (int a = 0; a < dirs.count(); ++a) {
1791−- QDirIterator iterator(QLatin1String(dirs.at(a)), symLinkFilter, QDir::Files);
1792−- if (iterator.hasNext()) {
1793−- s_loadRootCertsOnDemand = true;
1794−- break;
1795−- }
1796−- }
1797−-#endif
1798−-#endif // QT_CONFIG(library)
1799−- // if on-demand loading was not enabled, load the certs now
1800−- if (!s_loadRootCertsOnDemand)
1801−- setDefaultCaCertificates(systemCaCertificates());
1802−-#ifdef Q_OS_WIN
1803−- //Enabled for fetching additional root certs from windows update on windows 6+
1804−- //This flag is set false by setDefaultCaCertificates() indicating the app uses
1805−- //its own cert bundle rather than the system one.
1806−- //Same logic that disables the unix on demand cert loading.
1807−- //Unlike unix, we do preload the certificates from the cert store.
1808−- if ((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_6_0)
1809−- s_loadRootCertsOnDemand = true;
1810−-#endif
1811−-}
1812−
1813− /*!
1814− \internal
1815−@@ -587,26 +415,6 @@ void QSslSocketPrivate::ensureInitialized()
1816− ensureCiphersAndCertsLoaded();
1817− }
1818−
1819−-long QSslSocketPrivate::sslLibraryVersionNumber()
1820−-{
1821−- if (!supportsSsl())
1822−- return 0;
1823−-
1824−- return q_SSLeay();
1825−-}
1826−-
1827−-QString QSslSocketPrivate::sslLibraryVersionString()
1828−-{
1829−- if (!supportsSsl())
1830−- return QString();
1831−-
1832−- const char *versionString = q_SSLeay_version(SSLEAY_VERSION);
1833−- if (!versionString)
1834−- return QString();
1835−-
1836−- return QString::fromLatin1(versionString);
1837−-}
1838−-
1839− long QSslSocketPrivate::sslLibraryBuildVersionNumber()
1840− {
1841− return OPENSSL_VERSION_NUMBER;
1842−@@ -628,7 +436,11 @@ QString QSslSocketPrivate::sslLibraryBuildVersionString()
1843− */
1844− void QSslSocketPrivate::resetDefaultCiphers()
1845− {
1846−+#if QT_CONFIG(opensslv11)
1847−+ SSL_CTX *myCtx = q_SSL_CTX_new(q_TLS_client_method());
1848−+#else
1849− SSL_CTX *myCtx = q_SSL_CTX_new(q_SSLv23_client_method());
1850−+#endif
1851− SSL *mySsl = q_SSL_new(myCtx);
1852−
1853− QList<QSslCipher> ciphers;
1854−@@ -664,7 +476,7 @@ void QSslSocketPrivate::resetDefaultEllipticCurves()
1855− QVector<QSslEllipticCurve> curves;
1856−
1857− #ifndef OPENSSL_NO_EC
1858−- const size_t curveCount = q_EC_get_builtin_curves(NULL, 0);
1859−+ const size_t curveCount = q_EC_get_builtin_curves(nullptr, 0);
1860−
1861− QVarLengthArray<EC_builtin_curve> builtinCurves(static_cast<int>(curveCount));
1862−
1863−@@ -698,13 +510,14 @@ QList<QSslCertificate> QSslSocketPrivate::systemCaCertificates()
1864− if (ptrCertOpenSystemStoreW && ptrCertFindCertificateInStore && ptrCertCloseStore) {
1865− HCERTSTORE hSystemStore;
1866− hSystemStore = ptrCertOpenSystemStoreW(0, L"ROOT");
1867−- if(hSystemStore) {
1868−- PCCERT_CONTEXT pc = NULL;
1869−- while(1) {
1870−- pc = ptrCertFindCertificateInStore( hSystemStore, X509_ASN_ENCODING, 0, CERT_FIND_ANY, NULL, pc);
1871−- if(!pc)
1872−+ if (hSystemStore) {
1873−+ PCCERT_CONTEXT pc = nullptr;
1874−+ while (1) {
1875−+ pc = ptrCertFindCertificateInStore(hSystemStore, X509_ASN_ENCODING, 0, CERT_FIND_ANY, nullptr, pc);
1876−+ if (!pc)
1877− break;
1878−- QByteArray der((const char *)(pc->pbCertEncoded), static_cast<int>(pc->cbCertEncoded));
1879−+ QByteArray der(reinterpret_cast<const char *>(pc->pbCertEncoded),
1880−+ static_cast<int>(pc->cbCertEncoded));
1881− QSslCertificate cert(der, QSsl::Der);
1882− systemCerts.append(cert);
1883− }
1884−@@ -1504,14 +1317,8 @@ QSslCipher QSslSocketBackendPrivate::sessionCipher() const
1885− {
1886− if (!ssl)
1887− return QSslCipher();
1888−-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
1889−- // FIXME This is fairly evil, but needed to keep source level compatibility
1890−- // with the OpenSSL 0.9.x implementation at maximum -- some other functions
1891−- // don't take a const SSL_CIPHER* when they should
1892−- SSL_CIPHER *sessionCipher = const_cast<SSL_CIPHER *>(q_SSL_get_current_cipher(ssl));
1893−-#else
1894−- SSL_CIPHER *sessionCipher = q_SSL_get_current_cipher(ssl);
1895−-#endif
1896−+
1897−+ const SSL_CIPHER *sessionCipher = q_SSL_get_current_cipher(ssl);
1898− return sessionCipher ? QSslCipher_from_SSL_CIPHER(sessionCipher) : QSslCipher();
1899− }
1900−
1901−@@ -1537,112 +1344,6 @@ QSsl::SslProtocol QSslSocketBackendPrivate::sessionProtocol() const
1902− return QSsl::UnknownProtocol;
1903− }
1904−
1905−-void QSslSocketBackendPrivate::continueHandshake()
1906−-{
1907−- Q_Q(QSslSocket);
1908−- // if we have a max read buffer size, reset the plain socket's to match
1909−- if (readBufferMaxSize)
1910−- plainSocket->setReadBufferSize(readBufferMaxSize);
1911−-
1912−- if (q_SSL_ctrl((ssl), SSL_CTRL_GET_SESSION_REUSED, 0, NULL))
1913−- configuration.peerSessionShared = true;
1914−-
1915−-#ifdef QT_DECRYPT_SSL_TRAFFIC
1916−- if (ssl->session && ssl->s3) {
1917−- const char *mk = reinterpret_cast<const char *>(ssl->session->master_key);
1918−- QByteArray masterKey(mk, ssl->session->master_key_length);
1919−- const char *random = reinterpret_cast<const char *>(ssl->s3->client_random);
1920−- QByteArray clientRandom(random, SSL3_RANDOM_SIZE);
1921−-
1922−- // different format, needed for e.g. older Wireshark versions:
1923−-// const char *sid = reinterpret_cast<const char *>(ssl->session->session_id);
1924−-// QByteArray sessionID(sid, ssl->session->session_id_length);
1925−-// QByteArray debugLineRSA("RSA Session-ID:");
1926−-// debugLineRSA.append(sessionID.toHex().toUpper());
1927−-// debugLineRSA.append(" Master-Key:");
1928−-// debugLineRSA.append(masterKey.toHex().toUpper());
1929−-// debugLineRSA.append("\n");
1930−-
1931−- QByteArray debugLineClientRandom("CLIENT_RANDOM ");
1932−- debugLineClientRandom.append(clientRandom.toHex().toUpper());
1933−- debugLineClientRandom.append(" ");
1934−- debugLineClientRandom.append(masterKey.toHex().toUpper());
1935−- debugLineClientRandom.append("\n");
1936−-
1937−- QString sslKeyFile = QDir::tempPath() + QLatin1String("/qt-ssl-keys");
1938−- QFile file(sslKeyFile);
1939−- if (!file.open(QIODevice::Append))
1940−- qCWarning(lcSsl) << "could not open file" << sslKeyFile << "for appending";
1941−- if (!file.write(debugLineClientRandom))
1942−- qCWarning(lcSsl) << "could not write to file" << sslKeyFile;
1943−- file.close();
1944−- } else {
1945−- qCWarning(lcSsl, "could not decrypt SSL traffic");
1946−- }
1947−-#endif
1948−-
1949−- // Cache this SSL session inside the QSslContext
1950−- if (!(configuration.sslOptions & QSsl::SslOptionDisableSessionSharing)) {
1951−- if (!sslContextPointer->cacheSession(ssl)) {
1952−- sslContextPointer.clear(); // we could not cache the session
1953−- } else {
1954−- // Cache the session for permanent usage as well
1955−- if (!(configuration.sslOptions & QSsl::SslOptionDisableSessionPersistence)) {
1956−- if (!sslContextPointer->sessionASN1().isEmpty())
1957−- configuration.sslSession = sslContextPointer->sessionASN1();
1958−- configuration.sslSessionTicketLifeTimeHint = sslContextPointer->sessionTicketLifeTimeHint();
1959−- }
1960−- }
1961−- }
1962−-
1963−-#if OPENSSL_VERSION_NUMBER >= 0x1000100fL && !defined(OPENSSL_NO_NEXTPROTONEG)
1964−-
1965−- configuration.nextProtocolNegotiationStatus = sslContextPointer->npnContext().status;
1966−- if (sslContextPointer->npnContext().status == QSslConfiguration::NextProtocolNegotiationUnsupported) {
1967−- // we could not agree -> be conservative and use HTTP/1.1
1968−- configuration.nextNegotiatedProtocol = QByteArrayLiteral("http/1.1");
1969−- } else {
1970−- const unsigned char *proto = 0;
1971−- unsigned int proto_len = 0;
1972−-#if OPENSSL_VERSION_NUMBER >= 0x10002000L
1973−- if (q_SSLeay() >= 0x10002000L) {
1974−- q_SSL_get0_alpn_selected(ssl, &proto, &proto_len);
1975−- if (proto_len && mode == QSslSocket::SslClientMode) {
1976−- // Client does not have a callback that sets it ...
1977−- configuration.nextProtocolNegotiationStatus = QSslConfiguration::NextProtocolNegotiationNegotiated;
1978−- }
1979−- }
1980−-
1981−- if (!proto_len) { // Test if NPN was more lucky ...
1982−-#else
1983−- {
1984−-#endif
1985−- q_SSL_get0_next_proto_negotiated(ssl, &proto, &proto_len);
1986−- }
1987−-
1988−- if (proto_len)
1989−- configuration.nextNegotiatedProtocol = QByteArray(reinterpret_cast<const char *>(proto), proto_len);
1990−- else
1991−- configuration.nextNegotiatedProtocol.clear();
1992−- }
1993−-#endif // OPENSSL_VERSION_NUMBER >= 0x1000100fL ...
1994−-
1995−-#if OPENSSL_VERSION_NUMBER >= 0x10002000L
1996−- if (q_SSLeay() >= 0x10002000L && mode == QSslSocket::SslClientMode) {
1997−- EVP_PKEY *key;
1998−- if (q_SSL_get_server_tmp_key(ssl, &key))
1999−- configuration.ephemeralServerKey = QSslKey(key, QSsl::PublicKey);
2000−- }
2001−-#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L ...
2002−-
2003−- connectionEncrypted = true;
2004−- emit q->encrypted();
2005−- if (autoStartHandshake && pendingClose) {
2006−- pendingClose = false;
2007−- q->disconnectFromHost();
2008−- }
2009−-}
2010−-
2011− QList<QSslCertificate> QSslSocketBackendPrivate::STACKOFX509_to_QSslCertificates(STACK_OF(X509) *x509)
2012− {
2013− ensureInitialized();
2014−@@ -1696,12 +1397,12 @@ QList<QSslError> QSslSocketBackendPrivate::verify(const QList<QSslCertificate> &
2015− QMutexLocker sslErrorListMutexLocker(&_q_sslErrorList()->mutex);
2016−
2017− // Register a custom callback to get all verification errors.
2018−- X509_STORE_set_verify_cb_func(certStore, q_X509Callback);
2019−+ q_X509_STORE_set_verify_cb(certStore, q_X509Callback);
2020−
2021− // Build the chain of intermediate certificates
2022− STACK_OF(X509) *intermediates = 0;
2023− if (certificateChain.length() > 1) {
2024−- intermediates = (STACK_OF(X509) *) q_sk_new_null();
2025−+ intermediates = (STACK_OF(X509) *) q_OPENSSL_sk_new_null();
2026−
2027− if (!intermediates) {
2028− q_X509_STORE_free(certStore);
2029−@@ -1715,11 +1416,8 @@ QList<QSslError> QSslSocketBackendPrivate::verify(const QList<QSslCertificate> &
2030− first = false;
2031− continue;
2032− }
2033−-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
2034−- q_sk_push( (_STACK *)intermediates, reinterpret_cast<X509 *>(cert.handle()));
2035−-#else
2036−- q_sk_push( (STACK *)intermediates, reinterpret_cast<char *>(cert.handle()));
2037−-#endif
2038−+
2039−+ q_OPENSSL_sk_push((OPENSSL_STACK *)intermediates, reinterpret_cast<X509 *>(cert.handle()));
2040− }
2041− }
2042−
2043−@@ -1743,11 +1441,7 @@ QList<QSslError> QSslSocketBackendPrivate::verify(const QList<QSslCertificate> &
2044− (void) q_X509_verify_cert(storeContext);
2045−
2046− q_X509_STORE_CTX_free(storeContext);
2047−-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
2048−- q_sk_free( (_STACK *) intermediates);
2049−-#else
2050−- q_sk_free( (STACK *) intermediates);
2051−-#endif
2052−+ q_OPENSSL_sk_free((OPENSSL_STACK *)intermediates);
2053−
2054− // Now process the errors
2055− const auto errorList = std::move(_q_sslErrorList()->errors);
2056−@@ -1821,7 +1515,8 @@ bool QSslSocketBackendPrivate::importPkcs12(QIODevice *device,
2057− // Convert to Qt types
2058− if (!key->d->fromEVP_PKEY(pkey)) {
2059− qCWarning(lcSsl, "Unable to convert private key");
2060−- q_sk_pop_free(reinterpret_cast<STACK *>(ca), reinterpret_cast<void(*)(void*)>(q_sk_free));
2061−+ q_OPENSSL_sk_pop_free(reinterpret_cast<OPENSSL_STACK *>(ca),
2062−+ reinterpret_cast<void (*)(void *)>(q_OPENSSL_sk_free));
2063− q_X509_free(x509);
2064− q_EVP_PKEY_free(pkey);
2065− q_PKCS12_free(p12);
2066−@@ -1836,7 +1531,11 @@ bool QSslSocketBackendPrivate::importPkcs12(QIODevice *device,
2067− *caCertificates = QSslSocketBackendPrivate::STACKOFX509_to_QSslCertificates(ca);
2068−
2069− // Clean up
2070−- q_sk_pop_free(reinterpret_cast<STACK *>(ca), reinterpret_cast<void(*)(void*)>(q_sk_free));
2071−+ // TODO: verify ASAP, in the past we had sk_pop_free with q_OPENSSL_sk_free
2072−+ // which seems to be blatantly wrong and even crashes with 1.1.
2073−+ q_OPENSSL_sk_pop_free(reinterpret_cast<OPENSSL_STACK *>(ca),
2074−+ reinterpret_cast<void (*)(void *)>(q_X509_free));
2075−+
2076− q_X509_free(x509);
2077− q_EVP_PKEY_free(pkey);
2078− q_PKCS12_free(p12);
2079−diff --git a/src/network/ssl/qsslsocket_openssl11.cpp b/src/network/ssl/qsslsocket_openssl11.cpp
2080−new file mode 100644
2081−index 0000000000..b6d18943a5
2082−--- /dev/null
2083−+++ b/src/network/ssl/qsslsocket_openssl11.cpp
2084−@@ -0,0 +1,285 @@
2085−+/****************************************************************************
2086−+**
2087−+** Copyright (C) 2017 The Qt Company Ltd.
2088−+** Copyright (C) 2014 Governikus GmbH & Co. KG
2089−+** Copyright (C) 2016 Richard J. Moore <rich@kde.org>
2090−+** Contact: https://www.qt.io/licensing/
2091−+**
2092−+** This file is part of the QtNetwork module of the Qt Toolkit.
2093−+**
2094−+** $QT_BEGIN_LICENSE:LGPL$
2095−+** Commercial License Usage
2096−+** Licensees holding valid commercial Qt licenses may use this file in
2097−+** accordance with the commercial license agreement provided with the
2098−+** Software or, alternatively, in accordance with the terms contained in
2099−+** a written agreement between you and The Qt Company. For licensing terms
2100−+** and conditions see https://www.qt.io/terms-conditions. For further
2101−+** information use the contact form at https://www.qt.io/contact-us.
2102−+**
2103−+** GNU Lesser General Public License Usage
2104−+** Alternatively, this file may be used under the terms of the GNU Lesser
2105−+** General Public License version 3 as published by the Free Software
2106−+** Foundation and appearing in the file LICENSE.LGPL3 included in the
2107−+** packaging of this file. Please review the following information to
2108−+** ensure the GNU Lesser General Public License version 3 requirements
2109−+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
2110−+**
2111−+** GNU General Public License Usage
2112−+** Alternatively, this file may be used under the terms of the GNU
2113−+** General Public License version 2.0 or (at your option) the GNU General
2114−+** Public license version 3 or any later version approved by the KDE Free
2115−+** Qt Foundation. The licenses are as published by the Free Software
2116−+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
2117−+** included in the packaging of this file. Please review the following
2118−+** information to ensure the GNU General Public License requirements will
2119−+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
2120−+** https://www.gnu.org/licenses/gpl-3.0.html.
2121−+**
2122−+** $QT_END_LICENSE$
2123−+**
2124−+****************************************************************************/
2125−+
2126−+/****************************************************************************
2127−+**
2128−+** In addition, as a special exception, the copyright holders listed above give
2129−+** permission to link the code of its release of Qt with the OpenSSL project's
2130−+** "OpenSSL" library (or modified versions of the "OpenSSL" library that use the
2131−+** same license as the original version), and distribute the linked executables.
2132−+**
2133−+** You must comply with the GNU General Public License version 2 in all
2134−+** respects for all of the code used other than the "OpenSSL" code. If you
2135−+** modify this file, you may extend this exception to your version of the file,
2136−+** but you are not obligated to do so. If you do not wish to do so, delete
2137−+** this exception statement from your version of this file.
2138−+**
2139−+****************************************************************************/
2140−+
2141−+//#define QT_DECRYPT_SSL_TRAFFIC
2142−+
2143−+#include "qssl_p.h"
2144−+#include "qsslsocket_openssl_p.h"
2145−+#include "qsslsocket_openssl_symbols_p.h"
2146−+#include "qsslsocket.h"
2147−+#include "qsslkey.h"
2148−+
2149−+#include <QtCore/qdebug.h>
2150−+#include <QtCore/qdir.h>
2151−+#include <QtCore/qdiriterator.h>
2152−+#include <QtCore/qfile.h>
2153−+#include <QtCore/qmutex.h>
2154−+#include <QtCore/qlibrary.h>
2155−+
2156−+QT_BEGIN_NAMESPACE
2157−+
2158−+Q_GLOBAL_STATIC_WITH_ARGS(QMutex, qt_opensslInitMutex, (QMutex::Recursive))
2159−+
2160−+/*!
2161−+ \internal
2162−+*/
2163−+void QSslSocketPrivate::deinitialize()
2164−+{
2165−+ // This function exists only for compatibility with the pre-11 code,
2166−+ // where deinitialize() actually does some cleanup. To be discarded
2167−+ // once we retire < 1.1.
2168−+}
2169−+
2170−+bool QSslSocketPrivate::ensureLibraryLoaded()
2171−+{
2172−+ if (!q_resolveOpenSslSymbols())
2173−+ return false;
2174−+
2175−+ const QMutexLocker locker(qt_opensslInitMutex);
2176−+
2177−+ if (!s_libraryLoaded) {
2178−+ s_libraryLoaded = true;
2179−+
2180−+ // Initialize OpenSSL.
2181−+ if (q_OPENSSL_init_ssl(0, nullptr) != 1)
2182−+ return false;
2183−+ q_SSL_load_error_strings();
2184−+ q_OpenSSL_add_all_algorithms();
2185−+
2186−+ QSslSocketBackendPrivate::s_indexForSSLExtraData
2187−+ = q_CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, 0L, nullptr, nullptr,
2188−+ nullptr, nullptr);
2189−+
2190−+ // Initialize OpenSSL's random seed.
2191−+ if (!q_RAND_status()) {
2192−+ qWarning("Random number generator not seeded, disabling SSL support");
2193−+ return false;
2194−+ }
2195−+ }
2196−+ return true;
2197−+}
2198−+
2199−+void QSslSocketPrivate::ensureCiphersAndCertsLoaded()
2200−+{
2201−+ const QMutexLocker locker(qt_opensslInitMutex);
2202−+
2203−+ if (s_loadedCiphersAndCerts)
2204−+ return;
2205−+ s_loadedCiphersAndCerts = true;
2206−+
2207−+ resetDefaultCiphers();
2208−+ resetDefaultEllipticCurves();
2209−+
2210−+#if QT_CONFIG(library)
2211−+ //load symbols needed to receive certificates from system store
2212−+#if defined(Q_OS_WIN)
2213−+ HINSTANCE hLib = LoadLibraryW(L"Crypt32");
2214−+ if (hLib) {
2215−+ ptrCertOpenSystemStoreW = (PtrCertOpenSystemStoreW)GetProcAddress(hLib, "CertOpenSystemStoreW");
2216−+ ptrCertFindCertificateInStore = (PtrCertFindCertificateInStore)GetProcAddress(hLib, "CertFindCertificateInStore");
2217−+ ptrCertCloseStore = (PtrCertCloseStore)GetProcAddress(hLib, "CertCloseStore");
2218−+ if (!ptrCertOpenSystemStoreW || !ptrCertFindCertificateInStore || !ptrCertCloseStore)
2219−+ qCWarning(lcSsl, "could not resolve symbols in crypt32 library"); // should never happen
2220−+ } else {
2221−+ qCWarning(lcSsl, "could not load crypt32 library"); // should never happen
2222−+ }
2223−+#elif defined(Q_OS_QNX)
2224−+ s_loadRootCertsOnDemand = true;
2225−+#elif defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
2226−+ // check whether we can enable on-demand root-cert loading (i.e. check whether the sym links are there)
2227−+ QList<QByteArray> dirs = unixRootCertDirectories();
2228−+ QStringList symLinkFilter;
2229−+ symLinkFilter << QLatin1String("[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9]");
2230−+ for (int a = 0; a < dirs.count(); ++a) {
2231−+ QDirIterator iterator(QLatin1String(dirs.at(a)), symLinkFilter, QDir::Files);
2232−+ if (iterator.hasNext()) {
2233−+ s_loadRootCertsOnDemand = true;
2234−+ break;
2235−+ }
2236−+ }
2237−+#endif
2238−+#endif // QT_CONFIG(library)
2239−+ // if on-demand loading was not enabled, load the certs now
2240−+ if (!s_loadRootCertsOnDemand)
2241−+ setDefaultCaCertificates(systemCaCertificates());
2242−+#ifdef Q_OS_WIN
2243−+ //Enabled for fetching additional root certs from windows update on windows 6+
2244−+ //This flag is set false by setDefaultCaCertificates() indicating the app uses
2245−+ //its own cert bundle rather than the system one.
2246−+ //Same logic that disables the unix on demand cert loading.
2247−+ //Unlike unix, we do preload the certificates from the cert store.
2248−+ if ((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_6_0)
2249−+ s_loadRootCertsOnDemand = true;
2250−+#endif
2251−+}
2252−+
2253−+long QSslSocketPrivate::sslLibraryVersionNumber()
2254−+{
2255−+ if (!supportsSsl())
2256−+ return 0;
2257−+
2258−+ return q_OpenSSL_version_num();
2259−+}
2260−+
2261−+QString QSslSocketPrivate::sslLibraryVersionString()
2262−+{
2263−+ if (!supportsSsl())
2264−+ return QString();
2265−+
2266−+ const char *versionString = q_OpenSSL_version(OPENSSL_VERSION);
2267−+ if (!versionString)
2268−+ return QString();
2269−+
2270−+ return QString::fromLatin1(versionString);
2271−+}
2272−+
2273−+void QSslSocketBackendPrivate::continueHandshake()
2274−+{
2275−+ Q_Q(QSslSocket);
2276−+ // if we have a max read buffer size, reset the plain socket's to match
2277−+ if (readBufferMaxSize)
2278−+ plainSocket->setReadBufferSize(readBufferMaxSize);
2279−+
2280−+ if (q_SSL_session_reused(ssl))
2281−+ configuration.peerSessionShared = true;
2282−+
2283−+#ifdef QT_DECRYPT_SSL_TRAFFIC
2284−+ if (q_SSL_get_session(ssl)) {
2285−+ size_t master_key_len = q_SSL_SESSION_get_master_key(q_SSL_get_session(ssl), 0, 0);
2286−+ size_t client_random_len = q_SSL_get_client_random(ssl, 0, 0);
2287−+ QByteArray masterKey(int(master_key_len), 0); // Will not overflow
2288−+ QByteArray clientRandom(int(client_random_len), 0); // Will not overflow
2289−+
2290−+ q_SSL_SESSION_get_master_key(q_SSL_get_session(ssl),
2291−+ reinterpret_cast<unsigned char*>(masterKey.data()),
2292−+ masterKey.size());
2293−+ q_SSL_get_client_random(ssl, reinterpret_cast<unsigned char *>(clientRandom.data()),
2294−+ clientRandom.size());
2295−+
2296−+ QByteArray debugLineClientRandom("CLIENT_RANDOM ");
2297−+ debugLineClientRandom.append(clientRandom.toHex().toUpper());
2298−+ debugLineClientRandom.append(" ");
2299−+ debugLineClientRandom.append(masterKey.toHex().toUpper());
2300−+ debugLineClientRandom.append("\n");
2301−+
2302−+ QString sslKeyFile = QDir::tempPath() + QLatin1String("/qt-ssl-keys");
2303−+ QFile file(sslKeyFile);
2304−+ if (!file.open(QIODevice::Append))
2305−+ qCWarning(lcSsl) << "could not open file" << sslKeyFile << "for appending";
2306−+ if (!file.write(debugLineClientRandom))
2307−+ qCWarning(lcSsl) << "could not write to file" << sslKeyFile;
2308−+ file.close();
2309−+ } else {
2310−+ qCWarning(lcSsl, "could not decrypt SSL traffic");
2311−+ }
2312−+#endif
2313−+
2314−+ // Cache this SSL session inside the QSslContext
2315−+ if (!(configuration.sslOptions & QSsl::SslOptionDisableSessionSharing)) {
2316−+ if (!sslContextPointer->cacheSession(ssl)) {
2317−+ sslContextPointer.clear(); // we could not cache the session
2318−+ } else {
2319−+ // Cache the session for permanent usage as well
2320−+ if (!(configuration.sslOptions & QSsl::SslOptionDisableSessionPersistence)) {
2321−+ if (!sslContextPointer->sessionASN1().isEmpty())
2322−+ configuration.sslSession = sslContextPointer->sessionASN1();
2323−+ configuration.sslSessionTicketLifeTimeHint = sslContextPointer->sessionTicketLifeTimeHint();
2324−+ }
2325−+ }
2326−+ }
2327−+
2328−+#if !defined(OPENSSL_NO_NEXTPROTONEG)
2329−+
2330−+ configuration.nextProtocolNegotiationStatus = sslContextPointer->npnContext().status;
2331−+ if (sslContextPointer->npnContext().status == QSslConfiguration::NextProtocolNegotiationUnsupported) {
2332−+ // we could not agree -> be conservative and use HTTP/1.1
2333−+ configuration.nextNegotiatedProtocol = QByteArrayLiteral("http/1.1");
2334−+ } else {
2335−+ const unsigned char *proto = 0;
2336−+ unsigned int proto_len = 0;
2337−+
2338−+ q_SSL_get0_alpn_selected(ssl, &proto, &proto_len);
2339−+ if (proto_len && mode == QSslSocket::SslClientMode) {
2340−+ // Client does not have a callback that sets it ...
2341−+ configuration.nextProtocolNegotiationStatus = QSslConfiguration::NextProtocolNegotiationNegotiated;
2342−+ }
2343−+
2344−+ if (!proto_len) { // Test if NPN was more lucky ...
2345−+ q_SSL_get0_next_proto_negotiated(ssl, &proto, &proto_len);
2346−+ }
2347−+
2348−+ if (proto_len)
2349−+ configuration.nextNegotiatedProtocol = QByteArray(reinterpret_cast<const char *>(proto), proto_len);
2350−+ else
2351−+ configuration.nextNegotiatedProtocol.clear();
2352−+ }
2353−+#endif // !defined(OPENSSL_NO_NEXTPROTONEG)
2354−+
2355−+ if (mode == QSslSocket::SslClientMode) {
2356−+ EVP_PKEY *key;
2357−+ if (q_SSL_get_server_tmp_key(ssl, &key))
2358−+ configuration.ephemeralServerKey = QSslKey(key, QSsl::PublicKey);
2359−+ }
2360−+
2361−+ connectionEncrypted = true;
2362−+ emit q->encrypted();
2363−+ if (autoStartHandshake && pendingClose) {
2364−+ pendingClose = false;
2365−+ q->disconnectFromHost();
2366−+ }
2367−+}
2368−+
2369−+QT_END_NAMESPACE
2370−diff --git a/src/network/ssl/qsslsocket_openssl11_symbols_p.h b/src/network/ssl/qsslsocket_openssl11_symbols_p.h
2371−new file mode 100644
2372−index 0000000000..2980b3d23e
2373−--- /dev/null
2374−+++ b/src/network/ssl/qsslsocket_openssl11_symbols_p.h
2375−@@ -0,0 +1,132 @@
2376−+/****************************************************************************
2377−+**
2378−+** Copyright (C) 2017 The Qt Company Ltd.
2379−+** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
2380−+** Copyright (C) 2016 Richard J. Moore <rich@kde.org>
2381−+** Contact: https://www.qt.io/licensing/
2382−+**
2383−+** This file is part of the QtNetwork module of the Qt Toolkit.
2384−+**
2385−+** $QT_BEGIN_LICENSE:LGPL$
2386−+** Commercial License Usage
2387−+** Licensees holding valid commercial Qt licenses may use this file in
2388−+** accordance with the commercial license agreement provided with the
2389−+** Software or, alternatively, in accordance with the terms contained in
2390−+** a written agreement between you and The Qt Company. For licensing terms
2391−+** and conditions see https://www.qt.io/terms-conditions. For further
2392−+** information use the contact form at https://www.qt.io/contact-us.
2393−+**
2394−+** GNU Lesser General Public License Usage
2395−+** Alternatively, this file may be used under the terms of the GNU Lesser
2396−+** General Public License version 3 as published by the Free Software
2397−+** Foundation and appearing in the file LICENSE.LGPL3 included in the
2398−+** packaging of this file. Please review the following information to
2399−+** ensure the GNU Lesser General Public License version 3 requirements
2400−+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
2401−+**
2402−+** GNU General Public License Usage
2403−+** Alternatively, this file may be used under the terms of the GNU
2404−+** General Public License version 2.0 or (at your option) the GNU General
2405−+** Public license version 3 or any later version approved by the KDE Free
2406−+** Qt Foundation. The licenses are as published by the Free Software
2407−+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
2408−+** included in the packaging of this file. Please review the following
2409−+** information to ensure the GNU General Public License requirements will
2410−+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
2411−+** https://www.gnu.org/licenses/gpl-3.0.html.
2412−+**
2413−+** $QT_END_LICENSE$
2414−+**
2415−+****************************************************************************/
2416−+
2417−+/****************************************************************************
2418−+**
2419−+** In addition, as a special exception, the copyright holders listed above give
2420−+** permission to link the code of its release of Qt with the OpenSSL project's
2421−+** "OpenSSL" library (or modified versions of the "OpenSSL" library that use the
2422−+** same license as the original version), and distribute the linked executables.
2423−+**
2424−+** You must comply with the GNU General Public License version 2 in all
2425−+** respects for all of the code used other than the "OpenSSL" code. If you
2426−+** modify this file, you may extend this exception to your version of the file,
2427−+** but you are not obligated to do so. If you do not wish to do so, delete
2428−+** this exception statement from your version of this file.
2429−+**
2430−+****************************************************************************/
2431−+
2432−+#ifndef QSSLSOCKET_OPENSSL11_SYMBOLS_P_H
2433−+#define QSSLSOCKET_OPENSSL11_SYMBOLS_P_H
2434−+
2435−+//
2436−+// W A R N I N G
2437−+// -------------
2438−+//
2439−+// This file is not part of the Qt API. It exists purely as an
2440−+// implementation detail. This header file may change from version to
2441−+// version without notice, or even be removed.
2442−+//
2443−+// We mean it.
2444−+//
2445−+
2446−+// Note: this file does not have QT_BEGIN_NAMESPACE/QT_END_NAMESPACE, it's done
2447−+// in qsslsocket_openssl_symbols_p.h.
2448−+
2449−+#ifndef QSSLSOCKET_OPENSSL_SYMBOLS_P_H
2450−+#error "You are not supposed to use this header file, include qsslsocket_openssl_symbols_p.h instead"
2451−+#endif
2452−+
2453−+const unsigned char * q_ASN1_STRING_get0_data(const ASN1_STRING *x);
2454−+
2455−+Q_AUTOTEST_EXPORT BIO *q_BIO_new(const BIO_METHOD *a);
2456−+Q_AUTOTEST_EXPORT const BIO_METHOD *q_BIO_s_mem();
2457−+
2458−+int q_DSA_bits(DSA *a);
2459−+int q_EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *c);
2460−+int q_EVP_PKEY_base_id(EVP_PKEY *a);
2461−+int q_RSA_bits(RSA *a);
2462−+int q_OPENSSL_sk_num(OPENSSL_STACK *a);
2463−+void q_OPENSSL_sk_pop_free(OPENSSL_STACK *a, void (*b)(void *));
2464−+OPENSSL_STACK *q_OPENSSL_sk_new_null();
2465−+void q_OPENSSL_sk_push(OPENSSL_STACK *st, void *data);
2466−+void q_OPENSSL_sk_free(OPENSSL_STACK *a);
2467−+void * q_OPENSSL_sk_value(OPENSSL_STACK *a, int b);
2468−+int q_SSL_session_reused(SSL *a);
2469−+unsigned long q_SSL_CTX_set_options(SSL_CTX *ctx, unsigned long op);
2470−+int q_OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings);
2471−+size_t q_SSL_get_client_random(SSL *a, unsigned char *out, size_t outlen);
2472−+size_t q_SSL_SESSION_get_master_key(const SSL_SESSION *session, unsigned char *out, size_t outlen);
2473−+int q_CRYPTO_get_ex_new_index(int class_index, long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
2474−+const SSL_METHOD *q_TLS_method();
2475−+const SSL_METHOD *q_TLS_client_method();
2476−+const SSL_METHOD *q_TLS_server_method();
2477−+ASN1_TIME *q_X509_getm_notBefore(X509 *a);
2478−+ASN1_TIME *q_X509_getm_notAfter(X509 *a);
2479−+
2480−+long q_X509_get_version(X509 *a);
2481−+EVP_PKEY *q_X509_get_pubkey(X509 *a);
2482−+void q_X509_STORE_set_verify_cb(X509_STORE *ctx, X509_STORE_CTX_verify_cb verify_cb);
2483−+STACK_OF(X509) *q_X509_STORE_CTX_get0_chain(X509_STORE_CTX *ctx);
2484−+void q_DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g);
2485−+int q_DH_bits(DH *dh);
2486−+
2487−+# define q_SSL_load_error_strings() q_OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS \
2488−+ | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL)
2489−+
2490−+#define q_SKM_sk_num(type, st) ((int (*)(const STACK_OF(type) *))q_OPENSSL_sk_num)(st)
2491−+#define q_SKM_sk_value(type, st,i) ((type * (*)(const STACK_OF(type) *, int))q_OPENSSL_sk_value)(st, i)
2492−+
2493−+#define q_OPENSSL_add_all_algorithms_conf() q_OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \
2494−+ | OPENSSL_INIT_ADD_ALL_DIGESTS \
2495−+ | OPENSSL_INIT_LOAD_CONFIG, NULL)
2496−+#define q_OPENSSL_add_all_algorithms_noconf() q_OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \
2497−+ | OPENSSL_INIT_ADD_ALL_DIGESTS, NULL)
2498−+
2499−+int q_OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings);
2500−+void q_CRYPTO_free(void *str, const char *file, int line);
2501−+
2502−+long q_OpenSSL_version_num();
2503−+const char *q_OpenSSL_version(int type);
2504−+
2505−+unsigned long q_SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *session);
2506−+
2507−+#endif
2508−diff --git a/src/network/ssl/qsslsocket_openssl_p.h b/src/network/ssl/qsslsocket_openssl_p.h
2509−index b2adb3e547..7f9e884045 100644
2510−--- a/src/network/ssl/qsslsocket_openssl_p.h
2511−+++ b/src/network/ssl/qsslsocket_openssl_p.h
2512−@@ -1,6 +1,6 @@
2513− /****************************************************************************
2514− **
2515−-** Copyright (C) 2016 The Qt Company Ltd.
2516−+** Copyright (C) 2017 The Qt Company Ltd.
2517− ** Contact: https://www.qt.io/licensing/
2518− **
2519− ** This file is part of the QtNetwork module of the Qt Toolkit.
2520−@@ -98,8 +98,8 @@
2521− #include <openssl/crypto.h>
2522− #include <openssl/tls1.h>
2523−
2524−-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
2525−-typedef _STACK STACK;
2526−+#if QT_CONFIG(opensslv11)
2527−+#include <openssl/dh.h>
2528− #endif
2529−
2530− QT_BEGIN_NAMESPACE
2531−@@ -151,7 +151,7 @@ public:
2532− #endif
2533−
2534− Q_AUTOTEST_EXPORT static long setupOpenSslOptions(QSsl::SslProtocol protocol, QSsl::SslOptions sslOptions);
2535−- static QSslCipher QSslCipher_from_SSL_CIPHER(SSL_CIPHER *cipher);
2536−+ static QSslCipher QSslCipher_from_SSL_CIPHER(const SSL_CIPHER *cipher);
2537− static QList<QSslCertificate> STACKOFX509_to_QSslCertificates(STACK_OF(X509) *x509);
2538− static QList<QSslError> verify(const QList<QSslCertificate> &certificateChain, const QString &hostName);
2539− static QString getErrorsFromOpenSsl();
2540−diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp
2541−index c344a94427..0ef8bf6b5e 100644
2542−--- a/src/network/ssl/qsslsocket_openssl_symbols.cpp
2543−+++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp
2544−@@ -1,7 +1,8 @@
2545− /****************************************************************************
2546− **
2547−-** Copyright (C) 2016 The Qt Company Ltd.
2548−+** Copyright (C) 2017 The Qt Company Ltd.
2549− ** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
2550−+** Copyright (C) 2016 Richard J. Moore <rich@kde.org>
2551− ** Contact: https://www.qt.io/licensing/
2552− **
2553− ** This file is part of the QtNetwork module of the Qt Toolkit.
2554−@@ -136,49 +137,195 @@ void qsslSocketCannotResolveSymbolWarning(const char *functionName)
2555−
2556− #endif // QT_LINKED_OPENSSL
2557−
2558−+#if QT_CONFIG(opensslv11)
2559−+
2560−+// Below are the functions first introduced in version 1.1:
2561−+
2562−+DEFINEFUNC(const unsigned char *, ASN1_STRING_get0_data, const ASN1_STRING *a, a, return 0, return)
2563−+DEFINEFUNC2(int, OPENSSL_init_ssl, uint64_t opts, opts, const OPENSSL_INIT_SETTINGS *settings, settings, return 0, return)
2564−+DEFINEFUNC2(int, OPENSSL_init_crypto, uint64_t opts, opts, const OPENSSL_INIT_SETTINGS *settings, settings, return 0, return)
2565−+DEFINEFUNC(BIO *, BIO_new, const BIO_METHOD *a, a, return 0, return)
2566−+DEFINEFUNC(const BIO_METHOD *, BIO_s_mem, void, DUMMYARG, return 0, return)
2567−+DEFINEFUNC2(int, BN_is_word, BIGNUM *a, a, BN_ULONG w, w, return 0, return)
2568−+DEFINEFUNC(int, EVP_CIPHER_CTX_reset, EVP_CIPHER_CTX *c, c, return 0, return)
2569−+DEFINEFUNC(int, EVP_PKEY_base_id, EVP_PKEY *a, a, return NID_undef, return)
2570−+DEFINEFUNC(int, RSA_bits, RSA *a, a, return 0, return)
2571−+DEFINEFUNC(int, DSA_bits, DSA *a, a, return 0, return)
2572−+DEFINEFUNC(int, OPENSSL_sk_num, OPENSSL_STACK *a, a, return -1, return)
2573−+DEFINEFUNC2(void, OPENSSL_sk_pop_free, OPENSSL_STACK *a, a, void (*b)(void*), b, return, DUMMYARG)
2574−+DEFINEFUNC(OPENSSL_STACK *, OPENSSL_sk_new_null, DUMMYARG, DUMMYARG, return 0, return)
2575−+DEFINEFUNC2(void, OPENSSL_sk_push, OPENSSL_STACK *a, a, void *b, b, return, DUMMYARG)
2576−+DEFINEFUNC(void, OPENSSL_sk_free, OPENSSL_STACK *a, a, return, DUMMYARG)
2577−+DEFINEFUNC2(void *, OPENSSL_sk_value, OPENSSL_STACK *a, a, int b, b, return 0, return)
2578−+DEFINEFUNC(int, SSL_session_reused, SSL *a, a, return 0, return)
2579−+DEFINEFUNC2(unsigned long, SSL_CTX_set_options, SSL_CTX *ctx, ctx, unsigned long op, op, return 0, return)
2580−+DEFINEFUNC3(size_t, SSL_get_client_random, SSL *a, a, unsigned char *out, out, size_t outlen, outlen, return 0, return)
2581−+DEFINEFUNC3(size_t, SSL_SESSION_get_master_key, const SSL_SESSION *ses, ses, unsigned char *out, out, size_t outlen, outlen, return 0, return)
2582−+DEFINEFUNC6(int, CRYPTO_get_ex_new_index, int class_index, class_index, long argl, argl, void *argp, argp, CRYPTO_EX_new *new_func, new_func, CRYPTO_EX_dup *dup_func, dup_func, CRYPTO_EX_free *free_func, free_func, return -1, return)
2583−+
2584−+DEFINEFUNC(const SSL_METHOD *, TLS_method, DUMMYARG, DUMMYARG, return 0, return)
2585−+DEFINEFUNC(const SSL_METHOD *, TLS_client_method, DUMMYARG, DUMMYARG, return 0, return)
2586−+DEFINEFUNC(const SSL_METHOD *, TLS_server_method, DUMMYARG, DUMMYARG, return 0, return)
2587−+DEFINEFUNC(ASN1_TIME *, X509_getm_notBefore, X509 *a, a, return 0, return)
2588−+DEFINEFUNC(ASN1_TIME *, X509_getm_notAfter, X509 *a, a, return 0, return)
2589−+DEFINEFUNC(long, X509_get_version, X509 *a, a, return -1, return)
2590−+DEFINEFUNC(EVP_PKEY *, X509_get_pubkey, X509 *a, a, return 0, return)
2591−+DEFINEFUNC2(void, X509_STORE_set_verify_cb, X509_STORE *a, a, X509_STORE_CTX_verify_cb verify_cb, verify_cb, return, DUMMYARG)
2592−+DEFINEFUNC(STACK_OF(X509) *, X509_STORE_CTX_get0_chain, X509_STORE_CTX *a, a, return 0, return)
2593−+DEFINEFUNC3(void, CRYPTO_free, void *str, str, const char *file, file, int line, line, return, DUMMYARG)
2594−+DEFINEFUNC(long, OpenSSL_version_num, void, DUMMYARG, return 0, return)
2595−+DEFINEFUNC(const char *, OpenSSL_version, int a, a, return 0, return)
2596−+DEFINEFUNC(unsigned long, SSL_SESSION_get_ticket_lifetime_hint, const SSL_SESSION *session, session, return 0, return)
2597−+DEFINEFUNC4(void, DH_get0_pqg, const DH *dh, dh, const BIGNUM **p, p, const BIGNUM **q, q, const BIGNUM **g, g, return, DUMMYARG)
2598−+DEFINEFUNC(int, DH_bits, DH *dh, dh, return 0, return)
2599−+
2600−+#else // QT_CONFIG(opensslv11)
2601−+
2602−+// Functions below are either deprecated or removed in OpenSSL >= 1.1:
2603−+
2604−+DEFINEFUNC(unsigned char *, ASN1_STRING_data, ASN1_STRING *a, a, return 0, return)
2605−+
2606− #ifdef SSLEAY_MACROS
2607− DEFINEFUNC3(void *, ASN1_dup, i2d_of_void *a, a, d2i_of_void *b, b, char *c, c, return 0, return)
2608− #endif
2609−+DEFINEFUNC2(BIO *, BIO_new_file, const char *filename, filename, const char *mode, mode, return 0, return)
2610−+DEFINEFUNC(void, ERR_clear_error, DUMMYARG, DUMMYARG, return, DUMMYARG)
2611−+DEFINEFUNC(BIO *, BIO_new, BIO_METHOD *a, a, return 0, return)
2612−+DEFINEFUNC(BIO_METHOD *, BIO_s_mem, void, DUMMYARG, return 0, return)
2613−+DEFINEFUNC(int, CRYPTO_num_locks, DUMMYARG, DUMMYARG, return 0, return)
2614−+DEFINEFUNC(void, CRYPTO_set_locking_callback, void (*a)(int, int, const char *, int), a, return, DUMMYARG)
2615−+DEFINEFUNC(void, CRYPTO_set_id_callback, unsigned long (*a)(), a, return, DUMMYARG)
2616−+DEFINEFUNC(void, CRYPTO_free, void *a, a, return, DUMMYARG)
2617−+DEFINEFUNC(unsigned long, ERR_peek_last_error, DUMMYARG, DUMMYARG, return 0, return)
2618−+DEFINEFUNC(void, ERR_free_strings, void, DUMMYARG, return, DUMMYARG)
2619−+DEFINEFUNC(void, EVP_CIPHER_CTX_cleanup, EVP_CIPHER_CTX *a, a, return, DUMMYARG)
2620−+DEFINEFUNC(void, EVP_CIPHER_CTX_init, EVP_CIPHER_CTX *a, a, return, DUMMYARG)
2621−+
2622−+#ifdef SSLEAY_MACROS
2623−+DEFINEFUNC6(void *, PEM_ASN1_read_bio, d2i_of_void *a, a, const char *b, b, BIO *c, c, void **d, d, pem_password_cb *e, e, void *f, f, return 0, return)
2624−+DEFINEFUNC6(void *, PEM_ASN1_write_bio, d2i_of_void *a, a, const char *b, b, BIO *c, c, void **d, d, pem_password_cb *e, e, void *f, f, return 0, return)
2625−+#endif // SSLEAY_MACROS
2626−+
2627−+DEFINEFUNC(int, sk_num, STACK *a, a, return -1, return)
2628−+DEFINEFUNC2(void, sk_pop_free, STACK *a, a, void (*b)(void*), b, return, DUMMYARG)
2629−+
2630−+#if OPENSSL_VERSION_NUMBER >= 0x10000000L
2631−+DEFINEFUNC(_STACK *, sk_new_null, DUMMYARG, DUMMYARG, return 0, return)
2632−+DEFINEFUNC2(void, sk_push, _STACK *a, a, void *b, b, return, DUMMYARG)
2633−+DEFINEFUNC(void, sk_free, _STACK *a, a, return, DUMMYARG)
2634−+DEFINEFUNC2(void *, sk_value, STACK *a, a, int b, b, return 0, return)
2635−+#else
2636−+DEFINEFUNC(STACK *, sk_new_null, DUMMYARG, DUMMYARG, return 0, return)
2637−+DEFINEFUNC2(void, sk_push, STACK *a, a, char *b, b, return, DUMMYARG)
2638−+DEFINEFUNC(void, sk_free, STACK *a, a, return, DUMMYARG)
2639−+DEFINEFUNC2(char *, sk_value, STACK *a, a, int b, b, return 0, return)
2640−+#endif // OPENSSL_VERSION_NUMBER >= 0x10000000L
2641−+
2642−+DEFINEFUNC(int, SSL_library_init, void, DUMMYARG, return -1, return)
2643−+DEFINEFUNC(void, SSL_load_error_strings, void, DUMMYARG, return, DUMMYARG)
2644−+
2645−+#if OPENSSL_VERSION_NUMBER >= 0x10001000L
2646−+DEFINEFUNC5(int, SSL_get_ex_new_index, long argl, argl, void *argp, argp, CRYPTO_EX_new *new_func, new_func, CRYPTO_EX_dup *dup_func, dup_func, CRYPTO_EX_free *free_func, free_func, return -1, return)
2647−+#endif // OPENSSL_VERSION_NUMBER >= 0x10001000L
2648−+
2649−+#if OPENSSL_VERSION_NUMBER >= 0x10000000L
2650−+#ifndef OPENSSL_NO_SSL2
2651−+DEFINEFUNC(const SSL_METHOD *, SSLv2_client_method, DUMMYARG, DUMMYARG, return 0, return)
2652−+#endif
2653−+#ifndef OPENSSL_NO_SSL3_METHOD
2654−+DEFINEFUNC(const SSL_METHOD *, SSLv3_client_method, DUMMYARG, DUMMYARG, return 0, return)
2655−+#endif
2656−+DEFINEFUNC(const SSL_METHOD *, SSLv23_client_method, DUMMYARG, DUMMYARG, return 0, return)
2657−+DEFINEFUNC(const SSL_METHOD *, TLSv1_client_method, DUMMYARG, DUMMYARG, return 0, return)
2658−+#if OPENSSL_VERSION_NUMBER >= 0x10001000L
2659−+DEFINEFUNC(const SSL_METHOD *, TLSv1_1_client_method, DUMMYARG, DUMMYARG, return 0, return)
2660−+DEFINEFUNC(const SSL_METHOD *, TLSv1_2_client_method, DUMMYARG, DUMMYARG, return 0, return)
2661−+#endif
2662−+#ifndef OPENSSL_NO_SSL2
2663−+DEFINEFUNC(const SSL_METHOD *, SSLv2_server_method, DUMMYARG, DUMMYARG, return 0, return)
2664−+#endif
2665−+#ifndef OPENSSL_NO_SSL3_METHOD
2666−+DEFINEFUNC(const SSL_METHOD *, SSLv3_server_method, DUMMYARG, DUMMYARG, return 0, return)
2667−+#endif
2668−+DEFINEFUNC(const SSL_METHOD *, SSLv23_server_method, DUMMYARG, DUMMYARG, return 0, return)
2669−+DEFINEFUNC(const SSL_METHOD *, TLSv1_server_method, DUMMYARG, DUMMYARG, return 0, return)
2670−+#if OPENSSL_VERSION_NUMBER >= 0x10001000L
2671−+DEFINEFUNC(const SSL_METHOD *, TLSv1_1_server_method, DUMMYARG, DUMMYARG, return 0, return)
2672−+DEFINEFUNC(const SSL_METHOD *, TLSv1_2_server_method, DUMMYARG, DUMMYARG, return 0, return)
2673−+#endif
2674−+#else
2675−+#ifndef OPENSSL_NO_SSL2
2676−+DEFINEFUNC(SSL_METHOD *, SSLv2_client_method, DUMMYARG, DUMMYARG, return 0, return)
2677−+#endif
2678−+#ifndef OPENSSL_NO_SSL3_METHOD
2679−+DEFINEFUNC(SSL_METHOD *, SSLv3_client_method, DUMMYARG, DUMMYARG, return 0, return)
2680−+#endif
2681−+DEFINEFUNC(SSL_METHOD *, SSLv23_client_method, DUMMYARG, DUMMYARG, return 0, return)
2682−+DEFINEFUNC(SSL_METHOD *, TLSv1_client_method, DUMMYARG, DUMMYARG, return 0, return)
2683−+#ifndef OPENSSL_NO_SSL2
2684−+DEFINEFUNC(SSL_METHOD *, SSLv2_server_method, DUMMYARG, DUMMYARG, return 0, return)
2685−+#endif
2686−+#ifndef OPENSSL_NO_SSL3_METHOD
2687−+DEFINEFUNC(SSL_METHOD *, SSLv3_server_method, DUMMYARG, DUMMYARG, return 0, return)
2688−+#endif
2689−+DEFINEFUNC(SSL_METHOD *, SSLv23_server_method, DUMMYARG, DUMMYARG, return 0, return)
2690−+DEFINEFUNC(SSL_METHOD *, TLSv1_server_method, DUMMYARG, DUMMYARG, return 0, return)
2691−+#endif
2692−+
2693−+DEFINEFUNC(STACK_OF(X509) *, X509_STORE_CTX_get_chain, X509_STORE_CTX *a, a, return 0, return)
2694−+
2695−+#ifdef SSLEAY_MACROS
2696−+DEFINEFUNC2(int, i2d_DSAPrivateKey, const DSA *a, a, unsigned char **b, b, return -1, return)
2697−+DEFINEFUNC2(int, i2d_RSAPrivateKey, const RSA *a, a, unsigned char **b, b, return -1, return)
2698−+#ifndef OPENSSL_NO_EC
2699−+DEFINEFUNC2(int, i2d_ECPrivateKey, const EC_KEY *a, a, unsigned char **b, b, return -1, return)
2700−+#endif
2701−+DEFINEFUNC3(RSA *, d2i_RSAPrivateKey, RSA **a, a, unsigned char **b, b, long c, c, return 0, return)
2702−+DEFINEFUNC3(DSA *, d2i_DSAPrivateKey, DSA **a, a, unsigned char **b, b, long c, c, return 0, return)
2703−+#ifndef OPENSSL_NO_EC
2704−+DEFINEFUNC3(EC_KEY *, d2i_ECPrivateKey, EC_KEY **a, a, unsigned char **b, b, long c, c, return 0, return)
2705−+#endif
2706−+#endif
2707−+DEFINEFUNC(char *, CONF_get1_default_config_file, DUMMYARG, DUMMYARG, return 0, return)
2708−+DEFINEFUNC(void, OPENSSL_add_all_algorithms_noconf, void, DUMMYARG, return, DUMMYARG)
2709−+DEFINEFUNC(void, OPENSSL_add_all_algorithms_conf, void, DUMMYARG, return, DUMMYARG)
2710−+DEFINEFUNC(long, SSLeay, void, DUMMYARG, return 0, return)
2711−+DEFINEFUNC(const char *, SSLeay_version, int a, a, return 0, return)
2712−+
2713−+#endif // QT_CONFIG(opensslv11)
2714−+
2715− DEFINEFUNC(long, ASN1_INTEGER_get, ASN1_INTEGER *a, a, return 0, return)
2716−-DEFINEFUNC(unsigned char *, ASN1_STRING_data, ASN1_STRING *a, a, return 0, return)
2717− DEFINEFUNC(int, ASN1_STRING_length, ASN1_STRING *a, a, return 0, return)
2718−-DEFINEFUNC2(int, ASN1_STRING_to_UTF8, unsigned char **a, a, ASN1_STRING *b, b, return 0, return);
2719−+DEFINEFUNC2(int, ASN1_STRING_to_UTF8, unsigned char **a, a, ASN1_STRING *b, b, return 0, return)
2720− DEFINEFUNC4(long, BIO_ctrl, BIO *a, a, int b, b, long c, c, void *d, d, return -1, return)
2721− DEFINEFUNC(int, BIO_free, BIO *a, a, return 0, return)
2722−-DEFINEFUNC(BIO *, BIO_new, BIO_METHOD *a, a, return 0, return)
2723− DEFINEFUNC2(BIO *, BIO_new_mem_buf, void *a, a, int b, b, return 0, return)
2724− DEFINEFUNC3(int, BIO_read, BIO *a, a, void *b, b, int c, c, return -1, return)
2725−-DEFINEFUNC(BIO_METHOD *, BIO_s_mem, void, DUMMYARG, return 0, return)
2726−+
2727− DEFINEFUNC3(int, BIO_write, BIO *a, a, const void *b, b, int c, c, return -1, return)
2728− DEFINEFUNC(int, BN_num_bits, const BIGNUM *a, a, return 0, return)
2729−-#if OPENSSL_VERSION_NUMBER >= 0x10100000L
2730−-DEFINEFUNC2(int, BN_is_word, BIGNUM *a, a, BN_ULONG w, w, return 0, return)
2731−-#endif
2732− DEFINEFUNC2(BN_ULONG, BN_mod_word, const BIGNUM *a, a, BN_ULONG w, w, return static_cast<BN_ULONG>(-1), return)
2733− #ifndef OPENSSL_NO_EC
2734− DEFINEFUNC(const EC_GROUP*, EC_KEY_get0_group, const EC_KEY* k, k, return 0, return)
2735− DEFINEFUNC(int, EC_GROUP_get_degree, const EC_GROUP* g, g, return 0, return)
2736− #endif
2737−-DEFINEFUNC(int, CRYPTO_num_locks, DUMMYARG, DUMMYARG, return 0, return)
2738−-DEFINEFUNC(void, CRYPTO_set_locking_callback, void (*a)(int, int, const char *, int), a, return, DUMMYARG)
2739−-DEFINEFUNC(void, CRYPTO_set_id_callback, unsigned long (*a)(), a, return, DUMMYARG)
2740−-DEFINEFUNC(void, CRYPTO_free, void *a, a, return, DUMMYARG)
2741− DEFINEFUNC(DSA *, DSA_new, DUMMYARG, DUMMYARG, return 0, return)
2742− DEFINEFUNC(void, DSA_free, DSA *a, a, return, DUMMYARG)
2743− DEFINEFUNC3(X509 *, d2i_X509, X509 **a, a, const unsigned char **b, b, long c, c, return 0, return)
2744− DEFINEFUNC2(char *, ERR_error_string, unsigned long a, a, char *b, b, return 0, return)
2745− DEFINEFUNC(unsigned long, ERR_get_error, DUMMYARG, DUMMYARG, return 0, return)
2746−-DEFINEFUNC(void, ERR_free_strings, void, DUMMYARG, return, DUMMYARG)
2747−-DEFINEFUNC(void, EVP_CIPHER_CTX_cleanup, EVP_CIPHER_CTX *a, a, return, DUMMYARG)
2748−-DEFINEFUNC(void, EVP_CIPHER_CTX_init, EVP_CIPHER_CTX *a, a, return, DUMMYARG)
2749−-DEFINEFUNC4(int, EVP_CIPHER_CTX_ctrl, EVP_CIPHER_CTX *ctx, ctx, int type, type, int arg, arg, void *ptr, ptr, return 0, return);
2750−+DEFINEFUNC(EVP_CIPHER_CTX *, EVP_CIPHER_CTX_new, void, DUMMYARG, return 0, return)
2751−+DEFINEFUNC(void, EVP_CIPHER_CTX_free, EVP_CIPHER_CTX *a, a, return, DUMMYARG)
2752−+DEFINEFUNC4(int, EVP_CIPHER_CTX_ctrl, EVP_CIPHER_CTX *ctx, ctx, int type, type, int arg, arg, void *ptr, ptr, return 0, return)
2753− DEFINEFUNC2(int, EVP_CIPHER_CTX_set_key_length, EVP_CIPHER_CTX *ctx, ctx, int keylen, keylen, return 0, return)
2754−-DEFINEFUNC5(int, EVP_CipherInit, EVP_CIPHER_CTX *ctx, ctx, const EVP_CIPHER *type, type, const unsigned char *key, key, const unsigned char *iv, iv, int enc, enc, return 0, return);
2755−-DEFINEFUNC5(int, EVP_CipherUpdate, EVP_CIPHER_CTX *ctx, ctx, unsigned char *out, out, int *outl, outl, const unsigned char *in, in, int inl, inl, return 0, return);
2756−-DEFINEFUNC3(int, EVP_CipherFinal, EVP_CIPHER_CTX *ctx, ctx, unsigned char *out, out, int *outl, outl, return 0, return);
2757−+DEFINEFUNC5(int, EVP_CipherInit, EVP_CIPHER_CTX *ctx, ctx, const EVP_CIPHER *type, type, const unsigned char *key, key, const unsigned char *iv, iv, int enc, enc, return 0, return)
2758−+DEFINEFUNC6(int, EVP_CipherInit_ex, EVP_CIPHER_CTX *ctx, ctx, const EVP_CIPHER *cipher, cipher, ENGINE *impl, impl, const unsigned char *key, key, const unsigned char *iv, iv, int enc, enc, return 0, return)
2759−+DEFINEFUNC5(int, EVP_CipherUpdate, EVP_CIPHER_CTX *ctx, ctx, unsigned char *out, out, int *outl, outl, const unsigned char *in, in, int inl, inl, return 0, return)
2760−+DEFINEFUNC3(int, EVP_CipherFinal, EVP_CIPHER_CTX *ctx, ctx, unsigned char *out, out, int *outl, outl, return 0, return)
2761− DEFINEFUNC(const EVP_CIPHER *, EVP_des_cbc, DUMMYARG, DUMMYARG, return 0, return)
2762− DEFINEFUNC(const EVP_CIPHER *, EVP_des_ede3_cbc, DUMMYARG, DUMMYARG, return 0, return)
2763− DEFINEFUNC(const EVP_CIPHER *, EVP_rc2_cbc, DUMMYARG, DUMMYARG, return 0, return)
2764−+DEFINEFUNC(const EVP_MD *, EVP_sha1, DUMMYARG, DUMMYARG, return 0, return)
2765− DEFINEFUNC3(int, EVP_PKEY_assign, EVP_PKEY *a, a, int b, b, char *c, c, return -1, return)
2766− DEFINEFUNC2(int, EVP_PKEY_set1_RSA, EVP_PKEY *a, a, RSA *b, b, return -1, return)
2767− DEFINEFUNC2(int, EVP_PKEY_set1_DSA, EVP_PKEY *a, a, DSA *b, b, return -1, return)
2768−@@ -202,10 +349,8 @@ DEFINEFUNC3(int, i2t_ASN1_OBJECT, char *a, a, int b, b, ASN1_OBJECT *c, c, retur
2769− DEFINEFUNC4(int, OBJ_obj2txt, char *a, a, int b, b, ASN1_OBJECT *c, c, int d, d, return -1, return)
2770−
2771− DEFINEFUNC(int, OBJ_obj2nid, const ASN1_OBJECT *a, a, return NID_undef, return)
2772−-#ifdef SSLEAY_MACROS
2773−-DEFINEFUNC6(void *, PEM_ASN1_read_bio, d2i_of_void *a, a, const char *b, b, BIO *c, c, void **d, d, pem_password_cb *e, e, void *f, f, return 0, return)
2774−-DEFINEFUNC6(void *, PEM_ASN1_write_bio, d2i_of_void *a, a, const char *b, b, BIO *c, c, void **d, d, pem_password_cb *e, e, void *f, f, return 0, return)
2775−-#else
2776−+
2777−+#ifndef SSLEAY_MACROS
2778− DEFINEFUNC4(EVP_PKEY *, PEM_read_bio_PrivateKey, BIO *a, a, EVP_PKEY **b, b, pem_password_cb *c, c, void *d, d, return 0, return)
2779− DEFINEFUNC4(DSA *, PEM_read_bio_DSAPrivateKey, BIO *a, a, DSA **b, b, pem_password_cb *c, c, void *d, d, return 0, return)
2780− DEFINEFUNC4(RSA *, PEM_read_bio_RSAPrivateKey, BIO *a, a, RSA **b, b, pem_password_cb *c, c, void *d, d, return 0, return)
2781−@@ -218,7 +363,7 @@ DEFINEFUNC7(int, PEM_write_bio_RSAPrivateKey, BIO *a, a, RSA *b, b, const EVP_CI
2782− #ifndef OPENSSL_NO_EC
2783− DEFINEFUNC7(int, PEM_write_bio_ECPrivateKey, BIO *a, a, EC_KEY *b, b, const EVP_CIPHER *c, c, unsigned char *d, d, int e, e, pem_password_cb *f, f, void *g, g, return 0, return)
2784− #endif
2785−-#endif
2786−+#endif // !SSLEAY_MACROS
2787− DEFINEFUNC4(EVP_PKEY *, PEM_read_bio_PUBKEY, BIO *a, a, EVP_PKEY **b, b, pem_password_cb *c, c, void *d, d, return 0, return)
2788− DEFINEFUNC4(DSA *, PEM_read_bio_DSA_PUBKEY, BIO *a, a, DSA **b, b, pem_password_cb *c, c, void *d, d, return 0, return)
2789− DEFINEFUNC4(RSA *, PEM_read_bio_RSA_PUBKEY, BIO *a, a, RSA **b, b, pem_password_cb *c, c, void *d, d, return 0, return)
2790−@@ -234,23 +379,10 @@ DEFINEFUNC2(void, RAND_seed, const void *a, a, int b, b, return, DUMMYARG)
2791− DEFINEFUNC(int, RAND_status, void, DUMMYARG, return -1, return)
2792− DEFINEFUNC(RSA *, RSA_new, DUMMYARG, DUMMYARG, return 0, return)
2793− DEFINEFUNC(void, RSA_free, RSA *a, a, return, DUMMYARG)
2794−-DEFINEFUNC(int, sk_num, STACK *a, a, return -1, return)
2795−-DEFINEFUNC2(void, sk_pop_free, STACK *a, a, void (*b)(void*), b, return, DUMMYARG)
2796−-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
2797−-DEFINEFUNC(_STACK *, sk_new_null, DUMMYARG, DUMMYARG, return 0, return)
2798−-DEFINEFUNC2(void, sk_push, _STACK *a, a, void *b, b, return, DUMMYARG)
2799−-DEFINEFUNC(void, sk_free, _STACK *a, a, return, DUMMYARG)
2800−-DEFINEFUNC2(void *, sk_value, STACK *a, a, int b, b, return 0, return)
2801−-#else
2802−-DEFINEFUNC(STACK *, sk_new_null, DUMMYARG, DUMMYARG, return 0, return)
2803−-DEFINEFUNC2(void, sk_push, STACK *a, a, char *b, b, return, DUMMYARG)
2804−-DEFINEFUNC(void, sk_free, STACK *a, a, return, DUMMYARG)
2805−-DEFINEFUNC2(char *, sk_value, STACK *a, a, int b, b, return 0, return)
2806−-#endif
2807− DEFINEFUNC(int, SSL_accept, SSL *a, a, return -1, return)
2808− DEFINEFUNC(int, SSL_clear, SSL *a, a, return -1, return)
2809−-DEFINEFUNC3(char *, SSL_CIPHER_description, SSL_CIPHER *a, a, char *b, b, int c, c, return 0, return)
2810−-DEFINEFUNC2(int, SSL_CIPHER_get_bits, SSL_CIPHER *a, a, int *b, b, return 0, return)
2811−+DEFINEFUNC3(char *, SSL_CIPHER_description, const SSL_CIPHER *a, a, char *b, b, int c, c, return 0, return)
2812−+DEFINEFUNC2(int, SSL_CIPHER_get_bits, const SSL_CIPHER *a, a, int *b, b, return 0, return)
2813− DEFINEFUNC(int, SSL_connect, SSL *a, a, return -1, return)
2814− DEFINEFUNC(int, SSL_CTX_check_private_key, const SSL_CTX *a, a, return -1, return)
2815− DEFINEFUNC4(long, SSL_CTX_ctrl, SSL_CTX *a, a, int b, b, long c, c, void *d, d, return -1, return)
2816−@@ -287,8 +419,6 @@ DEFINEFUNC(long, SSL_get_verify_result, const SSL *a, a, return -1, return)
2817− #else
2818− DEFINEFUNC(long, SSL_get_verify_result, SSL *a, a, return -1, return)
2819− #endif
2820−-DEFINEFUNC(int, SSL_library_init, void, DUMMYARG, return -1, return)
2821−-DEFINEFUNC(void, SSL_load_error_strings, void, DUMMYARG, return, DUMMYARG)
2822− DEFINEFUNC(SSL *, SSL_new, SSL_CTX *a, a, return 0, return)
2823− DEFINEFUNC4(long, SSL_ctrl, SSL *a, a, int cmd, cmd, long larg, larg, void *parg, parg, return -1, return)
2824− DEFINEFUNC3(int, SSL_read, SSL *a, a, void *b, b, int c, c, return -1, return)
2825−@@ -301,7 +431,6 @@ DEFINEFUNC(void, SSL_SESSION_free, SSL_SESSION *ses, ses, return, DUMMYARG)
2826− DEFINEFUNC(SSL_SESSION*, SSL_get1_session, SSL *ssl, ssl, return 0, return)
2827− DEFINEFUNC(SSL_SESSION*, SSL_get_session, const SSL *ssl, ssl, return 0, return)
2828− #if OPENSSL_VERSION_NUMBER >= 0x10001000L
2829−-DEFINEFUNC5(int, SSL_get_ex_new_index, long argl, argl, void *argp, argp, CRYPTO_EX_new *new_func, new_func, CRYPTO_EX_dup *dup_func, dup_func, CRYPTO_EX_free *free_func, free_func, return -1, return)
2830− DEFINEFUNC3(int, SSL_set_ex_data, SSL *ssl, ssl, int idx, idx, void *arg, arg, return 0, return)
2831− DEFINEFUNC2(void *, SSL_get_ex_data, const SSL *ssl, ssl, int idx, idx, return NULL, return)
2832− #endif
2833−@@ -310,51 +439,9 @@ DEFINEFUNC2(void, SSL_set_psk_client_callback, SSL* ssl, ssl, q_psk_client_callb
2834− DEFINEFUNC2(void, SSL_set_psk_server_callback, SSL* ssl, ssl, q_psk_server_callback_t callback, callback, return, DUMMYARG)
2835− DEFINEFUNC2(int, SSL_CTX_use_psk_identity_hint, SSL_CTX* ctx, ctx, const char *hint, hint, return 0, return)
2836− #endif
2837−-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
2838−-#ifndef OPENSSL_NO_SSL2
2839−-DEFINEFUNC(const SSL_METHOD *, SSLv2_client_method, DUMMYARG, DUMMYARG, return 0, return)
2840−-#endif
2841−-#ifndef OPENSSL_NO_SSL3_METHOD
2842−-DEFINEFUNC(const SSL_METHOD *, SSLv3_client_method, DUMMYARG, DUMMYARG, return 0, return)
2843−-#endif
2844−-DEFINEFUNC(const SSL_METHOD *, SSLv23_client_method, DUMMYARG, DUMMYARG, return 0, return)
2845−-DEFINEFUNC(const SSL_METHOD *, TLSv1_client_method, DUMMYARG, DUMMYARG, return 0, return)
2846−-#if OPENSSL_VERSION_NUMBER >= 0x10001000L
2847−-DEFINEFUNC(const SSL_METHOD *, TLSv1_1_client_method, DUMMYARG, DUMMYARG, return 0, return)
2848−-DEFINEFUNC(const SSL_METHOD *, TLSv1_2_client_method, DUMMYARG, DUMMYARG, return 0, return)
2849−-#endif
2850−-#ifndef OPENSSL_NO_SSL2
2851−-DEFINEFUNC(const SSL_METHOD *, SSLv2_server_method, DUMMYARG, DUMMYARG, return 0, return)
2852−-#endif
2853−-#ifndef OPENSSL_NO_SSL3_METHOD
2854−-DEFINEFUNC(const SSL_METHOD *, SSLv3_server_method, DUMMYARG, DUMMYARG, return 0, return)
2855−-#endif
2856−-DEFINEFUNC(const SSL_METHOD *, SSLv23_server_method, DUMMYARG, DUMMYARG, return 0, return)
2857−-DEFINEFUNC(const SSL_METHOD *, TLSv1_server_method, DUMMYARG, DUMMYARG, return 0, return)
2858−-#if OPENSSL_VERSION_NUMBER >= 0x10001000L
2859−-DEFINEFUNC(const SSL_METHOD *, TLSv1_1_server_method, DUMMYARG, DUMMYARG, return 0, return)
2860−-DEFINEFUNC(const SSL_METHOD *, TLSv1_2_server_method, DUMMYARG, DUMMYARG, return 0, return)
2861−-#endif
2862−-#else
2863−-#ifndef OPENSSL_NO_SSL2
2864−-DEFINEFUNC(SSL_METHOD *, SSLv2_client_method, DUMMYARG, DUMMYARG, return 0, return)
2865−-#endif
2866−-#ifndef OPENSSL_NO_SSL3_METHOD
2867−-DEFINEFUNC(SSL_METHOD *, SSLv3_client_method, DUMMYARG, DUMMYARG, return 0, return)
2868−-#endif
2869−-DEFINEFUNC(SSL_METHOD *, SSLv23_client_method, DUMMYARG, DUMMYARG, return 0, return)
2870−-DEFINEFUNC(SSL_METHOD *, TLSv1_client_method, DUMMYARG, DUMMYARG, return 0, return)
2871−-#ifndef OPENSSL_NO_SSL2
2872−-DEFINEFUNC(SSL_METHOD *, SSLv2_server_method, DUMMYARG, DUMMYARG, return 0, return)
2873−-#endif
2874−-#ifndef OPENSSL_NO_SSL3_METHOD
2875−-DEFINEFUNC(SSL_METHOD *, SSLv3_server_method, DUMMYARG, DUMMYARG, return 0, return)
2876−-#endif
2877−-DEFINEFUNC(SSL_METHOD *, SSLv23_server_method, DUMMYARG, DUMMYARG, return 0, return)
2878−-DEFINEFUNC(SSL_METHOD *, TLSv1_server_method, DUMMYARG, DUMMYARG, return 0, return)
2879−-#endif
2880− DEFINEFUNC3(int, SSL_write, SSL *a, a, const void *b, b, int c, c, return -1, return)
2881− DEFINEFUNC2(int, X509_cmp, X509 *a, a, X509 *b, b, return -1, return)
2882−+DEFINEFUNC4(int, X509_digest, const X509 *x509, x509, const EVP_MD *type, type, unsigned char *md, md, unsigned int *len, len, return -1, return)
2883− #ifndef SSLEAY_MACROS
2884− DEFINEFUNC(X509 *, X509_dup, X509 *a, a, return 0, return)
2885− #endif
2886−@@ -378,6 +465,7 @@ DEFINEFUNC2(int, ASN1_STRING_print, BIO *a, a, ASN1_STRING *b, b, return 0, retu
2887− DEFINEFUNC2(int, X509_check_issued, X509 *a, a, X509 *b, b, return -1, return)
2888− DEFINEFUNC(X509_NAME *, X509_get_issuer_name, X509 *a, a, return 0, return)
2889− DEFINEFUNC(X509_NAME *, X509_get_subject_name, X509 *a, a, return 0, return)
2890−+DEFINEFUNC(ASN1_INTEGER *, X509_get_serialNumber, X509 *a, a, return 0, return)
2891− DEFINEFUNC(int, X509_verify_cert, X509_STORE_CTX *a, a, return -1, return)
2892− DEFINEFUNC(int, X509_NAME_entry_count, X509_NAME *a, a, return 0, return)
2893− DEFINEFUNC2(X509_NAME_ENTRY *, X509_NAME_get_entry, X509_NAME *a, a, int b, b, return 0, return)
2894−@@ -393,25 +481,8 @@ DEFINEFUNC2(int, X509_STORE_CTX_set_purpose, X509_STORE_CTX *a, a, int b, b, ret
2895− DEFINEFUNC(int, X509_STORE_CTX_get_error, X509_STORE_CTX *a, a, return -1, return)
2896− DEFINEFUNC(int, X509_STORE_CTX_get_error_depth, X509_STORE_CTX *a, a, return -1, return)
2897− DEFINEFUNC(X509 *, X509_STORE_CTX_get_current_cert, X509_STORE_CTX *a, a, return 0, return)
2898−-DEFINEFUNC(STACK_OF(X509) *, X509_STORE_CTX_get_chain, X509_STORE_CTX *a, a, return 0, return)
2899− DEFINEFUNC(X509_STORE_CTX *, X509_STORE_CTX_new, DUMMYARG, DUMMYARG, return 0, return)
2900−-#ifdef SSLEAY_MACROS
2901−-DEFINEFUNC2(int, i2d_DSAPrivateKey, const DSA *a, a, unsigned char **b, b, return -1, return)
2902−-DEFINEFUNC2(int, i2d_RSAPrivateKey, const RSA *a, a, unsigned char **b, b, return -1, return)
2903−-#ifndef OPENSSL_NO_EC
2904−-DEFINEFUNC2(int, i2d_ECPrivateKey, const EC_KEY *a, a, unsigned char **b, b, return -1, return)
2905−-#endif
2906−-DEFINEFUNC3(RSA *, d2i_RSAPrivateKey, RSA **a, a, unsigned char **b, b, long c, c, return 0, return)
2907−-DEFINEFUNC3(DSA *, d2i_DSAPrivateKey, DSA **a, a, unsigned char **b, b, long c, c, return 0, return)
2908−-#ifndef OPENSSL_NO_EC
2909−-DEFINEFUNC3(EC_KEY *, d2i_ECPrivateKey, EC_KEY **a, a, unsigned char **b, b, long c, c, return 0, return)
2910−-#endif
2911−-#endif
2912−-DEFINEFUNC(void, OPENSSL_add_all_algorithms_noconf, void, DUMMYARG, return, DUMMYARG)
2913−-DEFINEFUNC(void, OPENSSL_add_all_algorithms_conf, void, DUMMYARG, return, DUMMYARG)
2914− DEFINEFUNC3(int, SSL_CTX_load_verify_locations, SSL_CTX *ctx, ctx, const char *CAfile, CAfile, const char *CApath, CApath, return 0, return)
2915−-DEFINEFUNC(long, SSLeay, void, DUMMYARG, return 0, return)
2916−-DEFINEFUNC(const char *, SSLeay_version, int a, a, return 0, return)
2917− DEFINEFUNC2(int, i2d_SSL_SESSION, SSL_SESSION *in, in, unsigned char **pp, pp, return 0, return)
2918− DEFINEFUNC3(SSL_SESSION *, d2i_SSL_SESSION, SSL_SESSION **a, a, const unsigned char **pp, pp, long length, length, return 0, return)
2919− #if OPENSSL_VERSION_NUMBER >= 0x1000100fL && !defined(OPENSSL_NO_NEXTPROTONEG)
2920−@@ -694,8 +765,8 @@ static QPair<QLibrary*, QLibrary*> loadOpenSsl()
2921− #ifndef Q_OS_DARWIN
2922− // second attempt: find the development files libssl.so and libcrypto.so
2923− //
2924−- // disabled on OS X/iOS:
2925−- // OS X's /usr/lib/libssl.dylib, /usr/lib/libcrypto.dylib will be picked up in the third
2926−+ // disabled on macOS/iOS:
2927−+ // macOS's /usr/lib/libssl.dylib, /usr/lib/libcrypto.dylib will be picked up in the third
2928− // attempt, _after_ <bundle>/Contents/Frameworks has been searched.
2929− // iOS does not ship a system libssl.dylib, libcrypto.dylib in the first place.
2930− libssl->setFileNameAndVersion(QLatin1String("ssl"), -1);
2931−@@ -754,7 +825,11 @@ bool q_resolveOpenSslSymbols()
2932− static bool symbolsResolved = false;
2933− static bool triedToResolveSymbols = false;
2934− #ifndef QT_NO_THREAD
2935−+#if QT_CONFIG(opensslv11)
2936−+ QMutexLocker locker(QMutexPool::globalInstanceGet((void *)&q_OPENSSL_init_ssl));
2937−+#else
2938− QMutexLocker locker(QMutexPool::globalInstanceGet((void *)&q_SSL_library_init));
2939−+#endif
2940− #endif
2941− if (symbolsResolved)
2942− return true;
2943−@@ -771,11 +846,145 @@ bool q_resolveOpenSslSymbols()
2944− // failed to load them
2945− return false;
2946−
2947−+#if QT_CONFIG(opensslv11)
2948−+
2949−+ RESOLVEFUNC(OPENSSL_init_ssl)
2950−+ RESOLVEFUNC(OPENSSL_init_crypto)
2951−+ RESOLVEFUNC(ASN1_STRING_get0_data)
2952−+ RESOLVEFUNC(EVP_CIPHER_CTX_reset)
2953−+ RESOLVEFUNC(EVP_PKEY_base_id)
2954−+ RESOLVEFUNC(RSA_bits)
2955−+ RESOLVEFUNC(OPENSSL_sk_new_null)
2956−+ RESOLVEFUNC(OPENSSL_sk_push)
2957−+ RESOLVEFUNC(OPENSSL_sk_free)
2958−+ RESOLVEFUNC(OPENSSL_sk_num)
2959−+ RESOLVEFUNC(OPENSSL_sk_pop_free)
2960−+ RESOLVEFUNC(OPENSSL_sk_value)
2961−+ RESOLVEFUNC(DH_get0_pqg)
2962−+ RESOLVEFUNC(SSL_CTX_set_options)
2963−+ RESOLVEFUNC(SSL_get_client_random)
2964−+ RESOLVEFUNC(SSL_SESSION_get_master_key)
2965−+ RESOLVEFUNC(SSL_session_reused)
2966−+ RESOLVEFUNC(SSL_get_session)
2967−+ RESOLVEFUNC(CRYPTO_get_ex_new_index)
2968−+ RESOLVEFUNC(TLS_method)
2969−+ RESOLVEFUNC(TLS_client_method)
2970−+ RESOLVEFUNC(TLS_server_method)
2971−+ RESOLVEFUNC(X509_STORE_CTX_get0_chain)
2972−+ RESOLVEFUNC(X509_getm_notBefore)
2973−+ RESOLVEFUNC(X509_getm_notAfter)
2974−+ RESOLVEFUNC(X509_get_version)
2975−+ RESOLVEFUNC(X509_get_pubkey)
2976−+ RESOLVEFUNC(X509_STORE_set_verify_cb)
2977−+ RESOLVEFUNC(CRYPTO_free)
2978−+ RESOLVEFUNC(OpenSSL_version_num)
2979−+ RESOLVEFUNC(OpenSSL_version)
2980−+ if (!_q_OpenSSL_version) {
2981−+ // Apparently, we were built with OpenSSL 1.1 enabled but are now using
2982−+ // a wrong library.
2983−+ delete libs.first;
2984−+ delete libs.second;
2985−+ qCWarning(lcSsl, "Incompatible version of OpenSSL");
2986−+ return false;
2987−+ }
2988−+
2989−+ RESOLVEFUNC(SSL_SESSION_get_ticket_lifetime_hint)
2990−+ RESOLVEFUNC(DH_bits)
2991−+ RESOLVEFUNC(DSA_bits)
2992−+
2993−+#else // !opensslv11
2994−+
2995−+ RESOLVEFUNC(ASN1_STRING_data)
2996−+
2997− #ifdef SSLEAY_MACROS
2998− RESOLVEFUNC(ASN1_dup)
2999−+#endif // SSLEAY_MACROS
3000−+ RESOLVEFUNC(BIO_new_file)
3001−+ RESOLVEFUNC(ERR_clear_error)
3002−+ RESOLVEFUNC(CRYPTO_free)
3003−+ RESOLVEFUNC(CRYPTO_num_locks)
3004−+ RESOLVEFUNC(CRYPTO_set_id_callback)
3005−+ RESOLVEFUNC(CRYPTO_set_locking_callback)
3006−+ RESOLVEFUNC(ERR_peek_last_error)
3007−+ RESOLVEFUNC(ERR_free_strings)
3008−+ RESOLVEFUNC(EVP_CIPHER_CTX_cleanup)
3009−+ RESOLVEFUNC(EVP_CIPHER_CTX_init)
3010−+
3011−+#ifdef SSLEAY_MACROS // ### verify
3012−+ RESOLVEFUNC(PEM_ASN1_read_bio)
3013−+#endif // SSLEAY_MACROS
3014−+
3015−+ RESOLVEFUNC(sk_new_null)
3016−+ RESOLVEFUNC(sk_push)
3017−+ RESOLVEFUNC(sk_free)
3018−+ RESOLVEFUNC(sk_num)
3019−+ RESOLVEFUNC(sk_pop_free)
3020−+ RESOLVEFUNC(sk_value)
3021−+ RESOLVEFUNC(SSL_library_init)
3022−+ RESOLVEFUNC(SSL_load_error_strings)
3023−+#if OPENSSL_VERSION_NUMBER >= 0x10001000L
3024−+ RESOLVEFUNC(SSL_get_ex_new_index)
3025−+#endif
3026−+#ifndef OPENSSL_NO_SSL2
3027−+ RESOLVEFUNC(SSLv2_client_method)
3028− #endif
3029−+#ifndef OPENSSL_NO_SSL3_METHOD
3030−+ RESOLVEFUNC(SSLv3_client_method)
3031−+#endif
3032−+ RESOLVEFUNC(SSLv23_client_method)
3033−+ RESOLVEFUNC(TLSv1_client_method)
3034−+#if OPENSSL_VERSION_NUMBER >= 0x10001000L
3035−+ RESOLVEFUNC(TLSv1_1_client_method)
3036−+ RESOLVEFUNC(TLSv1_2_client_method)
3037−+#endif
3038−+#ifndef OPENSSL_NO_SSL2
3039−+ RESOLVEFUNC(SSLv2_server_method)
3040−+#endif
3041−+#ifndef OPENSSL_NO_SSL3_METHOD
3042−+ RESOLVEFUNC(SSLv3_server_method)
3043−+#endif
3044−+ RESOLVEFUNC(SSLv23_server_method)
3045−+ RESOLVEFUNC(TLSv1_server_method)
3046−+#if OPENSSL_VERSION_NUMBER >= 0x10001000L
3047−+ RESOLVEFUNC(TLSv1_1_server_method)
3048−+ RESOLVEFUNC(TLSv1_2_server_method)
3049−+#endif
3050−+ RESOLVEFUNC(X509_STORE_CTX_get_chain)
3051−+#ifdef SSLEAY_MACROS
3052−+ RESOLVEFUNC(i2d_DSAPrivateKey)
3053−+ RESOLVEFUNC(i2d_RSAPrivateKey)
3054−+ RESOLVEFUNC(d2i_DSAPrivateKey)
3055−+ RESOLVEFUNC(d2i_RSAPrivateKey)
3056−+#endif
3057−+ RESOLVEFUNC(CONF_get1_default_config_file)
3058−+ RESOLVEFUNC(OPENSSL_add_all_algorithms_noconf)
3059−+ RESOLVEFUNC(OPENSSL_add_all_algorithms_conf)
3060−+ RESOLVEFUNC(SSLeay)
3061−+
3062−+ if (!_q_SSLeay || q_SSLeay() >= 0x10100000L) {
3063−+ // OpenSSL 1.1 has deprecated and removed SSLeay. We consider a failure to
3064−+ // resolve this symbol as a failure to resolve symbols.
3065−+ // The right operand of '||' above is ... a bit of paranoia.
3066−+ delete libs.first;
3067−+ delete libs.second;
3068−+ qCWarning(lcSsl, "Incompatible version of OpenSSL");
3069−+ return false;
3070−+ }
3071−+
3072−+
3073−+ RESOLVEFUNC(SSLeay_version)
3074−+
3075−+#ifndef OPENSSL_NO_EC
3076−+#if OPENSSL_VERSION_NUMBER >= 0x10002000L
3077−+ if (q_SSLeay() >= 0x10002000L)
3078−+ RESOLVEFUNC(EC_curve_nist2nid)
3079−+#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L
3080−+#endif // OPENSSL_NO_EC
3081−+
3082−+
3083−+#endif // !opensslv11
3084−+
3085− RESOLVEFUNC(ASN1_INTEGER_get)
3086−- RESOLVEFUNC(ASN1_STRING_data)
3087− RESOLVEFUNC(ASN1_STRING_length)
3088− RESOLVEFUNC(ASN1_STRING_to_UTF8)
3089− RESOLVEFUNC(BIO_ctrl)
3090−@@ -794,25 +1003,22 @@ bool q_resolveOpenSslSymbols()
3091− RESOLVEFUNC(BN_is_word)
3092− #endif
3093− RESOLVEFUNC(BN_mod_word)
3094−- RESOLVEFUNC(CRYPTO_free)
3095−- RESOLVEFUNC(CRYPTO_num_locks)
3096−- RESOLVEFUNC(CRYPTO_set_id_callback)
3097−- RESOLVEFUNC(CRYPTO_set_locking_callback)
3098− RESOLVEFUNC(DSA_new)
3099− RESOLVEFUNC(DSA_free)
3100− RESOLVEFUNC(ERR_error_string)
3101− RESOLVEFUNC(ERR_get_error)
3102−- RESOLVEFUNC(ERR_free_strings)
3103−- RESOLVEFUNC(EVP_CIPHER_CTX_cleanup)
3104−- RESOLVEFUNC(EVP_CIPHER_CTX_init)
3105−+ RESOLVEFUNC(EVP_CIPHER_CTX_new)
3106−+ RESOLVEFUNC(EVP_CIPHER_CTX_free)
3107− RESOLVEFUNC(EVP_CIPHER_CTX_ctrl)
3108− RESOLVEFUNC(EVP_CIPHER_CTX_set_key_length)
3109− RESOLVEFUNC(EVP_CipherInit)
3110−+ RESOLVEFUNC(EVP_CipherInit_ex)
3111− RESOLVEFUNC(EVP_CipherUpdate)
3112− RESOLVEFUNC(EVP_CipherFinal)
3113− RESOLVEFUNC(EVP_des_cbc)
3114− RESOLVEFUNC(EVP_des_ede3_cbc)
3115− RESOLVEFUNC(EVP_rc2_cbc)
3116−+ RESOLVEFUNC(EVP_sha1)
3117− RESOLVEFUNC(EVP_PKEY_assign)
3118− RESOLVEFUNC(EVP_PKEY_set1_RSA)
3119− RESOLVEFUNC(EVP_PKEY_set1_DSA)
3120−@@ -834,9 +1040,8 @@ bool q_resolveOpenSslSymbols()
3121− RESOLVEFUNC(i2t_ASN1_OBJECT)
3122− RESOLVEFUNC(OBJ_obj2txt)
3123− RESOLVEFUNC(OBJ_obj2nid)
3124−-#ifdef SSLEAY_MACROS // ### verify
3125−- RESOLVEFUNC(PEM_ASN1_read_bio)
3126−-#else
3127−+
3128−+#ifndef SSLEAY_MACROS
3129− RESOLVEFUNC(PEM_read_bio_PrivateKey)
3130− RESOLVEFUNC(PEM_read_bio_DSAPrivateKey)
3131− RESOLVEFUNC(PEM_read_bio_RSAPrivateKey)
3132−@@ -849,7 +1054,8 @@ bool q_resolveOpenSslSymbols()
3133− #ifndef OPENSSL_NO_EC
3134− RESOLVEFUNC(PEM_write_bio_ECPrivateKey)
3135− #endif
3136−-#endif
3137−+#endif // !SSLEAY_MACROS
3138−+
3139− RESOLVEFUNC(PEM_read_bio_PUBKEY)
3140− RESOLVEFUNC(PEM_read_bio_DSA_PUBKEY)
3141− RESOLVEFUNC(PEM_read_bio_RSA_PUBKEY)
3142−@@ -865,12 +1071,6 @@ bool q_resolveOpenSslSymbols()
3143− RESOLVEFUNC(RAND_status)
3144− RESOLVEFUNC(RSA_new)
3145− RESOLVEFUNC(RSA_free)
3146−- RESOLVEFUNC(sk_new_null)
3147−- RESOLVEFUNC(sk_push)
3148−- RESOLVEFUNC(sk_free)
3149−- RESOLVEFUNC(sk_num)
3150−- RESOLVEFUNC(sk_pop_free)
3151−- RESOLVEFUNC(sk_value)
3152− RESOLVEFUNC(SSL_CIPHER_description)
3153− RESOLVEFUNC(SSL_CIPHER_get_bits)
3154− RESOLVEFUNC(SSL_CTX_check_private_key)
3155−@@ -898,8 +1098,6 @@ bool q_resolveOpenSslSymbols()
3156− RESOLVEFUNC(SSL_get_peer_cert_chain)
3157− RESOLVEFUNC(SSL_get_peer_certificate)
3158− RESOLVEFUNC(SSL_get_verify_result)
3159−- RESOLVEFUNC(SSL_library_init)
3160−- RESOLVEFUNC(SSL_load_error_strings)
3161− RESOLVEFUNC(SSL_new)
3162− RESOLVEFUNC(SSL_ctrl)
3163− RESOLVEFUNC(SSL_read)
3164−@@ -912,7 +1110,6 @@ bool q_resolveOpenSslSymbols()
3165− RESOLVEFUNC(SSL_get1_session)
3166− RESOLVEFUNC(SSL_get_session)
3167− #if OPENSSL_VERSION_NUMBER >= 0x10001000L
3168−- RESOLVEFUNC(SSL_get_ex_new_index)
3169− RESOLVEFUNC(SSL_set_ex_data)
3170− RESOLVEFUNC(SSL_get_ex_data)
3171− #endif
3172−@@ -922,30 +1119,6 @@ bool q_resolveOpenSslSymbols()
3173− RESOLVEFUNC(SSL_CTX_use_psk_identity_hint)
3174− #endif
3175− RESOLVEFUNC(SSL_write)
3176−-#ifndef OPENSSL_NO_SSL2
3177−- RESOLVEFUNC(SSLv2_client_method)
3178−-#endif
3179−-#ifndef OPENSSL_NO_SSL3_METHOD
3180−- RESOLVEFUNC(SSLv3_client_method)
3181−-#endif
3182−- RESOLVEFUNC(SSLv23_client_method)
3183−- RESOLVEFUNC(TLSv1_client_method)
3184−-#if OPENSSL_VERSION_NUMBER >= 0x10001000L
3185−- RESOLVEFUNC(TLSv1_1_client_method)
3186−- RESOLVEFUNC(TLSv1_2_client_method)
3187−-#endif
3188−-#ifndef OPENSSL_NO_SSL2
3189−- RESOLVEFUNC(SSLv2_server_method)
3190−-#endif
3191−-#ifndef OPENSSL_NO_SSL3_METHOD
3192−- RESOLVEFUNC(SSLv3_server_method)
3193−-#endif
3194−- RESOLVEFUNC(SSLv23_server_method)
3195−- RESOLVEFUNC(TLSv1_server_method)
3196−-#if OPENSSL_VERSION_NUMBER >= 0x10001000L
3197−- RESOLVEFUNC(TLSv1_1_server_method)
3198−- RESOLVEFUNC(TLSv1_2_server_method)
3199−-#endif
3200− RESOLVEFUNC(X509_NAME_entry_count)
3201− RESOLVEFUNC(X509_NAME_get_entry)
3202− RESOLVEFUNC(X509_NAME_ENTRY_get_data)
3203−@@ -961,12 +1134,12 @@ bool q_resolveOpenSslSymbols()
3204− RESOLVEFUNC(X509_STORE_CTX_get_error)
3205− RESOLVEFUNC(X509_STORE_CTX_get_error_depth)
3206− RESOLVEFUNC(X509_STORE_CTX_get_current_cert)
3207−- RESOLVEFUNC(X509_STORE_CTX_get_chain)
3208− RESOLVEFUNC(X509_cmp)
3209− #ifndef SSLEAY_MACROS
3210− RESOLVEFUNC(X509_dup)
3211− #endif
3212− RESOLVEFUNC(X509_print)
3213−+ RESOLVEFUNC(X509_digest)
3214− RESOLVEFUNC(X509_EXTENSION_get_object)
3215− RESOLVEFUNC(X509_free)
3216− RESOLVEFUNC(X509_get_ext)
3217−@@ -982,20 +1155,11 @@ bool q_resolveOpenSslSymbols()
3218− RESOLVEFUNC(X509_check_issued)
3219− RESOLVEFUNC(X509_get_issuer_name)
3220− RESOLVEFUNC(X509_get_subject_name)
3221−+ RESOLVEFUNC(X509_get_serialNumber)
3222− RESOLVEFUNC(X509_verify_cert)
3223− RESOLVEFUNC(d2i_X509)
3224− RESOLVEFUNC(i2d_X509)
3225−-#ifdef SSLEAY_MACROS
3226−- RESOLVEFUNC(i2d_DSAPrivateKey)
3227−- RESOLVEFUNC(i2d_RSAPrivateKey)
3228−- RESOLVEFUNC(d2i_DSAPrivateKey)
3229−- RESOLVEFUNC(d2i_RSAPrivateKey)
3230−-#endif
3231−- RESOLVEFUNC(OPENSSL_add_all_algorithms_noconf)
3232−- RESOLVEFUNC(OPENSSL_add_all_algorithms_conf)
3233− RESOLVEFUNC(SSL_CTX_load_verify_locations)
3234−- RESOLVEFUNC(SSLeay)
3235−- RESOLVEFUNC(SSLeay_version)
3236− RESOLVEFUNC(i2d_SSL_SESSION)
3237− RESOLVEFUNC(d2i_SSL_SESSION)
3238− #if OPENSSL_VERSION_NUMBER >= 0x1000100fL && !defined(OPENSSL_NO_NEXTPROTONEG)
3239−@@ -1019,27 +1183,14 @@ bool q_resolveOpenSslSymbols()
3240− RESOLVEFUNC(EC_KEY_new_by_curve_name)
3241− RESOLVEFUNC(EC_KEY_free)
3242− RESOLVEFUNC(EC_get_builtin_curves)
3243−-#if OPENSSL_VERSION_NUMBER >= 0x10002000L
3244−- if (q_SSLeay() >= 0x10002000L)
3245−- RESOLVEFUNC(EC_curve_nist2nid)
3246−-#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L
3247− #endif // OPENSSL_NO_EC
3248− RESOLVEFUNC(PKCS12_parse)
3249− RESOLVEFUNC(d2i_PKCS12_bio)
3250− RESOLVEFUNC(PKCS12_free)
3251−
3252−+ symbolsResolved = true;
3253− delete libs.first;
3254− delete libs.second;
3255−- if (!_q_SSLeay || q_SSLeay() >= 0x10100000L) {
3256−- // OpenSSL 1.1 deprecated and removed SSLeay. We consider a failure to
3257−- // resolve this symbol as a failure to resolve symbols.
3258−- // The right operand of '||' above ... a bit of paranoia.
3259−- qCWarning(lcSsl, "Incompatible version of OpenSSL");
3260−- return false;
3261−- }
3262−-
3263−- symbolsResolved = true;
3264−-
3265− return true;
3266− }
3267− #endif // QT_CONFIG(library)
3268−diff --git a/src/network/ssl/qsslsocket_openssl_symbols_p.h b/src/network/ssl/qsslsocket_openssl_symbols_p.h
3269−index b35a895d38..796bf2d4f5 100644
3270−--- a/src/network/ssl/qsslsocket_openssl_symbols_p.h
3271−+++ b/src/network/ssl/qsslsocket_openssl_symbols_p.h
3272−@@ -1,6 +1,6 @@
3273− /****************************************************************************
3274− **
3275−-** Copyright (C) 2016 The Qt Company Ltd.
3276−+** Copyright (C) 2017 The Qt Company Ltd.
3277− ** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
3278− ** Contact: https://www.qt.io/licensing/
3279− **
3280−@@ -56,6 +56,7 @@
3281− #ifndef QSSLSOCKET_OPENSSL_SYMBOLS_P_H
3282− #define QSSLSOCKET_OPENSSL_SYMBOLS_P_H
3283−
3284−+
3285− //
3286− // W A R N I N G
3287− // -------------
3288−@@ -215,17 +216,20 @@ QT_BEGIN_NAMESPACE
3289−
3290− #endif // !defined QT_LINKED_OPENSSL
3291−
3292−+#if QT_CONFIG(opensslv11)
3293−+#include "qsslsocket_openssl11_symbols_p.h"
3294−+#else
3295−+#include "qsslsocket_opensslpre11_symbols_p.h"
3296−+#endif // QT_CONFIG
3297−+
3298− bool q_resolveOpenSslSymbols();
3299− long q_ASN1_INTEGER_get(ASN1_INTEGER *a);
3300−-unsigned char * q_ASN1_STRING_data(ASN1_STRING *a);
3301− int q_ASN1_STRING_length(ASN1_STRING *a);
3302− int q_ASN1_STRING_to_UTF8(unsigned char **a, ASN1_STRING *b);
3303− long q_BIO_ctrl(BIO *a, int b, long c, void *d);
3304− Q_AUTOTEST_EXPORT int q_BIO_free(BIO *a);
3305−-Q_AUTOTEST_EXPORT BIO *q_BIO_new(BIO_METHOD *a);
3306− BIO *q_BIO_new_mem_buf(void *a, int b);
3307− int q_BIO_read(BIO *a, void *b, int c);
3308−-Q_AUTOTEST_EXPORT BIO_METHOD *q_BIO_s_mem();
3309− Q_AUTOTEST_EXPORT int q_BIO_write(BIO *a, const void *b, int c);
3310− int q_BN_num_bits(const BIGNUM *a);
3311− #if OPENSSL_VERSION_NUMBER >= 0x10100000L
3312−@@ -247,26 +251,23 @@ BN_ULONG q_BN_mod_word(const BIGNUM *a, BN_ULONG w);
3313− const EC_GROUP* q_EC_KEY_get0_group(const EC_KEY* k);
3314− int q_EC_GROUP_get_degree(const EC_GROUP* g);
3315− #endif
3316−-int q_CRYPTO_num_locks();
3317−-void q_CRYPTO_set_locking_callback(void (*a)(int, int, const char *, int));
3318−-void q_CRYPTO_set_id_callback(unsigned long (*a)());
3319−-void q_CRYPTO_free(void *a);
3320− DSA *q_DSA_new();
3321− void q_DSA_free(DSA *a);
3322− X509 *q_d2i_X509(X509 **a, const unsigned char **b, long c);
3323− char *q_ERR_error_string(unsigned long a, char *b);
3324− unsigned long q_ERR_get_error();
3325−-void q_ERR_free_strings();
3326−-void q_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
3327−-void q_EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a);
3328−+EVP_CIPHER_CTX *q_EVP_CIPHER_CTX_new();
3329−+void q_EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *a);
3330− int q_EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
3331− int q_EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);
3332− int q_EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, const unsigned char *key, const unsigned char *iv, int enc);
3333−+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);
3334− int q_EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl);
3335− int q_EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
3336− const EVP_CIPHER *q_EVP_des_cbc();
3337− const EVP_CIPHER *q_EVP_des_ede3_cbc();
3338− const EVP_CIPHER *q_EVP_rc2_cbc();
3339−+const EVP_MD *q_EVP_sha1();
3340− int q_EVP_PKEY_assign(EVP_PKEY *a, int b, char *c);
3341− Q_AUTOTEST_EXPORT int q_EVP_PKEY_set1_RSA(EVP_PKEY *a, RSA *b);
3342− int q_EVP_PKEY_set1_DSA(EVP_PKEY *a, DSA *b);
3343−@@ -310,7 +311,7 @@ int q_PEM_write_bio_RSAPrivateKey(BIO *a, RSA *b, const EVP_CIPHER *c, unsigned
3344− int q_PEM_write_bio_ECPrivateKey(BIO *a, EC_KEY *b, const EVP_CIPHER *c, unsigned char *d,
3345− int e, pem_password_cb *f, void *g);
3346− #endif
3347−-#endif
3348−+#endif // SSLEAY_MACROS
3349− Q_AUTOTEST_EXPORT EVP_PKEY *q_PEM_read_bio_PUBKEY(BIO *a, EVP_PKEY **b, pem_password_cb *c, void *d);
3350− DSA *q_PEM_read_bio_DSA_PUBKEY(BIO *a, DSA **b, pem_password_cb *c, void *d);
3351− RSA *q_PEM_read_bio_RSA_PUBKEY(BIO *a, RSA **b, pem_password_cb *c, void *d);
3352−@@ -326,23 +327,10 @@ void q_RAND_seed(const void *a, int b);
3353− int q_RAND_status();
3354− RSA *q_RSA_new();
3355− void q_RSA_free(RSA *a);
3356−-int q_sk_num(STACK *a);
3357−-void q_sk_pop_free(STACK *a, void (*b)(void *));
3358−-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
3359−-_STACK *q_sk_new_null();
3360−-void q_sk_push(_STACK *st, void *data);
3361−-void q_sk_free(_STACK *a);
3362−-void * q_sk_value(STACK *a, int b);
3363−-#else
3364−-STACK *q_sk_new_null();
3365−-void q_sk_push(STACK *st, char *data);
3366−-void q_sk_free(STACK *a);
3367−-char * q_sk_value(STACK *a, int b);
3368−-#endif
3369− int q_SSL_accept(SSL *a);
3370− int q_SSL_clear(SSL *a);
3371−-char *q_SSL_CIPHER_description(SSL_CIPHER *a, char *b, int c);
3372−-int q_SSL_CIPHER_get_bits(SSL_CIPHER *a, int *b);
3373−+char *q_SSL_CIPHER_description(const SSL_CIPHER *a, char *b, int c);
3374−+int q_SSL_CIPHER_get_bits(const SSL_CIPHER *a, int *b);
3375− int q_SSL_connect(SSL *a);
3376− int q_SSL_CTX_check_private_key(const SSL_CTX *a);
3377− long q_SSL_CTX_ctrl(SSL_CTX *a, int b, long c, void *d);
3378−@@ -374,8 +362,6 @@ int q_SSL_get_error(SSL *a, int b);
3379− STACK_OF(X509) *q_SSL_get_peer_cert_chain(SSL *a);
3380− X509 *q_SSL_get_peer_certificate(SSL *a);
3381− long q_SSL_get_verify_result(const SSL *a);
3382−-int q_SSL_library_init();
3383−-void q_SSL_load_error_strings();
3384− SSL *q_SSL_new(SSL_CTX *a);
3385− long q_SSL_ctrl(SSL *ssl,int cmd, long larg, void *parg);
3386− int q_SSL_read(SSL *a, void *b, int c);
3387−@@ -388,7 +374,6 @@ void q_SSL_SESSION_free(SSL_SESSION *ses);
3388− SSL_SESSION *q_SSL_get1_session(SSL *ssl);
3389− SSL_SESSION *q_SSL_get_session(const SSL *ssl);
3390− #if OPENSSL_VERSION_NUMBER >= 0x10001000L
3391−-int q_SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
3392− int q_SSL_set_ex_data(SSL *ssl, int idx, void *arg);
3393− void *q_SSL_get_ex_data(const SSL *ssl, int idx);
3394− #endif
3395−@@ -399,49 +384,6 @@ typedef unsigned int (*q_psk_server_callback_t)(SSL *ssl, const char *identity,
3396− void q_SSL_set_psk_server_callback(SSL *ssl, q_psk_server_callback_t callback);
3397− int q_SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *hint);
3398− #endif // OPENSSL_VERSION_NUMBER >= 0x10001000L && !defined(OPENSSL_NO_PSK)
3399−-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
3400−-#ifndef OPENSSL_NO_SSL2
3401−-const SSL_METHOD *q_SSLv2_client_method();
3402−-#endif
3403−-#ifndef OPENSSL_NO_SSL3_METHOD
3404−-const SSL_METHOD *q_SSLv3_client_method();
3405−-#endif
3406−-const SSL_METHOD *q_SSLv23_client_method();
3407−-const SSL_METHOD *q_TLSv1_client_method();
3408−-const SSL_METHOD *q_TLSv1_1_client_method();
3409−-const SSL_METHOD *q_TLSv1_2_client_method();
3410−-#ifndef OPENSSL_NO_SSL2
3411−-const SSL_METHOD *q_SSLv2_server_method();
3412−-#endif
3413−-#ifndef OPENSSL_NO_SSL3_METHOD
3414−-const SSL_METHOD *q_SSLv3_server_method();
3415−-#endif
3416−-const SSL_METHOD *q_SSLv23_server_method();
3417−-const SSL_METHOD *q_TLSv1_server_method();
3418−-const SSL_METHOD *q_TLSv1_1_server_method();
3419−-const SSL_METHOD *q_TLSv1_2_server_method();
3420−-#else
3421−-#ifndef OPENSSL_NO_SSL2
3422−-SSL_METHOD *q_SSLv2_client_method();
3423−-#endif
3424−-#ifndef OPENSSL_NO_SSL3_METHOD
3425−-SSL_METHOD *q_SSLv3_client_method();
3426−-#endif
3427−-SSL_METHOD *q_SSLv23_client_method();
3428−-SSL_METHOD *q_TLSv1_client_method();
3429−-SSL_METHOD *q_TLSv1_1_client_method();
3430−-SSL_METHOD *q_TLSv1_2_client_method();
3431−-#ifndef OPENSSL_NO_SSL2
3432−-SSL_METHOD *q_SSLv2_server_method();
3433−-#endif
3434−-#ifndef OPENSSL_NO_SSL3_METHOD
3435−-SSL_METHOD *q_SSLv3_server_method();
3436−-#endif
3437−-SSL_METHOD *q_SSLv23_server_method();
3438−-SSL_METHOD *q_TLSv1_server_method();
3439−-SSL_METHOD *q_TLSv1_1_server_method();
3440−-SSL_METHOD *q_TLSv1_2_server_method();
3441−-#endif
3442− int q_SSL_write(SSL *a, const void *b, int c);
3443− int q_X509_cmp(X509 *a, X509 *b);
3444− #ifdef SSLEAY_MACROS
3445−@@ -452,6 +394,7 @@ void *q_ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, char *x);
3446− X509 *q_X509_dup(X509 *a);
3447− #endif
3448− void q_X509_print(BIO *a, X509*b);
3449−+int q_X509_digest(const X509 *x509, const EVP_MD *type, unsigned char *md, unsigned int *len);
3450− ASN1_OBJECT *q_X509_EXTENSION_get_object(X509_EXTENSION *a);
3451− void q_X509_free(X509 *a);
3452− X509_EXTENSION *q_X509_get_ext(X509 *a, int b);
3453−@@ -471,6 +414,7 @@ int q_ASN1_STRING_print(BIO *a, ASN1_STRING *b);
3454− int q_X509_check_issued(X509 *a, X509 *b);
3455− X509_NAME *q_X509_get_issuer_name(X509 *a);
3456− X509_NAME *q_X509_get_subject_name(X509 *a);
3457−+ASN1_INTEGER *q_X509_get_serialNumber(X509 *a);
3458− int q_X509_verify_cert(X509_STORE_CTX *ctx);
3459− int q_X509_NAME_entry_count(X509_NAME *a);
3460− X509_NAME_ENTRY *q_X509_NAME_get_entry(X509_NAME *a,int b);
3461−@@ -488,7 +432,6 @@ int q_X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose);
3462− int q_X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);
3463− int q_X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
3464− X509 *q_X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);
3465−-STACK_OF(X509) *q_X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx);
3466−
3467− // Diffie-Hellman support
3468− DH *q_DH_new();
3469−@@ -522,34 +465,9 @@ int q_PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
3470− PKCS12 *q_d2i_PKCS12_bio(BIO *bio, PKCS12 **pkcs12);
3471− void q_PKCS12_free(PKCS12 *pkcs12);
3472−
3473−-
3474− #define q_BIO_get_mem_data(b, pp) (int)q_BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp)
3475− #define q_BIO_pending(b) (int)q_BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL)
3476−-#ifdef SSLEAY_MACROS
3477−-int q_i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
3478−-int q_i2d_RSAPrivateKey(const RSA *a, unsigned char **pp);
3479−-RSA *q_d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length);
3480−-DSA *q_d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length);
3481−-#define q_PEM_read_bio_RSAPrivateKey(bp, x, cb, u) \
3482−- (RSA *)q_PEM_ASN1_read_bio( \
3483−- (void *(*)(void**, const unsigned char**, long int))q_d2i_RSAPrivateKey, PEM_STRING_RSA, bp, (void **)x, cb, u)
3484−-#define q_PEM_read_bio_DSAPrivateKey(bp, x, cb, u) \
3485−- (DSA *)q_PEM_ASN1_read_bio( \
3486−- (void *(*)(void**, const unsigned char**, long int))q_d2i_DSAPrivateKey, PEM_STRING_DSA, bp, (void **)x, cb, u)
3487−-#define q_PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
3488−- PEM_ASN1_write_bio((int (*)(void*, unsigned char**))q_i2d_RSAPrivateKey,PEM_STRING_RSA,\
3489−- bp,(char *)x,enc,kstr,klen,cb,u)
3490−-#define q_PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
3491−- PEM_ASN1_write_bio((int (*)(void*, unsigned char**))q_i2d_DSAPrivateKey,PEM_STRING_DSA,\
3492−- bp,(char *)x,enc,kstr,klen,cb,u)
3493−-#define q_PEM_read_bio_DHparams(bp, dh, cb, u) \
3494−- (DH *)q_PEM_ASN1_read_bio( \
3495−- (void *(*)(void**, const unsigned char**, long int))q_d2i_DHparams, PEM_STRING_DHPARAMS, bp, (void **)x, cb, u)
3496−-#endif
3497−-#define q_SSL_CTX_set_options(ctx,op) q_SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,(op),NULL)
3498− #define q_SSL_CTX_set_mode(ctx,op) q_SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL)
3499−-#define q_SKM_sk_num(type, st) ((int (*)(const STACK_OF(type) *))q_sk_num)(st)
3500−-#define q_SKM_sk_value(type, st,i) ((type * (*)(const STACK_OF(type) *, int))q_sk_value)(st, i)
3501− #define q_sk_GENERAL_NAME_num(st) q_SKM_sk_num(GENERAL_NAME, (st))
3502− #define q_sk_GENERAL_NAME_value(st, i) q_SKM_sk_value(GENERAL_NAME, (st), (i))
3503− #define q_sk_X509_num(st) q_SKM_sk_num(X509, (st))
3504−@@ -558,18 +476,12 @@ DSA *q_d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length);
3505− #define q_sk_SSL_CIPHER_value(st, i) q_SKM_sk_value(SSL_CIPHER, (st), (i))
3506− #define q_SSL_CTX_add_extra_chain_cert(ctx,x509) \
3507− q_SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509)
3508−-#define q_X509_get_notAfter(x) X509_get_notAfter(x)
3509−-#define q_X509_get_notBefore(x) X509_get_notBefore(x)
3510− #define q_EVP_PKEY_assign_RSA(pkey,rsa) q_EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\
3511− (char *)(rsa))
3512− #define q_EVP_PKEY_assign_DSA(pkey,dsa) q_EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\
3513− (char *)(dsa))
3514− #define q_OpenSSL_add_all_algorithms() q_OPENSSL_add_all_algorithms_conf()
3515−-void q_OPENSSL_add_all_algorithms_noconf();
3516−-void q_OPENSSL_add_all_algorithms_conf();
3517− int q_SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, const char *CApath);
3518−-long q_SSLeay();
3519−-const char *q_SSLeay_version(int type);
3520− int q_i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp);
3521− SSL_SESSION *q_d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length);
3522−
3523−diff --git a/src/network/ssl/qsslsocket_opensslpre11.cpp b/src/network/ssl/qsslsocket_opensslpre11.cpp
3524−new file mode 100644
3525−index 0000000000..e51888c5f2
3526−--- /dev/null
3527−+++ b/src/network/ssl/qsslsocket_opensslpre11.cpp
3528−@@ -0,0 +1,424 @@
3529−+/****************************************************************************
3530−+**
3531−+** Copyright (C) 2017 The Qt Company Ltd.
3532−+** Copyright (C) 2014 Governikus GmbH & Co. KG
3533−+** Contact: https://www.qt.io/licensing/
3534−+**
3535−+** This file is part of the QtNetwork module of the Qt Toolkit.
3536−+**
3537−+** $QT_BEGIN_LICENSE:LGPL$
3538−+** Commercial License Usage
3539−+** Licensees holding valid commercial Qt licenses may use this file in
3540−+** accordance with the commercial license agreement provided with the
3541−+** Software or, alternatively, in accordance with the terms contained in
3542−+** a written agreement between you and The Qt Company. For licensing terms
3543−+** and conditions see https://www.qt.io/terms-conditions. For further
3544−+** information use the contact form at https://www.qt.io/contact-us.
3545−+**
3546−+** GNU Lesser General Public License Usage
3547−+** Alternatively, this file may be used under the terms of the GNU Lesser
3548−+** General Public License version 3 as published by the Free Software
3549−+** Foundation and appearing in the file LICENSE.LGPL3 included in the
3550−+** packaging of this file. Please review the following information to
3551−+** ensure the GNU Lesser General Public License version 3 requirements
3552−+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
3553−+**
3554−+** GNU General Public License Usage
3555−+** Alternatively, this file may be used under the terms of the GNU
3556−+** General Public License version 2.0 or (at your option) the GNU General
3557−+** Public license version 3 or any later version approved by the KDE Free
3558−+** Qt Foundation. The licenses are as published by the Free Software
3559−+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
3560−+** included in the packaging of this file. Please review the following
3561−+** information to ensure the GNU General Public License requirements will
3562−+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
3563−+** https://www.gnu.org/licenses/gpl-3.0.html.
3564−+**
3565−+** $QT_END_LICENSE$
3566−+**
3567−+****************************************************************************/
3568−+
3569−+/****************************************************************************
3570−+**
3571−+** In addition, as a special exception, the copyright holders listed above give
3572−+** permission to link the code of its release of Qt with the OpenSSL project's
3573−+** "OpenSSL" library (or modified versions of the "OpenSSL" library that use the
3574−+** same license as the original version), and distribute the linked executables.
3575−+**
3576−+** You must comply with the GNU General Public License version 2 in all
3577−+** respects for all of the code used other than the "OpenSSL" code. If you
3578−+** modify this file, you may extend this exception to your version of the file,
3579−+** but you are not obligated to do so. If you do not wish to do so, delete
3580−+** this exception statement from your version of this file.
3581−+**
3582−+****************************************************************************/
3583−+
3584−+//#define QT_DECRYPT_SSL_TRAFFIC
3585−+
3586−+#include "qssl_p.h"
3587−+#include "qsslsocket_openssl_p.h"
3588−+#include "qsslsocket_openssl_symbols_p.h"
3589−+#include "qsslsocket.h"
3590−+#include "qsslkey.h"
3591−+
3592−+#include <QtCore/qdebug.h>
3593−+#include <QtCore/qdir.h>
3594−+#include <QtCore/qdiriterator.h>
3595−+#include <QtCore/qthread.h>
3596−+#include <QtCore/qfile.h>
3597−+#include <QtCore/qmutex.h>
3598−+#include <QtCore/qlibrary.h>
3599−+
3600−+QT_BEGIN_NAMESPACE
3601−+
3602−+/* \internal
3603−+
3604−+ From OpenSSL's thread(3) manual page:
3605−+
3606−+ OpenSSL can safely be used in multi-threaded applications provided that at
3607−+ least two callback functions are set.
3608−+
3609−+ locking_function(int mode, int n, const char *file, int line) is needed to
3610−+ perform locking on shared data structures. (Note that OpenSSL uses a
3611−+ number of global data structures that will be implicitly shared
3612−+ whenever multiple threads use OpenSSL.) Multi-threaded
3613−+ applications will crash at random if it is not set. ...
3614−+ ...
3615−+ id_function(void) is a function that returns a thread ID. It is not
3616−+ needed on Windows nor on platforms where getpid() returns a different
3617−+ ID for each thread (most notably Linux)
3618−+*/
3619−+
3620−+class QOpenSslLocks
3621−+{
3622−+public:
3623−+ QOpenSslLocks()
3624−+ : initLocker(QMutex::Recursive),
3625−+ locksLocker(QMutex::Recursive)
3626−+ {
3627−+ QMutexLocker locker(&locksLocker);
3628−+ int numLocks = q_CRYPTO_num_locks();
3629−+ locks = new QMutex *[numLocks];
3630−+ memset(locks, 0, numLocks * sizeof(QMutex *));
3631−+ }
3632−+ ~QOpenSslLocks()
3633−+ {
3634−+ QMutexLocker locker(&locksLocker);
3635−+ for (int i = 0; i < q_CRYPTO_num_locks(); ++i)
3636−+ delete locks[i];
3637−+ delete [] locks;
3638−+
3639−+ QSslSocketPrivate::deinitialize();
3640−+ }
3641−+ QMutex *lock(int num)
3642−+ {
3643−+ QMutexLocker locker(&locksLocker);
3644−+ QMutex *tmp = locks[num];
3645−+ if (!tmp)
3646−+ tmp = locks[num] = new QMutex(QMutex::Recursive);
3647−+ return tmp;
3648−+ }
3649−+
3650−+ QMutex *globalLock()
3651−+ {
3652−+ return &locksLocker;
3653−+ }
3654−+
3655−+ QMutex *initLock()
3656−+ {
3657−+ return &initLocker;
3658−+ }
3659−+
3660−+private:
3661−+ QMutex initLocker;
3662−+ QMutex locksLocker;
3663−+ QMutex **locks;
3664−+};
3665−+
3666−+Q_GLOBAL_STATIC(QOpenSslLocks, openssl_locks)
3667−+
3668−+extern "C" {
3669−+static void locking_function(int mode, int lockNumber, const char *, int)
3670−+{
3671−+ QMutex *mutex = openssl_locks()->lock(lockNumber);
3672−+
3673−+ // Lock or unlock it
3674−+ if (mode & CRYPTO_LOCK)
3675−+ mutex->lock();
3676−+ else
3677−+ mutex->unlock();
3678−+}
3679−+static unsigned long id_function()
3680−+{
3681−+ return (quintptr)QThread::currentThreadId();
3682−+}
3683−+
3684−+} // extern "C"
3685−+
3686−+static void q_OpenSSL_add_all_algorithms_safe()
3687−+{
3688−+#ifdef Q_OS_WIN
3689−+ // Prior to version 1.0.1m an attempt to call OpenSSL_add_all_algorithms on
3690−+ // Windows could result in 'exit' call from OPENSSL_config (QTBUG-43843).
3691−+ // We can predict this and avoid OPENSSL_add_all_algorithms call.
3692−+ // From OpenSSL docs:
3693−+ // "An application does not need to add algorithms to use them explicitly,
3694−+ // for example by EVP_sha1(). It just needs to add them if it (or any of
3695−+ // the functions it calls) needs to lookup algorithms.
3696−+ // The cipher and digest lookup functions are used in many parts of the
3697−+ // library. If the table is not initialized several functions will
3698−+ // misbehave and complain they cannot find algorithms. This includes the
3699−+ // PEM, PKCS#12, SSL and S/MIME libraries. This is a common query in
3700−+ // the OpenSSL mailing lists."
3701−+ //
3702−+ // Anyway, as a result, we chose not to call this function if it would exit.
3703−+
3704−+ if (q_SSLeay() < 0x100010DFL)
3705−+ {
3706−+ // Now, before we try to call it, check if an attempt to open config file
3707−+ // will result in exit:
3708−+ if (char *confFileName = q_CONF_get1_default_config_file()) {
3709−+ BIO *confFile = q_BIO_new_file(confFileName, "r");
3710−+ const auto lastError = q_ERR_peek_last_error();
3711−+ q_CRYPTO_free(confFileName);
3712−+ if (confFile) {
3713−+ q_BIO_free(confFile);
3714−+ } else {
3715−+ q_ERR_clear_error();
3716−+ if (ERR_GET_REASON(lastError) == ERR_R_SYS_LIB) {
3717−+ qCWarning(lcSsl, "failed to open openssl.conf file");
3718−+ return;
3719−+ }
3720−+ }
3721−+ }
3722−+ }
3723−+#endif // Q_OS_WIN
3724−+
3725−+ q_OpenSSL_add_all_algorithms();
3726−+}
3727−+
3728−+
3729−+/*!
3730−+ \internal
3731−+*/
3732−+void QSslSocketPrivate::deinitialize()
3733−+{
3734−+ q_CRYPTO_set_id_callback(0);
3735−+ q_CRYPTO_set_locking_callback(0);
3736−+ q_ERR_free_strings();
3737−+}
3738−+
3739−+
3740−+bool QSslSocketPrivate::ensureLibraryLoaded()
3741−+{
3742−+ if (!q_resolveOpenSslSymbols())
3743−+ return false;
3744−+
3745−+ // Check if the library itself needs to be initialized.
3746−+ QMutexLocker locker(openssl_locks()->initLock());
3747−+
3748−+ if (!s_libraryLoaded) {
3749−+ s_libraryLoaded = true;
3750−+
3751−+ // Initialize OpenSSL.
3752−+ q_CRYPTO_set_id_callback(id_function);
3753−+ q_CRYPTO_set_locking_callback(locking_function);
3754−+ if (q_SSL_library_init() != 1)
3755−+ return false;
3756−+ q_SSL_load_error_strings();
3757−+ q_OpenSSL_add_all_algorithms_safe();
3758−+
3759−+#if OPENSSL_VERSION_NUMBER >= 0x10001000L
3760−+ if (q_SSLeay() >= 0x10001000L)
3761−+ QSslSocketBackendPrivate::s_indexForSSLExtraData = q_SSL_get_ex_new_index(0L, NULL, NULL, NULL, NULL);
3762−+#endif
3763−+
3764−+ // Initialize OpenSSL's random seed.
3765−+ if (!q_RAND_status()) {
3766−+ qWarning("Random number generator not seeded, disabling SSL support");
3767−+ return false;
3768−+ }
3769−+ }
3770−+ return true;
3771−+}
3772−+
3773−+void QSslSocketPrivate::ensureCiphersAndCertsLoaded()
3774−+{
3775−+ QMutexLocker locker(openssl_locks()->initLock());
3776−+ if (s_loadedCiphersAndCerts)
3777−+ return;
3778−+ s_loadedCiphersAndCerts = true;
3779−+
3780−+ resetDefaultCiphers();
3781−+ resetDefaultEllipticCurves();
3782−+
3783−+#if QT_CONFIG(library)
3784−+ //load symbols needed to receive certificates from system store
3785−+#if defined(Q_OS_WIN)
3786−+ HINSTANCE hLib = LoadLibraryW(L"Crypt32");
3787−+ if (hLib) {
3788−+ ptrCertOpenSystemStoreW = (PtrCertOpenSystemStoreW)GetProcAddress(hLib, "CertOpenSystemStoreW");
3789−+ ptrCertFindCertificateInStore = (PtrCertFindCertificateInStore)GetProcAddress(hLib, "CertFindCertificateInStore");
3790−+ ptrCertCloseStore = (PtrCertCloseStore)GetProcAddress(hLib, "CertCloseStore");
3791−+ if (!ptrCertOpenSystemStoreW || !ptrCertFindCertificateInStore || !ptrCertCloseStore)
3792−+ qCWarning(lcSsl, "could not resolve symbols in crypt32 library"); // should never happen
3793−+ } else {
3794−+ qCWarning(lcSsl, "could not load crypt32 library"); // should never happen
3795−+ }
3796−+#elif defined(Q_OS_QNX)
3797−+ s_loadRootCertsOnDemand = true;
3798−+#elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
3799−+ // check whether we can enable on-demand root-cert loading (i.e. check whether the sym links are there)
3800−+ QList<QByteArray> dirs = unixRootCertDirectories();
3801−+ QStringList symLinkFilter;
3802−+ symLinkFilter << QLatin1String("[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9]");
3803−+ for (int a = 0; a < dirs.count(); ++a) {
3804−+ QDirIterator iterator(QLatin1String(dirs.at(a)), symLinkFilter, QDir::Files);
3805−+ if (iterator.hasNext()) {
3806−+ s_loadRootCertsOnDemand = true;
3807−+ break;
3808−+ }
3809−+ }
3810−+#endif
3811−+#endif // QT_CONFIG(library)
3812−+ // if on-demand loading was not enabled, load the certs now
3813−+ if (!s_loadRootCertsOnDemand)
3814−+ setDefaultCaCertificates(systemCaCertificates());
3815−+#ifdef Q_OS_WIN
3816−+ //Enabled for fetching additional root certs from windows update on windows 6+
3817−+ //This flag is set false by setDefaultCaCertificates() indicating the app uses
3818−+ //its own cert bundle rather than the system one.
3819−+ //Same logic that disables the unix on demand cert loading.
3820−+ //Unlike unix, we do preload the certificates from the cert store.
3821−+ if ((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_6_0)
3822−+ s_loadRootCertsOnDemand = true;
3823−+#endif
3824−+}
3825−+
3826−+long QSslSocketPrivate::sslLibraryVersionNumber()
3827−+{
3828−+ if (!supportsSsl())
3829−+ return 0;
3830−+
3831−+ return q_SSLeay();
3832−+}
3833−+
3834−+QString QSslSocketPrivate::sslLibraryVersionString()
3835−+{
3836−+ if (!supportsSsl())
3837−+ return QString();
3838−+
3839−+ const char *versionString = q_SSLeay_version(SSLEAY_VERSION);
3840−+ if (!versionString)
3841−+ return QString();
3842−+
3843−+ return QString::fromLatin1(versionString);
3844−+}
3845−+
3846−+void QSslSocketBackendPrivate::continueHandshake()
3847−+{
3848−+ Q_Q(QSslSocket);
3849−+ // if we have a max read buffer size, reset the plain socket's to match
3850−+ if (readBufferMaxSize)
3851−+ plainSocket->setReadBufferSize(readBufferMaxSize);
3852−+
3853−+ if (q_SSL_ctrl((ssl), SSL_CTRL_GET_SESSION_REUSED, 0, NULL))
3854−+ configuration.peerSessionShared = true;
3855−+
3856−+#ifdef QT_DECRYPT_SSL_TRAFFIC
3857−+ if (ssl->session && ssl->s3) {
3858−+ const char *mk = reinterpret_cast<const char *>(ssl->session->master_key);
3859−+ QByteArray masterKey(mk, ssl->session->master_key_length);
3860−+ const char *random = reinterpret_cast<const char *>(ssl->s3->client_random);
3861−+ QByteArray clientRandom(random, SSL3_RANDOM_SIZE);
3862−+
3863−+ // different format, needed for e.g. older Wireshark versions:
3864−+// const char *sid = reinterpret_cast<const char *>(ssl->session->session_id);
3865−+// QByteArray sessionID(sid, ssl->session->session_id_length);
3866−+// QByteArray debugLineRSA("RSA Session-ID:");
3867−+// debugLineRSA.append(sessionID.toHex().toUpper());
3868−+// debugLineRSA.append(" Master-Key:");
3869−+// debugLineRSA.append(masterKey.toHex().toUpper());
3870−+// debugLineRSA.append("\n");
3871−+
3872−+ QByteArray debugLineClientRandom("CLIENT_RANDOM ");
3873−+ debugLineClientRandom.append(clientRandom.toHex().toUpper());
3874−+ debugLineClientRandom.append(" ");
3875−+ debugLineClientRandom.append(masterKey.toHex().toUpper());
3876−+ debugLineClientRandom.append("\n");
3877−+
3878−+ QString sslKeyFile = QDir::tempPath() + QLatin1String("/qt-ssl-keys");
3879−+ QFile file(sslKeyFile);
3880−+ if (!file.open(QIODevice::Append))
3881−+ qCWarning(lcSsl) << "could not open file" << sslKeyFile << "for appending";
3882−+ if (!file.write(debugLineClientRandom))
3883−+ qCWarning(lcSsl) << "could not write to file" << sslKeyFile;
3884−+ file.close();
3885−+ } else {
3886−+ qCWarning(lcSsl, "could not decrypt SSL traffic");
3887−+ }
3888−+#endif
3889−+
3890−+ // Cache this SSL session inside the QSslContext
3891−+ if (!(configuration.sslOptions & QSsl::SslOptionDisableSessionSharing)) {
3892−+ if (!sslContextPointer->cacheSession(ssl)) {
3893−+ sslContextPointer.clear(); // we could not cache the session
3894−+ } else {
3895−+ // Cache the session for permanent usage as well
3896−+ if (!(configuration.sslOptions & QSsl::SslOptionDisableSessionPersistence)) {
3897−+ if (!sslContextPointer->sessionASN1().isEmpty())
3898−+ configuration.sslSession = sslContextPointer->sessionASN1();
3899−+ configuration.sslSessionTicketLifeTimeHint = sslContextPointer->sessionTicketLifeTimeHint();
3900−+ }
3901−+ }
3902−+ }
3903−+
3904−+#if OPENSSL_VERSION_NUMBER >= 0x1000100fL && !defined(OPENSSL_NO_NEXTPROTONEG)
3905−+
3906−+ configuration.nextProtocolNegotiationStatus = sslContextPointer->npnContext().status;
3907−+ if (sslContextPointer->npnContext().status == QSslConfiguration::NextProtocolNegotiationUnsupported) {
3908−+ // we could not agree -> be conservative and use HTTP/1.1
3909−+ configuration.nextNegotiatedProtocol = QByteArrayLiteral("http/1.1");
3910−+ } else {
3911−+ const unsigned char *proto = 0;
3912−+ unsigned int proto_len = 0;
3913−+#if OPENSSL_VERSION_NUMBER >= 0x10002000L
3914−+ if (q_SSLeay() >= 0x10002000L) {
3915−+ q_SSL_get0_alpn_selected(ssl, &proto, &proto_len);
3916−+ if (proto_len && mode == QSslSocket::SslClientMode) {
3917−+ // Client does not have a callback that sets it ...
3918−+ configuration.nextProtocolNegotiationStatus = QSslConfiguration::NextProtocolNegotiationNegotiated;
3919−+ }
3920−+ }
3921−+
3922−+ if (!proto_len) { // Test if NPN was more lucky ...
3923−+#else
3924−+ {
3925−+#endif
3926−+ q_SSL_get0_next_proto_negotiated(ssl, &proto, &proto_len);
3927−+ }
3928−+
3929−+ if (proto_len)
3930−+ configuration.nextNegotiatedProtocol = QByteArray(reinterpret_cast<const char *>(proto), proto_len);
3931−+ else
3932−+ configuration.nextNegotiatedProtocol.clear();
3933−+ }
3934−+#endif // OPENSSL_VERSION_NUMBER >= 0x1000100fL ...
3935−+
3936−+#if OPENSSL_VERSION_NUMBER >= 0x10002000L
3937−+ if (q_SSLeay() >= 0x10002000L && mode == QSslSocket::SslClientMode) {
3938−+ EVP_PKEY *key;
3939−+ if (q_SSL_get_server_tmp_key(ssl, &key))
3940−+ configuration.ephemeralServerKey = QSslKey(key, QSsl::PublicKey);
3941−+ }
3942−+#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L ...
3943−+
3944−+ connectionEncrypted = true;
3945−+ emit q->encrypted();
3946−+ if (autoStartHandshake && pendingClose) {
3947−+ pendingClose = false;
3948−+ q->disconnectFromHost();
3949−+ }
3950−+}
3951−+
3952−+QT_END_NAMESPACE
3953−diff --git a/src/network/ssl/ssl.pri b/src/network/ssl/ssl.pri
3954−index d2b0c2d60d..2783effaf1 100644
3955−--- a/src/network/ssl/ssl.pri
3956−+++ b/src/network/ssl/ssl.pri
3957−@@ -60,13 +60,25 @@ qtConfig(ssl) {
3958− HEADERS += ssl/qsslcontext_openssl_p.h \
3959− ssl/qsslsocket_openssl_p.h \
3960− ssl/qsslsocket_openssl_symbols_p.h
3961−- SOURCES += ssl/qsslcertificate_openssl.cpp \
3962−- ssl/qsslcontext_openssl.cpp \
3963−+ SOURCES += ssl/qsslsocket_openssl_symbols.cpp \
3964− ssl/qssldiffiehellmanparameters_openssl.cpp \
3965−+ ssl/qsslcertificate_openssl.cpp \
3966− ssl/qsslellipticcurve_openssl.cpp \
3967− ssl/qsslkey_openssl.cpp \
3968− ssl/qsslsocket_openssl.cpp \
3969−- ssl/qsslsocket_openssl_symbols.cpp
3970−+ ssl/qsslcontext_openssl.cpp
3971−+
3972−+ qtConfig(opensslv11) {
3973−+ HEADERS += ssl/qsslsocket_openssl11_symbols_p.h
3974−+ SOURCES += ssl/qsslsocket_openssl11.cpp \
3975−+ ssl/qsslcontext_openssl11.cpp
3976−+
3977−+ QMAKE_CXXFLAGS += -DOPENSSL_API_COMPAT=0x10100000L
3978−+ } else {
3979−+ HEADERS += ssl/qsslsocket_opensslpre11_symbols_p.h
3980−+ SOURCES += ssl/qsslsocket_opensslpre11.cpp \
3981−+ ssl/qsslcontext_opensslpre11.cpp
3982−+ }
3983−
3984− darwin:SOURCES += ssl/qsslsocket_mac_shared.cpp
3985−