File indexing completed on 2024-04-28 15:26:28

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2007, 2008, 2010 Andreas Hartmetz <ahartmetz@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef _INCLUDE_KSSLCERTIFICATEMANAGER_H
0009 #define _INCLUDE_KSSLCERTIFICATEMANAGER_H
0010 
0011 #include "ktcpsocket.h" // TODO KF6 remove include
0012 
0013 #include <QDate>
0014 #include <QSslCertificate>
0015 #include <QSslError>
0016 #include <QString>
0017 #include <QStringList>
0018 
0019 #include <memory>
0020 
0021 class QDBusArgument;
0022 class KSslCertificateRulePrivate;
0023 class KSslCertificateManagerPrivate;
0024 
0025 // ### document this... :/
0026 /** Certificate rule. */
0027 class KIOCORE_EXPORT KSslCertificateRule
0028 {
0029 public:
0030     KSslCertificateRule(const QSslCertificate &cert = QSslCertificate(), const QString &hostName = QString());
0031     KSslCertificateRule(const KSslCertificateRule &other);
0032     ~KSslCertificateRule();
0033     KSslCertificateRule &operator=(const KSslCertificateRule &other);
0034 
0035     QSslCertificate certificate() const;
0036     QString hostName() const;
0037     void setExpiryDateTime(const QDateTime &dateTime);
0038     QDateTime expiryDateTime() const;
0039     void setRejected(bool rejected);
0040     bool isRejected() const;
0041 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 64)
0042     /** @deprecated since 5.64, use the QSslError variant. */
0043     KIOCORE_DEPRECATED_VERSION(5, 64, "Use KSslCertificateRule::isErrorIgnored(QSslError::SslError)")
0044     bool isErrorIgnored(KSslError::Error error) const;
0045 #endif
0046     /**
0047      * Returns whether @p error is ignored for this certificate.
0048      * @since 5.64
0049      */
0050     bool isErrorIgnored(QSslError::SslError error) const;
0051 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 64)
0052     /** @deprecated since 5.64, use the QSslError variant. */
0053     KIOCORE_DEPRECATED_VERSION(5, 64, "Use KSslCertificateRule::setIgnoredErrors(const QList<QSslError> &)")
0054     void setIgnoredErrors(const QList<KSslError::Error> &errors);
0055     /** @deprecated since 5.64, use the QSslError variant. */
0056     KIOCORE_DEPRECATED_VERSION(5, 64, "Use KSslCertificateRule::setIgnoredErrors(const QList<QSslError> &)")
0057     void setIgnoredErrors(const QList<KSslError> &errors);
0058 #endif
0059     /**
0060      * Set the ignored errors for this certificate.
0061      * @since 5.64
0062      */
0063     void setIgnoredErrors(const QList<QSslError> &errors);
0064     /**
0065      * Set the ignored errors for this certificate.
0066      * @since 5.64
0067      */
0068     void setIgnoredErrors(const QList<QSslError::SslError> &errors);
0069 #if KIOCORE_BUILD_DEPRECATED_SINCE(5, 64)
0070     QList<KSslError::Error> ignoredErrors() const;
0071 #else
0072     QList<QSslError::SslError> ignoredErrors() const;
0073 #endif
0074 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 64)
0075     /** @deprecated since 5.64, use the QSslError variant. */
0076     KIOCORE_DEPRECATED_VERSION(5, 64, "Use KSslCertificateRule::filterErrors(const QList<QSslError> &)")
0077     QList<KSslError::Error> filterErrors(const QList<KSslError::Error> &errors) const;
0078     /** @deprecated since 5.64, use the QSslError variant. */
0079     KIOCORE_DEPRECATED_VERSION(5, 64, "Use KSslCertificateRule::filterErrors(const QList<QSslError> &)")
0080     QList<KSslError> filterErrors(const QList<KSslError> &errors) const;
0081 #endif
0082     /**
0083      * Filter out errors that are already ignored.
0084      * @since 5.64
0085      */
0086     QList<QSslError> filterErrors(const QList<QSslError> &errors) const;
0087 
0088 private:
0089     friend QDBusArgument &operator<<(QDBusArgument &argument, const KSslCertificateRule &rule); // TODO KF6 remove
0090     friend class KSSLD; // TODO KF6 remove
0091     std::unique_ptr<KSslCertificateRulePrivate> const d;
0092 };
0093 
0094 // ### document this too... :/
0095 /** Certificate manager. */
0096 class KIOCORE_EXPORT KSslCertificateManager
0097 {
0098 public:
0099     static KSslCertificateManager *self();
0100     void setRule(const KSslCertificateRule &rule);
0101     void clearRule(const KSslCertificateRule &rule);
0102     void clearRule(const QSslCertificate &cert, const QString &hostName);
0103     KSslCertificateRule rule(const QSslCertificate &cert, const QString &hostName) const;
0104 
0105 #if KIOCORE_ENABLE_DEPRECATED_SINCE(4, 6)
0106     /** @deprecated Since 4.6, use caCertificates() instead */
0107     KIOCORE_DEPRECATED_VERSION(4, 6, "Use KSslCertificateManager::caCertificates()")
0108     QList<QSslCertificate> rootCertificates() const
0109     {
0110         return caCertificates();
0111     }
0112 #endif
0113 
0114     QList<QSslCertificate> caCertificates() const;
0115 
0116 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 64)
0117     /** @deprecated since 5.64, use the corresponding QSslError variant. */
0118     KIOCORE_DEPRECATED_VERSION(5, 64, "Use KSslCertificateManager::nonIgnorableErrors(const QList<QSslError> &)")
0119     static QList<KSslError> nonIgnorableErrors(const QList<KSslError> &errors);
0120     /** @deprecated since 5.64, use the corresponding QSslError variant. */
0121     KIOCORE_DEPRECATED_VERSION(5, 64, "Use KSslCertificateManager::nonIgnorableErrors(const QList<QSslError> &)")
0122     static QList<KSslError::Error> nonIgnorableErrors(const QList<KSslError::Error> &errors);
0123 #endif
0124     /**
0125      * Returns the subset of @p errors that cannot be ignored, ie. that is considered fatal.
0126      * @since 5.64
0127      */
0128     static QList<QSslError> nonIgnorableErrors(const QList<QSslError> &errors);
0129 
0130 private:
0131     friend class KSslCertificateManagerContainer;
0132     friend class KSslCertificateManagerPrivate;
0133     KIOCORE_NO_EXPORT KSslCertificateManager();
0134     KIOCORE_NO_EXPORT ~KSslCertificateManager();
0135 
0136     std::unique_ptr<KSslCertificateManagerPrivate> d;
0137 };
0138 
0139 #endif