• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KIO

ksslcertificatemanager.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  *
00003  * Copyright (C) 2007, 2008 Andreas Hartmetz <ahartmetz@gmail.com>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
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   Config file format:
00036 [<MD5-Digest>]
00037 <Host> = <Date> <List of ignored errors>
00038 #for example
00039 #mail.kdab.net =  ExpireUTC 2008-08-20T18:22:14, SelfSigned, Expired
00040 #very.old.com =  ExpireUTC 2008-08-20T18:22:14, TooWeakEncryption <- not actually planned to implement
00041 #clueless.admin.com =  ExpireUTC 2008-08-20T18:22:14, HostNameMismatch
00042 #
00043 #Wildcard syntax
00044 #* = ExpireUTC 2008-08-20T18:22:14, SelfSigned
00045 #*.kdab.net = ExpireUTC 2008-08-20T18:22:14, SelfSigned
00046 #mail.kdab.net = ExpireUTC 2008-08-20T18:22:14, All <- not implemented
00047 #* = ExpireUTC 9999-12-31T23:59:59, Reject  #we know that something is wrong with that certificate
00048 CertificatePEM = <PEM-encoded certificate> #host entries are all lowercase, thus no clashes
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     //### Quadratic runtime, woohoo! Use a QSet if that should ever be an issue.
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), //TODO really good conf filename
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     // Make sure kded is running
00216     if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kded")) {
00217         KToolInvocation::klauncher(); // this calls startKdeinit
00218     }
00219 }
00220 
00221 
00222 KSslCertificateManager::~KSslCertificateManager()
00223 {
00224     delete d;
00225 }
00226 
00227 
00228 //static
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"

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal