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

KIO

  • 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
28QStringList KSSLCertificateHome::getCertificateList()
29{
30 KConfig cfg("ksslcertificates", KConfig::SimpleConfig);
31 return cfg.groupList();
32}
33
34
35void 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
47void 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
53bool 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
65bool 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
77bool KSSLCertificateHome::deleteCertificate(const QString &filename, const QString &password) {
78KSSLPKCS12 *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
88bool KSSLCertificateHome::deleteCertificate(KSSLPKCS12 *cert) {
89 if (!cert) return false;
90
91 return deleteCertificateByName(cert->name());
92}
93
94bool 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
105KSSLPKCS12* 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
116KSSLPKCS12* 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
127bool KSSLCertificateHome::hasCertificateByName(const QString &name) {
128 KConfig cfg("ksslcertificates", KConfig::SimpleConfig);
129 if (!cfg.hasGroup(name)) return false;
130 return true;
131}
132
133KSSLPKCS12* KSSLCertificateHome::getCertificateByHost(const QString &host,
134 const QString &password, KSSLAuthAction *aa)
135{
136 return KSSLCertificateHome::getCertificateByName(KSSLCertificateHome::getDefaultCertificateName(host, aa), password);
137}
138
139
140QString 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
165QString 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
183KSSLPKCS12* 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
195KSSLPKCS12* 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
208void 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
218void KSSLCertificateHome::setDefaultCertificate(KSSLPKCS12 *cert, bool send, bool prompt) {
219 if (cert)
220 KSSLCertificateHome::setDefaultCertificate(cert->name(), send, prompt);
221}
222
KConfigBase::group
KConfigGroup group(const char *group)
KConfigBase::hasGroup
bool hasGroup(const char *group) const
KConfigBase::deleteGroup
void deleteGroup(const char *group, WriteConfigFlags flags=Normal)
KConfigGroup
KConfigGroup::writeEntry
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
KConfigGroup::readEntry
QString readEntry(const char *key, const char *aDefault=0) const
KConfigGroup::sync
void sync()
KConfigGroup::exists
bool exists() const
KConfig
KConfig::sync
void sync()
KConfig::SimpleConfig
SimpleConfig
KConfig::NoGlobals
NoGlobals
KConfig::groupList
QStringList groupList() const
KSSLCertificateHome::getCertificateByHost
static KSSLPKCS12 * getCertificateByHost(const QString &host, const QString &password, KSSLAuthAction *aa)
Definition: ksslcertificatehome.cpp:133
KSSLCertificateHome::getCertificateByName
static KSSLPKCS12 * getCertificateByName(const QString &name, const QString &password)
Definition: ksslcertificatehome.cpp:105
KSSLCertificateHome::getCertificateList
static QStringList getCertificateList()
Definition: ksslcertificatehome.cpp:28
KSSLCertificateHome::deleteCertificateByName
static bool deleteCertificateByName(const QString &name)
Definition: ksslcertificatehome.cpp:94
KSSLCertificateHome::getDefaultCertificate
static KSSLPKCS12 * getDefaultCertificate(const QString &password, KSSLAuthAction *aa=NULL)
Definition: ksslcertificatehome.cpp:183
KSSLCertificateHome::setDefaultCertificate
static void setDefaultCertificate(const QString &name, bool send=true, bool prompt=false)
Definition: ksslcertificatehome.cpp:208
KSSLCertificateHome::addCertificate
static bool addCertificate(const QString &filename, const QString &password, bool storePass=false)
Definition: ksslcertificatehome.cpp:53
KSSLCertificateHome::deleteCertificate
static bool deleteCertificate(const QString &filename, const QString &password)
Definition: ksslcertificatehome.cpp:77
KSSLCertificateHome::hasCertificateByName
static bool hasCertificateByName(const QString &name)
Definition: ksslcertificatehome.cpp:127
KSSLCertificateHome::getDefaultCertificateName
static QString getDefaultCertificateName(const QString &host, KSSLAuthAction *aa=NULL)
Definition: ksslcertificatehome.cpp:140
KSSLCertificateHome::KSSLAuthAction
KSSLAuthAction
Definition: ksslcertificatehome.h:36
KSSLCertificateHome::AuthPrompt
@ AuthPrompt
Definition: ksslcertificatehome.h:36
KSSLCertificateHome::AuthNone
@ AuthNone
Definition: ksslcertificatehome.h:36
KSSLCertificateHome::AuthSend
@ AuthSend
Definition: ksslcertificatehome.h:36
KSSLCertificateHome::AuthDont
@ AuthDont
Definition: ksslcertificatehome.h:36
KSSLPKCS12
KDE PKCS#12 Certificate.
Definition: ksslpkcs12.h:63
KSSLPKCS12::name
QString name() const
The name of this certificate.
Definition: ksslpkcs12.cpp:278
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
KSSLPKCS12::toString
QString toString()
Convert to a Base64 string.
Definition: ksslpkcs12.cpp:195
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
kconfig.h
kconfiggroup.h
ksslcertificate.h
ksslcertificatehome.h
ksslpkcs12.h
name
const char * name(StandardAction id)
ok
KGuiItem ok()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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