Qt 4.8
qsslsocket_openssl_symbols.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 
44 
45 #ifdef Q_OS_WIN
46 # include <private/qsystemlibrary_p.h>
47 #else
48 # include <QtCore/qlibrary.h>
49 #endif
50 #include <QtCore/qmutex.h>
51 #include <private/qmutexpool_p.h>
52 #include <QtCore/qdatetime.h>
53 #if defined(Q_OS_UNIX)
54 #include <QtCore/qdir.h>
55 #endif
56 #ifdef Q_OS_LINUX
57 #include <link.h>
58 #endif
59 
61 
62 /*
63  Note to maintainer:
64  -------------------
65 
66  We load OpenSSL symbols dynamically. Because symbols are known to
67  disappear, and signatures sometimes change, between releases, we need to
68  be careful about how this is done. To ensure we don't end up dereferencing
69  null function pointers, and continue running even if certain functions are
70  missing, we define helper functions for each of the symbols we load from
71  OpenSSL, all prefixed with "q_" (declared in
72  qsslsocket_openssl_symbols_p.h). So instead of calling SSL_connect
73  directly, we call q_SSL_connect, which is a function that checks if the
74  actual SSL_connect fptr is null, and returns a failure if it is, or calls
75  SSL_connect if it isn't.
76 
77  This requires a somewhat tedious process of declaring each function we
78  want to call in OpenSSL thrice: once with the q_, in _p.h, once using the
79  DEFINEFUNC macros below, and once in the function that actually resolves
80  the symbols, below the DEFINEFUNC declarations below.
81 
82  There's one DEFINEFUNC macro declared for every number of arguments
83  exposed by OpenSSL (feel free to extend when needed). The easiest thing to
84  do is to find an existing entry that matches the arg count of the function
85  you want to import, and do the same.
86 
87  The first macro arg is the function return type. The second is the
88  verbatim name of the function/symbol. Then follows a list of N pairs of
89  argument types with a variable name, and just the variable name (char *a,
90  a, char *b, b, etc). Finally there's two arguments - a suitable return
91  statement for the error case (for an int function, return 0 or return -1
92  is usually right). Then either just "return" or DUMMYARG, the latter being
93  for void functions.
94 
95  Note: Take into account that these macros and declarations are processed
96  at compile-time, and the result depends on the OpenSSL headers the
97  compiling host has installed, but the symbols are resolved at run-time,
98  possibly with a different version of OpenSSL.
99 */
100 
101 #ifdef SSLEAY_MACROS
102 DEFINEFUNC3(void *, ASN1_dup, i2d_of_void *a, a, d2i_of_void *b, b, char *c, c, return 0, return)
103 #endif
104 DEFINEFUNC(long, ASN1_INTEGER_get, ASN1_INTEGER *a, a, return 0, return)
105 DEFINEFUNC(unsigned char *, ASN1_STRING_data, ASN1_STRING *a, a, return 0, return)
106 DEFINEFUNC(int, ASN1_STRING_length, ASN1_STRING *a, a, return 0, return)
107 DEFINEFUNC2(int, ASN1_STRING_to_UTF8, unsigned char **a, a, ASN1_STRING *b, b, return 0, return);
108 DEFINEFUNC4(long, BIO_ctrl, BIO *a, a, int b, b, long c, c, void *d, d, return -1, return)
109 DEFINEFUNC(int, BIO_free, BIO *a, a, return 0, return)
110 DEFINEFUNC(BIO *, BIO_new, BIO_METHOD *a, a, return 0, return)
111 DEFINEFUNC2(BIO *, BIO_new_mem_buf, void *a, a, int b, b, return 0, return)
112 DEFINEFUNC3(int, BIO_read, BIO *a, a, void *b, b, int c, c, return -1, return)
113 DEFINEFUNC(BIO_METHOD *, BIO_s_mem, void, DUMMYARG, return 0, return)
114 DEFINEFUNC3(int, BIO_write, BIO *a, a, const void *b, b, int c, c, return -1, return)
115 DEFINEFUNC(int, BN_num_bits, const BIGNUM *a, a, return 0, return)
116 DEFINEFUNC(int, CRYPTO_num_locks, DUMMYARG, DUMMYARG, return 0, return)
117 DEFINEFUNC(void, CRYPTO_set_locking_callback, void (*a)(int, int, const char *, int), a, return, DUMMYARG)
118 DEFINEFUNC(void, CRYPTO_set_id_callback, unsigned long (*a)(), a, return, DUMMYARG)
119 DEFINEFUNC(void, CRYPTO_free, void *a, a, return, DUMMYARG)
120 DEFINEFUNC(void, DSA_free, DSA *a, a, return, DUMMYARG)
121 #if OPENSSL_VERSION_NUMBER < 0x00908000L
122 DEFINEFUNC3(X509 *, d2i_X509, X509 **a, a, unsigned char **b, b, long c, c, return 0, return)
123 #else // 0.9.8 broke SC and BC by changing this signature.
124 DEFINEFUNC3(X509 *, d2i_X509, X509 **a, a, const unsigned char **b, b, long c, c, return 0, return)
125 #endif
126 DEFINEFUNC2(char *, ERR_error_string, unsigned long a, a, char *b, b, return 0, return)
127 DEFINEFUNC(unsigned long, ERR_get_error, DUMMYARG, DUMMYARG, return 0, return)
128 DEFINEFUNC(const EVP_CIPHER *, EVP_des_ede3_cbc, DUMMYARG, DUMMYARG, return 0, return)
129 DEFINEFUNC3(int, EVP_PKEY_assign, EVP_PKEY *a, a, int b, b, char *c, c, return -1, return)
130 DEFINEFUNC2(int, EVP_PKEY_set1_RSA, EVP_PKEY *a, a, RSA *b, b, return -1, return)
131 DEFINEFUNC2(int, EVP_PKEY_set1_DSA, EVP_PKEY *a, a, DSA *b, b, return -1, return)
132 DEFINEFUNC(void, EVP_PKEY_free, EVP_PKEY *a, a, return, DUMMYARG)
133 DEFINEFUNC(DSA *, EVP_PKEY_get1_DSA, EVP_PKEY *a, a, return 0, return)
134 DEFINEFUNC(RSA *, EVP_PKEY_get1_RSA, EVP_PKEY *a, a, return 0, return)
135 DEFINEFUNC(EVP_PKEY *, EVP_PKEY_new, DUMMYARG, DUMMYARG, return 0, return)
136 DEFINEFUNC(int, EVP_PKEY_type, int a, a, return NID_undef, return)
137 DEFINEFUNC2(int, i2d_X509, X509 *a, a, unsigned char **b, b, return -1, return)
138 DEFINEFUNC(const char *, OBJ_nid2sn, int a, a, return 0, return)
139 DEFINEFUNC(int, OBJ_obj2nid, const ASN1_OBJECT *a, a, return NID_undef, return)
140 #ifdef SSLEAY_MACROS
141 DEFINEFUNC6(void *, PEM_ASN1_read_bio, d2i_of_void *a, a, const char *b, b, BIO *c, c, void **d, d, pem_password_cb *e, e, void *f, f, return 0, return)
142 DEFINEFUNC6(void *, PEM_ASN1_write_bio, d2i_of_void *a, a, const char *b, b, BIO *c, c, void **d, d, pem_password_cb *e, e, void *f, f, return 0, return)
143 #else
144 DEFINEFUNC4(DSA *, PEM_read_bio_DSAPrivateKey, BIO *a, a, DSA **b, b, pem_password_cb *c, c, void *d, d, return 0, return)
145 DEFINEFUNC4(RSA *, PEM_read_bio_RSAPrivateKey, BIO *a, a, RSA **b, b, pem_password_cb *c, c, void *d, d, return 0, return)
146 DEFINEFUNC7(int, PEM_write_bio_DSAPrivateKey, BIO *a, a, DSA *b, b, const EVP_CIPHER *c, c, unsigned char *d, d, int e, e, pem_password_cb *f, f, void *g, g, return 0, return)
147 DEFINEFUNC7(int, PEM_write_bio_RSAPrivateKey, BIO *a, a, RSA *b, b, const EVP_CIPHER *c, c, unsigned char *d, d, int e, e, pem_password_cb *f, f, void *g, g, return 0, return)
148 #endif
149 DEFINEFUNC4(DSA *, PEM_read_bio_DSA_PUBKEY, BIO *a, a, DSA **b, b, pem_password_cb *c, c, void *d, d, return 0, return)
150 DEFINEFUNC4(RSA *, PEM_read_bio_RSA_PUBKEY, BIO *a, a, RSA **b, b, pem_password_cb *c, c, void *d, d, return 0, return)
151 DEFINEFUNC2(int, PEM_write_bio_DSA_PUBKEY, BIO *a, a, DSA *b, b, return 0, return)
152 DEFINEFUNC2(int, PEM_write_bio_RSA_PUBKEY, BIO *a, a, RSA *b, b, return 0, return)
153 DEFINEFUNC2(void, RAND_seed, const void *a, a, int b, b, return, DUMMYARG)
154 DEFINEFUNC(int, RAND_status, void, DUMMYARG, return -1, return)
155 DEFINEFUNC(void, RSA_free, RSA *a, a, return, DUMMYARG)
156 DEFINEFUNC(int, sk_num, STACK *a, a, return -1, return)
157 DEFINEFUNC2(void, sk_pop_free, STACK *a, a, void (*b)(void*), b, return, DUMMYARG)
158 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
159 DEFINEFUNC(void, sk_free, _STACK *a, a, return, DUMMYARG)
160 DEFINEFUNC2(void *, sk_value, STACK *a, a, int b, b, return 0, return)
161 #else
162 DEFINEFUNC(void, sk_free, STACK *a, a, return, DUMMYARG)
163 DEFINEFUNC2(char *, sk_value, STACK *a, a, int b, b, return 0, return)
164 #endif
165 DEFINEFUNC(int, SSL_accept, SSL *a, a, return -1, return)
166 DEFINEFUNC(int, SSL_clear, SSL *a, a, return -1, return)
167 DEFINEFUNC3(char *, SSL_CIPHER_description, SSL_CIPHER *a, a, char *b, b, int c, c, return 0, return)
168 DEFINEFUNC(int, SSL_connect, SSL *a, a, return -1, return)
169 #if OPENSSL_VERSION_NUMBER >= 0x00908000L
170 // 0.9.8 broke SC and BC by changing this function's signature.
171 DEFINEFUNC(int, SSL_CTX_check_private_key, const SSL_CTX *a, a, return -1, return)
172 #else
173 DEFINEFUNC(int, SSL_CTX_check_private_key, SSL_CTX *a, a, return -1, return)
174 #endif
175 DEFINEFUNC4(long, SSL_CTX_ctrl, SSL_CTX *a, a, int b, b, long c, c, void *d, d, return -1, return)
176 DEFINEFUNC(void, SSL_CTX_free, SSL_CTX *a, a, return, DUMMYARG)
177 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
178 DEFINEFUNC(SSL_CTX *, SSL_CTX_new, const SSL_METHOD *a, a, return 0, return)
179 #else
180 DEFINEFUNC(SSL_CTX *, SSL_CTX_new, SSL_METHOD *a, a, return 0, return)
181 #endif
182 DEFINEFUNC2(int, SSL_CTX_set_cipher_list, SSL_CTX *a, a, const char *b, b, return -1, return)
183 DEFINEFUNC(int, SSL_CTX_set_default_verify_paths, SSL_CTX *a, a, return -1, return)
184 DEFINEFUNC3(void, SSL_CTX_set_verify, SSL_CTX *a, a, int b, b, int (*c)(int, X509_STORE_CTX *), c, return, DUMMYARG)
185 DEFINEFUNC2(void, SSL_CTX_set_verify_depth, SSL_CTX *a, a, int b, b, return, DUMMYARG)
186 DEFINEFUNC2(int, SSL_CTX_use_certificate, SSL_CTX *a, a, X509 *b, b, return -1, return)
187 DEFINEFUNC3(int, SSL_CTX_use_certificate_file, SSL_CTX *a, a, const char *b, b, int c, c, return -1, return)
188 DEFINEFUNC2(int, SSL_CTX_use_PrivateKey, SSL_CTX *a, a, EVP_PKEY *b, b, return -1, return)
189 DEFINEFUNC2(int, SSL_CTX_use_RSAPrivateKey, SSL_CTX *a, a, RSA *b, b, return -1, return)
190 DEFINEFUNC3(int, SSL_CTX_use_PrivateKey_file, SSL_CTX *a, a, const char *b, b, int c, c, return -1, return)
191 DEFINEFUNC(void, SSL_free, SSL *a, a, return, DUMMYARG)
192 #if OPENSSL_VERSION_NUMBER >= 0x00908000L
193 // 0.9.8 broke SC and BC by changing this function's signature.
194 DEFINEFUNC(STACK_OF(SSL_CIPHER) *, SSL_get_ciphers, const SSL *a, a, return 0, return)
195 #else
196 DEFINEFUNC(STACK_OF(SSL_CIPHER) *, SSL_get_ciphers, SSL *a, a, return 0, return)
197 #endif
198 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
199 DEFINEFUNC(const SSL_CIPHER *, SSL_get_current_cipher, SSL *a, a, return 0, return)
200 #else
201 DEFINEFUNC(SSL_CIPHER *, SSL_get_current_cipher, SSL *a, a, return 0, return)
202 #endif
203 DEFINEFUNC2(int, SSL_get_error, SSL *a, a, int b, b, return -1, return)
204 DEFINEFUNC(STACK_OF(X509) *, SSL_get_peer_cert_chain, SSL *a, a, return 0, return)
205 DEFINEFUNC(X509 *, SSL_get_peer_certificate, SSL *a, a, return 0, return)
206 #if OPENSSL_VERSION_NUMBER >= 0x00908000L
207 // 0.9.8 broke SC and BC by changing this function's signature.
208 DEFINEFUNC(long, SSL_get_verify_result, const SSL *a, a, return -1, return)
209 #else
210 DEFINEFUNC(long, SSL_get_verify_result, SSL *a, a, return -1, return)
211 #endif
212 DEFINEFUNC(int, SSL_library_init, void, DUMMYARG, return -1, return)
213 DEFINEFUNC(void, SSL_load_error_strings, void, DUMMYARG, return, DUMMYARG)
214 DEFINEFUNC(SSL *, SSL_new, SSL_CTX *a, a, return 0, return)
215 #if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT)
216 DEFINEFUNC4(long, SSL_ctrl, SSL *a, a, int cmd, cmd, long larg, larg, void *parg, parg, return -1, return)
217 #endif
218 DEFINEFUNC3(int, SSL_read, SSL *a, a, void *b, b, int c, c, return -1, return)
219 DEFINEFUNC3(void, SSL_set_bio, SSL *a, a, BIO *b, b, BIO *c, c, return, DUMMYARG)
220 DEFINEFUNC(void, SSL_set_accept_state, SSL *a, a, return, DUMMYARG)
221 DEFINEFUNC(void, SSL_set_connect_state, SSL *a, a, return, DUMMYARG)
222 DEFINEFUNC(int, SSL_shutdown, SSL *a, a, return -1, return)
223 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
224 #ifndef OPENSSL_NO_SSL2
225 DEFINEFUNC(const SSL_METHOD *, SSLv2_client_method, DUMMYARG, DUMMYARG, return 0, return)
226 #endif
227 DEFINEFUNC(const SSL_METHOD *, SSLv3_client_method, DUMMYARG, DUMMYARG, return 0, return)
228 DEFINEFUNC(const SSL_METHOD *, SSLv23_client_method, DUMMYARG, DUMMYARG, return 0, return)
229 DEFINEFUNC(const SSL_METHOD *, TLSv1_client_method, DUMMYARG, DUMMYARG, return 0, return)
230 #ifndef OPENSSL_NO_SSL2
231 DEFINEFUNC(const SSL_METHOD *, SSLv2_server_method, DUMMYARG, DUMMYARG, return 0, return)
232 #endif
233 DEFINEFUNC(const SSL_METHOD *, SSLv3_server_method, DUMMYARG, DUMMYARG, return 0, return)
234 DEFINEFUNC(const SSL_METHOD *, SSLv23_server_method, DUMMYARG, DUMMYARG, return 0, return)
235 DEFINEFUNC(const SSL_METHOD *, TLSv1_server_method, DUMMYARG, DUMMYARG, return 0, return)
236 #else
237 DEFINEFUNC(SSL_METHOD *, SSLv2_client_method, DUMMYARG, DUMMYARG, return 0, return)
238 DEFINEFUNC(SSL_METHOD *, SSLv3_client_method, DUMMYARG, DUMMYARG, return 0, return)
239 DEFINEFUNC(SSL_METHOD *, SSLv23_client_method, DUMMYARG, DUMMYARG, return 0, return)
240 DEFINEFUNC(SSL_METHOD *, TLSv1_client_method, DUMMYARG, DUMMYARG, return 0, return)
241 DEFINEFUNC(SSL_METHOD *, SSLv2_server_method, DUMMYARG, DUMMYARG, return 0, return)
242 DEFINEFUNC(SSL_METHOD *, SSLv3_server_method, DUMMYARG, DUMMYARG, return 0, return)
243 DEFINEFUNC(SSL_METHOD *, SSLv23_server_method, DUMMYARG, DUMMYARG, return 0, return)
244 DEFINEFUNC(SSL_METHOD *, TLSv1_server_method, DUMMYARG, DUMMYARG, return 0, return)
245 #endif
246 DEFINEFUNC3(int, SSL_write, SSL *a, a, const void *b, b, int c, c, return -1, return)
247 DEFINEFUNC2(int, X509_cmp, X509 *a, a, X509 *b, b, return -1, return)
248 #ifndef SSLEAY_MACROS
249 DEFINEFUNC(X509 *, X509_dup, X509 *a, a, return 0, return)
250 #endif
251 DEFINEFUNC(ASN1_OBJECT *, X509_EXTENSION_get_object, X509_EXTENSION *a, a, return 0, return)
252 DEFINEFUNC(void, X509_free, X509 *a, a, return, DUMMYARG)
253 DEFINEFUNC2(X509_EXTENSION *, X509_get_ext, X509 *a, a, int b, b, return 0, return)
254 DEFINEFUNC(int, X509_get_ext_count, X509 *a, a, return 0, return)
255 DEFINEFUNC4(void *, X509_get_ext_d2i, X509 *a, a, int b, b, int *c, c, int *d, d, return 0, return)
256 DEFINEFUNC(X509_NAME *, X509_get_issuer_name, X509 *a, a, return 0, return)
257 DEFINEFUNC(X509_NAME *, X509_get_subject_name, X509 *a, a, return 0, return)
258 DEFINEFUNC(int, X509_verify_cert, X509_STORE_CTX *a, a, return -1, return)
259 DEFINEFUNC(int, X509_NAME_entry_count, X509_NAME *a, a, return 0, return)
260 DEFINEFUNC2(X509_NAME_ENTRY *, X509_NAME_get_entry, X509_NAME *a, a, int b, b, return 0, return)
261 DEFINEFUNC(ASN1_STRING *, X509_NAME_ENTRY_get_data, X509_NAME_ENTRY *a, a, return 0, return)
262 DEFINEFUNC(ASN1_OBJECT *, X509_NAME_ENTRY_get_object, X509_NAME_ENTRY *a, a, return 0, return)
263 DEFINEFUNC(EVP_PKEY *, X509_PUBKEY_get, X509_PUBKEY *a, a, return 0, return)
264 DEFINEFUNC(void, X509_STORE_free, X509_STORE *a, a, return, DUMMYARG)
265 DEFINEFUNC(X509_STORE *, X509_STORE_new, DUMMYARG, DUMMYARG, return 0, return)
266 DEFINEFUNC2(int, X509_STORE_add_cert, X509_STORE *a, a, X509 *b, b, return 0, return)
267 DEFINEFUNC(void, X509_STORE_CTX_free, X509_STORE_CTX *a, a, return, DUMMYARG)
268 DEFINEFUNC4(int, X509_STORE_CTX_init, X509_STORE_CTX *a, a, X509_STORE *b, b, X509 *c, c, STACK_OF(X509) *d, d, return -1, return)
269 DEFINEFUNC2(int, X509_STORE_CTX_set_purpose, X509_STORE_CTX *a, a, int b, b, return -1, return)
270 DEFINEFUNC(int, X509_STORE_CTX_get_error, X509_STORE_CTX *a, a, return -1, return)
271 DEFINEFUNC(int, X509_STORE_CTX_get_error_depth, X509_STORE_CTX *a, a, return -1, return)
272 DEFINEFUNC(X509 *, X509_STORE_CTX_get_current_cert, X509_STORE_CTX *a, a, return 0, return)
273 DEFINEFUNC(STACK_OF(X509) *, X509_STORE_CTX_get_chain, X509_STORE_CTX *a, a, return 0, return)
274 DEFINEFUNC(X509_STORE_CTX *, X509_STORE_CTX_new, DUMMYARG, DUMMYARG, return 0, return)
275 #ifdef SSLEAY_MACROS
276 DEFINEFUNC2(int, i2d_DSAPrivateKey, const DSA *a, a, unsigned char **b, b, return -1, return)
277 DEFINEFUNC2(int, i2d_RSAPrivateKey, const RSA *a, a, unsigned char **b, b, return -1, return)
278 DEFINEFUNC3(RSA *, d2i_RSAPrivateKey, RSA **a, a, unsigned char **b, b, long c, c, return 0, return)
279 DEFINEFUNC3(DSA *, d2i_DSAPrivateKey, DSA **a, a, unsigned char **b, b, long c, c, return 0, return)
280 #endif
281 DEFINEFUNC(void, OPENSSL_add_all_algorithms_noconf, void, DUMMYARG, return, DUMMYARG)
282 DEFINEFUNC(void, OPENSSL_add_all_algorithms_conf, void, DUMMYARG, return, DUMMYARG)
283 DEFINEFUNC3(int, SSL_CTX_load_verify_locations, SSL_CTX *ctx, ctx, const char *CAfile, CAfile, const char *CApath, CApath, return 0, return)
284 DEFINEFUNC(long, SSLeay, void, DUMMYARG, return 0, return)
285 
286 #ifdef Q_OS_SYMBIAN
287 #define RESOLVEFUNC(func, ordinal, lib) \
288  if (!(_q_##func = _q_PTR_##func(lib->resolve(#ordinal)))) \
289  qWarning("QSslSocket: cannot resolve "#func);
290 #else
291 #define RESOLVEFUNC(func) \
292  if (!(_q_##func = _q_PTR_##func(libs.first->resolve(#func))) \
293  && !(_q_##func = _q_PTR_##func(libs.second->resolve(#func)))) \
294  qWarning("QSslSocket: cannot resolve "#func);
295 #endif
296 
297 #if !defined QT_LINKED_OPENSSL
298 
299 #ifdef QT_NO_LIBRARY
301 {
302  qWarning("QSslSocket: unable to resolve symbols. "
303  "QT_NO_LIBRARY is defined which means runtime resolving of "
304  "libraries won't work.");
305  qWarning("Either compile Qt statically or with support for runtime resolving "
306  "of libraries.");
307  return false;
308 }
309 #else
310 
311 # ifdef Q_OS_UNIX
312 static bool libGreaterThan(const QString &lhs, const QString &rhs)
313 {
314  QStringList lhsparts = lhs.split(QLatin1Char('.'));
315  QStringList rhsparts = rhs.split(QLatin1Char('.'));
316  Q_ASSERT(lhsparts.count() > 1 && rhsparts.count() > 1);
317 
318  for (int i = 1; i < rhsparts.count(); ++i) {
319  if (lhsparts.count() <= i)
320  // left hand side is shorter, so it's less than rhs
321  return false;
322 
323  bool ok = false;
324  int b = 0;
325  int a = lhsparts.at(i).toInt(&ok);
326  if (ok)
327  b = rhsparts.at(i).toInt(&ok);
328  if (ok) {
329  // both toInt succeeded
330  if (a == b)
331  continue;
332  return a > b;
333  } else {
334  // compare as strings;
335  if (lhsparts.at(i) == rhsparts.at(i))
336  continue;
337  return lhsparts.at(i) > rhsparts.at(i);
338  }
339  }
340 
341  // they compared strictly equally so far
342  // lhs cannot be less than rhs
343  return true;
344 }
345 
346 #ifdef Q_OS_LINUX
347 static int dlIterateCallback(struct dl_phdr_info *info, size_t size, void *data)
348 {
349  if (size < sizeof (info->dlpi_addr) + sizeof (info->dlpi_name))
350  return 1;
351  QSet<QString> *paths = (QSet<QString> *)data;
352  QString path = QString::fromLocal8Bit(info->dlpi_name);
353  if (!path.isEmpty()) {
354  QFileInfo fi(path);
355  path = fi.absolutePath();
356  if (!path.isEmpty())
357  paths->insert(path);
358  }
359  return 0;
360 }
361 #endif
362 
364 {
365  QStringList paths;
366 # ifdef Q_OS_DARWIN
367  paths = QString::fromLatin1(qgetenv("DYLD_LIBRARY_PATH"))
369 # else
370  paths = QString::fromLatin1(qgetenv("LD_LIBRARY_PATH"))
372 # endif
373  paths << QLatin1String("/lib") << QLatin1String("/usr/lib") << QLatin1String("/usr/local/lib");
374  paths << QLatin1String("/lib64") << QLatin1String("/usr/lib64") << QLatin1String("/usr/local/lib64");
375  paths << QLatin1String("/lib32") << QLatin1String("/usr/lib32") << QLatin1String("/usr/local/lib32");
376 
377 #ifdef Q_OS_LINUX
378  // discover paths of already loaded libraries
379  QSet<QString> loadedPaths;
380  dl_iterate_phdr(dlIterateCallback, &loadedPaths);
381  paths.append(loadedPaths.toList());
382 #endif
383 
384  return paths;
385 }
386 
387 
389 {
390  QStringList paths = libraryPathList();
391  QStringList foundSsls;
392 
393  foreach (const QString &path, paths) {
394  QDir dir(path);
395  QStringList entryList = dir.entryList(QStringList() << QLatin1String("libssl.*"), QDir::Files);
396 
397  qSort(entryList.begin(), entryList.end(), libGreaterThan);
398  foreach (const QString &entry, entryList)
399  foundSsls << path + QLatin1Char('/') + entry;
400  }
401 
402  return foundSsls;
403 }
404 
406 {
407  QStringList paths = libraryPathList();
408 
409  QStringList foundCryptos;
410  foreach (const QString &path, paths) {
411  QDir dir(path);
412  QStringList entryList = dir.entryList(QStringList() << QLatin1String("libcrypto.*"), QDir::Files);
413 
414  qSort(entryList.begin(), entryList.end(), libGreaterThan);
415  foreach (const QString &entry, entryList)
416  foundCryptos << path + QLatin1Char('/') + entry;
417  }
418 
419  return foundCryptos;
420 }
421 # endif
422 
423 #ifdef Q_OS_WIN
425 {
427  pair.first = 0;
428  pair.second = 0;
429 
430  QSystemLibrary *ssleay32 = new QSystemLibrary(QLatin1String("ssleay32"));
431  if (!ssleay32->load(false)) {
432  // Cannot find ssleay32.dll
433  delete ssleay32;
434  return pair;
435  }
436 
437  QSystemLibrary *libeay32 = new QSystemLibrary(QLatin1String("libeay32"));
438  if (!libeay32->load(false)) {
439  delete ssleay32;
440  delete libeay32;
441  return pair;
442  }
443 
444  pair.first = ssleay32;
445  pair.second = libeay32;
446  return pair;
447 }
448 #else
449 
450 static QPair<QLibrary*, QLibrary*> loadOpenSsl()
451 {
453  pair.first = 0;
454  pair.second = 0;
455 
456 # if defined(Q_OS_SYMBIAN)
457  QLibrary *libssl = new QLibrary(QLatin1String("libssl"));
458  if (!libssl->load()) {
459  // Cannot find ssleay32.dll
460  delete libssl;
461  return pair;
462  }
463 
464  QLibrary *libcrypto = new QLibrary(QLatin1String("libcrypto"));
465  if (!libcrypto->load()) {
466  delete libcrypto;
467  delete libssl;
468  return pair;
469  }
470 
471  pair.first = libssl;
472  pair.second = libcrypto;
473  return pair;
474 # elif defined(Q_OS_UNIX)
475  QLibrary *&libssl = pair.first;
476  QLibrary *&libcrypto = pair.second;
477  libssl = new QLibrary;
478  libcrypto = new QLibrary;
479 
480  // Try to find the libssl library on the system.
481  //
482  // Up until Qt 4.3, this only searched for the "ssl" library at version -1, that
483  // is, libssl.so on most Unix systems. However, the .so file isn't present in
484  // user installations because it's considered a development file.
485  //
486  // The right thing to do is to load the library at the major version we know how
487  // to work with: the SHLIB_VERSION_NUMBER version (macro defined in opensslv.h)
488  //
489  // However, OpenSSL is a well-known case of binary-compatibility breakage. To
490  // avoid such problems, many system integrators and Linux distributions change
491  // the soname of the binary, letting the full version number be the soname. So
492  // we'll find libssl.so.0.9.7, libssl.so.0.9.8, etc. in the system. For that
493  // reason, we will search a few common paths (see findAllLibSsl() above) in hopes
494  // we find one that works.
495  //
496  // It is important, however, to try the canonical name and the unversioned name
497  // without going through the loop. By not specifying a path, we let the system
498  // dlopen(3) function determine it for us. This will include any DT_RUNPATH or
499  // DT_RPATH tags on our library header as well as other system-specific search
500  // paths. See the man page for dlopen(3) on your system for more information.
501 
502 #ifdef Q_OS_OPENBSD
504 #endif
505 #if defined(Q_OS_QNX) // on QNX, the libs are always libssl.so and libcrypto.so
507  libcrypto->setLoadHints(libcrypto->loadHints() | QLibrary::ImprovedSearchHeuristics);
508 #elif defined(SHLIB_VERSION_NUMBER)
509  // first attempt: the canonical name is libssl.so.<SHLIB_VERSION_NUMBER>
510  libssl->setFileNameAndVersion(QLatin1String("ssl"), QLatin1String(SHLIB_VERSION_NUMBER));
512  libcrypto->setFileNameAndVersion(QLatin1String("crypto"), QLatin1String(SHLIB_VERSION_NUMBER));
513  libcrypto->setLoadHints(libcrypto->loadHints() | QLibrary::ImprovedSearchHeuristics);
514  if (libcrypto->load() && libssl->load()) {
515  // libssl.so.<SHLIB_VERSION_NUMBER> and libcrypto.so.<SHLIB_VERSION_NUMBER> found
516  return pair;
517  } else {
518  libssl->unload();
519  libcrypto->unload();
520  }
521 #endif
522 
523  // second attempt: find the development files libssl.so and libcrypto.so
524  libssl->setFileNameAndVersion(QLatin1String("ssl"), -1);
525  libcrypto->setFileNameAndVersion(QLatin1String("crypto"), -1);
526  if (libcrypto->load() && libssl->load()) {
527  // libssl.so.0 and libcrypto.so.0 found
528  return pair;
529  } else {
530  libssl->unload();
531  libcrypto->unload();
532  }
533 
534  // third attempt: loop on the most common library paths and find libssl
535  QStringList sslList = findAllLibSsl();
536  QStringList cryptoList = findAllLibCrypto();
537 
538  foreach (const QString &crypto, cryptoList) {
539  libcrypto->setFileNameAndVersion(crypto, -1);
540  if (libcrypto->load()) {
541  QFileInfo fi(crypto);
542  QString version = fi.completeSuffix();
543 
544  foreach (const QString &ssl, sslList) {
545  if (!ssl.endsWith(version))
546  continue;
547 
548  libssl->setFileNameAndVersion(ssl, -1);
549 
550  if (libssl->load()) {
551  // libssl.so.x and libcrypto.so.x found
552  return pair;
553  } else {
554  libssl->unload();
555  }
556  }
557  }
558  libcrypto->unload();
559  }
560 
561  // failed to load anything
562  delete libssl;
563  delete libcrypto;
564  libssl = libcrypto = 0;
565  return pair;
566 
567 # else
568  // not implemented for this platform yet
569  return pair;
570 # endif
571 }
572 #endif
573 
575 {
576  static volatile bool symbolsResolved = false;
577  static volatile bool triedToResolveSymbols = false;
578 #ifndef QT_NO_THREAD
580 #endif
581  if (symbolsResolved)
582  return true;
583  if (triedToResolveSymbols)
584  return false;
585  triedToResolveSymbols = true;
586 
587 #ifdef Q_OS_WIN
589 #else
590  QPair<QLibrary *, QLibrary *> libs = loadOpenSsl();
591 #endif
592  if (!libs.first || !libs.second)
593  // failed to load them
594  return false;
595 
596 #ifdef Q_OS_SYMBIAN
597 #ifdef SSLEAY_MACROS
598  RESOLVEFUNC(ASN1_dup, 125, libs.second )
599 #endif
600  RESOLVEFUNC(ASN1_INTEGER_get, 48, libs.second )
601  RESOLVEFUNC(ASN1_STRING_data, 71, libs.second )
602  RESOLVEFUNC(ASN1_STRING_length, 76, libs.second )
603  RESOLVEFUNC(ASN1_STRING_to_UTF8, 86, libs.second )
604  RESOLVEFUNC(BIO_ctrl, 184, libs.second )
605  RESOLVEFUNC(BIO_free, 209, libs.second )
606  RESOLVEFUNC(BIO_new, 222, libs.second )
607  RESOLVEFUNC(BIO_new_mem_buf, 230, libs.second )
608  RESOLVEFUNC(BIO_read, 244, libs.second )
609  RESOLVEFUNC(BIO_s_mem, 251, libs.second )
610  RESOLVEFUNC(BIO_write, 269, libs.second )
611  RESOLVEFUNC(BN_num_bits, 387, libs.second )
612  RESOLVEFUNC(CRYPTO_free, 469, libs.second )
613  RESOLVEFUNC(CRYPTO_num_locks, 500, libs.second )
614  RESOLVEFUNC(CRYPTO_set_id_callback, 513, libs.second )
615  RESOLVEFUNC(CRYPTO_set_locking_callback, 516, libs.second )
616  RESOLVEFUNC(DSA_free, 594, libs.second )
617  RESOLVEFUNC(ERR_error_string, 744, libs.second )
618  RESOLVEFUNC(ERR_get_error, 749, libs.second )
619  RESOLVEFUNC(EVP_des_ede3_cbc, 919, libs.second )
620  RESOLVEFUNC(EVP_PKEY_assign, 859, libs.second )
621  RESOLVEFUNC(EVP_PKEY_set1_RSA, 880, libs.second )
622  RESOLVEFUNC(EVP_PKEY_set1_DSA, 879, libs.second )
623  RESOLVEFUNC(EVP_PKEY_free, 867, libs.second )
624  RESOLVEFUNC(EVP_PKEY_get1_DSA, 869, libs.second )
625  RESOLVEFUNC(EVP_PKEY_get1_RSA, 870, libs.second )
626  RESOLVEFUNC(EVP_PKEY_new, 876, libs.second )
627  RESOLVEFUNC(EVP_PKEY_type, 882, libs.second )
628  RESOLVEFUNC(OBJ_nid2sn, 1036, libs.second )
629  RESOLVEFUNC(OBJ_obj2nid, 1037, libs.second )
630 #ifdef SSLEAY_MACROS // ### verify
631  RESOLVEFUNC(PEM_ASN1_read_bio, 1180, libs.second )
632 #else
633  RESOLVEFUNC(PEM_read_bio_DSAPrivateKey, 1219, libs.second )
634  RESOLVEFUNC(PEM_read_bio_RSAPrivateKey, 1228, libs.second )
635  RESOLVEFUNC(PEM_write_bio_DSAPrivateKey, 1260, libs.second )
636  RESOLVEFUNC(PEM_write_bio_RSAPrivateKey, 1271, libs.second )
637 #endif
638  RESOLVEFUNC(PEM_read_bio_DSA_PUBKEY, 1220, libs.second )
639  RESOLVEFUNC(PEM_read_bio_RSA_PUBKEY, 1230, libs.second )
640  RESOLVEFUNC(PEM_write_bio_DSA_PUBKEY, 1261, libs.second )
641  RESOLVEFUNC(PEM_write_bio_RSA_PUBKEY, 1273, libs.second )
642  RESOLVEFUNC(RAND_seed, 1426, libs.second )
643  RESOLVEFUNC(RAND_status, 1429, libs.second )
644  RESOLVEFUNC(RSA_free, 1450, libs.second )
645  RESOLVEFUNC(sk_free, 2571, libs.second )
646  RESOLVEFUNC(sk_num, 2576, libs.second )
647  RESOLVEFUNC(sk_pop_free, 2578, libs.second )
648  RESOLVEFUNC(sk_value, 2585, libs.second )
649  RESOLVEFUNC(SSL_CIPHER_description, 11, libs.first )
650  RESOLVEFUNC(SSL_CTX_check_private_key, 21, libs.first )
651  RESOLVEFUNC(SSL_CTX_ctrl, 22, libs.first )
652  RESOLVEFUNC(SSL_CTX_free, 24, libs.first )
653  RESOLVEFUNC(SSL_CTX_new, 35, libs.first )
654  RESOLVEFUNC(SSL_CTX_set_cipher_list, 40, libs.first )
655  RESOLVEFUNC(SSL_CTX_set_default_verify_paths, 44, libs.first )
656  RESOLVEFUNC(SSL_CTX_set_verify, 56, libs.first )
657  RESOLVEFUNC(SSL_CTX_set_verify_depth, 57, libs.first )
658  RESOLVEFUNC(SSL_CTX_use_certificate, 64, libs.first )
659  RESOLVEFUNC(SSL_CTX_use_certificate_file, 67, libs.first )
660  RESOLVEFUNC(SSL_CTX_use_PrivateKey, 58, libs.first )
661  RESOLVEFUNC(SSL_CTX_use_RSAPrivateKey, 61, libs.first )
662  RESOLVEFUNC(SSL_CTX_use_PrivateKey_file, 60, libs.first )
663  RESOLVEFUNC(SSL_accept, 82, libs.first )
664  RESOLVEFUNC(SSL_clear, 92, libs.first )
665  RESOLVEFUNC(SSL_connect, 93, libs.first )
666  RESOLVEFUNC(SSL_free, 99, libs.first )
667  RESOLVEFUNC(SSL_get_ciphers, 104, libs.first )
668  RESOLVEFUNC(SSL_get_current_cipher, 106, libs.first )
669  RESOLVEFUNC(SSL_get_error, 110, libs.first )
670  RESOLVEFUNC(SSL_get_peer_cert_chain, 117, libs.first )
671  RESOLVEFUNC(SSL_get_peer_certificate, 118, libs.first )
672  RESOLVEFUNC(SSL_get_verify_result, 132, libs.first )
673  RESOLVEFUNC(SSL_library_init, 137, libs.first )
674  RESOLVEFUNC(SSL_load_error_strings, 139, libs.first )
675  RESOLVEFUNC(SSL_new, 140, libs.first )
676 #if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT)
677  RESOLVEFUNC(SSL_ctrl, 95, libs.first )
678 #endif
679  RESOLVEFUNC(SSL_read, 143, libs.first )
680  RESOLVEFUNC(SSL_set_accept_state, 148, libs.first )
681  RESOLVEFUNC(SSL_set_bio, 149, libs.first )
682  RESOLVEFUNC(SSL_set_connect_state, 152, libs.first )
683  RESOLVEFUNC(SSL_shutdown, 173, libs.first )
684  RESOLVEFUNC(SSL_write, 188, libs.first )
686  RESOLVEFUNC(SSLv3_client_method, 195, libs.first )
687  RESOLVEFUNC(SSLv23_client_method, 189, libs.first )
688  RESOLVEFUNC(TLSv1_client_method, 198, libs.first )
689  RESOLVEFUNC(SSLv2_server_method, 194, libs.first )
690  RESOLVEFUNC(SSLv3_server_method, 197, libs.first )
691  RESOLVEFUNC(SSLv23_server_method, 191, libs.first )
692  RESOLVEFUNC(TLSv1_server_method, 200, libs.first )
693  RESOLVEFUNC(SSL_CTX_load_verify_locations, 34, libs.first )
694  RESOLVEFUNC(X509_NAME_entry_count, 1821, libs.second )
695  RESOLVEFUNC(X509_NAME_get_entry, 1823, libs.second )
696  RESOLVEFUNC(X509_NAME_ENTRY_get_data, 1808, libs.second )
697  RESOLVEFUNC(X509_NAME_ENTRY_get_object, 1809, libs.second )
698  RESOLVEFUNC(X509_PUBKEY_get, 1844, libs.second )
699  RESOLVEFUNC(X509_STORE_free, 1939, libs.second )
700  RESOLVEFUNC(X509_STORE_new, 1942, libs.second )
701  RESOLVEFUNC(X509_STORE_add_cert, 1936, libs.second )
702  RESOLVEFUNC(X509_STORE_CTX_free, 1907, libs.second )
703  RESOLVEFUNC(X509_STORE_CTX_init, 1919, libs.second )
704  RESOLVEFUNC(X509_STORE_CTX_new, 1920, libs.second )
705  RESOLVEFUNC(X509_STORE_CTX_set_purpose, 1931, libs.second )
706  RESOLVEFUNC(X509_cmp, 1992, libs.second )
707 #ifndef SSLEAY_MACROS
708  RESOLVEFUNC(X509_dup, 1997, libs.second )
709 #endif
710  RESOLVEFUNC(X509_EXTENSION_get_object, 1785, libs.second )
711  RESOLVEFUNC(X509_free, 2001, libs.second )
712  RESOLVEFUNC(X509_get_ext, 2012, libs.second )
713  RESOLVEFUNC(X509_get_ext_count, 2016, libs.second )
714  RESOLVEFUNC(X509_get_ext_d2i, 2017, libs.second )
715  RESOLVEFUNC(X509_get_issuer_name, 2018, libs.second )
716  RESOLVEFUNC(X509_get_subject_name, 2022, libs.second )
717  RESOLVEFUNC(X509_verify_cert, 2069, libs.second )
718  RESOLVEFUNC(d2i_X509, 2309, libs.second )
719  RESOLVEFUNC(i2d_X509, 2489, libs.second )
720 #ifdef SSLEAY_MACROS
721  RESOLVEFUNC(i2d_DSAPrivateKey, 2395, libs.second )
722  RESOLVEFUNC(i2d_RSAPrivateKey, 2476, libs.second )
723  RESOLVEFUNC(d2i_DSAPrivateKey, 2220, libs.second )
724  RESOLVEFUNC(d2i_RSAPrivateKey, 2296, libs.second )
725 #endif
726  RESOLVEFUNC(OPENSSL_add_all_algorithms_noconf, 1153, libs.second )
727  RESOLVEFUNC(OPENSSL_add_all_algorithms_conf, 1152, libs.second )
728  RESOLVEFUNC(SSLeay, 1504, libs.second )
729 #else // Q_OS_SYMBIAN
730 #ifdef SSLEAY_MACROS
731  RESOLVEFUNC(ASN1_dup)
732 #endif
733  RESOLVEFUNC(ASN1_INTEGER_get)
734  RESOLVEFUNC(ASN1_STRING_data)
735  RESOLVEFUNC(ASN1_STRING_length)
736  RESOLVEFUNC(ASN1_STRING_to_UTF8)
737  RESOLVEFUNC(BIO_ctrl)
738  RESOLVEFUNC(BIO_free)
739  RESOLVEFUNC(BIO_new)
740  RESOLVEFUNC(BIO_new_mem_buf)
741  RESOLVEFUNC(BIO_read)
742  RESOLVEFUNC(BIO_s_mem)
743  RESOLVEFUNC(BIO_write)
744  RESOLVEFUNC(BN_num_bits)
745  RESOLVEFUNC(CRYPTO_free)
746  RESOLVEFUNC(CRYPTO_num_locks)
747  RESOLVEFUNC(CRYPTO_set_id_callback)
748  RESOLVEFUNC(CRYPTO_set_locking_callback)
749  RESOLVEFUNC(DSA_free)
750  RESOLVEFUNC(ERR_error_string)
751  RESOLVEFUNC(ERR_get_error)
752  RESOLVEFUNC(EVP_des_ede3_cbc)
753  RESOLVEFUNC(EVP_PKEY_assign)
754  RESOLVEFUNC(EVP_PKEY_set1_RSA)
755  RESOLVEFUNC(EVP_PKEY_set1_DSA)
756  RESOLVEFUNC(EVP_PKEY_free)
757  RESOLVEFUNC(EVP_PKEY_get1_DSA)
758  RESOLVEFUNC(EVP_PKEY_get1_RSA)
759  RESOLVEFUNC(EVP_PKEY_new)
760  RESOLVEFUNC(EVP_PKEY_type)
761  RESOLVEFUNC(OBJ_nid2sn)
762  RESOLVEFUNC(OBJ_obj2nid)
763 #ifdef SSLEAY_MACROS // ### verify
764  RESOLVEFUNC(PEM_ASN1_read_bio)
765 #else
766  RESOLVEFUNC(PEM_read_bio_DSAPrivateKey)
767  RESOLVEFUNC(PEM_read_bio_RSAPrivateKey)
768  RESOLVEFUNC(PEM_write_bio_DSAPrivateKey)
769  RESOLVEFUNC(PEM_write_bio_RSAPrivateKey)
770 #endif
771  RESOLVEFUNC(PEM_read_bio_DSA_PUBKEY)
772  RESOLVEFUNC(PEM_read_bio_RSA_PUBKEY)
773  RESOLVEFUNC(PEM_write_bio_DSA_PUBKEY)
774  RESOLVEFUNC(PEM_write_bio_RSA_PUBKEY)
775  RESOLVEFUNC(RAND_seed)
776  RESOLVEFUNC(RAND_status)
777  RESOLVEFUNC(RSA_free)
778  RESOLVEFUNC(sk_free)
779  RESOLVEFUNC(sk_num)
780  RESOLVEFUNC(sk_pop_free)
781  RESOLVEFUNC(sk_value)
782  RESOLVEFUNC(SSL_CIPHER_description)
783  RESOLVEFUNC(SSL_CTX_check_private_key)
784  RESOLVEFUNC(SSL_CTX_ctrl)
785  RESOLVEFUNC(SSL_CTX_free)
786  RESOLVEFUNC(SSL_CTX_new)
787  RESOLVEFUNC(SSL_CTX_set_cipher_list)
788  RESOLVEFUNC(SSL_CTX_set_default_verify_paths)
789  RESOLVEFUNC(SSL_CTX_set_verify)
790  RESOLVEFUNC(SSL_CTX_set_verify_depth)
791  RESOLVEFUNC(SSL_CTX_use_certificate)
792  RESOLVEFUNC(SSL_CTX_use_certificate_file)
793  RESOLVEFUNC(SSL_CTX_use_PrivateKey)
794  RESOLVEFUNC(SSL_CTX_use_RSAPrivateKey)
795  RESOLVEFUNC(SSL_CTX_use_PrivateKey_file)
796  RESOLVEFUNC(SSL_accept)
797  RESOLVEFUNC(SSL_clear)
798  RESOLVEFUNC(SSL_connect)
799  RESOLVEFUNC(SSL_free)
800  RESOLVEFUNC(SSL_get_ciphers)
801  RESOLVEFUNC(SSL_get_current_cipher)
802  RESOLVEFUNC(SSL_get_error)
803  RESOLVEFUNC(SSL_get_peer_cert_chain)
804  RESOLVEFUNC(SSL_get_peer_certificate)
805  RESOLVEFUNC(SSL_get_verify_result)
806  RESOLVEFUNC(SSL_library_init)
807  RESOLVEFUNC(SSL_load_error_strings)
808  RESOLVEFUNC(SSL_new)
809 #if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT)
810  RESOLVEFUNC(SSL_ctrl)
811 #endif
812  RESOLVEFUNC(SSL_read)
813  RESOLVEFUNC(SSL_set_accept_state)
814  RESOLVEFUNC(SSL_set_bio)
815  RESOLVEFUNC(SSL_set_connect_state)
816  RESOLVEFUNC(SSL_shutdown)
817  RESOLVEFUNC(SSL_write)
818 #ifndef OPENSSL_NO_SSL2
820 #endif
821  RESOLVEFUNC(SSLv3_client_method)
822  RESOLVEFUNC(SSLv23_client_method)
823  RESOLVEFUNC(TLSv1_client_method)
824 #ifndef OPENSSL_NO_SSL2
825  RESOLVEFUNC(SSLv2_server_method)
826 #endif
827  RESOLVEFUNC(SSLv3_server_method)
828  RESOLVEFUNC(SSLv23_server_method)
829  RESOLVEFUNC(TLSv1_server_method)
830  RESOLVEFUNC(X509_NAME_entry_count)
831  RESOLVEFUNC(X509_NAME_get_entry)
832  RESOLVEFUNC(X509_NAME_ENTRY_get_data)
833  RESOLVEFUNC(X509_NAME_ENTRY_get_object)
834  RESOLVEFUNC(X509_PUBKEY_get)
835  RESOLVEFUNC(X509_STORE_free)
836  RESOLVEFUNC(X509_STORE_new)
837  RESOLVEFUNC(X509_STORE_add_cert)
838  RESOLVEFUNC(X509_STORE_CTX_free)
839  RESOLVEFUNC(X509_STORE_CTX_init)
840  RESOLVEFUNC(X509_STORE_CTX_new)
841  RESOLVEFUNC(X509_STORE_CTX_set_purpose)
842  RESOLVEFUNC(X509_STORE_CTX_get_error)
843  RESOLVEFUNC(X509_STORE_CTX_get_error_depth)
844  RESOLVEFUNC(X509_STORE_CTX_get_current_cert)
845  RESOLVEFUNC(X509_STORE_CTX_get_chain)
846  RESOLVEFUNC(X509_cmp)
847 #ifndef SSLEAY_MACROS
848  RESOLVEFUNC(X509_dup)
849 #endif
850  RESOLVEFUNC(X509_EXTENSION_get_object)
851  RESOLVEFUNC(X509_free)
852  RESOLVEFUNC(X509_get_ext)
853  RESOLVEFUNC(X509_get_ext_count)
854  RESOLVEFUNC(X509_get_ext_d2i)
855  RESOLVEFUNC(X509_get_issuer_name)
856  RESOLVEFUNC(X509_get_subject_name)
857  RESOLVEFUNC(X509_verify_cert)
858  RESOLVEFUNC(d2i_X509)
859  RESOLVEFUNC(i2d_X509)
860 #ifdef SSLEAY_MACROS
861  RESOLVEFUNC(i2d_DSAPrivateKey)
862  RESOLVEFUNC(i2d_RSAPrivateKey)
863  RESOLVEFUNC(d2i_DSAPrivateKey)
864  RESOLVEFUNC(d2i_RSAPrivateKey)
865 #endif
866  RESOLVEFUNC(OPENSSL_add_all_algorithms_noconf)
867  RESOLVEFUNC(OPENSSL_add_all_algorithms_conf)
868  RESOLVEFUNC(SSL_CTX_load_verify_locations)
869  RESOLVEFUNC(SSLeay)
870 #endif // Q_OS_SYMBIAN
871  symbolsResolved = true;
872  delete libs.first;
873  delete libs.second;
874  return true;
875 }
876 #endif // QT_NO_LIBRARY
877 
878 #else // !defined QT_LINKED_OPENSSL
879 
881 {
882 #ifdef QT_NO_OPENSSL
883  return false;
884 #endif
885  return true;
886 }
887 #endif // !defined QT_LINKED_OPENSSL
888 
889 //==============================================================================
890 // contributed by Jay Case of Sarvega, Inc.; http://sarvega.com/
891 // Based on X509_cmp_time() for intitial buffer hacking.
892 //==============================================================================
893 QDateTime q_getTimeFromASN1(const ASN1_TIME *aTime)
894 {
895  size_t lTimeLength = aTime->length;
896  char *pString = (char *) aTime->data;
897 
898  if (aTime->type == V_ASN1_UTCTIME) {
899 
900  char lBuffer[24];
901  char *pBuffer = lBuffer;
902 
903  if ((lTimeLength < 11) || (lTimeLength > 17))
904  return QDateTime();
905 
906  memcpy(pBuffer, pString, 10);
907  pBuffer += 10;
908  pString += 10;
909 
910  if ((*pString == 'Z') || (*pString == '-') || (*pString == '+')) {
911  *pBuffer++ = '0';
912  *pBuffer++ = '0';
913  } else {
914  *pBuffer++ = *pString++;
915  *pBuffer++ = *pString++;
916  // Skip any fractional seconds...
917  if (*pString == '.') {
918  pString++;
919  while ((*pString >= '0') && (*pString <= '9'))
920  pString++;
921  }
922  }
923 
924  *pBuffer++ = 'Z';
925  *pBuffer++ = '\0';
926 
927  time_t lSecondsFromUCT;
928  if (*pString == 'Z') {
929  lSecondsFromUCT = 0;
930  } else {
931  if ((*pString != '+') && (*pString != '-'))
932  return QDateTime();
933 
934  lSecondsFromUCT = ((pString[1] - '0') * 10 + (pString[2] - '0')) * 60;
935  lSecondsFromUCT += (pString[3] - '0') * 10 + (pString[4] - '0');
936  lSecondsFromUCT *= 60;
937  if (*pString == '-')
938  lSecondsFromUCT = -lSecondsFromUCT;
939  }
940 
941  tm lTime;
942  lTime.tm_sec = ((lBuffer[10] - '0') * 10) + (lBuffer[11] - '0');
943  lTime.tm_min = ((lBuffer[8] - '0') * 10) + (lBuffer[9] - '0');
944  lTime.tm_hour = ((lBuffer[6] - '0') * 10) + (lBuffer[7] - '0');
945  lTime.tm_mday = ((lBuffer[4] - '0') * 10) + (lBuffer[5] - '0');
946  lTime.tm_mon = (((lBuffer[2] - '0') * 10) + (lBuffer[3] - '0')) - 1;
947  lTime.tm_year = ((lBuffer[0] - '0') * 10) + (lBuffer[1] - '0');
948  if (lTime.tm_year < 50)
949  lTime.tm_year += 100; // RFC 2459
950 
951  QDate resDate(lTime.tm_year + 1900, lTime.tm_mon + 1, lTime.tm_mday);
952  QTime resTime(lTime.tm_hour, lTime.tm_min, lTime.tm_sec);
953 
954  QDateTime result(resDate, resTime, Qt::UTC);
955  result = result.addSecs(lSecondsFromUCT);
956  return result;
957 
958  } else if (aTime->type == V_ASN1_GENERALIZEDTIME) {
959 
960  if (lTimeLength < 15)
961  return QDateTime(); // hopefully never triggered
962 
963  // generalized time is always YYYYMMDDHHMMSSZ (RFC 2459, section 4.1.2.5.2)
964  tm lTime;
965  lTime.tm_sec = ((pString[12] - '0') * 10) + (pString[13] - '0');
966  lTime.tm_min = ((pString[10] - '0') * 10) + (pString[11] - '0');
967  lTime.tm_hour = ((pString[8] - '0') * 10) + (pString[9] - '0');
968  lTime.tm_mday = ((pString[6] - '0') * 10) + (pString[7] - '0');
969  lTime.tm_mon = (((pString[4] - '0') * 10) + (pString[5] - '0'));
970  lTime.tm_year = ((pString[0] - '0') * 1000) + ((pString[1] - '0') * 100) +
971  ((pString[2] - '0') * 10) + (pString[3] - '0');
972 
973  QDate resDate(lTime.tm_year, lTime.tm_mon, lTime.tm_mday);
974  QTime resTime(lTime.tm_hour, lTime.tm_min, lTime.tm_sec);
975 
976  QDateTime result(resDate, resTime, Qt::UTC);
977  return result;
978 
979  } else {
980  qWarning("unsupported date format detected");
981  return QDateTime();
982  }
983 
984 }
985 
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
QDateTime addSecs(int secs) const
Returns a QDateTime object containing a datetime s seconds later than the datetime of this object (or...
Definition: qdatetime.cpp:2869
double d
Definition: qnumeric_p.h:62
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
int tm_min
void setFileNameAndVersion(const QString &fileName, int verNum)
Sets the fileName property and major version number to fileName and versionNumber respectively...
Definition: qlibrary.cpp:1092
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
static mach_timebase_info_data_t info
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool q_resolveOpenSslSymbols()
bool unload()
Unloads the library and returns true if the library could be unloaded; otherwise returns false...
Definition: qlibrary.cpp:934
static QStringList findAllLibCrypto()
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
#define DEFINEFUNC(ret, func, args, argcall, funcret)
return SSL_METHOD * TLSv1_client_method
int tm_mday
T1 first
Definition: qpair.h:65
return SSL_METHOD * SSLv23_client_method
T2 second
Definition: qpair.h:66
static QPair< QSystemLibrary *, QSystemLibrary * > loadOpenSslWin32()
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QString completeSuffix() const
Returns the complete suffix of the file.
Definition: qfileinfo.cpp:811
return SSL_METHOD * SSLv23_server_method
The QDate class provides date functions.
Definition: qdatetime.h:55
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int tm_year
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define RESOLVEFUNC(func)
return DEFINEFUNC3(void, SSL_CTX_set_verify, SSL_CTX *a, a, int b, b, int(*c)(int, X509_STORE_CTX *), c, return, DUMMYARG) void SSL_free SSL *a
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static bool libGreaterThan(const QString &lhs, const QString &rhs)
bool load(bool onlySystemDirectory=true)
static int dlIterateCallback(struct dl_phdr_info *info, size_t size, void *data)
#define DUMMYARG
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static QStringList findAllLibSsl()
The QTime class provides clock time functions.
Definition: qdatetime.h:148
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
return SSL_METHOD * TLSv1_server_method
#define DEFINEFUNC4(ret, func, arg1, a, arg2, b, arg3, c, arg4, d, err, funcret)
int q_SSL_library_init()
return EVP_PKEY * EVP_PKEY_new
X509_STORE * X509_STORE_new
unsigned long time_t
struct x509_st X509
return int CRYPTO_num_locks
QList< T > toList() const
Definition: qset.h:296
int tm_mon
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
return const EVP_CIPHER * EVP_des_ede3_cbc
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static QStringList libraryPathList()
Q_CORE_EXPORT void qWarning(const char *,...)
const_iterator insert(const T &value)
Definition: qset.h:179
static const char * data(const QByteArray &arr)
return SSL_METHOD * SSLv2_client_method
return DEFINEFUNC2(int, ASN1_STRING_to_UTF8, unsigned char **a, a, ASN1_STRING *b, b, return 0, return)
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
QDateTime q_getTimeFromASN1(const ASN1_TIME *aTime)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
#define DEFINEFUNC7(ret, func, arg1, a, arg2, b, arg3, c, arg4, d, arg5, e, arg6, f, arg7, g, err, funcret)
bool load()
Loads the library and returns true if the library was loaded successfully; otherwise returns false...
Definition: qlibrary.cpp:909
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
return X509_STORE_CTX * X509_STORE_CTX_new
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
#define ctx
Definition: qgl.cpp:6094
if(void) toggleToolbarShown
void setLoadHints(LoadHints hints)
Definition: qlibrary.cpp:1304
unsigned long ERR_get_error
return(isPopup||isToolTip)
int tm_sec
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
int tm_hour
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
#define parg(name)
STACK_OF(SSL_CIPHER) *SSL_get_ciphers SSL *a
return SSL_METHOD * SSLv3_client_method
return SSL_METHOD * SSLv2_server_method
QString absolutePath() const
Returns a file&#39;s path absolute path.
Definition: qfileinfo.cpp:577
return SSL_METHOD * SSLv3_server_method
static QMutex * globalInstanceGet(const void *address)
Returns a QMutex from the global mutex pool.
Definition: qmutexpool.cpp:150
QStringList entryList(Filters filters=NoFilter, SortFlags sort=NoSort) const
Returns a list of the names of all the files and directories in the directory, ordered according to t...
Definition: qdir.cpp:1290
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
LoadHints loadHints
Give the load() function some hints on how it should behave.
Definition: qlibrary.h:66
#define DEFINEFUNC6(ret, func, arg1, a, arg2, b, arg3, c, arg4, d, arg5, e, arg6, f, err, funcret)
The QLibrary class loads shared libraries at runtime.
Definition: qlibrary.h:62