KHtml

kopenssl.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2001-2003 George Staikos <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "kopenssl.h"
20 
21 
22 #if KSSL_HAVE_SSL
23 #include <openssl/opensslv.h>
24 #endif
25 
26 #include <kconfig.h>
27 #include <kconfiggroup.h>
28 #include <QCoreApplication>
29 #include <QFile>
30 #include <QLibrary>
31 #include <QRegExp>
32 
33 extern "C" {
34 #if KSSL_HAVE_SSL
35  static int (*K_SSL_connect)(SSL *) = nullptr;
36  static int (*K_SSL_accept)(SSL *) = nullptr;
37  static int (*K_SSL_read)(SSL *, void *, int) = nullptr;
38  static int (*K_SSL_write)(SSL *, const void *, int) = nullptr;
39  static SSL *(*K_SSL_new)(SSL_CTX *) = nullptr;
40  static void (*K_SSL_free)(SSL *) = nullptr;
41  static int (*K_SSL_shutdown)(SSL *) = nullptr;
42  static SSL_CTX *(*K_SSL_CTX_new)(SSL_METHOD *) = nullptr;
43  static void (*K_SSL_CTX_free)(SSL_CTX *) = nullptr;
44  static int (*K_SSL_set_fd)(SSL *, int) = nullptr;
45  static int (*K_SSL_pending)(SSL *) = nullptr;
46  static int (*K_SSL_peek)(SSL *, void *, int) = nullptr;
47  static int (*K_SSL_CTX_set_cipher_list)(SSL_CTX *, const char *) = nullptr;
48  static void (*K_SSL_CTX_set_verify)(SSL_CTX *, int,
49  int (*)(int, X509_STORE_CTX *)) = nullptr;
50  static int (*K_SSL_use_certificate)(SSL *, X509 *) = nullptr;
51  static SSL_CIPHER *(*K_SSL_get_current_cipher)(SSL *) = nullptr;
52  static long(*K_SSL_ctrl)(SSL *, int, long, char *) = nullptr;
53  static int (*K_RAND_egd)(const char *) = nullptr;
54  static const char *(*K_RAND_file_name)(char *, size_t) = nullptr;
55  static int (*K_RAND_load_file)(const char *, long) = nullptr;
56  static int (*K_RAND_write_file)(const char *) = nullptr;
57  static SSL_METHOD *(*K_TLSv1_client_method)() = nullptr;
58  static SSL_METHOD *(*K_SSLv23_client_method)() = nullptr;
59  static X509 *(*K_SSL_get_peer_certificate)(SSL *) = nullptr;
60  static int (*K_SSL_CIPHER_get_bits)(SSL_CIPHER *, int *) = nullptr;
61  static char *(*K_SSL_CIPHER_get_version)(SSL_CIPHER *) = nullptr;
62  static const char *(*K_SSL_CIPHER_get_name)(SSL_CIPHER *) = nullptr;
63  static char *(*K_SSL_CIPHER_description)(SSL_CIPHER *, char *, int) = nullptr;
64  static X509 *(*K_d2i_X509)(X509 **, unsigned char **, long) = nullptr;
65  static int (*K_i2d_X509)(X509 *, unsigned char **) = nullptr;
66  static int (*K_X509_cmp)(X509 *, X509 *) = nullptr;
67  static void (*K_X509_STORE_CTX_free)(X509_STORE_CTX *) = nullptr;
68  static int (*K_X509_verify_cert)(X509_STORE_CTX *) = nullptr;
69  static X509_STORE_CTX *(*K_X509_STORE_CTX_new)(void) = nullptr;
70  static void (*K_X509_STORE_free)(X509_STORE *) = nullptr;
71  static X509_STORE *(*K_X509_STORE_new)(void) = nullptr;
72  static void (*K_X509_free)(X509 *) = nullptr;
73  static char *(*K_X509_NAME_oneline)(X509_NAME *, char *, int) = nullptr;
74  static X509_NAME *(*K_X509_get_subject_name)(X509 *) = nullptr;
75  static X509_NAME *(*K_X509_get_issuer_name)(X509 *) = nullptr;
76  static X509_LOOKUP *(*K_X509_STORE_add_lookup)(X509_STORE *, X509_LOOKUP_METHOD *) = nullptr;
77  static X509_LOOKUP_METHOD *(*K_X509_LOOKUP_file)(void) = nullptr;
78  static void (*K_X509_LOOKUP_free)(X509_LOOKUP *) = nullptr;
79  static int (*K_X509_LOOKUP_ctrl)(X509_LOOKUP *, int, const char *, long, char **) = nullptr;
80  static void (*K_X509_STORE_CTX_init)(X509_STORE_CTX *, X509_STORE *, X509 *, STACK_OF(X509) *) = nullptr;
81  static void (*K_CRYPTO_free)(void *) = nullptr;
82  static X509 *(*K_X509_dup)(X509 *) = nullptr;
83  static BIO_METHOD *(*K_BIO_s_mem)(void) = nullptr;
84  static BIO *(*K_BIO_new)(BIO_METHOD *) = nullptr;
85  static BIO *(*K_BIO_new_fp)(FILE *, int) = nullptr;
86  static BIO *(*K_BIO_new_mem_buf)(void *, int) = nullptr;
87  static int (*K_BIO_free)(BIO *) = nullptr;
88  static long(*K_BIO_ctrl)(BIO *, int, long, void *) = nullptr;
89  static int (*K_BIO_write)(BIO *b, const void *data, int len) = nullptr;
90  static int (*K_PEM_ASN1_write_bio)(int (*)(), const char *, BIO *, char *,
91  const EVP_CIPHER *, unsigned char *, int,
92  pem_password_cb *, void *) = nullptr;
93  static int (*K_ASN1_item_i2d_fp)(ASN1_ITEM *, FILE *, unsigned char *) = nullptr;
94  static ASN1_ITEM *K_NETSCAPE_X509_it = nullptr;
95  static int (*K_X509_print_fp)(FILE *, X509 *) = nullptr;
96  static int (*K_i2d_PKCS12)(PKCS12 *, unsigned char **) = nullptr;
97  static int (*K_i2d_PKCS12_fp)(FILE *, PKCS12 *) = nullptr;
98  static int (*K_PKCS12_newpass)(PKCS12 *, char *, char *) = nullptr;
99  static PKCS12 *(*K_d2i_PKCS12_fp)(FILE *, PKCS12 **) = nullptr;
100  static PKCS12 *(*K_PKCS12_new)(void) = nullptr;
101  static void (*K_PKCS12_free)(PKCS12 *) = nullptr;
102  static int (*K_PKCS12_parse)(PKCS12 *, const char *, EVP_PKEY **,
103  X509 **, STACK_OF(X509) **) = nullptr;
104  static void (*K_EVP_PKEY_free)(EVP_PKEY *) = nullptr;
105  static EVP_PKEY *(*K_EVP_PKEY_new)() = nullptr;
106  static void (*K_X509_REQ_free)(X509_REQ *) = nullptr;
107  static X509_REQ *(*K_X509_REQ_new)() = nullptr;
108  static int (*K_SSL_CTX_use_PrivateKey)(SSL_CTX *, EVP_PKEY *) = nullptr;
109  static int (*K_SSL_CTX_use_certificate)(SSL_CTX *, X509 *) = nullptr;
110  static int (*K_SSL_get_error)(SSL *, int) = nullptr;
111  static STACK_OF(X509) *(*K_SSL_get_peer_cert_chain)(SSL *) = nullptr;
112  static void (*K_X509_STORE_CTX_set_chain)(X509_STORE_CTX *, STACK_OF(X509) *) = nullptr;
113  static void (*K_X509_STORE_CTX_set_purpose)(X509_STORE_CTX *, int) = nullptr;
114  static void (*K_sk_free)(STACK *) = nullptr;
115  static int (*K_sk_num)(STACK *) = nullptr;
116  static char *(*K_sk_pop)(STACK *) = nullptr;
117  static char *(*K_sk_value)(STACK *, int) = nullptr;
118  static STACK *(*K_sk_new)(int (*)()) = nullptr;
119  static int (*K_sk_push)(STACK *, char *) = nullptr;
120  static STACK *(*K_sk_dup)(STACK *) = nullptr;
121  static char *(*K_i2s_ASN1_INTEGER)(X509V3_EXT_METHOD *, ASN1_INTEGER *) = nullptr;
122  static ASN1_INTEGER *(*K_X509_get_serialNumber)(X509 *) = nullptr;
123  static EVP_PKEY *(*K_X509_get_pubkey)(X509 *) = nullptr;
124  static int (*K_i2d_PublicKey)(EVP_PKEY *, unsigned char **) = nullptr;
125  static int (*K_X509_check_private_key)(X509 *, EVP_PKEY *) = nullptr;
126  static char *(*K_BN_bn2hex)(const BIGNUM *) = nullptr;
127  static int (*K_X509_digest)(const X509 *, const EVP_MD *, unsigned char *, unsigned int *) = nullptr;
128  static EVP_MD *(*K_EVP_md5)() = nullptr;
129  static void (*K_ASN1_INTEGER_free)(ASN1_INTEGER *) = nullptr;
130  static int (*K_OBJ_obj2nid)(ASN1_OBJECT *) = nullptr;
131  static const char *(*K_OBJ_nid2ln)(int) = nullptr;
132  static int (*K_X509_get_ext_count)(X509 *) = nullptr;
133  static int (*K_X509_get_ext_by_NID)(X509 *, int, int) = nullptr;
134  static int (*K_X509_get_ext_by_OBJ)(X509 *, ASN1_OBJECT *, int) = nullptr;
135  static X509_EXTENSION *(*K_X509_get_ext)(X509 *, int loc) = nullptr;
136  static X509_EXTENSION *(*K_X509_delete_ext)(X509 *, int) = nullptr;
137  static int (*K_X509_add_ext)(X509 *, X509_EXTENSION *, int) = nullptr;
138  static void *(*K_X509_get_ext_d2i)(X509 *, int, int *, int *) = nullptr;
139  static char *(*K_i2s_ASN1_OCTET_STRING)(X509V3_EXT_METHOD *, ASN1_OCTET_STRING *) = nullptr;
140  static int (*K_ASN1_BIT_STRING_get_bit)(ASN1_BIT_STRING *, int) = nullptr;
141  static PKCS7 *(*K_PKCS7_new)() = nullptr;
142  static void (*K_PKCS7_free)(PKCS7 *) = nullptr;
143  static void (*K_PKCS7_content_free)(PKCS7 *) = nullptr;
144  static int (*K_i2d_PKCS7)(PKCS7 *, unsigned char **) = nullptr;
145  static PKCS7 *(*K_d2i_PKCS7)(PKCS7 **, unsigned char **, long) = nullptr;
146  static int (*K_i2d_PKCS7_fp)(FILE *, PKCS7 *) = nullptr;
147  static PKCS7 *(*K_d2i_PKCS7_fp)(FILE *, PKCS7 **) = nullptr;
148  static int (*K_i2d_PKCS7_bio)(BIO *bp, PKCS7 *p7) = nullptr;
149  static PKCS7 *(*K_d2i_PKCS7_bio)(BIO *bp, PKCS7 **p7) = nullptr;
150  static PKCS7 *(*K_PKCS7_dup)(PKCS7 *) = nullptr;
151  static STACK_OF(X509_NAME) *(*K_SSL_load_client_CA_file)(const char *) = nullptr;
152  static STACK_OF(X509_INFO) *(*K_PEM_X509_INFO_read)(FILE *, STACK_OF(X509_INFO) *, pem_password_cb *, void *) = nullptr;
153  static char *(*K_ASN1_d2i_fp)(char *(*)(), char *(*)(), FILE *, unsigned char **) = nullptr;
154  static X509 *(*K_X509_new)() = nullptr;
155  static int (*K_X509_PURPOSE_get_count)() = nullptr;
156  static int (*K_X509_PURPOSE_get_id)(X509_PURPOSE *) = nullptr;
157  static int (*K_X509_check_purpose)(X509 *, int, int) = nullptr;
158  static X509_PURPOSE *(*K_X509_PURPOSE_get0)(int) = nullptr;
159  static int (*K_EVP_PKEY_assign)(EVP_PKEY *, int, char *) = nullptr;
160  static int (*K_X509_REQ_set_pubkey)(X509_REQ *, EVP_PKEY *) = nullptr;
161  static RSA *(*K_RSA_generate_key)(int, unsigned long, void (*)(int, int, void *), void *) = nullptr;
162  static int (*K_i2d_X509_REQ_fp)(FILE *, X509_REQ *) = nullptr;
163  static void (*K_ERR_clear_error)() = nullptr;
164  static unsigned long(*K_ERR_get_error)() = nullptr;
165  static void (*K_ERR_print_errors_fp)(FILE *) = nullptr;
166  static PKCS7 *(*K_PKCS7_sign)(X509 *, EVP_PKEY *, STACK_OF(X509) *, BIO *, int) = nullptr;
167  static int (*K_PKCS7_verify)(PKCS7 *, STACK_OF(X509) *, X509_STORE *, BIO *, BIO *, int) = nullptr;
168  static STACK_OF(X509) *(*K_PKCS7_get0_signers)(PKCS7 *, STACK_OF(X509) *, int) = nullptr;
169  static PKCS7 *(*K_PKCS7_encrypt)(STACK_OF(X509) *, BIO *, EVP_CIPHER *, int) = nullptr;
170  static int (*K_PKCS7_decrypt)(PKCS7 *, EVP_PKEY *, X509 *, BIO *, int) = nullptr;
171  static SSL_SESSION *(*K_SSL_get1_session)(SSL *) = nullptr;
172  static void (*K_SSL_SESSION_free)(SSL_SESSION *) = nullptr;
173  static int (*K_SSL_set_session)(SSL *, SSL_SESSION *) = nullptr;
174  static SSL_SESSION *(*K_d2i_SSL_SESSION)(SSL_SESSION **, unsigned char **, long) = nullptr;
175  static int (*K_i2d_SSL_SESSION)(SSL_SESSION *, unsigned char **) = nullptr;
176  static STACK *(*K_X509_get1_email)(X509 *x) = nullptr;
177  static void (*K_X509_email_free)(STACK *sk) = nullptr;
178  static EVP_CIPHER *(*K_EVP_des_ede3_cbc)() = nullptr;
179  static EVP_CIPHER *(*K_EVP_des_cbc)() = nullptr;
180  static EVP_CIPHER *(*K_EVP_rc2_cbc)() = nullptr;
181  static EVP_CIPHER *(*K_EVP_rc2_64_cbc)() = nullptr;
182  static EVP_CIPHER *(*K_EVP_rc2_40_cbc)() = nullptr;
183  static int (*K_i2d_PrivateKey_fp)(FILE *, EVP_PKEY *) = nullptr;
184  static int (*K_i2d_PKCS8PrivateKey_fp)(FILE *, EVP_PKEY *, const EVP_CIPHER *, char *, int, pem_password_cb *, void *) = nullptr;
185  static void (*K_RSA_free)(RSA *) = nullptr;
186  static EVP_CIPHER *(*K_EVP_bf_cbc)() = nullptr;
187  static int (*K_X509_REQ_sign)(X509_REQ *, EVP_PKEY *, const EVP_MD *) = nullptr;
188  static int (*K_X509_NAME_add_entry_by_txt)(X509_NAME *, char *, int, unsigned char *, int, int, int) = nullptr;
189  static X509_NAME *(*K_X509_NAME_new)() = nullptr;
190  static int (*K_X509_REQ_set_subject_name)(X509_REQ *, X509_NAME *) = nullptr;
191  static unsigned char *(*K_ASN1_STRING_data)(ASN1_STRING *) = nullptr;
192  static int (*K_ASN1_STRING_length)(ASN1_STRING *) = nullptr;
193  static STACK_OF(SSL_CIPHER) *(*K_SSL_get_ciphers)(const SSL *ssl) = nullptr;
194 
195 #endif
196 }
197 
198 class KOpenSSLProxyPrivate
199 {
200 public:
201  KOpenSSLProxyPrivate()
202  : sslLib(nullptr), cryptoLib(nullptr), ok(false)
203  {}
204 
205  QLibrary *sslLib;
206  QLibrary *cryptoLib;
207  bool ok;
208 
209  static KOpenSSLProxy *sSelf;
210  static void cleanupKOpenSSLProxy()
211  {
212  delete KOpenSSLProxyPrivate::sSelf;
213  }
214 };
215 KOpenSSLProxy *KOpenSSLProxyPrivate::sSelf = nullptr;
216 
218 {
219  return d->sslLib != nullptr;
220 }
221 
223 {
224  return d->cryptoLib != nullptr;
225 }
226 
228 {
229  KOpenSSLProxy *x = KOpenSSLProxyPrivate::sSelf;
230  KOpenSSLProxyPrivate::sSelf = nullptr;
231  delete x;
232 }
233 
234 #ifdef __OpenBSD__
235 #include <QDir>
236 #include <QString>
237 #include <QStringList>
238 
239 static QString findMostRecentLib(QString dir, QString name)
240 {
241  // Grab all shared libraries in the directory
242  QString filter = "lib" + name + ".so.*";
243  QDir d(dir, filter);
244  if (!d.exists()) {
245  return 0L;
246  }
247  QStringList l = d.entryList();
248 
249  // Find the best one
250  int bestmaj = -1;
251  int bestmin = -1;
252  QString best = 0L;
253  // where do we start
254  uint s = filter.length() - 1;
255  for (QStringList::const_iterator it = l.begin(); it != l.end(); ++it) {
256  QString numberpart = (*it).mid(s);
257  uint endmaj = numberpart.indexOf('.');
258  if (endmaj == -1) {
259  continue;
260  }
261  bool ok;
262  int maj = numberpart.left(endmaj).toInt(&ok);
263  if (!ok) {
264  continue;
265  }
266  int min = numberpart.mid(endmaj + 1).toInt(&ok);
267  if (!ok) {
268  continue;
269  }
270  if (maj > bestmaj || (maj == bestmaj && min > bestmin)) {
271  bestmaj = maj;
272  bestmin = min;
273  best = (*it);
274  }
275  }
276  if (best.isNull()) {
277  return 0L;
278  } else {
279  return dir + '/' + best;
280  }
281 }
282 #endif
283 
284 KOpenSSLProxy::KOpenSSLProxy()
285  : d(new KOpenSSLProxyPrivate())
286 {
287  QStringList libpaths, libnamesc, libnamess;
288 
289  d->cryptoLib = nullptr;
290  d->sslLib = nullptr;
291 
292  KConfig cfg("cryptodefaults", KConfig::NoGlobals);
293  KConfigGroup cg(&cfg, "OpenSSL");
294  QString upath = cg.readPathEntry("Path", QString());
295  if (!upath.isEmpty()) {
296  libpaths << upath;
297  }
298 
299 #ifdef Q_OS_WIN
300  d->cryptoLib = new QLibrary("libeay32.dll");
301  if (!d->cryptoLib->load()) {
302  delete d->cryptoLib;
303  d->cryptoLib = 0;
304  }
305 #elif defined(__OpenBSD__)
306  {
307  QString libname = findMostRecentLib("/usr/lib" KDELIBSUFF, "crypto");
308  if (!libname.isNull()) {
309  d->cryptoLib = new QLibrary(libname);
310  d->cryptoLib->setLoadHints(QLibrary::ExportExternalSymbolsHint);
311  if (!d->cryptoLib->load()) {
312  delete d->cryptoLib;
313  d->cryptoLib = 0;
314  }
315  }
316  }
317 #elif defined(__CYGWIN__)
318  libpaths << "/usr/bin/"
319  << "";
320 
321  libnamess << "cygssl-0.9.8.dll"
322  << "cygssl-0.9.7.dll"
323  << "";
324 
325  libnamesc << "cygcrypto-0.9.8.dll"
326  << "cygcrypto-0.9.7.dll"
327  << "";
328 #else
329  libpaths
330 #ifdef _AIX
331  << "/opt/freeware/lib/"
332 #endif
333  << "/usr/lib" KDELIBSUFF "/"
334  << "/usr/ssl/lib" KDELIBSUFF "/"
335  << "/usr/local/lib" KDELIBSUFF "/"
336  << "/usr/local/openssl/lib" KDELIBSUFF "/"
337  << "/usr/local/ssl/lib" KDELIBSUFF "/"
338  << "/opt/openssl/lib" KDELIBSUFF "/"
339  << "/lib" KDELIBSUFF "/"
340  << "";
341 
342 // FIXME: #define here for the various OS types to optimize
343  libnamess
344 #ifdef hpux
345  << "libssl.sl"
346 #elif defined(_AIX)
347  << "libssl.a(libssl.so.0)"
348 #elif defined(__APPLE__)
349  << "libssl.dylib"
350  << "libssl.0.9.dylib"
351 #else
352 #ifdef SHLIB_VERSION_NUMBER
353  << "libssl.so." SHLIB_VERSION_NUMBER
354 #endif
355  << "libssl.so"
356  << "libssl.so.0"
357 #endif
358  ;
359 
360  libnamesc
361 #ifdef hpux
362  << "libcrypto.sl"
363 #elif defined(_AIX)
364  << "libcrypto.a(libcrypto.so.0)"
365 #elif defined(__APPLE__)
366  << "libcrypto.dylib"
367  << "libcrypto.0.9.dylib"
368 #else
369 #ifdef SHLIB_VERSION_NUMBER
370  << "libcrypto.so." SHLIB_VERSION_NUMBER
371 #endif
372  << "libcrypto.so"
373  << "libcrypto.so.0"
374 #endif
375  ;
376 #endif
377 
378  for (QStringList::const_iterator it = libpaths.constBegin();
379  it != libpaths.constEnd();
380  ++it) {
381  for (QStringList::const_iterator shit = libnamesc.constBegin();
382  shit != libnamesc.constEnd();
383  ++shit) {
384  QString alib = *it;
385  if (!alib.isEmpty() && !alib.endsWith('/')) {
386  alib += '/';
387  }
388  alib += *shit;
389  // someone knows why this is needed?
390  QString tmpStr(alib);
391  tmpStr.remove(QRegExp("\\(.*\\)"));
392  if (QFile(tmpStr).isReadable()) {
393  d->cryptoLib = new QLibrary(alib);
394  d->cryptoLib->setLoadHints(QLibrary::ExportExternalSymbolsHint);
395  }
396  if (d->cryptoLib && d->cryptoLib->load()) {
397  break;
398  } else {
399  delete d->cryptoLib;
400  d->cryptoLib = nullptr;
401  }
402  }
403  if (d->cryptoLib) {
404  break;
405  }
406  }
407 
408  if (d->cryptoLib) {
409 #if KSSL_HAVE_SSL
410  K_X509_free = (void (*)(X509 *)) d->cryptoLib->resolve("X509_free");
411  K_RAND_egd = (int (*)(const char *)) d->cryptoLib->resolve("RAND_egd");
412  K_RAND_load_file = (int (*)(const char *, long)) d->cryptoLib->resolve("RAND_load_file");
413  K_RAND_file_name = (const char *(*)(char *, size_t)) d->cryptoLib->resolve("RAND_file_name");
414  K_RAND_write_file = (int (*)(const char *)) d->cryptoLib->resolve("RAND_write_file");
415  K_CRYPTO_free = (void (*)(void *)) d->cryptoLib->resolve("CRYPTO_free");
416  K_d2i_X509 = (X509 * (*)(X509 **, unsigned char **, long)) d->cryptoLib->resolve("d2i_X509");
417  K_i2d_X509 = (int (*)(X509 *, unsigned char **)) d->cryptoLib->resolve("i2d_X509");
418  K_X509_cmp = (int (*)(X509 *, X509 *)) d->cryptoLib->resolve("X509_cmp");
419  K_X509_STORE_CTX_new = (X509_STORE_CTX * (*)(void)) d->cryptoLib->resolve("X509_STORE_CTX_new");
420  K_X509_STORE_CTX_free = (void (*)(X509_STORE_CTX *)) d->cryptoLib->resolve("X509_STORE_CTX_free");
421  K_X509_verify_cert = (int (*)(X509_STORE_CTX *)) d->cryptoLib->resolve("X509_verify_cert");
422  K_X509_STORE_new = (X509_STORE * (*)(void)) d->cryptoLib->resolve("X509_STORE_new");
423  K_X509_STORE_free = (void (*)(X509_STORE *)) d->cryptoLib->resolve("X509_STORE_free");
424  K_X509_NAME_oneline = (char *(*)(X509_NAME *, char *, int)) d->cryptoLib->resolve("X509_NAME_oneline");
425  K_X509_get_subject_name = (X509_NAME * (*)(X509 *)) d->cryptoLib->resolve("X509_get_subject_name");
426  K_X509_get_issuer_name = (X509_NAME * (*)(X509 *)) d->cryptoLib->resolve("X509_get_issuer_name");
427  K_X509_STORE_add_lookup = (X509_LOOKUP * (*)(X509_STORE *, X509_LOOKUP_METHOD *)) d->cryptoLib->resolve("X509_STORE_add_lookup");
428  K_X509_LOOKUP_file = (X509_LOOKUP_METHOD * (*)(void)) d->cryptoLib->resolve("X509_LOOKUP_file");
429  K_X509_LOOKUP_free = (void (*)(X509_LOOKUP *)) d->cryptoLib->resolve("X509_LOOKUP_free");
430  K_X509_LOOKUP_ctrl = (int (*)(X509_LOOKUP *, int, const char *, long, char **)) d->cryptoLib->resolve("X509_LOOKUP_ctrl");
431  K_X509_STORE_CTX_init = (void (*)(X509_STORE_CTX *, X509_STORE *, X509 *, STACK_OF(X509) *)) d->cryptoLib->resolve("X509_STORE_CTX_init");
432  K_X509_dup = (X509 * (*)(X509 *)) d->cryptoLib->resolve("X509_dup");
433  K_BIO_s_mem = (BIO_METHOD * (*)(void)) d->cryptoLib->resolve("BIO_s_mem");
434  K_BIO_new = (BIO * (*)(BIO_METHOD *)) d->cryptoLib->resolve("BIO_new");
435  K_BIO_new_fp = (BIO * (*)(FILE *, int)) d->cryptoLib->resolve("BIO_new_fp");
436  K_BIO_new_mem_buf = (BIO * (*)(void *, int)) d->cryptoLib->resolve("BIO_new_mem_buf");
437  K_BIO_free = (int (*)(BIO *)) d->cryptoLib->resolve("BIO_free");
438  K_BIO_ctrl = (long(*)(BIO *, int, long, void *)) d->cryptoLib->resolve("BIO_ctrl");
439  K_BIO_write = (int (*)(BIO * b, const void *data, int len)) d->cryptoLib->resolve("BIO_write");
440  K_PEM_ASN1_write_bio = (int (*)(int (*)(), const char *, BIO *, char *, const EVP_CIPHER *, unsigned char *, int, pem_password_cb *, void *)) d->cryptoLib->resolve("PEM_ASN1_write_bio");
441  K_ASN1_item_i2d_fp = (int (*)(ASN1_ITEM *, FILE *, unsigned char *))
442  d->cryptoLib->resolve("ASN1_item_i2d_fp");
443  K_NETSCAPE_X509_it = (ASN1_ITEM *) d->cryptoLib->resolve("NETSCAPE_X509_it");
444  K_X509_print_fp = (int (*)(FILE *, X509 *)) d->cryptoLib->resolve("X509_print_fp");
445  K_i2d_PKCS12 = (int (*)(PKCS12 *, unsigned char **)) d->cryptoLib->resolve("i2d_PKCS12");
446  K_i2d_PKCS12_fp = (int (*)(FILE *, PKCS12 *)) d->cryptoLib->resolve("i2d_PKCS12_fp");
447  K_PKCS12_newpass = (int (*)(PKCS12 *, char *, char *)) d->cryptoLib->resolve("PKCS12_newpass");
448  K_d2i_PKCS12_fp = (PKCS12 * (*)(FILE *, PKCS12 **)) d->cryptoLib->resolve("d2i_PKCS12_fp");
449  K_PKCS12_new = (PKCS12 * (*)()) d->cryptoLib->resolve("PKCS12_new");
450  K_PKCS12_free = (void (*)(PKCS12 *)) d->cryptoLib->resolve("PKCS12_free");
451  K_PKCS12_parse = (int (*)(PKCS12 *, const char *, EVP_PKEY **,
452  X509 **, STACK_OF(X509) **)) d->cryptoLib->resolve("PKCS12_parse");
453  K_EVP_PKEY_free = (void (*)(EVP_PKEY *)) d->cryptoLib->resolve("EVP_PKEY_free");
454  K_EVP_PKEY_new = (EVP_PKEY * (*)()) d->cryptoLib->resolve("EVP_PKEY_new");
455  K_X509_REQ_free = (void (*)(X509_REQ *)) d->cryptoLib->resolve("X509_REQ_free");
456  K_X509_REQ_new = (X509_REQ * (*)()) d->cryptoLib->resolve("X509_REQ_new");
457  K_X509_STORE_CTX_set_chain = (void (*)(X509_STORE_CTX *, STACK_OF(X509) *)) d->cryptoLib->resolve("X509_STORE_CTX_set_chain");
458  K_X509_STORE_CTX_set_purpose = (void (*)(X509_STORE_CTX *, int)) d->cryptoLib->resolve("X509_STORE_CTX_set_purpose");
459  K_sk_free = (void (*)(STACK *)) d->cryptoLib->resolve("sk_free");
460  K_sk_num = (int (*)(STACK *)) d->cryptoLib->resolve("sk_num");
461  K_sk_pop = (char *(*)(STACK *)) d->cryptoLib->resolve("sk_pop");
462  K_sk_value = (char *(*)(STACK *, int)) d->cryptoLib->resolve("sk_value");
463  K_sk_new = (STACK * (*)(int (*)())) d->cryptoLib->resolve("sk_new");
464  K_sk_push = (int (*)(STACK *, char *)) d->cryptoLib->resolve("sk_push");
465  K_sk_dup = (STACK * (*)(STACK *)) d->cryptoLib->resolve("sk_dup");
466  K_i2s_ASN1_INTEGER = (char *(*)(X509V3_EXT_METHOD *, ASN1_INTEGER *)) d->cryptoLib->resolve("i2s_ASN1_INTEGER");
467  K_X509_get_serialNumber = (ASN1_INTEGER * (*)(X509 *)) d->cryptoLib->resolve("X509_get_serialNumber");
468  K_X509_get_pubkey = (EVP_PKEY * (*)(X509 *)) d->cryptoLib->resolve("X509_get_pubkey");
469  K_i2d_PublicKey = (int (*)(EVP_PKEY *, unsigned char **)) d->cryptoLib->resolve("i2d_PublicKey");
470  K_X509_check_private_key = (int (*)(X509 *, EVP_PKEY *)) d->cryptoLib->resolve("X509_check_private_key");
471  K_BN_bn2hex = (char *(*)(const BIGNUM *)) d->cryptoLib->resolve("BN_bn2hex");
472  K_X509_digest = (int (*)(const X509 *, const EVP_MD *, unsigned char *, unsigned int *)) d->cryptoLib->resolve("X509_digest");
473  K_EVP_md5 = (EVP_MD * (*)()) d->cryptoLib->resolve("EVP_md5");
474  K_ASN1_INTEGER_free = (void (*)(ASN1_INTEGER *)) d->cryptoLib->resolve("ASN1_INTEGER_free");
475  K_OBJ_obj2nid = (int (*)(ASN1_OBJECT *)) d->cryptoLib->resolve("OBJ_obj2nid");
476  K_OBJ_nid2ln = (const char *(*)(int)) d->cryptoLib->resolve("OBJ_nid2ln");
477  K_X509_get_ext_count = (int (*)(X509 *)) d->cryptoLib->resolve("X509_get_ext_count");
478  K_X509_get_ext_by_NID = (int (*)(X509 *, int, int)) d->cryptoLib->resolve("X509_get_ext_by_NID");
479  K_X509_get_ext_by_OBJ = (int (*)(X509 *, ASN1_OBJECT *, int)) d->cryptoLib->resolve("X509_get_ext_by_OBJ");
480  K_X509_get_ext = (X509_EXTENSION * (*)(X509 *, int)) d->cryptoLib->resolve("X509_get_ext");
481  K_X509_delete_ext = (X509_EXTENSION * (*)(X509 *, int)) d->cryptoLib->resolve("X509_delete_ext");
482  K_X509_add_ext = (int (*)(X509 *, X509_EXTENSION *, int)) d->cryptoLib->resolve("X509_add_ext");
483  K_X509_get_ext_d2i = (void *(*)(X509 *, int, int *, int *)) d->cryptoLib->resolve("X509_get_ext_d2i");
484  K_i2s_ASN1_OCTET_STRING = (char *(*)(X509V3_EXT_METHOD *, ASN1_OCTET_STRING *)) d->cryptoLib->resolve("i2s_ASN1_OCTET_STRING");
485  K_ASN1_BIT_STRING_get_bit = (int (*)(ASN1_BIT_STRING *, int)) d->cryptoLib->resolve("ASN1_BIT_STRING_get_bit");
486  K_PKCS7_new = (PKCS7 * (*)()) d->cryptoLib->resolve("PKCS7_new");
487  K_PKCS7_free = (void (*)(PKCS7 *)) d->cryptoLib->resolve("PKCS7_free");
488  K_PKCS7_content_free = (void (*)(PKCS7 *)) d->cryptoLib->resolve("PKCS7_content_free");
489  K_i2d_PKCS7 = (int (*)(PKCS7 *, unsigned char **)) d->cryptoLib->resolve("i2d_PKCS7");
490  K_i2d_PKCS7_fp = (int (*)(FILE *, PKCS7 *)) d->cryptoLib->resolve("i2d_PKCS7_fp");
491  K_i2d_PKCS7_bio = (int (*)(BIO * bp, PKCS7 * p7)) d->cryptoLib->resolve("i2d_PKCS7_bio");
492  K_d2i_PKCS7 = (PKCS7 * (*)(PKCS7 **, unsigned char **, long)) d->cryptoLib->resolve("d2i_PKCS7");
493  K_d2i_PKCS7_fp = (PKCS7 * (*)(FILE *, PKCS7 **)) d->cryptoLib->resolve("d2i_PKCS7_fp");
494  K_d2i_PKCS7_bio = (PKCS7 * (*)(BIO * bp, PKCS7 **p7)) d->cryptoLib->resolve("d2i_PKCS7_bio");
495  K_PKCS7_dup = (PKCS7 * (*)(PKCS7 *)) d->cryptoLib->resolve("PKCS7_dup");
496  K_PKCS7_sign = (PKCS7 * (*)(X509 *, EVP_PKEY *, STACK_OF(X509) *, BIO *, int)) d->cryptoLib->resolve("PKCS7_sign");
497  K_PKCS7_verify = (int (*)(PKCS7 *, STACK_OF(X509) *, X509_STORE *, BIO *, BIO *, int)) d->cryptoLib->resolve("PKCS7_verify");
498  K_PKCS7_get0_signers = (STACK_OF(X509) * (*)(PKCS7 *, STACK_OF(X509) *, int)) d->cryptoLib->resolve("PKCS7_get0_signers");
499  K_PKCS7_encrypt = (PKCS7 * (*)(STACK_OF(X509) *, BIO *, EVP_CIPHER *, int)) d->cryptoLib->resolve("PKCS7_encrypt");
500  K_PKCS7_decrypt = (int (*)(PKCS7 *, EVP_PKEY *, X509 *, BIO *, int)) d->cryptoLib->resolve("PKCS7_decrypt");
501  K_PEM_X509_INFO_read = (STACK_OF(X509_INFO) * (*)(FILE *, STACK_OF(X509_INFO) *, pem_password_cb *, void *)) d->cryptoLib->resolve("PEM_X509_INFO_read");
502  K_ASN1_d2i_fp = (char *(*)(char *(*)(), char *(*)(), FILE *, unsigned char **)) d->cryptoLib->resolve("ASN1_d2i_fp");
503  K_X509_new = (X509 * (*)()) d->cryptoLib->resolve("X509_new");
504  K_X509_PURPOSE_get_count = (int (*)()) d->cryptoLib->resolve("X509_PURPOSE_get_count");
505  K_X509_PURPOSE_get_id = (int (*)(X509_PURPOSE *)) d->cryptoLib->resolve("X509_PURPOSE_get_id");
506  K_X509_check_purpose = (int (*)(X509 *, int, int)) d->cryptoLib->resolve("X509_check_purpose");
507  K_X509_PURPOSE_get0 = (X509_PURPOSE * (*)(int)) d->cryptoLib->resolve("X509_PURPOSE_get0");
508  K_EVP_PKEY_assign = (int (*)(EVP_PKEY *, int, char *)) d->cryptoLib->resolve("EVP_PKEY_assign");
509  K_X509_REQ_set_pubkey = (int (*)(X509_REQ *, EVP_PKEY *)) d->cryptoLib->resolve("X509_REQ_set_pubkey");
510  K_RSA_generate_key = (RSA * (*)(int, unsigned long, void (*)(int, int, void *), void *)) d->cryptoLib->resolve("RSA_generate_key");
511  K_i2d_X509_REQ_fp = (int (*)(FILE *, X509_REQ *)) d->cryptoLib->resolve("i2d_X509_REQ_fp");
512  K_ERR_clear_error = (void (*)()) d->cryptoLib->resolve("ERR_clear_error");
513  K_ERR_get_error = (unsigned long(*)()) d->cryptoLib->resolve("ERR_get_error");
514  K_ERR_print_errors_fp = (void (*)(FILE *)) d->cryptoLib->resolve("ERR_print_errors_fp");
515  K_X509_get1_email = (STACK * (*)(X509 * x)) d->cryptoLib->resolve("X509_get1_email");
516  K_X509_email_free = (void (*)(STACK * sk)) d->cryptoLib->resolve("X509_email_free");
517  K_EVP_des_ede3_cbc = (EVP_CIPHER * (*)()) d->cryptoLib->resolve("EVP_des_ede3_cbc");
518  K_EVP_des_cbc = (EVP_CIPHER * (*)()) d->cryptoLib->resolve("EVP_des_cbc");
519  K_EVP_rc2_cbc = (EVP_CIPHER * (*)()) d->cryptoLib->resolve("EVP_rc2_cbc");
520  K_EVP_rc2_64_cbc = (EVP_CIPHER * (*)()) d->cryptoLib->resolve("EVP_rc2_64_cbc");
521  K_EVP_rc2_40_cbc = (EVP_CIPHER * (*)()) d->cryptoLib->resolve("EVP_rc2_40_cbc");
522  K_i2d_PrivateKey_fp = (int (*)(FILE *, EVP_PKEY *)) d->cryptoLib->resolve("i2d_PrivateKey_fp");
523  K_i2d_PKCS8PrivateKey_fp = (int (*)(FILE *, EVP_PKEY *, const EVP_CIPHER *, char *, int, pem_password_cb *, void *)) d->cryptoLib->resolve("i2d_PKCS8PrivateKey_fp");
524  K_RSA_free = (void (*)(RSA *)) d->cryptoLib->resolve("RSA_free");
525  K_EVP_bf_cbc = (EVP_CIPHER * (*)()) d->cryptoLib->resolve("EVP_bf_cbc");
526  K_X509_REQ_sign = (int (*)(X509_REQ *, EVP_PKEY *, const EVP_MD *)) d->cryptoLib->resolve("X509_REQ_sign");
527  K_X509_NAME_add_entry_by_txt = (int (*)(X509_NAME *, char *, int, unsigned char *, int, int, int)) d->cryptoLib->resolve("X509_NAME_add_entry_by_txt");
528  K_X509_NAME_new = (X509_NAME * (*)()) d->cryptoLib->resolve("X509_NAME_new");
529  K_X509_REQ_set_subject_name = (int (*)(X509_REQ *, X509_NAME *)) d->cryptoLib->resolve("X509_REQ_set_subject_name");
530  K_ASN1_STRING_data = (unsigned char *(*)(ASN1_STRING *)) d->cryptoLib->resolve("ASN1_STRING_data");
531  K_ASN1_STRING_length = (int (*)(ASN1_STRING *)) d->cryptoLib->resolve("ASN1_STRING_length");
532 #endif
533  }
534 
535 #ifdef Q_OS_WIN
536  d->sslLib = new QLibrary("ssleay32.dll");
537  if (!d->sslLib->load()) {
538  delete d->sslLib;
539  d->sslLib = 0;
540  }
541 #elif defined(__OpenBSD__)
542  {
543  QString libname = findMostRecentLib("/usr/lib", "ssl");
544  if (!libname.isNull()) {
545  d->sslLib = new QLibrary(libname);
546  d->sslLib->setLoadHints(QLibrary::ExportExternalSymbolsHint);
547  if (!d->sslLib->load()) {
548  delete d->sslLib;
549  d->sslLib = 0;
550  }
551  }
552  }
553 #else
554  for (QStringList::const_iterator it = libpaths.constBegin();
555  it != libpaths.constEnd();
556  ++it) {
557  for (QStringList::const_iterator shit = libnamess.constBegin();
558  shit != libnamess.constEnd();
559  ++shit) {
560  QString alib = *it;
561  if (!alib.isEmpty() && !alib.endsWith('/')) {
562  alib += '/';
563  }
564  alib += *shit;
565  QString tmpStr(alib);
566  tmpStr.remove(QRegExp("\\(.*\\)"));
567  if (QFile(tmpStr).isReadable()) {
568  d->sslLib = new QLibrary(alib);
569  d->sslLib->setLoadHints(QLibrary::ExportExternalSymbolsHint);
570  }
571  if (d->sslLib && d->sslLib->load()) {
572  break;
573  } else {
574  delete d->sslLib;
575  d->sslLib = nullptr;
576  }
577  }
578  if (d->sslLib) {
579  break;
580  }
581  }
582 #endif
583 
584  if (d->sslLib) {
585 #if KSSL_HAVE_SSL
586  // stand back from your monitor and look at this. it's fun! :)
587  K_SSL_connect = (int (*)(SSL *)) d->sslLib->resolve("SSL_connect");
588  K_SSL_accept = (int (*)(SSL *)) d->sslLib->resolve("SSL_accept");
589  K_SSL_read = (int (*)(SSL *, void *, int)) d->sslLib->resolve("SSL_read");
590  K_SSL_write = (int (*)(SSL *, const void *, int))
591  d->sslLib->resolve("SSL_write");
592  K_SSL_new = (SSL * (*)(SSL_CTX *)) d->sslLib->resolve("SSL_new");
593  K_SSL_free = (void (*)(SSL *)) d->sslLib->resolve("SSL_free");
594  K_SSL_shutdown = (int (*)(SSL *)) d->sslLib->resolve("SSL_shutdown");
595  K_SSL_CTX_new = (SSL_CTX * (*)(SSL_METHOD *)) d->sslLib->resolve("SSL_CTX_new");
596  K_SSL_CTX_free = (void (*)(SSL_CTX *)) d->sslLib->resolve("SSL_CTX_free");
597  K_SSL_set_fd = (int (*)(SSL *, int)) d->sslLib->resolve("SSL_set_fd");
598  K_SSL_pending = (int (*)(SSL *)) d->sslLib->resolve("SSL_pending");
599  K_SSL_CTX_set_cipher_list = (int (*)(SSL_CTX *, const char *))
600  d->sslLib->resolve("SSL_CTX_set_cipher_list");
601  K_SSL_CTX_set_verify = (void (*)(SSL_CTX *, int, int (*)(int, X509_STORE_CTX *))) d->sslLib->resolve("SSL_CTX_set_verify");
602  K_SSL_use_certificate = (int (*)(SSL *, X509 *))
603  d->sslLib->resolve("SSL_CTX_use_certificate");
604  K_SSL_get_current_cipher = (SSL_CIPHER * (*)(SSL *))
605  d->sslLib->resolve("SSL_get_current_cipher");
606  K_SSL_ctrl = (long(*)(SSL *, int, long, char *))
607  d->sslLib->resolve("SSL_ctrl");
608  K_TLSv1_client_method = (SSL_METHOD * (*)()) d->sslLib->resolve("TLSv1_client_method");
609  K_SSLv23_client_method = (SSL_METHOD * (*)()) d->sslLib->resolve("SSLv23_client_method");
610  K_SSL_get_peer_certificate = (X509 * (*)(SSL *)) d->sslLib->resolve("SSL_get_peer_certificate");
611  K_SSL_CIPHER_get_bits = (int (*)(SSL_CIPHER *, int *)) d->sslLib->resolve("SSL_CIPHER_get_bits");
612  K_SSL_CIPHER_get_version = (char *(*)(SSL_CIPHER *)) d->sslLib->resolve("SSL_CIPHER_get_version");
613  K_SSL_CIPHER_get_name = (const char *(*)(SSL_CIPHER *)) d->sslLib->resolve("SSL_CIPHER_get_name");
614  K_SSL_CIPHER_description = (char *(*)(SSL_CIPHER *, char *, int)) d->sslLib->resolve("SSL_CIPHER_description");
615  K_SSL_CTX_use_PrivateKey = (int (*)(SSL_CTX *, EVP_PKEY *)) d->sslLib->resolve("SSL_CTX_use_PrivateKey");
616  K_SSL_CTX_use_certificate = (int (*)(SSL_CTX *, X509 *)) d->sslLib->resolve("SSL_CTX_use_certificate");
617  K_SSL_get_error = (int (*)(SSL *, int)) d->sslLib->resolve("SSL_get_error");
618  K_SSL_get_peer_cert_chain = (STACK_OF(X509) * (*)(SSL *)) d->sslLib->resolve("SSL_get_peer_cert_chain");
619  K_SSL_load_client_CA_file = (STACK_OF(X509_NAME) * (*)(const char *)) d->sslLib->resolve("SSL_load_client_CA_file");
620  K_SSL_peek = (int (*)(SSL *, void *, int)) d->sslLib->resolve("SSL_peek");
621  K_SSL_get1_session = (SSL_SESSION * (*)(SSL *)) d->sslLib->resolve("SSL_get1_session");
622  K_SSL_SESSION_free = (void (*)(SSL_SESSION *)) d->sslLib->resolve("SSL_SESSION_free");
623  K_SSL_set_session = (int (*)(SSL *, SSL_SESSION *)) d->sslLib->resolve("SSL_set_session");
624  K_d2i_SSL_SESSION = (SSL_SESSION * (*)(SSL_SESSION **, unsigned char **, long)) d->sslLib->resolve("d2i_SSL_SESSION");
625  K_i2d_SSL_SESSION = (int (*)(SSL_SESSION *, unsigned char **)) d->sslLib->resolve("i2d_SSL_SESSION");
626  K_SSL_get_ciphers = (STACK_OF(SSL_CIPHER) * (*)(const SSL *)) d->sslLib->resolve("SSL_get_ciphers");
627 #endif
628 
629  // Initialize the library (once only!)
630  QFunctionPointer x;
631  x = d->sslLib->resolve("SSL_library_init");
632  if (d->cryptoLib) {
633  if (x) {
634  ((int (*)())x)();
635  }
636  x = d->cryptoLib->resolve("OpenSSL_add_all_algorithms");
637  if (!x) {
638  x = d->cryptoLib->resolve("OPENSSL_add_all_algorithms");
639  }
640  if (x) {
641  ((void (*)())x)();
642  } else {
643  x = d->cryptoLib->resolve("OpenSSL_add_all_algorithms_conf");
644  if (!x) {
645  x = d->cryptoLib->resolve("OPENSSL_add_all_algorithms_conf");
646  }
647  if (x) {
648  ((void (*)())x)();
649  } else {
650  x = d->cryptoLib->resolve("OpenSSL_add_all_algorithms_noconf");
651  if (!x) {
652  x = d->cryptoLib->resolve("OPENSSL_add_all_algorithms_noconf");
653  }
654  if (x) {
655  ((void (*)())x)();
656  }
657  }
658  }
659  x = d->cryptoLib->resolve("OpenSSL_add_all_ciphers");
660  if (!x) {
661  x = d->cryptoLib->resolve("OPENSSL_add_all_ciphers");
662  }
663  if (x) {
664  ((void (*)())x)();
665  }
666  x = d->cryptoLib->resolve("OpenSSL_add_all_digests");
667  if (!x) {
668  x = d->cryptoLib->resolve("OPENSSL_add_all_digests");
669  }
670  if (x) {
671  ((void (*)())x)();
672  }
673  }
674  }
675 
676 }
677 
678 KOpenSSLProxy::~KOpenSSLProxy()
679 {
680  if (d->sslLib) {
681  d->sslLib->unload();
682  }
683  if (d->cryptoLib) {
684  d->cryptoLib->unload();
685  }
686 
687  KOpenSSLProxyPrivate::sSelf = nullptr;
688  delete d;
689 }
690 
691 // FIXME: we should check "ok" and allow this to init the lib if !ok.
692 
694 {
695 #if KSSL_HAVE_SSL
696  if (!KOpenSSLProxyPrivate::sSelf) {
697  KOpenSSLProxyPrivate::sSelf = new KOpenSSLProxy();
698  qAddPostRoutine(KOpenSSLProxyPrivate::cleanupKOpenSSLProxy);
699  }
700 #endif
701  return KOpenSSLProxyPrivate::sSelf;
702 }
703 
704 #if KSSL_HAVE_SSL
705 
706 int KOpenSSLProxy::SSL_connect(SSL *ssl)
707 {
708  if (K_SSL_connect) {
709  return (K_SSL_connect)(ssl);
710  }
711  return -1;
712 }
713 
714 int KOpenSSLProxy::SSL_accept(SSL *ssl)
715 {
716  if (K_SSL_accept) {
717  return (K_SSL_accept)(ssl);
718  }
719  return -1;
720 }
721 
722 int KOpenSSLProxy::SSL_read(SSL *ssl, void *buf, int num)
723 {
724  if (K_SSL_read) {
725  return (K_SSL_read)(ssl, buf, num);
726  }
727  return -1;
728 }
729 
730 int KOpenSSLProxy::SSL_write(SSL *ssl, const void *buf, int num)
731 {
732  if (K_SSL_write) {
733  return (K_SSL_write)(ssl, buf, num);
734  }
735  return -1;
736 }
737 
738 SSL *KOpenSSLProxy::SSL_new(SSL_CTX *ctx)
739 {
740  if (K_SSL_new) {
741  return (K_SSL_new)(ctx);
742  }
743  return nullptr;
744 }
745 
746 void KOpenSSLProxy::SSL_free(SSL *ssl)
747 {
748  if (K_SSL_free) {
749  (K_SSL_free)(ssl);
750  }
751 }
752 
753 int KOpenSSLProxy::SSL_shutdown(SSL *ssl)
754 {
755  if (K_SSL_shutdown) {
756  return (K_SSL_shutdown)(ssl);
757  }
758  return -1;
759 }
760 
761 SSL_CTX *KOpenSSLProxy::SSL_CTX_new(SSL_METHOD *method)
762 {
763  if (K_SSL_CTX_new) {
764  return (K_SSL_CTX_new)(method);
765  }
766  return nullptr;
767 }
768 
769 void KOpenSSLProxy::SSL_CTX_free(SSL_CTX *ctx)
770 {
771  if (K_SSL_CTX_free) {
772  (K_SSL_CTX_free)(ctx);
773  }
774 }
775 
776 int KOpenSSLProxy::SSL_set_fd(SSL *ssl, int fd)
777 {
778  if (K_SSL_set_fd) {
779  return (K_SSL_set_fd)(ssl, fd);
780  }
781  return -1;
782 }
783 
784 int KOpenSSLProxy::SSL_pending(SSL *ssl)
785 {
786  if (K_SSL_pending) {
787  return (K_SSL_pending)(ssl);
788  }
789  return -1;
790 }
791 
792 int KOpenSSLProxy::SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str)
793 {
794  if (K_SSL_CTX_set_cipher_list) {
795  return (K_SSL_CTX_set_cipher_list)(ctx, str);
796  }
797  return -1;
798 }
799 
800 void KOpenSSLProxy::SSL_CTX_set_verify(SSL_CTX *ctx, int mode,
801  int (*verify_callback)(int, X509_STORE_CTX *))
802 {
803  if (K_SSL_CTX_set_verify) {
804  (K_SSL_CTX_set_verify)(ctx, mode, verify_callback);
805  }
806 }
807 
808 int KOpenSSLProxy::SSL_use_certificate(SSL *ssl, X509 *x)
809 {
810  if (K_SSL_use_certificate) {
811  return (K_SSL_use_certificate)(ssl, x);
812  }
813  return -1;
814 }
815 
816 SSL_CIPHER *KOpenSSLProxy::SSL_get_current_cipher(SSL *ssl)
817 {
818  if (K_SSL_get_current_cipher) {
819  return (K_SSL_get_current_cipher)(ssl);
820  }
821  return nullptr;
822 }
823 
824 long KOpenSSLProxy::SSL_ctrl(SSL *ssl, int cmd, long larg, char *parg)
825 {
826  if (K_SSL_ctrl) {
827  return (K_SSL_ctrl)(ssl, cmd, larg, parg);
828  }
829  return -1;
830 }
831 
832 int KOpenSSLProxy::RAND_egd(const char *path)
833 {
834  if (K_RAND_egd) {
835  return (K_RAND_egd)(path);
836  }
837  return -1;
838 }
839 
840 SSL_METHOD *KOpenSSLProxy::TLSv1_client_method()
841 {
842  if (K_TLSv1_client_method) {
843  return (K_TLSv1_client_method)();
844  }
845  return nullptr;
846 }
847 
848 SSL_METHOD *KOpenSSLProxy::SSLv23_client_method()
849 {
850  if (K_SSLv23_client_method) {
851  return (K_SSLv23_client_method)();
852  }
853  return nullptr;
854 }
855 
856 X509 *KOpenSSLProxy::SSL_get_peer_certificate(SSL *s)
857 {
858  if (K_SSL_get_peer_certificate) {
859  return (K_SSL_get_peer_certificate)(s);
860  }
861  return nullptr;
862 }
863 
864 int KOpenSSLProxy::SSL_CIPHER_get_bits(SSL_CIPHER *c, int *alg_bits)
865 {
866  if (K_SSL_CIPHER_get_bits) {
867  return (K_SSL_CIPHER_get_bits)(c, alg_bits);
868  }
869  return -1;
870 }
871 
872 char *KOpenSSLProxy::SSL_CIPHER_get_version(SSL_CIPHER *c)
873 {
874  if (K_SSL_CIPHER_get_version) {
875  return (K_SSL_CIPHER_get_version)(c);
876  }
877  return nullptr;
878 }
879 
880 const char *KOpenSSLProxy::SSL_CIPHER_get_name(SSL_CIPHER *c)
881 {
882  if (K_SSL_CIPHER_get_name) {
883  return (K_SSL_CIPHER_get_name)(c);
884  }
885  return nullptr;
886 }
887 
888 char *KOpenSSLProxy::SSL_CIPHER_description(SSL_CIPHER *c, char *buf, int size)
889 {
890  if (K_SSL_CIPHER_description) {
891  return (K_SSL_CIPHER_description)(c, buf, size);
892  }
893  return nullptr;
894 }
895 
896 X509 *KOpenSSLProxy::d2i_X509(X509 **a, unsigned char **pp, long length)
897 {
898  if (K_d2i_X509) {
899  return (K_d2i_X509)(a, pp, length);
900  }
901  return nullptr;
902 }
903 
904 int KOpenSSLProxy::i2d_X509(X509 *a, unsigned char **pp)
905 {
906  if (K_i2d_X509) {
907  return (K_i2d_X509)(a, pp);
908  }
909  return -1;
910 }
911 
912 int KOpenSSLProxy::X509_cmp(X509 *a, X509 *b)
913 {
914  if (K_X509_cmp) {
915  return (K_X509_cmp)(a, b);
916  }
917  return 0;
918 }
919 
920 X509_STORE *KOpenSSLProxy::X509_STORE_new(void)
921 {
922  if (K_X509_STORE_new) {
923  return (K_X509_STORE_new)();
924  }
925  return nullptr;
926 }
927 
928 void KOpenSSLProxy::X509_STORE_free(X509_STORE *v)
929 {
930  if (K_X509_STORE_free) {
931  (K_X509_STORE_free)(v);
932  }
933 }
934 
935 X509_STORE_CTX *KOpenSSLProxy::X509_STORE_CTX_new(void)
936 {
937  if (K_X509_STORE_CTX_new) {
938  return (K_X509_STORE_CTX_new)();
939  }
940  return nullptr;
941 }
942 
943 void KOpenSSLProxy::X509_STORE_CTX_free(X509_STORE_CTX *ctx)
944 {
945  if (K_X509_STORE_CTX_free) {
946  (K_X509_STORE_CTX_free)(ctx);
947  }
948 }
949 
950 int KOpenSSLProxy::X509_verify_cert(X509_STORE_CTX *ctx)
951 {
952  if (K_X509_verify_cert) {
953  return (K_X509_verify_cert)(ctx);
954  }
955  return -1;
956 }
957 
958 void KOpenSSLProxy::X509_free(X509 *a)
959 {
960  if (K_X509_free) {
961  (K_X509_free)(a);
962  }
963 }
964 
965 char *KOpenSSLProxy::X509_NAME_oneline(X509_NAME *a, char *buf, int size)
966 {
967  if (K_X509_NAME_oneline) {
968  return (K_X509_NAME_oneline)(a, buf, size);
969  }
970  return nullptr;
971 }
972 
973 X509_NAME *KOpenSSLProxy::X509_get_subject_name(X509 *a)
974 {
975  if (K_X509_get_subject_name) {
976  return (K_X509_get_subject_name)(a);
977  }
978  return nullptr;
979 }
980 
981 X509_NAME *KOpenSSLProxy::X509_get_issuer_name(X509 *a)
982 {
983  if (K_X509_get_issuer_name) {
984  return (K_X509_get_issuer_name)(a);
985  }
986  return nullptr;
987 }
988 
989 X509_LOOKUP *KOpenSSLProxy::X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m)
990 {
991  if (K_X509_STORE_add_lookup) {
992  return (K_X509_STORE_add_lookup)(v, m);
993  }
994  return nullptr;
995 }
996 
997 X509_LOOKUP_METHOD *KOpenSSLProxy::X509_LOOKUP_file(void)
998 {
999  if (K_X509_LOOKUP_file) {
1000  return (K_X509_LOOKUP_file)();
1001  }
1002  return nullptr;
1003 }
1004 
1005 void KOpenSSLProxy::X509_LOOKUP_free(X509_LOOKUP *x)
1006 {
1007  if (K_X509_LOOKUP_free) {
1008  (K_X509_LOOKUP_free)(x);
1009  }
1010 }
1011 
1012 int KOpenSSLProxy::X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, long argl, char **ret)
1013 {
1014  if (K_X509_LOOKUP_ctrl) {
1015  return (K_X509_LOOKUP_ctrl)(ctx, cmd, argc, argl, ret);
1016  }
1017  return -1;
1018 }
1019 
1020 void KOpenSSLProxy::X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509, STACK_OF(X509) *chain)
1021 {
1022  if (K_X509_STORE_CTX_init) {
1023  (K_X509_STORE_CTX_init)(ctx, store, x509, chain);
1024  }
1025 }
1026 
1027 void KOpenSSLProxy::CRYPTO_free(void *x)
1028 {
1029  if (K_CRYPTO_free) {
1030  (K_CRYPTO_free)(x);
1031  }
1032 }
1033 
1034 X509 *KOpenSSLProxy::X509_dup(X509 *x509)
1035 {
1036  if (K_X509_dup) {
1037  return (K_X509_dup)(x509);
1038  }
1039  return nullptr;
1040 }
1041 
1042 BIO *KOpenSSLProxy::BIO_new(BIO_METHOD *type)
1043 {
1044  if (K_BIO_new) {
1045  return (K_BIO_new)(type);
1046  } else {
1047  return nullptr;
1048  }
1049 }
1050 
1051 BIO_METHOD *KOpenSSLProxy::BIO_s_mem(void)
1052 {
1053  if (K_BIO_s_mem) {
1054  return (K_BIO_s_mem)();
1055  } else {
1056  return nullptr;
1057  }
1058 }
1059 
1060 BIO *KOpenSSLProxy::BIO_new_fp(FILE *stream, int close_flag)
1061 {
1062  if (K_BIO_new_fp) {
1063  return (K_BIO_new_fp)(stream, close_flag);
1064  }
1065  return nullptr;
1066 }
1067 
1068 BIO *KOpenSSLProxy::BIO_new_mem_buf(void *buf, int len)
1069 {
1070  if (K_BIO_new_mem_buf) {
1071  return (K_BIO_new_mem_buf)(buf, len);
1072  } else {
1073  return nullptr;
1074  }
1075 }
1076 
1077 int KOpenSSLProxy::BIO_free(BIO *a)
1078 {
1079  if (K_BIO_free) {
1080  return (K_BIO_free)(a);
1081  }
1082  return -1;
1083 }
1084 
1085 long KOpenSSLProxy::BIO_ctrl(BIO *bp, int cmd, long larg, void *parg)
1086 {
1087  if (K_BIO_ctrl) {
1088  return (K_BIO_ctrl)(bp, cmd, larg, parg);
1089  } else {
1090  return 0; // failure return for BIO_ctrl is quite individual, maybe we should abort() instead
1091  }
1092 }
1093 
1094 int KOpenSSLProxy::BIO_write(BIO *b, const void *data, int len)
1095 {
1096  if (K_BIO_write) {
1097  return (K_BIO_write)(b, data, len);
1098  } else {
1099  return -1;
1100  }
1101 }
1102 
1103 int KOpenSSLProxy::PEM_write_bio_X509(BIO *bp, X509 *x)
1104 {
1105  if (K_PEM_ASN1_write_bio) {
1106  return (K_PEM_ASN1_write_bio)((int (*)())K_i2d_X509, PEM_STRING_X509, bp, (char *)x, nullptr, nullptr, 0, nullptr, nullptr);
1107  } else {
1108  return -1;
1109  }
1110 }
1111 
1112 int KOpenSSLProxy::ASN1_item_i2d_fp(FILE *out, unsigned char *x)
1113 {
1114  if (K_ASN1_item_i2d_fp && K_NETSCAPE_X509_it) {
1115  return (K_ASN1_item_i2d_fp)(K_NETSCAPE_X509_it, out, x);
1116  } else {
1117  return -1;
1118  }
1119 }
1120 
1121 int KOpenSSLProxy::X509_print(FILE *fp, X509 *x)
1122 {
1123  if (K_X509_print_fp) {
1124  return (K_X509_print_fp)(fp, x);
1125  }
1126  return -1;
1127 }
1128 
1129 PKCS12 *KOpenSSLProxy::d2i_PKCS12_fp(FILE *fp, PKCS12 **p12)
1130 {
1131  if (K_d2i_PKCS12_fp) {
1132  return (K_d2i_PKCS12_fp)(fp, p12);
1133  } else {
1134  return nullptr;
1135  }
1136 }
1137 
1138 int KOpenSSLProxy::PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass)
1139 {
1140  if (K_PKCS12_newpass) {
1141  return (K_PKCS12_newpass)(p12, oldpass, newpass);
1142  } else {
1143  return -1;
1144  }
1145 }
1146 
1147 int KOpenSSLProxy::i2d_PKCS12(PKCS12 *p12, unsigned char **p)
1148 {
1149  if (K_i2d_PKCS12) {
1150  return (K_i2d_PKCS12)(p12, p);
1151  } else {
1152  return -1;
1153  }
1154 }
1155 
1156 int KOpenSSLProxy::i2d_PKCS12_fp(FILE *fp, PKCS12 *p12)
1157 {
1158  if (K_i2d_PKCS12_fp) {
1159  return (K_i2d_PKCS12_fp)(fp, p12);
1160  } else {
1161  return -1;
1162  }
1163 }
1164 
1165 PKCS12 *KOpenSSLProxy::PKCS12_new(void)
1166 {
1167  if (K_PKCS12_new) {
1168  return (K_PKCS12_new)();
1169  } else {
1170  return nullptr;
1171  }
1172 }
1173 
1174 void KOpenSSLProxy::PKCS12_free(PKCS12 *a)
1175 {
1176  if (K_PKCS12_free) {
1177  (K_PKCS12_free)(a);
1178  }
1179 }
1180 
1181 int KOpenSSLProxy::PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey,
1182  X509 **cert, STACK_OF(X509) **ca)
1183 {
1184  if (K_PKCS12_parse) {
1185  return (K_PKCS12_parse)(p12, pass, pkey, cert, ca);
1186  } else {
1187  return -1;
1188  }
1189 }
1190 
1191 void KOpenSSLProxy::EVP_PKEY_free(EVP_PKEY *x)
1192 {
1193  if (K_EVP_PKEY_free) {
1194  (K_EVP_PKEY_free)(x);
1195  }
1196 }
1197 
1198 EVP_PKEY *KOpenSSLProxy::EVP_PKEY_new()
1199 {
1200  if (K_EVP_PKEY_new) {
1201  return (K_EVP_PKEY_new)();
1202  } else {
1203  return nullptr;
1204  }
1205 }
1206 
1207 void KOpenSSLProxy::X509_REQ_free(X509_REQ *x)
1208 {
1209  if (K_X509_REQ_free) {
1210  (K_X509_REQ_free)(x);
1211  }
1212 }
1213 
1214 X509_REQ *KOpenSSLProxy::X509_REQ_new()
1215 {
1216  if (K_X509_REQ_new) {
1217  return (K_X509_REQ_new)();
1218  } else {
1219  return nullptr;
1220  }
1221 }
1222 
1223 int KOpenSSLProxy::SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey)
1224 {
1225  if (K_SSL_CTX_use_PrivateKey) {
1226  return (K_SSL_CTX_use_PrivateKey)(ctx, pkey);
1227  } else {
1228  return -1;
1229  }
1230 }
1231 
1232 int KOpenSSLProxy::SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x)
1233 {
1234  if (K_SSL_CTX_use_certificate) {
1235  return (K_SSL_CTX_use_certificate)(ctx, x);
1236  } else {
1237  return -1;
1238  }
1239 }
1240 
1241 int KOpenSSLProxy::SSL_get_error(SSL *ssl, int rc)
1242 {
1243  if (K_SSL_get_error) {
1244  return (K_SSL_get_error)(ssl, rc);
1245  } else {
1246  return -1;
1247  }
1248 }
1249 
1250 STACK_OF(X509) *KOpenSSLProxy::SSL_get_peer_cert_chain(SSL *s)
1251 {
1252  if (K_SSL_get_peer_cert_chain) {
1253  return (K_SSL_get_peer_cert_chain)(s);
1254  } else {
1255  return nullptr;
1256  }
1257 }
1258 
1259 void KOpenSSLProxy::sk_free(STACK *s)
1260 {
1261  if (K_sk_free) {
1262  (K_sk_free)(s);
1263  }
1264 }
1265 
1266 int KOpenSSLProxy::sk_num(STACK *s)
1267 {
1268  if (K_sk_num) {
1269  return (K_sk_num)(s);
1270  } else {
1271  return -1;
1272  }
1273 }
1274 
1275 char *KOpenSSLProxy::sk_pop(STACK *s)
1276 {
1277  if (K_sk_pop) {
1278  return (K_sk_pop)(s);
1279  } else {
1280  return nullptr;
1281  }
1282 }
1283 
1284 char *KOpenSSLProxy::sk_value(STACK *s, int n)
1285 {
1286  if (K_sk_value) {
1287  return (K_sk_value)(s, n);
1288  } else {
1289  return nullptr;
1290  }
1291 }
1292 
1293 void KOpenSSLProxy::X509_STORE_CTX_set_chain(X509_STORE_CTX *v, STACK_OF(X509)* x)
1294 {
1295  if (K_X509_STORE_CTX_set_chain) {
1296  (K_X509_STORE_CTX_set_chain)(v, x);
1297  }
1298 }
1299 
1300 void KOpenSSLProxy::X509_STORE_CTX_set_purpose(X509_STORE_CTX *v, int purpose)
1301 {
1302  if (K_X509_STORE_CTX_set_purpose) {
1303  (K_X509_STORE_CTX_set_purpose)(v, purpose);
1304  }
1305 }
1306 
1307 STACK *KOpenSSLProxy::sk_dup(STACK *s)
1308 {
1309  if (K_sk_dup) {
1310  return (K_sk_dup)(s);
1311  } else {
1312  return nullptr;
1313  }
1314 }
1315 
1316 STACK *KOpenSSLProxy::sk_new(int (*cmp)())
1317 {
1318  if (K_sk_new) {
1319  return (K_sk_new)(cmp);
1320  } else {
1321  return nullptr;
1322  }
1323 }
1324 
1325 int KOpenSSLProxy::sk_push(STACK *s, char *d)
1326 {
1327  if (K_sk_push) {
1328  return (K_sk_push)(s, d);
1329  } else {
1330  return -1;
1331  }
1332 }
1333 
1334 char *KOpenSSLProxy::i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint)
1335 {
1336  if (K_i2s_ASN1_INTEGER) {
1337  return (K_i2s_ASN1_INTEGER)(meth, aint);
1338  } else {
1339  return nullptr;
1340  }
1341 }
1342 
1343 ASN1_INTEGER *KOpenSSLProxy::X509_get_serialNumber(X509 *x)
1344 {
1345  if (K_X509_get_serialNumber) {
1346  return (K_X509_get_serialNumber)(x);
1347  } else {
1348  return nullptr;
1349  }
1350 }
1351 
1352 EVP_PKEY *KOpenSSLProxy::X509_get_pubkey(X509 *x)
1353 {
1354  if (K_X509_get_pubkey) {
1355  return (K_X509_get_pubkey)(x);
1356  } else {
1357  return nullptr;
1358  }
1359 }
1360 
1361 int KOpenSSLProxy::i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
1362 {
1363  if (K_i2d_PublicKey) {
1364  return (K_i2d_PublicKey)(a, pp);
1365  } else {
1366  return 0;
1367  }
1368 }
1369 
1370 int KOpenSSLProxy::X509_check_private_key(X509 *x, EVP_PKEY *p)
1371 {
1372  if (K_X509_check_private_key) {
1373  return (K_X509_check_private_key)(x, p);
1374  }
1375  return -1;
1376 }
1377 
1378 char *KOpenSSLProxy::BN_bn2hex(const BIGNUM *a)
1379 {
1380  if (K_BN_bn2hex) {
1381  return (K_BN_bn2hex)(a);
1382  } else {
1383  return nullptr;
1384  }
1385 }
1386 
1387 int KOpenSSLProxy::X509_digest(const X509 *x, const EVP_MD *t, unsigned char *md, unsigned int *len)
1388 {
1389  if (K_X509_digest) {
1390  return (K_X509_digest)(x, t, md, len);
1391  } else {
1392  return -1;
1393  }
1394 }
1395 
1396 EVP_MD *KOpenSSLProxy::EVP_md5()
1397 {
1398  if (K_EVP_md5) {
1399  return (K_EVP_md5)();
1400  }
1401  return nullptr;
1402 }
1403 
1404 void KOpenSSLProxy::ASN1_INTEGER_free(ASN1_INTEGER *a)
1405 {
1406  if (K_ASN1_INTEGER_free) {
1407  (K_ASN1_INTEGER_free)(a);
1408  }
1409 }
1410 
1411 int KOpenSSLProxy::OBJ_obj2nid(ASN1_OBJECT *o)
1412 {
1413  if (K_OBJ_obj2nid) {
1414  return (K_OBJ_obj2nid)(o);
1415  } else {
1416  return -1;
1417  }
1418 }
1419 
1420 const char *KOpenSSLProxy::OBJ_nid2ln(int n)
1421 {
1422  if (K_OBJ_nid2ln) {
1423  return (K_OBJ_nid2ln)(n);
1424  } else {
1425  return nullptr;
1426  }
1427 }
1428 
1429 int KOpenSSLProxy::X509_get_ext_count(X509 *x)
1430 {
1431  if (K_X509_get_ext_count) {
1432  return (K_X509_get_ext_count)(x);
1433  } else {
1434  return -1;
1435  }
1436 }
1437 
1438 int KOpenSSLProxy::X509_get_ext_by_NID(X509 *x, int nid, int lastpos)
1439 {
1440  if (K_X509_get_ext_by_NID) {
1441  return (K_X509_get_ext_by_NID)(x, nid, lastpos);
1442  } else {
1443  return -1;
1444  }
1445 }
1446 
1447 int KOpenSSLProxy::X509_get_ext_by_OBJ(X509 *x, ASN1_OBJECT *obj, int lastpos)
1448 {
1449  if (K_X509_get_ext_by_OBJ) {
1450  return (K_X509_get_ext_by_OBJ)(x, obj, lastpos);
1451  } else {
1452  return -1;
1453  }
1454 }
1455 
1456 X509_EXTENSION *KOpenSSLProxy::X509_get_ext(X509 *x, int loc)
1457 {
1458  if (K_X509_get_ext) {
1459  return (K_X509_get_ext)(x, loc);
1460  } else {
1461  return nullptr;
1462  }
1463 }
1464 
1465 X509_EXTENSION *KOpenSSLProxy::X509_delete_ext(X509 *x, int loc)
1466 {
1467  if (K_X509_delete_ext) {
1468  return (K_X509_delete_ext)(x, loc);
1469  } else {
1470  return nullptr;
1471  }
1472 }
1473 
1474 int KOpenSSLProxy::X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc)
1475 {
1476  if (K_X509_add_ext) {
1477  return (K_X509_add_ext)(x, ex, loc);
1478  } else {
1479  return -1;
1480  }
1481 }
1482 
1483 void *KOpenSSLProxy::X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx)
1484 {
1485  if (K_X509_get_ext_d2i) {
1486  return (K_X509_get_ext_d2i)(x, nid, crit, idx);
1487  } else {
1488  return nullptr;
1489  }
1490 }
1491 
1492 char *KOpenSSLProxy::i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *ia5)
1493 {
1494  if (K_i2s_ASN1_OCTET_STRING) {
1495  return (K_i2s_ASN1_OCTET_STRING)(method, ia5);
1496  } else {
1497  return nullptr;
1498  }
1499 }
1500 
1501 int KOpenSSLProxy::ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
1502 {
1503  if (K_ASN1_BIT_STRING_get_bit) {
1504  return (K_ASN1_BIT_STRING_get_bit)(a, n);
1505  } else {
1506  return -1;
1507  }
1508 }
1509 
1510 PKCS7 *KOpenSSLProxy::PKCS7_new(void)
1511 {
1512  if (K_PKCS7_new) {
1513  return (K_PKCS7_new)();
1514  } else {
1515  return nullptr;
1516  }
1517 }
1518 
1519 void KOpenSSLProxy::PKCS7_free(PKCS7 *a)
1520 {
1521  if (K_PKCS7_free) {
1522  (K_PKCS7_free)(a);
1523  }
1524 }
1525 
1526 void KOpenSSLProxy::PKCS7_content_free(PKCS7 *a)
1527 {
1528  if (K_PKCS7_content_free) {
1529  (K_PKCS7_content_free)(a);
1530  }
1531 }
1532 
1533 int KOpenSSLProxy::i2d_PKCS7(PKCS7 *a, unsigned char **pp)
1534 {
1535  if (K_i2d_PKCS7) {
1536  return (K_i2d_PKCS7)(a, pp);
1537  } else {
1538  return -1;
1539  }
1540 }
1541 
1542 PKCS7 *KOpenSSLProxy::d2i_PKCS7(PKCS7 **a, unsigned char **pp, long length)
1543 {
1544  if (K_d2i_PKCS7) {
1545  return (K_d2i_PKCS7)(a, pp, length);
1546  } else {
1547  return nullptr;
1548  }
1549 }
1550 
1551 int KOpenSSLProxy::i2d_PKCS7_fp(FILE *fp, PKCS7 *p7)
1552 {
1553  if (K_i2d_PKCS7_fp) {
1554  return (K_i2d_PKCS7_fp)(fp, p7);
1555  } else {
1556  return -1;
1557  }
1558 }
1559 
1560 PKCS7 *KOpenSSLProxy::d2i_PKCS7_fp(FILE *fp, PKCS7 **p7)
1561 {
1562  if (K_d2i_PKCS7_fp) {
1563  return (K_d2i_PKCS7_fp)(fp, p7);
1564  } else {
1565  return nullptr;
1566  }
1567 }
1568 
1569 int KOpenSSLProxy::i2d_PKCS7_bio(BIO *bp, PKCS7 *p7)
1570 {
1571  if (K_i2d_PKCS7_bio) {
1572  return (K_i2d_PKCS7_bio)(bp, p7);
1573  } else {
1574  return -1;
1575  }
1576 }
1577 
1578 PKCS7 *KOpenSSLProxy::d2i_PKCS7_bio(BIO *bp, PKCS7 **p7)
1579 {
1580  if (K_d2i_PKCS7_bio) {
1581  return (K_d2i_PKCS7_bio)(bp, p7);
1582  } else {
1583  return nullptr;
1584  }
1585 }
1586 
1587 PKCS7 *KOpenSSLProxy::PKCS7_dup(PKCS7 *p7)
1588 {
1589  if (K_PKCS7_dup) {
1590  return (K_PKCS7_dup)(p7);
1591  } else {
1592  return nullptr;
1593  }
1594 }
1595 
1596 PKCS7 *KOpenSSLProxy::PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
1597  BIO *data, int flags)
1598 {
1599  if (K_PKCS7_sign) {
1600  return (K_PKCS7_sign)(signcert, pkey, certs, data, flags);
1601  } else {
1602  return nullptr;
1603  }
1604 }
1605 
1606 int KOpenSSLProxy::PKCS7_verify(PKCS7 *p, STACK_OF(X509)* st, X509_STORE *s, BIO *in, BIO *out, int flags)
1607 {
1608  if (K_PKCS7_verify) {
1609  return (K_PKCS7_verify)(p, st, s, in, out, flags);
1610  } else {
1611  return 0;
1612  }
1613 }
1614 
1615 STACK_OF(X509) *KOpenSSLProxy::PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
1616 {
1617  if (K_PKCS7_get0_signers) {
1618  return (K_PKCS7_get0_signers)(p7, certs, flags);
1619  } else {
1620  return nullptr;
1621  }
1622 }
1623 
1624 PKCS7 *KOpenSSLProxy::PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, EVP_CIPHER *cipher,
1625  int flags)
1626 {
1627  if (K_PKCS7_encrypt) {
1628  return (K_PKCS7_encrypt)(certs, in, cipher, flags);
1629  } else {
1630  return nullptr;
1631  }
1632 }
1633 
1634 int KOpenSSLProxy::PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags)
1635 {
1636  if (K_PKCS7_decrypt) {
1637  return (K_PKCS7_decrypt)(p7, pkey, cert, data, flags);
1638  } else {
1639  return 0;
1640  }
1641 }
1642 
1643 STACK_OF(X509_NAME) *KOpenSSLProxy::SSL_load_client_CA_file(const char *file)
1644 {
1645  if (K_SSL_load_client_CA_file) {
1646  return (K_SSL_load_client_CA_file)(file);
1647  } else {
1648  return nullptr;
1649  }
1650 }
1651 
1652 STACK_OF(X509_INFO) *KOpenSSLProxy::PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
1653 {
1654  if (K_PEM_X509_INFO_read) {
1655  return (K_PEM_X509_INFO_read)(fp, sk, cb, u);
1656  } else {
1657  return nullptr;
1658  }
1659 }
1660 
1661 X509 *KOpenSSLProxy::X509_d2i_fp(FILE *out, X509 **buf)
1662 {
1663  if (K_ASN1_d2i_fp) {
1664  return reinterpret_cast<X509 *>((K_ASN1_d2i_fp)(reinterpret_cast<char *(*)()>(K_X509_new), reinterpret_cast<char *(*)()>(K_d2i_X509), out, reinterpret_cast<unsigned char **>(buf)));
1665  } else {
1666  return nullptr;
1667  }
1668 }
1669 
1670 int KOpenSSLProxy::SSL_peek(SSL *ssl, void *buf, int num)
1671 {
1672  if (K_SSL_peek) {
1673  return (K_SSL_peek)(ssl, buf, num);
1674  } else {
1675  return -1;
1676  }
1677 }
1678 
1679 const char *KOpenSSLProxy::RAND_file_name(char *buf, size_t num)
1680 {
1681  if (K_RAND_file_name) {
1682  return (K_RAND_file_name)(buf, num);
1683  } else {
1684  return nullptr;
1685  }
1686 }
1687 
1688 int KOpenSSLProxy::RAND_load_file(const char *filename, long max_bytes)
1689 {
1690  if (K_RAND_load_file) {
1691  return (K_RAND_load_file)(filename, max_bytes);
1692  } else {
1693  return -1;
1694  }
1695 }
1696 
1697 int KOpenSSLProxy::RAND_write_file(const char *filename)
1698 {
1699  if (K_RAND_write_file) {
1700  return (K_RAND_write_file)(filename);
1701  } else {
1702  return -1;
1703  }
1704 }
1705 
1706 int KOpenSSLProxy::X509_PURPOSE_get_count()
1707 {
1708  if (K_X509_PURPOSE_get_count) {
1709  return (K_X509_PURPOSE_get_count)();
1710  } else {
1711  return -1;
1712  }
1713 }
1714 
1715 int KOpenSSLProxy::X509_PURPOSE_get_id(X509_PURPOSE *p)
1716 {
1717  if (K_X509_PURPOSE_get_id) {
1718  return (K_X509_PURPOSE_get_id)(p);
1719  } else {
1720  return -1;
1721  }
1722 }
1723 
1724 int KOpenSSLProxy::X509_check_purpose(X509 *x, int id, int ca)
1725 {
1726  if (K_X509_check_purpose) {
1727  return (K_X509_check_purpose)(x, id, ca);
1728  } else {
1729  return -1;
1730  }
1731 }
1732 
1733 X509_PURPOSE *KOpenSSLProxy::X509_PURPOSE_get0(int idx)
1734 {
1735  if (K_X509_PURPOSE_get0) {
1736  return (K_X509_PURPOSE_get0)(idx);
1737  } else {
1738  return nullptr;
1739  }
1740 }
1741 
1742 int KOpenSSLProxy::EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
1743 {
1744  if (K_EVP_PKEY_assign) {
1745  return (K_EVP_PKEY_assign)(pkey, type, key);
1746  } else {
1747  return -1;
1748  }
1749 }
1750 
1751 int KOpenSSLProxy::X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey)
1752 {
1753  if (K_X509_REQ_set_pubkey) {
1754  return (K_X509_REQ_set_pubkey)(x, pkey);
1755  } else {
1756  return -1;
1757  }
1758 }
1759 
1760 RSA *KOpenSSLProxy::RSA_generate_key(int bits, unsigned long e, void
1761  (*callback)(int, int, void *), void *cb_arg)
1762 {
1763  if (K_RSA_generate_key) {
1764  return (K_RSA_generate_key)(bits, e, callback, cb_arg);
1765  } else {
1766  return nullptr;
1767  }
1768 }
1769 
1770 STACK *KOpenSSLProxy::X509_get1_email(X509 *x)
1771 {
1772  if (K_X509_get1_email) {
1773  return (K_X509_get1_email)(x);
1774  } else {
1775  return nullptr;
1776  }
1777 }
1778 
1779 void KOpenSSLProxy::X509_email_free(STACK *sk)
1780 {
1781  if (K_X509_email_free) {
1782  (K_X509_email_free)(sk);
1783  }
1784 }
1785 
1786 EVP_CIPHER *KOpenSSLProxy::EVP_des_ede3_cbc()
1787 {
1788  if (K_EVP_des_ede3_cbc) {
1789  return (K_EVP_des_ede3_cbc)();
1790  } else {
1791  return nullptr;
1792  }
1793 }
1794 
1795 EVP_CIPHER *KOpenSSLProxy::EVP_des_cbc()
1796 {
1797  if (K_EVP_des_cbc) {
1798  return (K_EVP_des_cbc)();
1799  } else {
1800  return nullptr;
1801  }
1802 }
1803 
1804 EVP_CIPHER *KOpenSSLProxy::EVP_rc2_cbc()
1805 {
1806  if (K_EVP_rc2_cbc) {
1807  return (K_EVP_rc2_cbc)();
1808  } else {
1809  return nullptr;
1810  }
1811 }
1812 
1813 EVP_CIPHER *KOpenSSLProxy::EVP_rc2_64_cbc()
1814 {
1815  if (K_EVP_rc2_64_cbc) {
1816  return (K_EVP_rc2_64_cbc)();
1817  } else {
1818  return nullptr;
1819  }
1820 }
1821 
1822 EVP_CIPHER *KOpenSSLProxy::EVP_rc2_40_cbc()
1823 {
1824  if (K_EVP_rc2_40_cbc) {
1825  return (K_EVP_rc2_40_cbc)();
1826  } else {
1827  return nullptr;
1828  }
1829 }
1830 
1831 int KOpenSSLProxy::i2d_X509_REQ_fp(FILE *fp, X509_REQ *x)
1832 {
1833  if (K_i2d_X509_REQ_fp) {
1834  return (K_i2d_X509_REQ_fp)(fp, x);
1835  } else {
1836  return -1;
1837  }
1838 }
1839 
1840 void KOpenSSLProxy::ERR_clear_error()
1841 {
1842  if (K_ERR_clear_error) {
1843  (K_ERR_clear_error)();
1844  }
1845 }
1846 
1847 unsigned long KOpenSSLProxy::ERR_get_error()
1848 {
1849  if (K_ERR_get_error) {
1850  return (K_ERR_get_error)();
1851  } else {
1852  return 0xffffffff;
1853  }
1854 }
1855 
1856 void KOpenSSLProxy::ERR_print_errors_fp(FILE *fp)
1857 {
1858  if (K_ERR_print_errors_fp) {
1859  (K_ERR_print_errors_fp)(fp);
1860  }
1861 }
1862 
1863 SSL_SESSION *KOpenSSLProxy::SSL_get1_session(SSL *ssl)
1864 {
1865  if (K_SSL_get1_session) {
1866  return (K_SSL_get1_session)(ssl);
1867  } else {
1868  return nullptr;
1869  }
1870 }
1871 
1872 void KOpenSSLProxy::SSL_SESSION_free(SSL_SESSION *session)
1873 {
1874  if (K_SSL_SESSION_free) {
1875  (K_SSL_SESSION_free)(session);
1876  }
1877 }
1878 
1879 int KOpenSSLProxy::SSL_set_session(SSL *ssl, SSL_SESSION *session)
1880 {
1881  if (K_SSL_set_session) {
1882  return (K_SSL_set_session)(ssl, session);
1883  } else {
1884  return -1;
1885  }
1886 }
1887 
1888 SSL_SESSION *KOpenSSLProxy::d2i_SSL_SESSION(SSL_SESSION **a, unsigned char **pp, long length)
1889 {
1890  if (K_d2i_SSL_SESSION) {
1891  return (K_d2i_SSL_SESSION)(a, pp, length);
1892  } else {
1893  return nullptr;
1894  }
1895 }
1896 
1897 int KOpenSSLProxy::i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
1898 {
1899  if (K_i2d_SSL_SESSION) {
1900  return (K_i2d_SSL_SESSION)(in, pp);
1901  } else {
1902  return -1;
1903  }
1904 }
1905 
1906 int KOpenSSLProxy::i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *p)
1907 {
1908  if (K_i2d_PrivateKey_fp) {
1909  return (K_i2d_PrivateKey_fp)(fp, p);
1910  } else {
1911  return -1;
1912  }
1913 }
1914 
1915 int KOpenSSLProxy::i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *p, const EVP_CIPHER *c, char *k, int klen, pem_password_cb *cb, void *u)
1916 {
1917  if (K_i2d_PKCS8PrivateKey_fp) {
1918  return (K_i2d_PKCS8PrivateKey_fp)(fp, p, c, k, klen, cb, u);
1919  } else {
1920  return -1;
1921  }
1922 }
1923 
1924 void KOpenSSLProxy::RSA_free(RSA *rsa)
1925 {
1926  if (K_RSA_free) {
1927  (K_RSA_free)(rsa);
1928  }
1929 }
1930 
1931 EVP_CIPHER *KOpenSSLProxy::EVP_bf_cbc()
1932 {
1933  if (K_EVP_bf_cbc) {
1934  return (K_EVP_bf_cbc)();
1935  }
1936  return nullptr;
1937 }
1938 
1939 int KOpenSSLProxy::X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md)
1940 {
1941  if (K_X509_REQ_sign) {
1942  return (K_X509_REQ_sign)(x, pkey, md);
1943  }
1944  return -1;
1945 }
1946 
1947 int KOpenSSLProxy::X509_NAME_add_entry_by_txt(X509_NAME *name, char *field,
1948  int type, unsigned char *bytes, int len, int loc, int set)
1949 {
1950  if (K_X509_NAME_add_entry_by_txt) {
1951  return (K_X509_NAME_add_entry_by_txt)(name, field, type, bytes, len, loc, set);
1952  }
1953  return -1;
1954 }
1955 
1956 X509_NAME *KOpenSSLProxy::X509_NAME_new()
1957 {
1958  if (K_X509_NAME_new) {
1959  return (K_X509_NAME_new)();
1960  }
1961  return nullptr;
1962 }
1963 
1964 int KOpenSSLProxy::X509_REQ_set_subject_name(X509_REQ *req, X509_NAME *name)
1965 {
1966  if (K_X509_REQ_set_subject_name) {
1967  return (K_X509_REQ_set_subject_name)(req, name);
1968  }
1969  return -1;
1970 }
1971 
1972 unsigned char *KOpenSSLProxy::ASN1_STRING_data(ASN1_STRING *x)
1973 {
1974  if (K_ASN1_STRING_data) {
1975  return (K_ASN1_STRING_data)(x);
1976  }
1977  return nullptr;
1978 }
1979 
1980 int KOpenSSLProxy::ASN1_STRING_length(ASN1_STRING *x)
1981 {
1982  if (K_ASN1_STRING_length) {
1983  return (K_ASN1_STRING_length)(x);
1984  }
1985  return 0L;
1986 }
1987 
1988 STACK_OF(SSL_CIPHER) *KOpenSSLProxy::SSL_get_ciphers(const SSL *ssl)
1989 {
1990  if (K_SSL_get_ciphers) {
1991  return (K_SSL_get_ciphers)(ssl);
1992  }
1993  return nullptr;
1994 }
1995 
1996 #endif
1997 
QString readPathEntry(const QString &pKey, const QString &aDefault) const
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
bool hasLibCrypto() const
Return true of libcrypto was found and loaded.
Definition: kopenssl.cpp:222
QString & remove(int position, int n)
Dynamically load and wrap OpenSSL.
Definition: kopenssl.h:62
bool isNull() const const
bool exists() const const
int toInt(bool *ok, int base) const const
bool isEmpty() const const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
ExportExternalSymbolsHint
QList::iterator end()
QString mid(int position, int n) const const
QStringList entryList(QDir::Filters filters, QDir::SortFlags sort) const const
int length() const const
QString left(int n) const const
QList::const_iterator constEnd() const const
QList::const_iterator constBegin() const const
QList::iterator begin()
bool hasLibSSL() const
Return true of libssl was found and loaded.
Definition: kopenssl.cpp:217
static KOpenSSLProxy * self()
Return an instance of class KOpenSSLProxy * You cannot delete this object.
Definition: kopenssl.cpp:693
void destroy()
Destroy the class and start over - don&#39;t use this unless you know what you are doing.
Definition: kopenssl.cpp:227
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:06 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.