• 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
ksslsettings.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2000 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 "ksslsettings.h"
22 
23 #include <config.h>
24 #include <ksslconfig.h>
25 
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 
29 #include <stdlib.h>
30 #include <pwd.h>
31 #include <unistd.h>
32 
33 #include <QtCore/QFile>
34 
35 #include <kglobal.h>
36 #include <kstandarddirs.h>
37 #include <kdebug.h>
38 #include <kconfiggroup.h>
39 
40 // this hack provided by Malte Starostik to avoid glibc/openssl bug
41 // on some systems
42 #ifdef KSSL_HAVE_SSL
43 #define crypt _openssl_crypt
44 #include <openssl/ssl.h>
45 #undef crypt
46 #endif
47 
48 #include <kopenssl.h>
49 
50 #ifdef KSSL_HAVE_SSL
51 #define sk_new d->kossl->sk_new
52 #define sk_push d->kossl->sk_push
53 #define sk_free d->kossl->sk_free
54 #define sk_value d->kossl->sk_value
55 #define sk_num d->kossl->sk_num
56 #define sk_dup d->kossl->sk_dup
57 #define sk_pop d->kossl->sk_pop
58 #endif
59 
60 class CipherNode {
61  public:
62  CipherNode(const char *_name, int _keylen) :
63  name(_name), keylen(_keylen) {}
64  QString name;
65  int keylen;
66  inline int operator==(CipherNode &x)
67  { return ((x.keylen == keylen) && (x.name == name)); }
68  inline int operator< (CipherNode &x) { return keylen < x.keylen; }
69  inline int operator<=(CipherNode &x) { return keylen <= x.keylen; }
70  inline int operator> (CipherNode &x) { return keylen > x.keylen; }
71  inline int operator>=(CipherNode &x) { return keylen >= x.keylen; }
72 };
73 
74 
75 class KSSLSettingsPrivate {
76  public:
77  KSSLSettingsPrivate() {
78  kossl = 0L; // try to delay this as long as possible
79  }
80  ~KSSLSettingsPrivate() {
81 
82  }
83 
84  KOSSL *kossl;
85  bool m_bUseEGD;
86  bool m_bUseEFile;
87  QString m_EGDPath;
88  bool m_bSendX509;
89  bool m_bPromptX509;
90 };
91 
92 //
93 // FIXME
94 // Implementation note: for now, we only read cipher settings from disk,
95 // and do not store them in memory. This should change.
96 //
97 
98 KSSLSettings::KSSLSettings(bool readConfig)
99  :d(new KSSLSettingsPrivate)
100 {
101  m_cfg = new KConfig("cryptodefaults", KConfig::NoGlobals);
102 
103  if (!KGlobal::dirs()->addResourceType("kssl", "data", "kssl")) {
104  //kDebug(7029) << "Error adding (kssl, share/apps/kssl)";
105  }
106 
107  if (readConfig) load();
108 }
109 
110 
111 // we don't save settings incase it was a temporary object
112 KSSLSettings::~KSSLSettings() {
113  delete m_cfg;
114  delete d;
115 }
116 
117 
118 QString KSSLSettings::getCipherList() {
119  QString clist;
120  // TODO fill in list here (or just remove this method!)
121  return clist;
122 }
123 
124 // FIXME - sync these up so that we can use them with the control module!!
125 void KSSLSettings::load() {
126  m_cfg->reparseConfiguration();
127 
128  KConfigGroup cfg(m_cfg, "Warnings");
129  m_bWarnOnEnter = cfg.readEntry("OnEnter", false);
130  m_bWarnOnLeave = cfg.readEntry("OnLeave", true);
131  m_bWarnOnUnencrypted = cfg.readEntry("OnUnencrypted", false);
132  m_bWarnOnMixed = cfg.readEntry("OnMixed", true);
133 
134  cfg = KConfigGroup(m_cfg, "Validation");
135  m_bWarnSelfSigned = cfg.readEntry("WarnSelfSigned", true);
136  m_bWarnExpired = cfg.readEntry("WarnExpired", true);
137  m_bWarnRevoked = cfg.readEntry("WarnRevoked", true);
138 
139  cfg = KConfigGroup(m_cfg, "EGD");
140  d->m_bUseEGD = cfg.readEntry("UseEGD", false);
141  d->m_bUseEFile = cfg.readEntry("UseEFile", false);
142  d->m_EGDPath = cfg.readPathEntry("EGDPath", QString());
143 
144  cfg = KConfigGroup(m_cfg, "Auth");
145  d->m_bSendX509 = ("send" == cfg.readEntry("AuthMethod", ""));
146  d->m_bPromptX509 = ("prompt" == cfg.readEntry("AuthMethod", ""));
147 
148 #ifdef KSSL_HAVE_SSL
149 
150 
151 
152 #endif
153 }
154 
155 
156 void KSSLSettings::defaults() {
157  m_bWarnOnEnter = false;
158  m_bWarnOnLeave = true;
159  m_bWarnOnUnencrypted = true;
160  m_bWarnOnMixed = true;
161  m_bWarnSelfSigned = true;
162  m_bWarnExpired = true;
163  m_bWarnRevoked = true;
164  d->m_bUseEGD = false;
165  d->m_bUseEFile = false;
166  d->m_EGDPath = "";
167 }
168 
169 
170 void KSSLSettings::save() {
171  KConfigGroup cfg(m_cfg, "Warnings");
172  cfg.writeEntry("OnEnter", m_bWarnOnEnter);
173  cfg.writeEntry("OnLeave", m_bWarnOnLeave);
174  cfg.writeEntry("OnUnencrypted", m_bWarnOnUnencrypted);
175  cfg.writeEntry("OnMixed", m_bWarnOnMixed);
176 
177  cfg = KConfigGroup(m_cfg, "Validation");
178  cfg.writeEntry("WarnSelfSigned", m_bWarnSelfSigned);
179  cfg.writeEntry("WarnExpired", m_bWarnExpired);
180  cfg.writeEntry("WarnRevoked", m_bWarnRevoked);
181 
182  cfg = KConfigGroup(m_cfg, "EGD");
183  cfg.writeEntry("UseEGD", d->m_bUseEGD);
184  cfg.writeEntry("UseEFile", d->m_bUseEFile);
185  cfg.writePathEntry("EGDPath", d->m_EGDPath);
186 
187  m_cfg->sync();
188  // FIXME - ciphers
189 #if 0
190 #ifdef KSSL_HAVE_SSL
191  cfg.setGroup("SSLv3");
192  for (unsigned int i = 0; i < v3ciphers.count(); i++) {
193  QString ciphername;
194  ciphername.sprintf("cipher_%s", v3ciphers[i].ascii());
195  if (v3selectedciphers.contains(v3ciphers[i])) {
196  cfg.writeEntry(ciphername, true);
197  } else cfg.writeEntry(ciphername, false);
198  }
199  m_cfg->sync();
200 #endif
201 
202  // insure proper permissions -- contains sensitive data
203  QString cfgName(KGlobal::dirs()->findResource("config", "cryptodefaults"));
204  if (!cfgName.isEmpty())
205  KDE::chmod(cfgName, 0600);
206 #endif
207 }
208 
209 
210 bool KSSLSettings::warnOnEnter() const { return m_bWarnOnEnter; }
211 void KSSLSettings::setWarnOnEnter(bool x) { m_bWarnOnEnter = x; }
212 bool KSSLSettings::warnOnUnencrypted() const { return m_bWarnOnUnencrypted; }
213 void KSSLSettings::setWarnOnUnencrypted(bool x) { m_bWarnOnUnencrypted = x; }
214 bool KSSLSettings::warnOnLeave() const { return m_bWarnOnLeave; }
215 void KSSLSettings::setWarnOnLeave(bool x) { m_bWarnOnLeave = x; }
216 bool KSSLSettings::warnOnMixed() const { return m_bWarnOnMixed; }
217 bool KSSLSettings::useEGD() const { return d->m_bUseEGD; }
218 bool KSSLSettings::useEFile() const { return d->m_bUseEFile; }
219 bool KSSLSettings::autoSendX509() const { return d->m_bSendX509; }
220 bool KSSLSettings::promptSendX509() const { return d->m_bPromptX509; }
221 QString& KSSLSettings::getEGDPath() { return d->m_EGDPath; }
222 
223 #ifdef KSSL_HAVE_SSL
224 #undef sk_new
225 #undef sk_push
226 #undef sk_free
227 #undef sk_value
228 #undef sk_num
229 #undef sk_pop
230 #undef sk_dup
231 #endif
KConfigGroup::readPathEntry
QString readPathEntry(const QString &pKey, const QString &aDefault) const
KConfig::sync
void sync()
KSSLSettings::warnOnLeave
bool warnOnLeave() const
Does the user want to be warned on leaving SSL mode.
Definition: ksslsettings.cpp:214
KConfigGroup::writePathEntry
void writePathEntry(const QString &pKey, const QString &path, WriteConfigFlags pFlags=Normal)
KSSLSettings::useEFile
bool useEFile() const
Does the user want to use an entropy file?
Definition: ksslsettings.cpp:218
kdebug.h
KSSLSettings::autoSendX509
bool autoSendX509() const
Does the user want X.509 client certificates to always be sent when possible?
Definition: ksslsettings.cpp:219
KSSLSettings::getCipherList
QString getCipherList()
Get the OpenSSL cipher list for selecting the list of ciphers to use in a connection.
Definition: ksslsettings.cpp:118
KGlobal::dirs
KStandardDirs * dirs()
name
const char * name(StandardAction id)
KDE::chmod
int chmod(const QString &path, mode_t mode)
KSSLSettings::setWarnOnLeave
void setWarnOnLeave(bool x)
Change the user's warnOnLeave() setting.
Definition: ksslsettings.cpp:215
KConfigGroup::writeEntry
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
KSSLSettings::warnOnMixed
bool warnOnMixed() const
Does the user want to be warned during mixed SSL/non-SSL mode.
Definition: ksslsettings.cpp:216
KSSLSettings::setWarnOnEnter
void setWarnOnEnter(bool x)
Change the user's warnOnEnter() setting.
Definition: ksslsettings.cpp:211
KSSLSettings::useEGD
bool useEGD() const
Does the user want to use the Entropy Gathering Daemon?
Definition: ksslsettings.cpp:217
KSSLSettings::warnOnUnencrypted
bool warnOnUnencrypted() const
Does the user want to be warned on sending unencrypted data.
Definition: ksslsettings.cpp:212
KSSLSettings::KSSLSettings
KSSLSettings(bool readConfig=true)
Construct a KSSL Settings object.
Definition: ksslsettings.cpp:98
kglobal.h
QList::count
int count(const T &value) const
KConfig::NoGlobals
KSSLSettings::setWarnOnUnencrypted
void setWarnOnUnencrypted(bool x)
Change the user's warnOnUnencrypted() setting.
Definition: ksslsettings.cpp:213
QString::isEmpty
bool isEmpty() const
KOSSL
#define KOSSL
Definition: kopenssl.h:25
KSSLSettings::defaults
void defaults()
Revert to default settings.
Definition: ksslsettings.cpp:156
KSSLSettings::load
void load()
Load the user's settings.
Definition: ksslsettings.cpp:125
QString
QList::contains
bool contains(const T &value) const
KSSLSettings::getEGDPath
QString & getEGDPath()
Get the configured path to the entropy gathering daemon or entropy file.
Definition: ksslsettings.cpp:221
KSSLSettings::~KSSLSettings
~KSSLSettings()
Destroy this KSSL Settings object.
Definition: ksslsettings.cpp:112
KConfigGroup
KConfig
kstandarddirs.h
QString::sprintf
QString & sprintf(const char *cformat,...)
KConfig::reparseConfiguration
void reparseConfiguration()
KSSLSettings::promptSendX509
bool promptSendX509() const
Does the user want to be prompted to send X.509 client certificates when possible?
Definition: ksslsettings.cpp:220
KSSLSettings::warnOnEnter
bool warnOnEnter() const
Does the user want to be warned on entering SSL mode.
Definition: ksslsettings.cpp:210
ksslsettings.h
kopenssl.h
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
operator==
int operator==(KSSLCertificate &x, KSSLCertificate &y)
Definition: ksslcertificate.cpp:1026
KSSLSettings::save
void save()
Save the current settings.
Definition: ksslsettings.cpp:170
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