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

KIO

  • 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
58class KSSLPrivate {
59public:
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
77KSSL::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
91KSSL::~KSSL() {
92 close();
93 delete m_cfg;
94 delete d;
95}
96
97
98int KSSL::seedWithEGD() {
99int 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
115return rc;
116}
117
118
119bool 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;
143return true;
144#else
145return false;
146#endif
147}
148
149
150void 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
172bool KSSL::reInitialize() {
173 close();
174return initialize();
175}
176
177// get the callback file - it's hidden away in here
178//#include "ksslcallback.c"
179
180
181bool KSSL::reconfig() {
182 return reInitialize();
183}
184
185
186void KSSL::setAutoReconfig(bool ar) {
187 m_bAutoReconfig = ar;
188}
189
190
191bool KSSL::setSettings(KSSLSettings *settings) {
192 delete m_cfg;
193 m_cfg = settings;
194 return reconfig();
195}
196
197KSSLSettings * KSSL::settings()
198{
199 return m_cfg;
200}
201
202
203#ifdef KSSL_HAVE_SSL
204bool KSSL::m_bSSLWorks = true;
205#else
206bool KSSL::m_bSSLWorks = false;
207#endif
208
209bool KSSL::doesSSLWork() {
210 return m_bSSLWorks;
211}
212
KOpenSSLProxy::self
static KOpenSSLProxy * self()
Return an instance of class KOpenSSLProxy * You cannot delete this object.
Definition: kopenssl.cpp:722
KSSLCertificate::KSSLValidation
KSSLValidation
Result of the validate() call.
Definition: ksslcertificate.h:119
KSSLSettings
KDE SSL Settings.
Definition: ksslsettings.h:41
KSSLSettings::getCipherList
QString getCipherList()
Get the OpenSSL cipher list for selecting the list of ciphers to use in a connection.
Definition: ksslsettings.cpp:118
KSSLSettings::load
void load()
Load the user's settings.
Definition: ksslsettings.cpp:125
KSSLSettings::useEFile
bool useEFile() const
Does the user want to use an entropy file?
Definition: ksslsettings.cpp:218
KSSLSettings::useEGD
bool useEGD() const
Does the user want to use the Entropy Gathering Daemon?
Definition: ksslsettings.cpp:217
KSSLSettings::getEGDPath
QString & getEGDPath()
Get the configured path to the entropy gathering daemon or entropy file.
Definition: ksslsettings.cpp:221
KSSL::setAutoReconfig
void setAutoReconfig(bool ar)
Enable or disable automatic reconfiguration on initialize().
Definition: kssl.cpp:186
KSSL::reconfig
bool reconfig()
Trigger a reread of KSSL configuration and reInitialize() KSSL.
Definition: kssl.cpp:181
KSSL::setSettings
bool setSettings(KSSLSettings *settings)
Set a new KSSLSettings instance as the settings.
Definition: kssl.cpp:191
KSSL::doesSSLWork
static bool doesSSLWork()
Determine if SSL is available and works.
Definition: kssl.cpp:209
KSSL::close
void close()
Close the SSL session.
Definition: kssl.cpp:150
KSSL::reInitialize
bool reInitialize()
Reinitialize OpenSSL.
Definition: kssl.cpp:172
KSSL::KSSL
KSSL(bool init=true)
Construct a KSSL object.
Definition: kssl.cpp:77
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::seedWithEGD
int seedWithEGD()
This will reseed the pseudo-random number generator with the EGD (entropy gathering daemon) if the EG...
Definition: kssl.cpp:98
KSSL::~KSSL
~KSSL()
Destroy this KSSL object.
Definition: kssl.cpp:91
KSSL::initialize
bool initialize()
Initialize OpenSSL.
Definition: kssl.cpp:119
kDebug
#define kDebug
k3clientsocketbase.h
k3socketdevice.h
kdebug.h
klocale.h
kopenssl.h
KOSSL
#define KOSSL
Definition: kopenssl.h:25
kssl.h
ksslcertificate.h
ksslx509v3.h
kstandarddirs.h
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