File indexing completed on 2023-09-24 08:55:08

0001 /* This file is part of the KDE project
0002  *
0003  * Copyright (C) 2000-2005 George Staikos <staikos@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #ifndef _KSSL_H
0022 #define _KSSL_H
0023 
0024 #include <ksslsettings.h>
0025 
0026 class QIODevice;
0027 class KSSLPrivate;
0028 class KSSLSession;
0029 
0030 /**
0031  * KDE SSL Wrapper Class
0032  *
0033  * This class implements KDE's SSL support by wrapping OpenSSL.
0034  *
0035  * @author George Staikos <staikos@kde.org>
0036  * @see KExtendedSocket, TCPSlaveBase
0037  * @short KDE SSL Class
0038  */
0039 class KIO_EXPORT KSSL {
0040 public:
0041     /**
0042      *  Construct a KSSL object
0043      *
0044      *  @param init Set this to false if you do not want this class to
0045      *         immediately initialize OpenSSL.
0046      */
0047     KSSL(bool init = true);
0048 
0049     /**
0050      *  Destroy this KSSL object
0051      *
0052      *  Does not close any socket.
0053      */
0054     ~KSSL();
0055 
0056     /**
0057      *  Determine if SSL is available and works.
0058      *
0059      *  @return true is SSL is available and usable
0060      */
0061     static bool doesSSLWork();
0062 
0063     /**
0064      *  Initialize OpenSSL.
0065      *
0066      *  @return true on success
0067      *
0068      *  This will do nothing if it is already initialized.
0069      *  @see reInitialize
0070      */
0071     bool initialize();
0072 
0073     /**
0074      *  This is used for applicationss which do STARTTLS or something
0075      *  similar. It creates a TLS method regardless of the user's settings.
0076      *
0077      *  @return true if TLS is successfully initialized
0078      */
0079     bool TLSInit();
0080 
0081     /**
0082      *  Set an SSL session to use.  This deep copies the session so it
0083      *  doesn't have to remain valid.  You need to call it after calling
0084      *  initialize or reInitialize.  The ID is cleared in close().
0085      *
0086      *  @param session A valid session to reuse.  If 0L, it will clear the
0087      *                 session ID in memory.
0088      *
0089      *  @return true on success
0090      */
0091     bool setSession(const KSSLSession *session);
0092 
0093     /**
0094      *  Close the SSL session.
0095      */
0096     void close();
0097 
0098     /**
0099      *  Reinitialize OpenSSL.
0100      *
0101      *  @return true on success
0102      *
0103      *  This is not generally needed unless you are reusing the KSSL object
0104      *  for a new session.
0105      *  @see initialize
0106      */
0107     bool reInitialize();
0108 
0109     /**
0110      *  Trigger a reread of KSSL configuration and reInitialize() KSSL.
0111      *
0112      *  @return true on successful reinitalizations
0113      *
0114      *  If you setAutoReconfig() to false, then this will simply
0115      * reInitialize() and not read in the new configuration.
0116      *  @see setAutoReconfig
0117      */
0118     bool reconfig();
0119 
0120     /**
0121      *  Enable or disable automatic reconfiguration on initialize().
0122      *
0123      *  @param ar Set to false in order to disable auto-reloading of the
0124      *         KSSL configuration during initialize().
0125      *
0126      *  By default, KSSL will read its configuration on initialize().  You
0127      *  might want to disable this for performance reasons.
0128      */
0129     void setAutoReconfig(bool ar);
0130 
0131     /**
0132      *  This will reseed the pseudo-random number generator with the EGD
0133      *  (entropy gathering daemon) if the EGD is configured and enabled.
0134      *  You don't need to call this yourself normally.
0135      *
0136      *  @return 0 on success
0137      */
0138     int seedWithEGD();
0139 
0140     /**
0141      *  Set a new KSSLSettings instance as the settings. This deletes the
0142      *  current instance of KSSLSettings.
0143      *
0144      *  @param settings A new, valid settings object.
0145      *
0146      *  @return true on success
0147      */
0148     bool setSettings(KSSLSettings *settings);
0149 
0150     /**
0151      *  One is built by the constructor, so this will only return a NULL
0152      *  pointer if you set one with setSettings().
0153      *
0154      *  @return the current settings instance
0155      */
0156     KSSLSettings * settings();
0157 
0158 private:
0159     static bool m_bSSLWorks;
0160     bool m_bInit;
0161     bool m_bAutoReconfig;
0162     KSSLSettings *m_cfg;
0163 
0164     KSSLPrivate *d;
0165 };
0166 
0167 
0168 #endif
0169