File indexing completed on 2024-04-21 03:55:10

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2010 Andreas Hartmetz <ahartmetz@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KSSLCERTIFICATEMANAGER_P_H
0009 #define KSSLCERTIFICATEMANAGER_P_H
0010 
0011 #include <QMutex>
0012 #include <QSet>
0013 #include <QString>
0014 
0015 #include <KConfig>
0016 
0017 class KSslCertificateRulePrivate
0018 {
0019 public:
0020     QSslCertificate certificate;
0021     QString hostName;
0022     bool isRejected;
0023     QDateTime expiryDateTime;
0024     QList<QSslError::SslError> ignoredErrors;
0025 };
0026 
0027 struct KSslCaCertificate {
0028     enum Store {
0029         SystemStore = 0,
0030         UserStore,
0031     };
0032 
0033     // TODO see if we can get rid of the .toHex() for storage and comparison; requires
0034     //      several changes in KSslCertificateManager and CaCertificatesPage!
0035     KSslCaCertificate(const QSslCertificate &c, Store s, bool _isBlacklisted)
0036         : cert(c)
0037         , certHash(c.digest().toHex())
0038         , store(s)
0039         , isBlacklisted(_isBlacklisted)
0040     {
0041     }
0042 
0043     QSslCertificate cert;
0044     QByteArray certHash;
0045     Store store;
0046     bool isBlacklisted;
0047 };
0048 
0049 class OrgKdeKSSLDInterface; // aka org::kde::KSSLDInterface
0050 namespace org
0051 {
0052 namespace kde
0053 {
0054 typedef ::OrgKdeKSSLDInterface KSSLDInterface;
0055 }
0056 }
0057 
0058 class KSslCertificateManagerPrivate
0059 {
0060 public:
0061     KSslCertificateManagerPrivate();
0062     ~KSslCertificateManagerPrivate();
0063 
0064     static KSslCertificateManagerPrivate *get(KSslCertificateManager *q)
0065     {
0066         return q->d.get();
0067     }
0068 
0069     void loadDefaultCaCertificates();
0070 
0071     // helpers for setAllCertificates()
0072     bool addCertificate(const KSslCaCertificate &in);
0073     bool removeCertificate(const KSslCaCertificate &old);
0074     bool updateCertificateBlacklisted(const KSslCaCertificate &cert);
0075     bool setCertificateBlacklisted(const QByteArray &certHash, bool isBlacklisted);
0076 
0077     void setAllCertificates(const QList<KSslCaCertificate> &certsIn);
0078     QList<KSslCaCertificate> allCertificates() const;
0079 
0080     KConfig config;
0081     org::kde::KSSLDInterface *iface;
0082 
0083     QList<QSslCertificate> defaultCaCertificates;
0084 
0085     // for use in setAllCertificates() only
0086     QSet<QByteArray> knownCerts;
0087     QMutex certListMutex;
0088     bool isCertListLoaded;
0089     QString userCertDir;
0090 };
0091 
0092 // don't export KSslCertificateManagerPrivate to avoid unnecessary symbols
0093 KIOCORE_EXPORT QList<KSslCaCertificate> _allKsslCaCertificates(KSslCertificateManager *cm);
0094 KIOCORE_EXPORT void _setAllKsslCaCertificates(KSslCertificateManager *cm, const QList<KSslCaCertificate> &certsIn);
0095 
0096 #endif // KSSLCERTIFICATEMANAGER_P_H