KIO
ksslcertificatemanager.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "ksslcertificatemanager.h"
00023 #include "ktcpsocket.h"
00024 #include <ktoolinvocation.h>
00025 #include <kconfig.h>
00026 #include <kconfiggroup.h>
00027 #include <kdebug.h>
00028 #include <kglobal.h>
00029
00030 #include <QtDBus/QtDBus>
00031
00032 #include "kssld_interface.h"
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 class KSslCertificateRulePrivate
00053 {
00054 public:
00055 QSslCertificate certificate;
00056 QString hostName;
00057 bool isRejected;
00058 QDateTime expiryDateTime;
00059 QList<KSslError::Error> ignoredErrors;
00060 };
00061
00062
00063 KSslCertificateRule::KSslCertificateRule(const QSslCertificate &cert, const QString &hostName)
00064 : d(new KSslCertificateRulePrivate())
00065 {
00066 d->certificate = cert;
00067 d->hostName = hostName;
00068 d->isRejected = false;
00069 }
00070
00071
00072 KSslCertificateRule::KSslCertificateRule(const KSslCertificateRule &other)
00073 : d(new KSslCertificateRulePrivate())
00074 {
00075 *d = *other.d;
00076 }
00077
00078
00079 KSslCertificateRule::~KSslCertificateRule()
00080 {
00081 delete d;
00082 }
00083
00084
00085 KSslCertificateRule &KSslCertificateRule::operator=(const KSslCertificateRule &other)
00086 {
00087 *d = *other.d;
00088 return *this;
00089 }
00090
00091
00092 QSslCertificate KSslCertificateRule::certificate() const
00093 {
00094 return d->certificate;
00095 }
00096
00097
00098 QString KSslCertificateRule::hostName() const
00099 {
00100 return d->hostName;
00101 }
00102
00103
00104 void KSslCertificateRule::setExpiryDateTime(const QDateTime &dateTime)
00105 {
00106 d->expiryDateTime = dateTime;
00107 }
00108
00109
00110 QDateTime KSslCertificateRule::expiryDateTime() const
00111 {
00112 return d->expiryDateTime;
00113 }
00114
00115
00116 void KSslCertificateRule::setRejected(bool rejected)
00117 {
00118 d->isRejected = rejected;
00119 }
00120
00121
00122 bool KSslCertificateRule::isRejected() const
00123 {
00124 return d->isRejected;
00125 }
00126
00127
00128 bool KSslCertificateRule::isErrorIgnored(KSslError::Error error) const
00129 {
00130 foreach (KSslError::Error ignoredError, d->ignoredErrors)
00131 if (error == ignoredError)
00132 return true;
00133
00134 return false;
00135 }
00136
00137
00138 void KSslCertificateRule::setIgnoredErrors(const QList<KSslError::Error> &errors)
00139 {
00140 d->ignoredErrors.clear();
00141
00142 foreach(KSslError::Error e, errors)
00143 if (!isErrorIgnored(e))
00144 d->ignoredErrors.append(e);
00145 }
00146
00147
00148 void KSslCertificateRule::setIgnoredErrors(const QList<KSslError> &errors)
00149 {
00150 QList<KSslError::Error> el;
00151 foreach(const KSslError &e, errors)
00152 el.append(e.error());
00153 setIgnoredErrors(el);
00154 }
00155
00156
00157 QList<KSslError::Error> KSslCertificateRule::ignoredErrors() const
00158 {
00159 return d->ignoredErrors;
00160 }
00161
00162
00163 QList<KSslError::Error> KSslCertificateRule::filterErrors(const QList<KSslError::Error> &errors) const
00164 {
00165 QList<KSslError::Error> ret;
00166 foreach (KSslError::Error error, errors) {
00167 if (!isErrorIgnored(error))
00168 ret.append(error);
00169 }
00170 return ret;
00171 }
00172
00173
00174 QList<KSslError> KSslCertificateRule::filterErrors(const QList<KSslError> &errors) const
00175 {
00176 QList<KSslError> ret;
00177 foreach (const KSslError &error, errors) {
00178 if (!isErrorIgnored(error.error()))
00179 ret.append(error);
00180 }
00181 return ret;
00182 }
00183
00184
00186
00187 class KSslCertificateManagerContainer
00188 {
00189 public:
00190 KSslCertificateManager sslCertificateManager;
00191 };
00192
00193 K_GLOBAL_STATIC(KSslCertificateManagerContainer, g_instance)
00194
00195
00196 class KSslCertificateManagerPrivate
00197 {
00198 public:
00199 KSslCertificateManagerPrivate()
00200 : config("ksslcertificatemanager", KConfig::SimpleConfig),
00201 iface("org.kde.kded", "/modules/kssld", QDBusConnection::sessionBus())
00202 {
00203 }
00204
00205 KConfig config;
00206 org::kde::KSSLDInterface iface;
00207 QHash<QString, KSslError::Error> stringToSslError;
00208 QHash<KSslError::Error, QString> sslErrorToString;
00209 };
00210
00211
00212 KSslCertificateManager::KSslCertificateManager()
00213 : d(new KSslCertificateManagerPrivate())
00214 {
00215
00216 if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kded")) {
00217 KToolInvocation::klauncher();
00218 }
00219 }
00220
00221
00222 KSslCertificateManager::~KSslCertificateManager()
00223 {
00224 delete d;
00225 }
00226
00227
00228
00229 KSslCertificateManager *KSslCertificateManager::self()
00230 {
00231 return &g_instance->sslCertificateManager;
00232 }
00233
00234
00235 void KSslCertificateManager::setRule(const KSslCertificateRule &rule)
00236 {
00237 d->iface.setRule(rule);
00238 }
00239
00240
00241 void KSslCertificateManager::clearRule(const KSslCertificateRule &rule)
00242 {
00243 d->iface.clearRule(rule);
00244 }
00245
00246
00247 void KSslCertificateManager::clearRule(const QSslCertificate &cert, const QString &hostName)
00248 {
00249 d->iface.clearRule(cert, hostName);
00250 }
00251
00252
00253 KSslCertificateRule KSslCertificateManager::rule(const QSslCertificate &cert, const QString &hostName) const
00254 {
00255 return d->iface.rule(cert, hostName);
00256 }
00257
00258
00259 void KSslCertificateManager::setRootCertificates(const QList<QSslCertificate> &rootCertificates)
00260 {
00261 d->iface.setRootCertificates(rootCertificates);
00262 }
00263
00264
00265 QList<QSslCertificate> KSslCertificateManager::rootCertificates() const
00266 {
00267 return d->iface.rootCertificates();
00268 }
00269
00270
00271 #include "kssld_interface.moc"