kio Library: ksslcertificatehome.cc Source File (kio Library)

| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# ksslcertificatehome.cc

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

This file is part of the documentation for kio Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:24:04 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003