TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2124 lines
79KB

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