kio Library API Documentation

ksslcertificatehome.cc

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., 59 Temple Place - Suite 330,
00018  * Boston, MA 02111-1307, 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    cfg.setGroup(KResolver::domainToAscii(host));
00048    cfg.writeEntry("certificate", name);
00049    cfg.writeEntry("send", send);
00050    cfg.writeEntry("prompt", prompt);
00051    cfg.sync();
00052 }
00053 
00054 
00055 // KDE 4: make it const QString &
00056 void KSSLCertificateHome::setDefaultCertificate(KSSLPKCS12 *cert, QString host, bool send, bool prompt) {
00057    if (cert)
00058       KSSLCertificateHome::setDefaultCertificate(cert->name(), host, send, prompt);
00059 }
00060 
00061 
00062 // KDE 4: make it const QString &
00063 bool KSSLCertificateHome::addCertificate(QString filename, QString password, bool storePass) {
00064 KSSLPKCS12 *pkcs = KSSLPKCS12::loadCertFile(filename, password);
00065 
00066   if (!pkcs) return false;
00067 
00068   KSSLCertificateHome::addCertificate(pkcs, storePass?password:QString(""));
00069   delete pkcs;
00070 
00071 return true;
00072 }
00073 
00074 
00075 // KDE 4: make it const QString &
00076 bool KSSLCertificateHome::addCertificate(KSSLPKCS12 *cert, QString passToStore) {
00077    if (!cert) return false;
00078 
00079 KSimpleConfig cfg("ksslcertificates", false);
00080 
00081    cfg.setGroup(cert->name());
00082    cfg.writeEntry("PKCS12Base64", cert->toString());
00083    cfg.writeEntry("Password", passToStore);
00084    cfg.sync();
00085 return true;
00086 }
00087 
00088 bool KSSLCertificateHome::deleteCertificate(const QString &filename, const QString &password) {
00089 KSSLPKCS12 *pkcs = KSSLPKCS12::loadCertFile(filename, password);
00090 
00091    if (!pkcs) return false;
00092 
00093    bool ok = deleteCertificate(pkcs);
00094    delete pkcs;
00095 
00096 return ok;
00097 }
00098 
00099 bool KSSLCertificateHome::deleteCertificate(KSSLPKCS12 *cert) {
00100    if (!cert) return false;
00101    
00102    return deleteCertificateByName(cert->name());
00103 }
00104 
00105 bool KSSLCertificateHome::deleteCertificateByName(const QString &name) {
00106    if (name.isEmpty()) return false;
00107 
00108 KSimpleConfig cfg("ksslcertificates", false);
00109 
00110    bool ok = cfg.deleteGroup(name);
00111    cfg.sync();
00112 
00113 return ok;
00114 }
00115 
00116 // KDE 4: make it const QString &
00117 KSSLPKCS12* KSSLCertificateHome::getCertificateByName(QString name, QString password) {
00118 KSimpleConfig cfg("ksslcertificates", false);
00119   if (!cfg.hasGroup(name)) return NULL;
00120 
00121   cfg.setGroup(name);
00122 
00123   return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""), password);
00124 }
00125 
00126 
00127 // KDE 4: make it const QString &
00128 KSSLPKCS12* KSSLCertificateHome::getCertificateByName(QString name) {
00129 KSimpleConfig cfg("ksslcertificates", false);
00130   if (!cfg.hasGroup(name)) return NULL;
00131 
00132   cfg.setGroup(name);
00133 
00134   return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""), cfg.readEntry("Password", ""));
00135 }
00136 
00137 
00138 // KDE 4: make it const QString &
00139 bool KSSLCertificateHome::hasCertificateByName(QString name) {
00140 KSimpleConfig cfg("ksslcertificates", false);
00141   if (!cfg.hasGroup(name)) return false;
00142   return true;
00143 }
00144 
00145 // KDE 4: make it const QString &
00146 KSSLPKCS12* KSSLCertificateHome::getCertificateByHost(QString host, QString password, KSSLAuthAction *aa) {
00147    return KSSLCertificateHome::getCertificateByName(KSSLCertificateHome::getDefaultCertificateName(host, aa), password);
00148 }
00149 
00150 
00151 // KDE 4: make it const QString &
00152 QString KSSLCertificateHome::getDefaultCertificateName(QString host, KSSLAuthAction *aa) {
00153 KSimpleConfig cfg("ksslauthmap", false);
00154 
00155    if (!cfg.hasGroup(KResolver::domainToAscii(host))) {
00156       if (aa) *aa = AuthNone;
00157       return QString::null;
00158    } else {
00159       cfg.setGroup(KResolver::domainToAscii(host));
00160       if (aa) {
00161          bool tmp = cfg.readBoolEntry("send", false);
00162          *aa = AuthSend; 
00163          if (!tmp) {
00164             tmp = cfg.readBoolEntry("prompt", false);
00165             *aa = AuthPrompt; 
00166             if (!tmp) {
00167                *aa = AuthDont;
00168             }
00169          }
00170       }
00171       return cfg.readEntry("certificate", "");
00172    }
00173 }
00174 
00175 
00176 QString KSSLCertificateHome::getDefaultCertificateName(KSSLAuthAction *aa) {
00177 KConfig cfg("cryptodefaults", false);
00178 
00179    cfg.setGroup("Auth");
00180    if (aa) {
00181       QString am = cfg.readEntry("AuthMethod", "");
00182       if (am == "send")
00183          *aa = AuthSend;
00184       else if (am == "prompt")
00185          *aa = AuthPrompt;
00186       else 
00187          *aa = AuthDont;
00188    }
00189 
00190 return cfg.readEntry("DefaultCert", "");
00191 }
00192 
00193 
00194 // KDE 4: make it const QString &
00195 KSSLPKCS12* KSSLCertificateHome::getDefaultCertificate(QString password, KSSLAuthAction *aa) {
00196 QString name = KSSLCertificateHome::getDefaultCertificateName(aa);
00197 KSimpleConfig cfg("ksslcertificates", false);
00198 
00199    if (name.isEmpty()) return NULL;
00200 
00201    cfg.setGroup(name);
00202    return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""), password);
00203 }
00204 
00205 
00206 
00207 KSSLPKCS12* KSSLCertificateHome::getDefaultCertificate(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", ""), 
00215                                  cfg.readEntry("Password", ""));
00216 }
00217 
00218 
00219 // KDE 4: make it const QString &
00220 void KSSLCertificateHome::setDefaultCertificate(QString name, bool send, bool prompt) {
00221 KSimpleConfig cfg("ksslauthmap", false);
00222 
00223    cfg.setGroup("<default>");
00224    cfg.writeEntry("defaultCertificate", name);
00225    cfg.writeEntry("send", send);
00226    cfg.writeEntry("prompt", prompt);
00227 }
00228 
00229 
00230 void KSSLCertificateHome::setDefaultCertificate(KSSLPKCS12 *cert, bool send, bool prompt) {
00231    if (cert)
00232    KSSLCertificateHome::setDefaultCertificate(cert->name(), send, prompt);
00233 }
00234 
KDE Logo
This file is part of the documentation for kio Library Version 3.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Jul 20 13:55:16 2006 by doxygen 1.4.4 written by Dimitri van Heesch, © 1997-2003