• 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
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 class KSSLPrivate {
59 public:
60  KSSLPrivate() {
61  kossl = KOpenSSLProxy::self();
62  }
63 
64  ~KSSLPrivate() {}
65 
66  KSSLCertificate::KSSLValidation m_cert_vfy_res;
67 
68 #ifdef KSSL_HAVE_SSL
69  SSL *m_ssl;
70  SSL_CTX *m_ctx;
71  SSL_METHOD *m_meth;
72 #endif
73  KOSSL *kossl;
74 };
75 
76 
77 KSSL::KSSL(bool init) {
78  d = new KSSLPrivate;
79  m_bInit = false;
80  m_bAutoReconfig = true;
81  m_cfg = new KSSLSettings();
82 #ifdef KSSL_HAVE_SSL
83  d->m_ssl = 0L;
84 #endif
85 
86  if (init)
87  initialize();
88 }
89 
90 
91 KSSL::~KSSL() {
92  close();
93  delete m_cfg;
94  delete d;
95 }
96 
97 
98 int KSSL::seedWithEGD() {
99 int rc = 0;
100 #ifdef KSSL_HAVE_SSL
101  if (m_cfg->useEGD() && !m_cfg->getEGDPath().isEmpty()) {
102  rc = d->kossl->RAND_egd(m_cfg->getEGDPath().toLatin1().constData());
103  if (rc < 0)
104  kDebug(7029) << "KSSL: Error seeding PRNG with the EGD.";
105  else kDebug(7029) << "KSSL: PRNG was seeded with " << rc
106  << " bytes from the EGD." << endl;
107  } else if (m_cfg->useEFile() && !m_cfg->getEGDPath().isEmpty()) {
108  rc = d->kossl->RAND_load_file(m_cfg->getEGDPath().toLatin1().constData(), -1);
109  if (rc < 0)
110  kDebug(7029) << "KSSL: Error seeding PRNG with the entropy file.";
111  else kDebug(7029) << "KSSL: PRNG was seeded with " << rc
112  << " bytes from the entropy file." << endl;
113  }
114 #endif
115 return rc;
116 }
117 
118 
119 bool KSSL::initialize() {
120 #ifdef KSSL_HAVE_SSL
121  kDebug(7029) << "KSSL initialize";
122  if (m_bInit)
123  return false;
124 
125  if (m_bAutoReconfig)
126  m_cfg->load();
127 
128  seedWithEGD();
129 
130  d->m_meth = d->kossl->SSLv23_client_method();
131  d->m_ctx = d->kossl->SSL_CTX_new(d->m_meth);
132  if (d->m_ctx == 0L) {
133  return false;
134  }
135 
136  // set cipher list
137  QString clist = m_cfg->getCipherList();
138  kDebug(7029) << "Cipher list: " << clist;
139  if (!clist.isEmpty())
140  d->kossl->SSL_CTX_set_cipher_list(d->m_ctx, const_cast<char *>(clist.toLatin1().constData()));
141 
142  m_bInit = true;
143 return true;
144 #else
145 return false;
146 #endif
147 }
148 
149 
150 void KSSL::close() {
151 #ifdef KSSL_HAVE_SSL
152 //kDebug(7029) << "KSSL close";
153  if (!m_bInit)
154  return;
155 
156  if (d->m_ssl) {
157  d->kossl->SSL_shutdown(d->m_ssl);
158  d->kossl->SSL_free(d->m_ssl);
159  d->m_ssl = 0L;
160  }
161 
162  d->kossl->SSL_CTX_free(d->m_ctx);
163  if (m_cfg->useEFile() && !m_cfg->getEGDPath().isEmpty()) {
164  d->kossl->RAND_write_file(m_cfg->getEGDPath().toLatin1().constData());
165  }
166 
167  m_bInit = false;
168 #endif
169 }
170 
171 
172 bool KSSL::reInitialize() {
173  close();
174 return initialize();
175 }
176 
177 // get the callback file - it's hidden away in here
178 //#include "ksslcallback.c"
179 
180 
181 bool KSSL::reconfig() {
182  return reInitialize();
183 }
184 
185 
186 void KSSL::setAutoReconfig(bool ar) {
187  m_bAutoReconfig = ar;
188 }
189 
190 
191 bool KSSL::setSettings(KSSLSettings *settings) {
192  delete m_cfg;
193  m_cfg = settings;
194  return reconfig();
195 }
196 
197 KSSLSettings * KSSL::settings()
198 {
199  return m_cfg;
200 }
201 
202 
203 #ifdef KSSL_HAVE_SSL
204 bool KSSL::m_bSSLWorks = true;
205 #else
206 bool KSSL::m_bSSLWorks = false;
207 #endif
208 
209 bool KSSL::doesSSLWork() {
210  return m_bSSLWorks;
211 }
212 
KSSL::reconfig
bool reconfig()
Trigger a reread of KSSL configuration and reInitialize() KSSL.
Definition: kssl.cpp:181
KSSL::seedWithEGD
int seedWithEGD()
This will reseed the pseudo-random number generator with the EGD (entropy gathering daemon) if the EG...
Definition: kssl.cpp:98
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:119
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:197
KSSL::KSSL
KSSL(bool init=true)
Construct a KSSL object.
Definition: kssl.cpp:77
KSSL::~KSSL
~KSSL()
Destroy this KSSL object.
Definition: kssl.cpp:91
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
QString::isEmpty
bool isEmpty() const
KOSSL
#define KOSSL
Definition: kopenssl.h:25
QByteArray::constData
const char * constData() const
KSSLSettings::load
void load()
Load the user's settings.
Definition: ksslsettings.cpp:125
QString
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
QString::toLatin1
QByteArray toLatin1() const
kstandarddirs.h
KSSL::doesSSLWork
static bool doesSSLWork()
Determine if SSL is available and works.
Definition: kssl.cpp:209
KSSL::setAutoReconfig
void setAutoReconfig(bool ar)
Enable or disable automatic reconfiguration on initialize().
Definition: kssl.cpp:186
kopenssl.h
KSSL::setSettings
bool setSettings(KSSLSettings *settings)
Set a new KSSLSettings instance as the settings.
Definition: kssl.cpp:191
KSSL::close
void close()
Close the SSL session.
Definition: kssl.cpp:150
KOpenSSLProxy::self
static KOpenSSLProxy * self()
Return an instance of class KOpenSSLProxy * You cannot delete this object.
Definition: kopenssl.cpp:722
KSSL::reInitialize
bool reInitialize()
Reinitialize OpenSSL.
Definition: kssl.cpp:172
kssl.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