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

KIO

  • sources
  • kde-4.12
  • kdelibs
  • kio
  • kssl
kssl.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2000-2003 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 "kssl.h"
22 
23 #include <config.h>
24 #include <ksslconfig.h>
25 
26 // this hack provided by Malte Starostik to avoid glibc/openssl bug
27 // on some systems
28 #ifdef KSSL_HAVE_SSL
29 #include <unistd.h>
30 #include <netinet/in.h>
31 #include <sys/socket.h>
32 #define crypt _openssl_crypt
33 #include <openssl/ssl.h>
34 #include <openssl/x509.h>
35 #include <openssl/x509v3.h>
36 #include <openssl/pem.h>
37 #include <openssl/rand.h>
38 #undef crypt
39 #endif
40 
41 #include <kdebug.h>
42 #include <kstandarddirs.h>
43 
44 #include <kopenssl.h>
45 #include <ksslx509v3.h>
46 #include <ksslcertificate.h>
47 #include <klocale.h>
48 
49 #include <QtNetwork/QAbstractSocket>
50 #include <k3clientsocketbase.h>
51 #include <k3socketdevice.h>
52 
53 #ifdef __GNUC__
54 #warning "kssl.cc contains temporary functions! Clean up"
55 #warning "kssl.cc needs to be ported to QSslSocket"
56 #endif
57 
58 #define sk_dup d->kossl->sk_dup
59 
60 class KSSLPrivate {
61 public:
62  KSSLPrivate() {
63  kossl = KOpenSSLProxy::self();
64  }
65 
66  ~KSSLPrivate() {}
67 
68  KSSLCertificate::KSSLValidation m_cert_vfy_res;
69 
70 #ifdef KSSL_HAVE_SSL
71  SSL *m_ssl;
72  SSL_CTX *m_ctx;
73  SSL_METHOD *m_meth;
74 #endif
75  KOSSL *kossl;
76 };
77 
78 
79 KSSL::KSSL(bool init) {
80  d = new KSSLPrivate;
81  m_bInit = false;
82  m_bAutoReconfig = true;
83  m_cfg = new KSSLSettings();
84 #ifdef KSSL_HAVE_SSL
85  d->m_ssl = 0L;
86 #endif
87 
88  if (init)
89  initialize();
90 }
91 
92 
93 KSSL::~KSSL() {
94  close();
95  delete m_cfg;
96  delete d;
97 }
98 
99 
100 int KSSL::seedWithEGD() {
101 int rc = 0;
102 #ifdef KSSL_HAVE_SSL
103  if (m_cfg->useEGD() && !m_cfg->getEGDPath().isEmpty()) {
104  rc = d->kossl->RAND_egd(m_cfg->getEGDPath().toLatin1().constData());
105  if (rc < 0)
106  kDebug(7029) << "KSSL: Error seeding PRNG with the EGD.";
107  else kDebug(7029) << "KSSL: PRNG was seeded with " << rc
108  << " bytes from the EGD." << endl;
109  } else if (m_cfg->useEFile() && !m_cfg->getEGDPath().isEmpty()) {
110  rc = d->kossl->RAND_load_file(m_cfg->getEGDPath().toLatin1().constData(), -1);
111  if (rc < 0)
112  kDebug(7029) << "KSSL: Error seeding PRNG with the entropy file.";
113  else kDebug(7029) << "KSSL: PRNG was seeded with " << rc
114  << " bytes from the entropy file." << endl;
115  }
116 #endif
117 return rc;
118 }
119 
120 
121 bool KSSL::initialize() {
122 #ifdef KSSL_HAVE_SSL
123  kDebug(7029) << "KSSL initialize";
124  if (m_bInit)
125  return false;
126 
127  if (m_bAutoReconfig)
128  m_cfg->load();
129 
130  seedWithEGD();
131 
132  d->m_meth = d->kossl->SSLv23_client_method();
133  d->m_ctx = d->kossl->SSL_CTX_new(d->m_meth);
134  if (d->m_ctx == 0L) {
135  return false;
136  }
137 
138  // set cipher list
139  QString clist = m_cfg->getCipherList();
140  kDebug(7029) << "Cipher list: " << clist;
141  if (!clist.isEmpty())
142  d->kossl->SSL_CTX_set_cipher_list(d->m_ctx, const_cast<char *>(clist.toLatin1().constData()));
143 
144  m_bInit = true;
145 return true;
146 #else
147 return false;
148 #endif
149 }
150 
151 
152 void KSSL::close() {
153 #ifdef KSSL_HAVE_SSL
154 //kDebug(7029) << "KSSL close";
155  if (!m_bInit)
156  return;
157 
158  if (d->m_ssl) {
159  d->kossl->SSL_shutdown(d->m_ssl);
160  d->kossl->SSL_free(d->m_ssl);
161  d->m_ssl = 0L;
162  }
163 
164  d->kossl->SSL_CTX_free(d->m_ctx);
165  if (m_cfg->useEFile() && !m_cfg->getEGDPath().isEmpty()) {
166  d->kossl->RAND_write_file(m_cfg->getEGDPath().toLatin1().constData());
167  }
168 
169  m_bInit = false;
170 #endif
171 }
172 
173 
174 bool KSSL::reInitialize() {
175  close();
176 return initialize();
177 }
178 
179 // get the callback file - it's hidden away in here
180 //#include "ksslcallback.c"
181 
182 
183 bool KSSL::reconfig() {
184  return reInitialize();
185 }
186 
187 
188 void KSSL::setAutoReconfig(bool ar) {
189  m_bAutoReconfig = ar;
190 }
191 
192 
193 bool KSSL::setSettings(KSSLSettings *settings) {
194  delete m_cfg;
195  m_cfg = settings;
196  return reconfig();
197 }
198 
199 KSSLSettings * KSSL::settings()
200 {
201  return m_cfg;
202 }
203 
204 
205 #ifdef KSSL_HAVE_SSL
206 bool KSSL::m_bSSLWorks = true;
207 #else
208 bool KSSL::m_bSSLWorks = false;
209 #endif
210 
211 bool KSSL::doesSSLWork() {
212  return m_bSSLWorks;
213 }
214 
215 #undef sk_dup
216 
KSSL::reconfig
bool reconfig()
Trigger a reread of KSSL configuration and reInitialize() KSSL.
Definition: kssl.cpp:183
KSSL::seedWithEGD
int seedWithEGD()
This will reseed the pseudo-random number generator with the EGD (entropy gathering daemon) if the EG...
Definition: kssl.cpp:100
k3socketdevice.h
KSSLSettings::useEFile
bool useEFile() const
Does the user want to use an entropy file?
Definition: ksslsettings.cpp:218
kdebug.h
k3clientsocketbase.h
KSSL::initialize
bool initialize()
Initialize OpenSSL.
Definition: kssl.cpp:121
ksslcertificate.h
KSSLSettings::getCipherList
QString getCipherList()
Get the OpenSSL cipher list for selecting the list of ciphers to use in a connection.
Definition: ksslsettings.cpp:118
KSSL::settings
KSSLSettings * settings()
One is built by the constructor, so this will only return a NULL pointer if you set one with setSetti...
Definition: kssl.cpp:199
KSSL::KSSL
KSSL(bool init=true)
Construct a KSSL object.
Definition: kssl.cpp:79
QString
KSSL::~KSSL
~KSSL()
Destroy this KSSL object.
Definition: kssl.cpp:93
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
klocale.h
KSSLSettings::useEGD
bool useEGD() const
Does the user want to use the Entropy Gathering Daemon?
Definition: ksslsettings.cpp:217
ksslx509v3.h
KSSLCertificate::KSSLValidation
KSSLValidation
Result of the validate() call.
Definition: ksslcertificate.h:119
KOSSL
#define KOSSL
Definition: kopenssl.h:25
KSSLSettings::load
void load()
Load the user's settings.
Definition: ksslsettings.cpp:125
KSSLSettings
KDE SSL Settings.
Definition: ksslsettings.h:41
KSSLSettings::getEGDPath
QString & getEGDPath()
Get the configured path to the entropy gathering daemon or entropy file.
Definition: ksslsettings.cpp:221
kstandarddirs.h
KSSL::doesSSLWork
static bool doesSSLWork()
Determine if SSL is available and works.
Definition: kssl.cpp:211
KSSL::setAutoReconfig
void setAutoReconfig(bool ar)
Enable or disable automatic reconfiguration on initialize().
Definition: kssl.cpp:188
kopenssl.h
KSSL::setSettings
bool setSettings(KSSLSettings *settings)
Set a new KSSLSettings instance as the settings.
Definition: kssl.cpp:193
KSSL::close
void close()
Close the SSL session.
Definition: kssl.cpp:152
KOpenSSLProxy::self
static KOpenSSLProxy * self()
Return an instance of class KOpenSSLProxy * You cannot delete this object.
Definition: kopenssl.cpp:678
KSSL::reInitialize
bool reInitialize()
Reinitialize OpenSSL.
Definition: kssl.cpp:174
kssl.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:02 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • 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