• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KIO

  • sources
  • kde-4.14
  • kdelibs
  • kio
  • kssl
ksslcertificatehome.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2000-2005 George Staikos <staikos@kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include <ksslcertificatehome.h>
22 #include <ksslcertificate.h>
23 #include <ksslpkcs12.h>
24 
25 #include <kconfiggroup.h>
26 #include <kconfig.h>
27 
28 QStringList KSSLCertificateHome::getCertificateList()
29 {
30  KConfig cfg("ksslcertificates", KConfig::SimpleConfig);
31  return cfg.groupList();
32 }
33 
34 
35 void KSSLCertificateHome::setDefaultCertificate(const QString & name, const QString &host, bool send, bool prompt)
36 {
37  KConfig file("ksslauthmap", KConfig::SimpleConfig);
38  KConfigGroup cfg(&file, QString::fromLatin1(QUrl::toAce(host)));
39 
40  cfg.writeEntry("certificate", name);
41  cfg.writeEntry("send", send);
42  cfg.writeEntry("prompt", prompt);
43  cfg.sync();
44 }
45 
46 
47 void KSSLCertificateHome::setDefaultCertificate(KSSLPKCS12 *cert, const QString &host, bool send, bool prompt) {
48  if (cert)
49  KSSLCertificateHome::setDefaultCertificate(cert->name(), host, send, prompt);
50 }
51 
52 
53 bool KSSLCertificateHome::addCertificate(const QString &filename, const QString &password, bool storePass) {
54  KSSLPKCS12 *pkcs = KSSLPKCS12::loadCertFile(filename, password);
55 
56  if (!pkcs) return false;
57 
58  KSSLCertificateHome::addCertificate(pkcs, storePass?password:QString(""));
59  delete pkcs;
60 
61  return true;
62 }
63 
64 
65 bool KSSLCertificateHome::addCertificate(KSSLPKCS12 *cert, const QString &passToStore) {
66  if (!cert) return false;
67 
68  KConfig file("ksslcertificates", KConfig::SimpleConfig);
69  KConfigGroup cfg = file.group(cert->name().toLatin1());
70 
71  cfg.writeEntry("PKCS12Base64", cert->toString());
72  cfg.writeEntry("Password", passToStore);
73  cfg.sync();
74  return true;
75 }
76 
77 bool KSSLCertificateHome::deleteCertificate(const QString &filename, const QString &password) {
78 KSSLPKCS12 *pkcs = KSSLPKCS12::loadCertFile(filename, password);
79 
80  if (!pkcs) return false;
81 
82  bool ok = deleteCertificate(pkcs);
83  delete pkcs;
84 
85  return ok;
86 }
87 
88 bool KSSLCertificateHome::deleteCertificate(KSSLPKCS12 *cert) {
89  if (!cert) return false;
90 
91  return deleteCertificateByName(cert->name());
92 }
93 
94 bool KSSLCertificateHome::deleteCertificateByName(const QString &name) {
95  if (name.isEmpty()) return false;
96 
97  KConfig cfg("ksslcertificates", KConfig::SimpleConfig);
98 
99  cfg.deleteGroup(name);
100  cfg.sync();
101 
102  return true;
103 }
104 
105 KSSLPKCS12* KSSLCertificateHome::getCertificateByName(const QString &name, const QString &password)
106 {
107  KConfig cfg("ksslcertificates", KConfig::SimpleConfig);
108  if (!cfg.hasGroup(name)) return NULL;
109 
110  KConfigGroup cg(&cfg, name);
111 
112  return KSSLPKCS12::fromString(cg.readEntry("PKCS12Base64", ""), password);
113 }
114 
115 
116 KSSLPKCS12* KSSLCertificateHome::getCertificateByName(const QString &name)
117 {
118  KConfig cfg("ksslcertificates", KConfig::SimpleConfig);
119  if (!cfg.hasGroup(name)) return NULL;
120 
121  KConfigGroup cg(&cfg, name);
122 
123  return KSSLPKCS12::fromString(cg.readEntry("PKCS12Base64", ""), cg.readEntry("Password", ""));
124 }
125 
126 
127 bool KSSLCertificateHome::hasCertificateByName(const QString &name) {
128  KConfig cfg("ksslcertificates", KConfig::SimpleConfig);
129  if (!cfg.hasGroup(name)) return false;
130  return true;
131 }
132 
133 KSSLPKCS12* KSSLCertificateHome::getCertificateByHost(const QString &host,
134  const QString &password, KSSLAuthAction *aa)
135 {
136  return KSSLCertificateHome::getCertificateByName(KSSLCertificateHome::getDefaultCertificateName(host, aa), password);
137 }
138 
139 
140 QString KSSLCertificateHome::getDefaultCertificateName(const QString &host, KSSLAuthAction *aa)
141 {
142  KConfig file("ksslauthmap", KConfig::SimpleConfig);
143  KConfigGroup cfg = file.group(QString::fromLatin1(QUrl::toAce(host)));
144 
145  if (!cfg.exists()) {
146  if (aa) *aa = AuthNone;
147  return QString();
148  } else {
149  if (aa) {
150  bool tmp = cfg.readEntry("send", false);
151  *aa = AuthSend;
152  if (!tmp) {
153  tmp = cfg.readEntry("prompt", false);
154  *aa = AuthPrompt;
155  if (!tmp) {
156  *aa = AuthDont;
157  }
158  }
159  }
160  return cfg.readEntry("certificate", "");
161  }
162 }
163 
164 
165 QString KSSLCertificateHome::getDefaultCertificateName(KSSLAuthAction *aa)
166 {
167  KConfig _cfg("cryptodefaults", KConfig::NoGlobals);
168  KConfigGroup cfg(&_cfg, "Auth");
169  if (aa) {
170  QString am = cfg.readEntry("AuthMethod", "");
171  if (am == "send")
172  *aa = AuthSend;
173  else if (am == "prompt")
174  *aa = AuthPrompt;
175  else
176  *aa = AuthDont;
177  }
178 
179  return cfg.readEntry("DefaultCert", "");
180 }
181 
182 
183 KSSLPKCS12* KSSLCertificateHome::getDefaultCertificate(const QString &password, KSSLAuthAction *aa) {
184  QString name = KSSLCertificateHome::getDefaultCertificateName(aa);
185  KConfig cfg("ksslcertificates", KConfig::SimpleConfig);
186 
187  if (name.isEmpty()) return NULL;
188 
189  KConfigGroup cg(&cfg, name);
190  return KSSLPKCS12::fromString(cg.readEntry("PKCS12Base64", ""), password);
191 }
192 
193 
194 
195 KSSLPKCS12* KSSLCertificateHome::getDefaultCertificate(KSSLAuthAction *aa) {
196  QString name = KSSLCertificateHome::getDefaultCertificateName(aa);
197  KConfig cfg("ksslcertificates", KConfig::SimpleConfig);
198 
199  if (name.isEmpty()) return NULL;
200 
201  KConfigGroup cg(&cfg, name);
202 
203  return KSSLPKCS12::fromString(cg.readEntry("PKCS12Base64", ""),
204  cg.readEntry("Password", ""));
205 }
206 
207 
208 void KSSLCertificateHome::setDefaultCertificate(const QString &name, bool send, bool prompt)
209 {
210  KConfig cfg("ksslauthmap", KConfig::SimpleConfig);
211  KConfigGroup cg(&cfg, "<default>");
212  cg.writeEntry("defaultCertificate", name);
213  cg.writeEntry("send", send);
214  cg.writeEntry("prompt", prompt);
215 }
216 
217 
218 void KSSLCertificateHome::setDefaultCertificate(KSSLPKCS12 *cert, bool send, bool prompt) {
219  if (cert)
220  KSSLCertificateHome::setDefaultCertificate(cert->name(), send, prompt);
221 }
222 
KSSLCertificateHome::getCertificateByHost
static KSSLPKCS12 * getCertificateByHost(const QString &host, const QString &password, KSSLAuthAction *aa)
Definition: ksslcertificatehome.cpp:133
KConfig::sync
void sync()
KSSLCertificateHome::deleteCertificateByName
static bool deleteCertificateByName(const QString &name)
Definition: ksslcertificatehome.cpp:94
ksslcertificate.h
kconfig.h
name
const char * name(StandardAction id)
KConfig::deleteGroup
void deleteGroup(const QByteArray &group, WriteConfigFlags flags=Normal)
KConfig::hasGroup
bool hasGroup(const QString &group) const
KConfig::SimpleConfig
KConfig::group
KConfigGroup group(const QByteArray &group)
KConfigGroup::writeEntry
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
KSSLPKCS12::toString
QString toString()
Convert to a Base64 string.
Definition: ksslpkcs12.cpp:195
KSSLCertificateHome::getDefaultCertificateName
static QString getDefaultCertificateName(const QString &host, KSSLAuthAction *aa=NULL)
Definition: ksslcertificatehome.cpp:140
KSSLPKCS12
KDE PKCS#12 Certificate.
Definition: ksslpkcs12.h:63
KSSLCertificateHome::AuthPrompt
Definition: ksslcertificatehome.h:36
KSSLCertificateHome::KSSLAuthAction
KSSLAuthAction
Definition: ksslcertificatehome.h:36
KSSLCertificateHome::AuthSend
Definition: ksslcertificatehome.h:36
KConfig::NoGlobals
KConfigGroup::exists
bool exists() const
QUrl::toAce
QByteArray toAce(const QString &domain)
KConfig::groupList
QStringList groupList() const
KSSLPKCS12::name
QString name() const
The name of this certificate.
Definition: ksslpkcs12.cpp:278
QString::isEmpty
bool isEmpty() const
KSSLCertificateHome::getCertificateByName
static KSSLPKCS12 * getCertificateByName(const QString &name, const QString &password)
Definition: ksslcertificatehome.cpp:105
ksslcertificatehome.h
QString
KSSLCertificateHome::AuthNone
Definition: ksslcertificatehome.h:36
QStringList
KSSLCertificateHome::deleteCertificate
static bool deleteCertificate(const QString &filename, const QString &password)
Definition: ksslcertificatehome.cpp:77
KSSLPKCS12::loadCertFile
static KSSLPKCS12 * loadCertFile(const QString &filename, const QString &password=QLatin1String(""))
Create a KSSLPKCS12 object by reading a PKCS#12 file.
Definition: ksslpkcs12.cpp:92
ok
KGuiItem ok()
KSSLPKCS12::fromString
static KSSLPKCS12 * fromString(const QString &base64, const QString &password=QLatin1String(""))
Create a KSSLPKCS12 object from a Base64 in a QString.
Definition: ksslpkcs12.cpp:75
KConfigGroup
KConfig
QString::toLatin1
QByteArray toLatin1() const
KSSLCertificateHome::hasCertificateByName
static bool hasCertificateByName(const QString &name)
Definition: ksslcertificatehome.cpp:127
KSSLCertificateHome::addCertificate
static bool addCertificate(const QString &filename, const QString &password, bool storePass=false)
Definition: ksslcertificatehome.cpp:53
KSSLCertificateHome::getDefaultCertificate
static KSSLPKCS12 * getDefaultCertificate(const QString &password, KSSLAuthAction *aa=NULL)
Definition: ksslcertificatehome.cpp:183
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KSSLCertificateHome::setDefaultCertificate
static void setDefaultCertificate(const QString &name, bool send=true, bool prompt=false)
Definition: ksslcertificatehome.cpp:208
ksslpkcs12.h
KConfigGroup::sync
void sync()
KSSLCertificateHome::getCertificateList
static QStringList getCertificateList()
Definition: ksslcertificatehome.cpp:28
KSSLCertificateHome::AuthDont
Definition: ksslcertificatehome.h:36
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
kconfiggroup.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal