File indexing completed on 2024-04-14 03:52:59

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 <QDate>
0012 #include <QSslCertificate>
0013 #include <QSslError>
0014 #include <QString>
0015 #include <QStringList>
0016 
0017 #include "kiocore_export.h"
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     /**
0042      * Returns whether @p error is ignored for this certificate.
0043      * @since 5.64
0044      */
0045     bool isErrorIgnored(QSslError::SslError error) const;
0046     /**
0047      * Set the ignored errors for this certificate.
0048      * @since 5.64
0049      */
0050     void setIgnoredErrors(const QList<QSslError> &errors);
0051     /**
0052      * Set the ignored errors for this certificate.
0053      * @since 5.64
0054      */
0055     void setIgnoredErrors(const QList<QSslError::SslError> &errors);
0056     QList<QSslError::SslError> ignoredErrors() const;
0057     /**
0058      * Filter out errors that are already ignored.
0059      * @since 5.64
0060      */
0061     QList<QSslError> filterErrors(const QList<QSslError> &errors) const;
0062 
0063 private:
0064     std::unique_ptr<KSslCertificateRulePrivate> const d;
0065 };
0066 
0067 // ### document this too... :/
0068 /** Certificate manager. */
0069 class KIOCORE_EXPORT KSslCertificateManager
0070 {
0071 public:
0072     static KSslCertificateManager *self();
0073     void setRule(const KSslCertificateRule &rule);
0074     void clearRule(const KSslCertificateRule &rule);
0075     void clearRule(const QSslCertificate &cert, const QString &hostName);
0076     KSslCertificateRule rule(const QSslCertificate &cert, const QString &hostName) const;
0077 
0078     QList<QSslCertificate> caCertificates() const;
0079 
0080     /**
0081      * Returns the subset of @p errors that cannot be ignored, ie. that is considered fatal.
0082      * @since 5.64
0083      */
0084     static QList<QSslError> nonIgnorableErrors(const QList<QSslError> &errors);
0085 
0086 private:
0087     friend class KSslCertificateManagerContainer;
0088     friend class KSslCertificateManagerPrivate;
0089     KIOCORE_NO_EXPORT KSslCertificateManager();
0090     KIOCORE_NO_EXPORT ~KSslCertificateManager();
0091 
0092     std::unique_ptr<KSslCertificateManagerPrivate> d;
0093 };
0094 
0095 #endif