ksslcertificatehome.cc Source File (kio Library)

| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | 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 void KSSLCertificateHome::setDefaultCertificate(QString name, QString host, bool send, bool prompt) {
    00042 KSimpleConfig cfg("ksslauthmap", false);
    00043
    00044    cfg.setGroup(host);
    00045    cfg.writeEntry("certificate", name);
    00046    cfg.writeEntry("send", send);
    00047    cfg.writeEntry("prompt", prompt);
    00048    cfg.sync();
    00049 }
    00050
    00051
    00052 void KSSLCertificateHome::setDefaultCertificate(KSSLPKCS12 *cert, QString host, bool send, bool prompt) {
    00053    if (cert)
    00054       KSSLCertificateHome::setDefaultCertificate(cert->name(), host, send, prompt);
    00055 }
    00056
    00057
    00058 bool KSSLCertificateHome::addCertificate(QString filename, QString password, bool storePass) {
    00059 KSSLPKCS12 *pkcs = KSSLPKCS12::loadCertFile(filename, password);
    00060
    00061   if (!pkcs) return false;
    00062
    00063   KSSLCertificateHome::addCertificate(pkcs, storePass?password:QString(""));
    00064   delete pkcs;
    00065
    00066 return true;
    00067 }
    00068
    00069
    00070 void KSSLCertificateHome::addCertificate(KSSLPKCS12 *cert, QString passToStore) {
    00071    if (!cert) return;
    00072
    00073 KSimpleConfig cfg("ksslcertificates", false);
    00074
    00075    cfg.setGroup(cert->name());
    00076    cfg.writeEntry("PKCS12Base64", cert->toString());
    00077    cfg.writeEntry("Password", passToStore);
    00078    cfg.sync();
    00079 }
    00080
    00081
    00082 KSSLPKCS12* KSSLCertificateHome::getCertificateByName(QString name, QString password) {
    00083 KSimpleConfig cfg("ksslcertificates", false);
    00084   if (!cfg.hasGroup(name)) return NULL;
    00085
    00086   cfg.setGroup(name);
    00087
    00088   return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""), password);
    00089 }
    00090
    00091
    00092 KSSLPKCS12* KSSLCertificateHome::getCertificateByName(QString name) {
    00093 KSimpleConfig cfg("ksslcertificates", false);
    00094   if (!cfg.hasGroup(name)) return NULL;
    00095
    00096   cfg.setGroup(name);
    00097
    00098   return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""), cfg.readEntry("Password", ""));
    00099 }
    00100
    00101
    00102 bool KSSLCertificateHome::hasCertificateByName(QString name) {
    00103 KSimpleConfig cfg("ksslcertificates", false);
    00104   if (!cfg.hasGroup(name)) return false;
    00105   return true;
    00106 }
    00107
    00108 KSSLPKCS12* KSSLCertificateHome::getCertificateByHost(QString host, QString password, KSSLAuthAction *aa) {
    00109    return KSSLCertificateHome::getCertificateByName(KSSLCertificateHome::getDefaultCertificateName(host, aa), password);
    00110 }
    00111
    00112
    00113 QString KSSLCertificateHome::getDefaultCertificateName(QString host, KSSLAuthAction *aa) {
    00114 KSimpleConfig cfg("ksslauthmap", false);
    00115
    00116    if (!cfg.hasGroup(host)) {
    00117       if (aa) *aa = AuthNone;
    00118       return QString::null;
    00119    } else {
    00120       cfg.setGroup(host);
    00121       if (aa) {
    00122          bool tmp = cfg.readBoolEntry("send", false);
    00123          *aa = AuthSend;
    00124          if (!tmp) {
    00125             tmp = cfg.readBoolEntry("prompt", false);
    00126             *aa = AuthPrompt;
    00127             if (!tmp) {
    00128                *aa = AuthDont;
    00129             }
    00130          }
    00131       }
    00132       return cfg.readEntry("certificate", "");
    00133    }
    00134 }
    00135
    00136
    00137 QString KSSLCertificateHome::getDefaultCertificateName(KSSLAuthAction *aa) {
    00138 KConfig cfg("cryptodefaults", false);
    00139
    00140    cfg.setGroup("Auth");
    00141    if (aa) {
    00142       QString am = cfg.readEntry("AuthMethod", "");
    00143       if (am == "send")
    00144          *aa = AuthSend;
    00145       else if (am == "prompt")
    00146          *aa = AuthPrompt;
    00147       else
    00148          *aa = AuthDont;
    00149    }
    00150
    00151 return cfg.readEntry("DefaultCert", "");
    00152 }
    00153
    00154
    00155 KSSLPKCS12* KSSLCertificateHome::getDefaultCertificate(QString password, KSSLAuthAction *aa) {
    00156 QString name = KSSLCertificateHome::getDefaultCertificateName(aa);
    00157 KSimpleConfig cfg("ksslcertificates", false);
    00158
    00159    if (name.isEmpty()) return NULL;
    00160
    00161    cfg.setGroup(name);
    00162    return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""), password);
    00163 }
    00164
    00165
    00166
    00167 KSSLPKCS12* KSSLCertificateHome::getDefaultCertificate(KSSLAuthAction *aa) {
    00168 QString name = KSSLCertificateHome::getDefaultCertificateName(aa);
    00169 KSimpleConfig cfg("ksslcertificates", false);
    00170
    00171    if (name.isEmpty()) return NULL;
    00172
    00173    cfg.setGroup(name);
    00174    return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""),
    00175                                  cfg.readEntry("Password", ""));
    00176 }
    00177
    00178
    00179 void KSSLCertificateHome::setDefaultCertificate(QString name, bool send, bool prompt) {
    00180 KSimpleConfig cfg("ksslauthmap", false);
    00181
    00182    cfg.setGroup("<default>");
    00183    cfg.writeEntry("defaultCertificate", name);
    00184    cfg.writeEntry("send", send);
    00185    cfg.writeEntry("prompt", prompt);
    00186 }
    00187
    00188
    00189 void KSSLCertificateHome::setDefaultCertificate(KSSLPKCS12 *cert, bool send, bool prompt) {
    00190    if (cert)
    00191    KSSLCertificateHome::setDefaultCertificate(cert->name(), send, prompt);
    00192 }
    00193
    00194
    00195
    00196
    00197

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:14:24 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001