|
| 1 | +--- /dev/null |
| 2 | ++++ b/src/network/certfix.cpp |
| 3 | +@@ -0,0 +1,102 @@ |
| 4 | ++/**************************************************************************** |
| 5 | ++** |
| 6 | ++** Copyright (C) 2017 The Qt Company Ltd. |
| 7 | ++** Copyright (C) 2014 Governikus GmbH & Co. KG |
| 8 | ++** Contact: https://www.qt.io/licensing/ |
| 9 | ++** |
| 10 | ++** This file is part of the QtNetwork module of the Qt Toolkit. |
| 11 | ++** |
| 12 | ++** $QT_BEGIN_LICENSE:LGPL$ |
| 13 | ++** Commercial License Usage |
| 14 | ++** Licensees holding valid commercial Qt licenses may use this file in |
| 15 | ++** accordance with the commercial license agreement provided with the |
| 16 | ++** Software or, alternatively, in accordance with the terms contained in |
| 17 | ++** a written agreement between you and The Qt Company. For licensing terms |
| 18 | ++** and conditions see https://www.qt.io/terms-conditions. For further |
| 19 | ++** information use the contact form at https://www.qt.io/contact-us. |
| 20 | ++** |
| 21 | ++** GNU Lesser General Public License Usage |
| 22 | ++** Alternatively, this file may be used under the terms of the GNU Lesser |
| 23 | ++** General Public License version 3 as published by the Free Software |
| 24 | ++** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 25 | ++** packaging of this file. Please review the following information to |
| 26 | ++** ensure the GNU Lesser General Public License version 3 requirements |
| 27 | ++** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 28 | ++** |
| 29 | ++** GNU General Public License Usage |
| 30 | ++** Alternatively, this file may be used under the terms of the GNU |
| 31 | ++** General Public License version 2.0 or (at your option) the GNU General |
| 32 | ++** Public license version 3 or any later version approved by the KDE Free |
| 33 | ++** Qt Foundation. The licenses are as published by the Free Software |
| 34 | ++** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 35 | ++** included in the packaging of this file. Please review the following |
| 36 | ++** information to ensure the GNU General Public License requirements will |
| 37 | ++** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 38 | ++** https://www.gnu.org/licenses/gpl-3.0.html. |
| 39 | ++** |
| 40 | ++** $QT_END_LICENSE$ |
| 41 | ++** |
| 42 | ++****************************************************************************/ |
| 43 | ++ |
| 44 | ++/**************************************************************************** |
| 45 | ++** |
| 46 | ++** In addition, as a special exception, the copyright holders listed above give |
| 47 | ++** permission to link the code of its release of Qt with the OpenSSL project's |
| 48 | ++** "OpenSSL" library (or modified versions of the "OpenSSL" library that use the |
| 49 | ++** same license as the original version), and distribute the linked executables. |
| 50 | ++** |
| 51 | ++** You must comply with the GNU General Public License version 2 in all |
| 52 | ++** respects for all of the code used other than the "OpenSSL" code. If you |
| 53 | ++** modify this file, you may extend this exception to your version of the file, |
| 54 | ++** but you are not obligated to do so. If you do not wish to do so, delete |
| 55 | ++** this exception statement from your version of this file. |
| 56 | ++** |
| 57 | ++****************************************************************************/ |
| 58 | ++ |
| 59 | ++#include <QDirIterator> |
| 60 | ++#include <QDir> |
| 61 | ++#include <qsslconfiguration.h> |
| 62 | ++#include <qsslerror.h> |
| 63 | ++ |
| 64 | ++QList<QByteArray> unixRootCertDirectories_backport() |
| 65 | ++{ |
| 66 | ++ return QList<QByteArray>() << "/etc/ssl/certs/" // (K)ubuntu, OpenSUSE, Mandriva ... |
| 67 | ++ << "/usr/lib/ssl/certs/" // Gentoo, Mandrake |
| 68 | ++ << "/usr/share/ssl/" // Centos, Redhat, SuSE |
| 69 | ++ << "/usr/local/ssl/" // Normal OpenSSL Tarball |
| 70 | ++ << "/var/ssl/certs/" // AIX |
| 71 | ++ << "/usr/local/ssl/certs/" // Solaris |
| 72 | ++ << "/etc/openssl/certs/" // BlackBerry |
| 73 | ++ << "/opt/openssl/certs/" // HP-UX |
| 74 | ++ << "/etc/ssl/"; // OpenBSD |
| 75 | ++} |
| 76 | ++ |
| 77 | ++QList<QSslCertificate> systemCaCertificates_backport() |
| 78 | ++{ |
| 79 | ++ QList<QSslCertificate> systemCerts; |
| 80 | ++ QList<QString> certFiles; |
| 81 | ++ QDir currentDir; |
| 82 | ++ QStringList nameFilters; |
| 83 | ++ QList<QByteArray> directories; |
| 84 | ++ QSsl::EncodingFormat platformEncodingFormat; |
| 85 | ++ directories = unixRootCertDirectories_backport(); |
| 86 | ++ nameFilters << QLatin1String("*.pem") << QLatin1String("*.crt"); |
| 87 | ++ platformEncodingFormat = QSsl::Pem; |
| 88 | ++ { |
| 89 | ++ currentDir.setNameFilters(nameFilters); |
| 90 | ++ for (int a = 0; a < directories.count(); a++) { |
| 91 | ++ currentDir.setPath(QLatin1String(directories.at(a))); |
| 92 | ++ QDirIterator it(currentDir); |
| 93 | ++ while (it.hasNext()) { |
| 94 | ++ it.next(); |
| 95 | ++ certFiles.insert(certFiles.size(), it.fileInfo().canonicalFilePath()); |
| 96 | ++ } |
| 97 | ++ } |
| 98 | ++ for (int a = 0; a < certFiles.count(); a++) |
| 99 | ++ systemCerts.append(QSslCertificate::fromPath(certFiles.at(a), platformEncodingFormat)); |
| 100 | ++ systemCerts.append(QSslCertificate::fromPath(QLatin1String("/etc/pki/tls/certs/ca-bundle.crt"), QSsl::Pem)); |
| 101 | ++ systemCerts.append(QSslCertificate::fromPath(QLatin1String("/usr/local/share/certs/ca-root-nss.crt"), QSsl::Pem)); |
| 102 | ++ } |
| 103 | ++ |
| 104 | ++ return systemCerts; |
| 105 | ++} |
| 106 | +--- a/src/network/networkaccessmanager.cpp |
| 107 | ++++ b/src/network/networkaccessmanager.cpp |
| 108 | +@@ -88,6 +88,8 @@ |
| 109 | + #include <qsslerror.h> |
| 110 | + #include <qdatetime.h> |
| 111 | + |
| 112 | ++#include "certfix.cpp" |
| 113 | ++ |
| 114 | + // #define NETWORKACCESSMANAGER_DEBUG |
| 115 | + |
| 116 | + NetworkAccessManager::NetworkAccessManager(QObject *parent) |
| 117 | +@@ -164,6 +166,7 @@ void NetworkAccessManager::loadSettings() |
| 118 | + |
| 119 | + #ifndef QT_NO_OPENSSL |
| 120 | + QSslConfiguration sslCfg = QSslConfiguration::defaultConfiguration(); |
| 121 | ++ sslCfg.setCaCertificates(systemCaCertificates_backport()); |
| 122 | + QList<QSslCertificate> ca_list = sslCfg.caCertificates(); |
| 123 | + QList<QSslCertificate> ca_new = QSslCertificate::fromData(settings.value(QLatin1String("CaCertificates")).toByteArray()); |
| 124 | + ca_list += ca_new; |
0 commit comments