kio Library API Documentation

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 void KSSLCertificateHome::addCertificate(KSSLPKCS12 *cert, QString passToStore) {
00075    if (!cert) return;
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 }
00084 
00085 
00086 // KDE 4: make it const QString &
00087 KSSLPKCS12* KSSLCertificateHome::getCertificateByName(QString name, QString password) {
00088 KSimpleConfig cfg("ksslcertificates", false);
00089   if (!cfg.hasGroup(name)) return NULL;
00090 
00091   cfg.setGroup(name);
00092 
00093   return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""), password);
00094 }
00095 
00096 
00097 // KDE 4: make it const QString &
00098 KSSLPKCS12* KSSLCertificateHome::getCertificateByName(QString name) {
00099 KSimpleConfig cfg("ksslcertificates", false);
00100   if (!cfg.hasGroup(name)) return NULL;
00101 
00102   cfg.setGroup(name);
00103 
00104   return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""), cfg.readEntry("Password", ""));
00105 }
00106 
00107 
00108 // KDE 4: make it const QString &
00109 bool KSSLCertificateHome::hasCertificateByName(QString name) {
00110 KSimpleConfig cfg("ksslcertificates", false);
00111   if (!cfg.hasGroup(name)) return false;
00112   return true;
00113 }
00114 
00115 // KDE 4: make it const QString &
00116 KSSLPKCS12* KSSLCertificateHome::getCertificateByHost(QString host, QString password, KSSLAuthAction *aa) {
00117    return KSSLCertificateHome::getCertificateByName(KSSLCertificateHome::getDefaultCertificateName(host, aa), password);
00118 }
00119 
00120 
00121 // KDE 4: make it const QString &
00122 QString KSSLCertificateHome::getDefaultCertificateName(QString host, KSSLAuthAction *aa) {
00123 KSimpleConfig cfg("ksslauthmap", false);
00124 
00125    if (!cfg.hasGroup(host)) {
00126       if (aa) *aa = AuthNone;
00127       return QString::null;
00128    } else {
00129       cfg.setGroup(host);
00130       if (aa) {
00131          bool tmp = cfg.readBoolEntry("send", false);
00132          *aa = AuthSend; 
00133          if (!tmp) {
00134             tmp = cfg.readBoolEntry("prompt", false);
00135             *aa = AuthPrompt; 
00136             if (!tmp) {
00137                *aa = AuthDont;
00138             }
00139          }
00140       }
00141       return cfg.readEntry("certificate", "");
00142    }
00143 }
00144 
00145 
00146 QString KSSLCertificateHome::getDefaultCertificateName(KSSLAuthAction *aa) {
00147 KConfig cfg("cryptodefaults", false);
00148 
00149    cfg.setGroup("Auth");
00150    if (aa) {
00151       QString am = cfg.readEntry("AuthMethod", "");
00152       if (am == "send")
00153          *aa = AuthSend;
00154       else if (am == "prompt")
00155          *aa = AuthPrompt;
00156       else 
00157          *aa = AuthDont;
00158    }
00159 
00160 return cfg.readEntry("DefaultCert", "");
00161 }
00162 
00163 
00164 // KDE 4: make it const QString &
00165 KSSLPKCS12* KSSLCertificateHome::getDefaultCertificate(QString password, KSSLAuthAction *aa) {
00166 QString name = KSSLCertificateHome::getDefaultCertificateName(aa);
00167 KSimpleConfig cfg("ksslcertificates", false);
00168 
00169    if (name.isEmpty()) return NULL;
00170 
00171    cfg.setGroup(name);
00172    return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""), password);
00173 }
00174 
00175 
00176 
00177 KSSLPKCS12* KSSLCertificateHome::getDefaultCertificate(KSSLAuthAction *aa) {
00178 QString name = KSSLCertificateHome::getDefaultCertificateName(aa);
00179 KSimpleConfig cfg("ksslcertificates", false);
00180 
00181    if (name.isEmpty()) return NULL;
00182 
00183    cfg.setGroup(name);
00184    return KSSLPKCS12::fromString(cfg.readEntry("PKCS12Base64", ""), 
00185                                  cfg.readEntry("Password", ""));
00186 }
00187 
00188 
00189 // KDE 4: make it const QString &
00190 void KSSLCertificateHome::setDefaultCertificate(QString name, bool send, bool prompt) {
00191 KSimpleConfig cfg("ksslauthmap", false);
00192 
00193    cfg.setGroup("<default>");
00194    cfg.writeEntry("defaultCertificate", name);
00195    cfg.writeEntry("send", send);
00196    cfg.writeEntry("prompt", prompt);
00197 }
00198 
00199 
00200 void KSSLCertificateHome::setDefaultCertificate(KSSLPKCS12 *cert, bool send, bool prompt) {
00201    if (cert)
00202    KSSLCertificateHome::setDefaultCertificate(cert->name(), send, prompt);
00203 }
00204 
00205 
00206 
00207 
00208 
KDE Logo
This file is part of the documentation for kio Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Sep 30 05:18:27 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2003