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

kio

ksslcertificatehome.cc

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  *
00003  * Copyright (C) 2000-2005 George Staikos <staikos@kde.org>
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 #include <ksslcertificatehome.h>
00022 #include <ksslcertificate.h>
00023 #include <ksslpkcs12.h>
00024 
00025 #include <kresolver.h>
00026 #include <ksimpleconfig.h>
00027 
00028 using namespace KNetwork;
00029 
00030 QStringList KSSLCertificateHome::getCertificateList() {
00031 KSimpleConfig cfg("ksslcertificates", false);
00032 QStringList list = cfg.groupList();
00033 QString defaultstr("<default>");
00034 QString blankstr("");
00035 
00036 list.remove(defaultstr);
00037 list.remove(blankstr);
00038 
00039 return list;
00040 }
00041 
00042 
00043 // KDE 4: make it const QString &
00044 void KSSLCertificateHome::setDefaultCertificate(QString name, QString host, bool send, bool prompt) {
00045 KSimpleConfig cfg("ksslauthmap", false);
00046 
00047 #ifdef Q_WS_WIN //temporary 
00048    cfg.setGroup(host);
00049 #else
00050    cfg.setGroup(KResolver::domainToAscii(host));
00051 #endif
00052    cfg.writeEntry("certificate", name);
00053    cfg.writeEntry("send", send);
00054    cfg.writeEntry("prompt", prompt);
00055    cfg.sync();
00056 }
00057 
00058 
00059 // KDE 4: make it const QString &
00060 void KSSLCertificateHome::setDefaultCertificate(KSSLPKCS12 *cert, QString host, bool send, bool prompt) {
00061    if (cert)
00062       KSSLCertificateHome::setDefaultCertificate(cert->name(), host, send, prompt);
00063 }
00064 
00065 
00066 // KDE 4: make it const QString &
00067 bool KSSLCertificateHome::addCertificate(QString filename, QString password, bool storePass) {
00068 KSSLPKCS12 *pkcs = KSSLPKCS12::loadCertFile(filename, password);
00069 
00070   if (!pkcs) return false;
00071 
00072   KSSLCertificateHome::addCertificate(pkcs, storePass?password:QString(""));
00073   delete pkcs;
00074 
00075 return true;
00076 }
00077 
00078 
00079 // KDE 4: make it const QString &
00080 bool KSSLCertificateHome::addCertificate(KSSLPKCS12 *cert, QString passToStore) {
00081    if (!cert) return false;
00082 
00083 KSimpleConfig cfg("ksslcertificates", false);
00084 
00085    cfg.setGroup(cert->name());
00086    cfg.writeEntry("PKCS12Base64", cert->toString());
00087    cfg.writeEntry("Password", passToStore);
00088    cfg.sync();
00089 return true;
00090 }
00091 
00092 bool KSSLCertificateHome::deleteCertificate(const QString &filename, const QString &password) {
00093 KSSLPKCS12 *pkcs = KSSLPKCS12::loadCertFile(filename, password);
00094 
00095    if (!pkcs) return false;
00096 
00097    bool ok = deleteCertificate(pkcs);
00098    delete pkcs;
00099 
00100 return ok;
00101 }
00102 
00103 bool KSSLCertificateHome::deleteCertificate(KSSLPKCS12 *cert) {
00104    if (!cert) return false;
00105    
00106    return deleteCertificateByName(cert->name());
00107 }
00108 
00109 bool KSSLCertificateHome::deleteCertificateByName(const QString &name) {
00110    if (name.isEmpty()) return false;
00111 
00112 KSimpleConfig cfg("ksslcertificates", false);
00113 
00114    bool ok = cfg.deleteGroup(name);
00115    cfg.sync();
00116 
00117 return ok;
00118 }
00119 
00120 // KDE 4: make it const QString &
00121 KSSLPKCS12* KSSLCertificateHome::getCertificateByName(QString name, QString password) {
00122 KSimpleConfig cfg("ksslcertificates", false);
00123   if (!cfg.hasGroup(name)) return NULL;
00124 
00125   cfg.setGroup(name);
00126 
00127   return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""), password);
00128 }
00129 
00130 
00131 // KDE 4: make it const QString &
00132 KSSLPKCS12* KSSLCertificateHome::getCertificateByName(QString name) {
00133 KSimpleConfig cfg("ksslcertificates", false);
00134   if (!cfg.hasGroup(name)) return NULL;
00135 
00136   cfg.setGroup(name);
00137 
00138   return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""), cfg.readEntry("Password", ""));
00139 }
00140 
00141 
00142 // KDE 4: make it const QString &
00143 bool KSSLCertificateHome::hasCertificateByName(QString name) {
00144 KSimpleConfig cfg("ksslcertificates", false);
00145   if (!cfg.hasGroup(name)) return false;
00146   return true;
00147 }
00148 
00149 // KDE 4: make it const QString &
00150 KSSLPKCS12* KSSLCertificateHome::getCertificateByHost(QString host, QString password, KSSLAuthAction *aa) {
00151    return KSSLCertificateHome::getCertificateByName(KSSLCertificateHome::getDefaultCertificateName(host, aa), password);
00152 }
00153 
00154 
00155 // KDE 4: make it const QString &
00156 QString KSSLCertificateHome::getDefaultCertificateName(QString host, KSSLAuthAction *aa) {
00157 KSimpleConfig cfg("ksslauthmap", false);
00158 
00159 #ifdef Q_WS_WIN //temporary 
00160    if (!cfg.hasGroup(host)) {
00161 #else
00162    if (!cfg.hasGroup(KResolver::domainToAscii(host))) {
00163 #endif
00164       if (aa) *aa = AuthNone;
00165       return QString::null;
00166    } else {
00167 #ifdef Q_WS_WIN //temporary 
00168       cfg.setGroup(host);
00169 #else
00170       cfg.setGroup(KResolver::domainToAscii(host));
00171 #endif
00172       if (aa) {
00173          bool tmp = cfg.readBoolEntry("send", false);
00174          *aa = AuthSend; 
00175          if (!tmp) {
00176             tmp = cfg.readBoolEntry("prompt", false);
00177             *aa = AuthPrompt; 
00178             if (!tmp) {
00179                *aa = AuthDont;
00180             }
00181          }
00182       }
00183       return cfg.readEntry("certificate", "");
00184    }
00185 }
00186 
00187 
00188 QString KSSLCertificateHome::getDefaultCertificateName(KSSLAuthAction *aa) {
00189 KConfig cfg("cryptodefaults", false);
00190 
00191    cfg.setGroup("Auth");
00192    if (aa) {
00193       QString am = cfg.readEntry("AuthMethod", "");
00194       if (am == "send")
00195          *aa = AuthSend;
00196       else if (am == "prompt")
00197          *aa = AuthPrompt;
00198       else 
00199          *aa = AuthDont;
00200    }
00201 
00202 return cfg.readEntry("DefaultCert", "");
00203 }
00204 
00205 
00206 // KDE 4: make it const QString &
00207 KSSLPKCS12* KSSLCertificateHome::getDefaultCertificate(QString password, KSSLAuthAction *aa) {
00208 QString name = KSSLCertificateHome::getDefaultCertificateName(aa);
00209 KSimpleConfig cfg("ksslcertificates", false);
00210 
00211    if (name.isEmpty()) return NULL;
00212 
00213    cfg.setGroup(name);
00214    return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""), password);
00215 }
00216 
00217 
00218 
00219 KSSLPKCS12* KSSLCertificateHome::getDefaultCertificate(KSSLAuthAction *aa) {
00220 QString name = KSSLCertificateHome::getDefaultCertificateName(aa);
00221 KSimpleConfig cfg("ksslcertificates", false);
00222 
00223    if (name.isEmpty()) return NULL;
00224 
00225    cfg.setGroup(name);
00226    return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""), 
00227                                  cfg.readEntry("Password", ""));
00228 }
00229 
00230 
00231 // KDE 4: make it const QString &
00232 void KSSLCertificateHome::setDefaultCertificate(QString name, bool send, bool prompt) {
00233 KSimpleConfig cfg("ksslauthmap", false);
00234 
00235    cfg.setGroup("<default>");
00236    cfg.writeEntry("defaultCertificate", name);
00237    cfg.writeEntry("send", send);
00238    cfg.writeEntry("prompt", prompt);
00239 }
00240 
00241 
00242 void KSSLCertificateHome::setDefaultCertificate(KSSLPKCS12 *cert, bool send, bool prompt) {
00243    if (cert)
00244    KSSLCertificateHome::setDefaultCertificate(cert->name(), send, prompt);
00245 }
00246 

kio

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

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
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