File indexing completed on 2023-09-24 04:05:18
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 #include <kdelibs4support_export.h> 0026 0027 class QIODevice; 0028 class KSSLPrivate; 0029 class KSSLSession; 0030 0031 /** 0032 * KDE SSL Wrapper Class 0033 * 0034 * This class implements KDE's SSL support by wrapping OpenSSL. 0035 * 0036 * @author George Staikos <staikos@kde.org> 0037 * @see KExtendedSocket, TCPSlaveBase 0038 * @short KDE SSL Class 0039 */ 0040 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KSSL 0041 { 0042 public: 0043 /** 0044 * Construct a KSSL object 0045 * 0046 * @param init Set this to false if you do not want this class to 0047 * immediately initialize OpenSSL. 0048 */ 0049 KSSL(bool init = true); 0050 0051 /** 0052 * Destroy this KSSL object 0053 * 0054 * Does not close any socket. 0055 */ 0056 ~KSSL(); 0057 0058 /** 0059 * Determine if SSL is available and works. 0060 * 0061 * @return true is SSL is available and usable 0062 */ 0063 static bool doesSSLWork(); 0064 0065 /** 0066 * Initialize OpenSSL. 0067 * 0068 * @return true on success 0069 * 0070 * This will do nothing if it is already initialized. 0071 * @see reInitialize 0072 */ 0073 bool initialize(); 0074 0075 /** 0076 * This is used for applicationss which do STARTTLS or something 0077 * similar. It creates a TLS method regardless of the user's settings. 0078 * 0079 * @return true if TLS is successfully initialized 0080 */ 0081 bool TLSInit(); 0082 0083 /** 0084 * Set an SSL session to use. This deep copies the session so it 0085 * doesn't have to remain valid. You need to call it after calling 0086 * initialize or reInitialize. The ID is cleared in close(). 0087 * 0088 * @param session A valid session to reuse. If 0L, it will clear the 0089 * session ID in memory. 0090 * 0091 * @return true on success 0092 */ 0093 bool setSession(const KSSLSession *session); 0094 0095 /** 0096 * Close the SSL session. 0097 */ 0098 void close(); 0099 0100 /** 0101 * Reinitialize OpenSSL. 0102 * 0103 * @return true on success 0104 * 0105 * This is not generally needed unless you are reusing the KSSL object 0106 * for a new session. 0107 * @see initialize 0108 */ 0109 bool reInitialize(); 0110 0111 /** 0112 * Trigger a reread of KSSL configuration and reInitialize() KSSL. 0113 * 0114 * @return true on successful reinitalizations 0115 * 0116 * If you setAutoReconfig() to false, then this will simply 0117 * reInitialize() and not read in the new configuration. 0118 * @see setAutoReconfig 0119 */ 0120 bool reconfig(); 0121 0122 /** 0123 * Enable or disable automatic reconfiguration on initialize(). 0124 * 0125 * @param ar Set to false in order to disable auto-reloading of the 0126 * KSSL configuration during initialize(). 0127 * 0128 * By default, KSSL will read its configuration on initialize(). You 0129 * might want to disable this for performance reasons. 0130 */ 0131 void setAutoReconfig(bool ar); 0132 0133 /** 0134 * This will reseed the pseudo-random number generator with the EGD 0135 * (entropy gathering daemon) if the EGD is configured and enabled. 0136 * You don't need to call this yourself normally. 0137 * 0138 * @return 0 on success 0139 */ 0140 int seedWithEGD(); 0141 0142 /** 0143 * Set a new KSSLSettings instance as the settings. This deletes the 0144 * current instance of KSSLSettings. 0145 * 0146 * @param settings A new, valid settings object. 0147 * 0148 * @return true on success 0149 */ 0150 bool setSettings(KSSLSettings *settings); 0151 0152 /** 0153 * One is built by the constructor, so this will only return a NULL 0154 * pointer if you set one with setSettings(). 0155 * 0156 * @return the current settings instance 0157 */ 0158 KSSLSettings *settings(); 0159 0160 private: 0161 static bool m_bSSLWorks; 0162 bool m_bInit; 0163 bool m_bAutoReconfig; 0164 KSSLSettings *m_cfg; 0165 0166 KSSLPrivate *d; 0167 }; 0168 0169 #endif 0170