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.
 
 
 
 
 
 

2142 lines
80 KiB

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