diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -87,6 +87,7 @@ faviconscache.cpp ksslcertificatemanager.cpp + ksslerroruidata.cpp ktcpsocket.cpp kssl/ksslsettings.cpp @@ -264,6 +265,7 @@ KProtocolManager KRecentDocument KSslCertificateManager + KSslErrorUiData KTcpSocket REQUIRED_HEADERS KIOCore_HEADERS diff --git a/src/core/ksslcertificatemanager.cpp b/src/core/ksslcertificatemanager.cpp --- a/src/core/ksslcertificatemanager.cpp +++ b/src/core/ksslcertificatemanager.cpp @@ -22,7 +22,7 @@ #include "ksslcertificatemanager_p.h" #include "ktcpsocket.h" -#include "ktcpsocket_p.h" +#include "ksslerroruidata_p.h" #include #include #include diff --git a/src/core/ksslerroruidata.h b/src/core/ksslerroruidata.h new file mode 100644 --- /dev/null +++ b/src/core/ksslerroruidata.h @@ -0,0 +1,74 @@ +/* This file is part of the KDE libraries + Copyright (C) 2007 Thiago Macieira + Copyright (C) 2007 Andreas Hartmetz + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KSSLERRORUIDATA_H +#define KSSLERRORUIDATA_H + +#include + +template class QList; +class KTcpSocket; +class QNetworkReply; +class QSslError; +class QSslSocket; + +/** + * This class can hold all the necessary data from a KTcpSocket to ask the user + * to continue connecting in the face of SSL errors. + * It can be used to carry the data for the UI over time or over thread boundaries. + * + * @see: KSslCertificateManager::askIgnoreSslErrors() + */ +class KIOCORE_EXPORT KSslErrorUiData +{ +public: + /** + * Default construct an instance with no useful data. + */ + KSslErrorUiData(); + /** + * Create an instance and initialize it with SSL error data from @p socket. + */ + KSslErrorUiData(const KTcpSocket *socket); + /** + * Create an instance and initialize it with SSL error data from @p socket. + */ + KSslErrorUiData(const QSslSocket *socket); + /** + * Create an instance and initialize it with SSL error data from @p reply. + * @since 5.62 + */ + KSslErrorUiData(const QNetworkReply *reply, const QList &sslErrors); + + KSslErrorUiData(const KSslErrorUiData &other); + KSslErrorUiData &operator=(const KSslErrorUiData &); + /** + * Destructor + * @since 4.7 + */ + ~KSslErrorUiData(); + + class Private; +private: + friend class Private; + Private *const d; +}; + +#endif // KSSLERRORUIDATA_H diff --git a/src/core/ksslerroruidata.cpp b/src/core/ksslerroruidata.cpp new file mode 100644 --- /dev/null +++ b/src/core/ksslerroruidata.cpp @@ -0,0 +1,102 @@ +/* This file is part of the KDE libraries + Copyright (C) 2007, 2008 Andreas Hartmetz + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "ksslerroruidata.h" +#include "ksslerroruidata_p.h" +#include "ktcpsocket.h" + +#include +#include +#include + +KSslErrorUiData::KSslErrorUiData() + : d(new Private()) +{ + d->usedBits = 0; + d->bits = 0; +} + +KSslErrorUiData::KSslErrorUiData(const KTcpSocket *socket) + : d(new Private()) +{ + d->certificateChain = socket->peerCertificateChain(); + d->sslErrors = socket->sslErrors(); + d->ip = socket->peerAddress().toString(); + d->host = socket->peerName(); + d->sslProtocol = socket->negotiatedSslVersionName(); + d->cipher = socket->sessionCipher().name(); + d->usedBits = socket->sessionCipher().usedBits(); + d->bits = socket->sessionCipher().supportedBits(); +} + +KSslErrorUiData::KSslErrorUiData(const QSslSocket *socket) + : d(new Private()) +{ + d->certificateChain = socket->peerCertificateChain(); + + // See KTcpSocket::sslErrors() + const auto qsslErrors = socket->sslErrors(); + d->sslErrors.reserve(qsslErrors.size()); + for (const QSslError &e : qsslErrors) { + d->sslErrors.append(KSslError(e)); + } + + d->ip = socket->peerAddress().toString(); + d->host = socket->peerName(); + if (socket->isEncrypted()) { + d->sslProtocol = socket->sessionCipher().protocolString(); + } + d->cipher = socket->sessionCipher().name(); + d->usedBits = socket->sessionCipher().usedBits(); + d->bits = socket->sessionCipher().supportedBits(); +} + +KSslErrorUiData::KSslErrorUiData(const QNetworkReply *reply, const QList &sslErrors) + : d(new Private()) +{ + const auto sslConfig = reply->sslConfiguration(); + d->certificateChain = sslConfig.peerCertificateChain(); + + d->sslErrors.reserve(sslErrors.size()); + for (const QSslError &e : sslErrors) { + d->sslErrors.append(KSslError(e)); + } + + d->host = reply->request().url().host(); + d->sslProtocol = sslConfig.sessionCipher().protocolString(); + d->cipher = sslConfig.sessionCipher().name(); + d->usedBits = sslConfig.sessionCipher().usedBits(); + d->bits = sslConfig.sessionCipher().supportedBits(); +} + +KSslErrorUiData::KSslErrorUiData(const KSslErrorUiData &other) + : d(new Private(*other.d)) +{} + +KSslErrorUiData::~KSslErrorUiData() +{ + delete d; +} + +KSslErrorUiData &KSslErrorUiData::operator=(const KSslErrorUiData &other) +{ + *d = *other.d; + return *this; +} + diff --git a/src/core/ktcpsocket_p.h b/src/core/ksslerroruidata_p.h rename from src/core/ktcpsocket_p.h rename to src/core/ksslerroruidata_p.h --- a/src/core/ktcpsocket_p.h +++ b/src/core/ksslerroruidata_p.h @@ -17,8 +17,14 @@ Boston, MA 02110-1301, USA. */ -#ifndef KTCPSOCKET_P_H -#define KTCPSOCKET_P_H +#ifndef KSSLERRORUIDATA_P_H +#define KSSLERRORUIDATA_P_H + +#include "ksslerroruidata.h" +#include "ktcpsocket.h" + +#include +#include class Q_DECL_HIDDEN KSslErrorUiData::Private { @@ -38,4 +44,4 @@ int bits; }; -#endif // KTCPSOCKET_P_H +#endif // KSSLERRORUIDATA_P_H diff --git a/src/core/ktcpsocket.h b/src/core/ktcpsocket.h --- a/src/core/ktcpsocket.h +++ b/src/core/ktcpsocket.h @@ -25,8 +25,7 @@ #include #include "kiocore_export.h" - -class QNetworkReply; +#include "ksslerroruidata.h" /* Notes on QCA::TLS compatibility @@ -390,45 +389,4 @@ KTcpSocketPrivate *const d; }; -/** - * This class can hold all the necessary data from a KTcpSocket to ask the user - * to continue connecting in the face of SSL errors. - * It can be used to carry the data for the UI over time or over thread boundaries. - * - * @see: KSslCertificateManager::askIgnoreSslErrors() - */ -class KIOCORE_EXPORT KSslErrorUiData -{ -public: - /** - * Default construct an instance with no useful data. - */ - KSslErrorUiData(); - /** - * Create an instance and initialize it with SSL error data from @p socket. - */ - KSslErrorUiData(const KTcpSocket *socket); - /** - * Create an instance and initialize it with SSL error data from @p socket. - */ - KSslErrorUiData(const QSslSocket *socket); - /** - * Create an instance and initialize it with SSL error data from @p reply. - * @since 5.62 - */ - KSslErrorUiData(const QNetworkReply *reply, const QList &sslErrors); - - KSslErrorUiData(const KSslErrorUiData &other); - KSslErrorUiData &operator=(const KSslErrorUiData &); - /** - * Destructor - * @since 4.7 - */ - ~KSslErrorUiData(); - class Private; -private: - friend class Private; - Private *const d; -}; - #endif // KTCPSOCKET_H diff --git a/src/core/ktcpsocket.cpp b/src/core/ktcpsocket.cpp --- a/src/core/ktcpsocket.cpp +++ b/src/core/ktcpsocket.cpp @@ -18,7 +18,6 @@ */ #include "ktcpsocket.h" -#include "ktcpsocket_p.h" #include "kiocoredebug.h" #include @@ -29,7 +28,6 @@ #include #include #include -#include #include static KTcpSocket::SslVersion kSslVersionFromQ(QSsl::SslProtocol protocol) @@ -1056,79 +1054,4 @@ return ret; } -KSslErrorUiData::KSslErrorUiData() - : d(new Private()) -{ - d->usedBits = 0; - d->bits = 0; -} - -KSslErrorUiData::KSslErrorUiData(const KTcpSocket *socket) - : d(new Private()) -{ - d->certificateChain = socket->peerCertificateChain(); - d->sslErrors = socket->sslErrors(); - d->ip = socket->peerAddress().toString(); - d->host = socket->peerName(); - d->sslProtocol = socket->negotiatedSslVersionName(); - d->cipher = socket->sessionCipher().name(); - d->usedBits = socket->sessionCipher().usedBits(); - d->bits = socket->sessionCipher().supportedBits(); -} - -KSslErrorUiData::KSslErrorUiData(const QSslSocket *socket) - : d(new Private()) -{ - d->certificateChain = socket->peerCertificateChain(); - - // See KTcpSocket::sslErrors() - const auto qsslErrors = socket->sslErrors(); - d->sslErrors.reserve(qsslErrors.size()); - for (const QSslError &e : qsslErrors) { - d->sslErrors.append(KSslError(e)); - } - - d->ip = socket->peerAddress().toString(); - d->host = socket->peerName(); - if (socket->isEncrypted()) { - d->sslProtocol = socket->sessionCipher().protocolString(); - } - d->cipher = socket->sessionCipher().name(); - d->usedBits = socket->sessionCipher().usedBits(); - d->bits = socket->sessionCipher().supportedBits(); -} - -KSslErrorUiData::KSslErrorUiData(const QNetworkReply *reply, const QList &sslErrors) - : d(new Private()) -{ - const auto sslConfig = reply->sslConfiguration(); - d->certificateChain = sslConfig.peerCertificateChain(); - - d->sslErrors.reserve(sslErrors.size()); - for (const QSslError &e : sslErrors) { - d->sslErrors.append(KSslError(e)); - } - - d->host = reply->request().url().host(); - d->sslProtocol = sslConfig.sessionCipher().protocolString(); - d->cipher = sslConfig.sessionCipher().name(); - d->usedBits = sslConfig.sessionCipher().usedBits(); - d->bits = sslConfig.sessionCipher().supportedBits(); -} - -KSslErrorUiData::KSslErrorUiData(const KSslErrorUiData &other) - : d(new Private(*other.d)) -{} - -KSslErrorUiData::~KSslErrorUiData() -{ - delete d; -} - -KSslErrorUiData &KSslErrorUiData::operator=(const KSslErrorUiData &other) -{ - *d = *other.d; - return *this; -} - #include "moc_ktcpsocket.cpp" diff --git a/src/widgets/sslui.cpp b/src/widgets/sslui.cpp --- a/src/widgets/sslui.cpp +++ b/src/widgets/sslui.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include bool KIO::SslUi::askIgnoreSslErrors(const KTcpSocket *socket, RulesStorage storedRules) {