ReactOS  0.4.13-dev-257-gfabbd7c
schannel_mbedtls_lazyload.h
Go to the documentation of this file.
1 /* Copyright 2015 Ismael Ferreras Morezuelas <swyterzone+ros@gmail.com>
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  *
17  * --
18  *
19  * This file transparently wraps lazy-loading hooks in the schannel
20  * implementation on top of the PolarSSL/mbedTLS open source library.
21  */
22 
23 static void *libmbedtls_handle;
24 
25 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
26 
60 
61 #undef MAKE_FUNCPTR
62 
63 /* replace the initialization functions by our own, specially tailored, ones */
64 
66 {
68 
69  if (!libmbedtls_handle)
70  {
71  WARN("Failed to load the mbedTLS dynamic library (" SONAME_LIBMBEDTLS ").\n");
72  return FALSE;
73  }
74 
75 #define LOAD_FUNCPTR(f) \
76  if (!(p##f = wine_dlsym(libmbedtls_handle, #f, NULL, 0))) \
77  { \
78  ERR("Failed to retrieve function %s from the mbedTLS dynamic library (" SONAME_LIBMBEDTLS ")\n", #f); \
79  goto fail; \
80  }
81 
115 
116 #undef LOAD_FUNCPTR
117 
118  return TRUE;
119 
120 fail:
121 
124 
125  return FALSE;
126 }
127 
129 {
132 }
133 
134 /* now that we have overridden the initialization functions
135  cancel out the original stubs used when dynamically linking */
136 
137 #define schan_imp_init schan_imp_init_unused
138 #define schan_imp_deinit schan_imp_deinit_unused
139 
140 /* seamlessly redirect the function pointers with some preprocessor magic */
141 
142 #define mbedtls_ctr_drbg_free pmbedtls_ctr_drbg_free
143 #define mbedtls_ctr_drbg_init pmbedtls_ctr_drbg_init
144 #define mbedtls_ctr_drbg_random pmbedtls_ctr_drbg_random
145 #define mbedtls_entropy_free pmbedtls_entropy_free
146 #define mbedtls_entropy_func pmbedtls_entropy_func
147 #define mbedtls_entropy_init pmbedtls_entropy_init
148 #define mbedtls_ssl_ciphersuite_from_id pmbedtls_ssl_ciphersuite_from_id
149 #define mbedtls_ssl_free pmbedtls_ssl_free
150 #define mbedtls_ssl_get_ciphersuite pmbedtls_ssl_get_ciphersuite
151 #define mbedtls_ssl_get_ciphersuite_id pmbedtls_ssl_get_ciphersuite_id
152 #define mbedtls_ssl_get_max_frag_len pmbedtls_ssl_get_max_frag_len
153 #define mbedtls_ssl_get_version pmbedtls_ssl_get_version
154 #define mbedtls_ssl_handshake pmbedtls_ssl_handshake
155 #define mbedtls_ssl_init pmbedtls_ssl_init
156 #define mbedtls_ssl_read pmbedtls_ssl_read
157 #define mbedtls_ssl_conf_authmode pmbedtls_ssl_conf_authmode
158 #define mbedtls_ssl_set_bio pmbedtls_ssl_set_bio
159 #define mbedtls_ssl_conf_endpoint pmbedtls_ssl_conf_endpoint
160 #define mbedtls_ssl_set_hostname pmbedtls_ssl_set_hostname
161 #define mbedtls_ssl_conf_max_version pmbedtls_ssl_conf_max_version
162 #define mbedtls_ssl_conf_min_version pmbedtls_ssl_conf_min_version
163 #define mbedtls_ssl_conf_rng pmbedtls_ssl_conf_rng
164 #define mbedtls_ssl_write pmbedtls_ssl_write
165 #define mbedtls_ssl_get_peer_cert pmbedtls_ssl_get_peer_cert
166 #define mbedtls_ssl_config_init pmbedtls_ssl_config_init
167 #define mbedtls_ssl_config_free pmbedtls_ssl_config_free
168 #define mbedtls_ssl_config_defaults pmbedtls_ssl_config_defaults
169 #define mbedtls_ssl_conf_dbg pmbedtls_ssl_conf_dbg
170 #define mbedtls_ssl_setup pmbedtls_ssl_setup
171 #define mbedtls_cipher_info_from_type pmbedtls_cipher_info_from_type
172 #define mbedtls_md_info_from_type pmbedtls_md_info_from_type
173 #define mbedtls_pk_get_bitlen pmbedtls_pk_get_bitlen
174 #define mbedtls_ctr_drbg_seed pmbedtls_ctr_drbg_seed
#define mbedtls_ssl_set_bio
#define TRUE
Definition: types.h:120
#define mbedtls_ssl_get_ciphersuite_id
static void * libmbedtls_handle
#define schan_imp_init
#define WARN(fmt,...)
Definition: debug.h:111
#define mbedtls_ssl_conf_max_version
#define mbedtls_ssl_get_version
#define mbedtls_ssl_free
#define mbedtls_ssl_config_free
#define mbedtls_ssl_config_defaults
unsigned int BOOL
Definition: ntddk_ex.h:94
#define mbedtls_ctr_drbg_init
#define mbedtls_ctr_drbg_free
smooth NULL
Definition: ftsmooth.c:416
void * wine_dlopen(const char *filename, int flag, char *error, size_t errorsize)
Definition: loader.c:53
#define mbedtls_ssl_conf_rng
#define mbedtls_ssl_conf_authmode
#define mbedtls_ssl_config_init
#define mbedtls_ssl_setup
#define mbedtls_ssl_init
#define RTLD_NOW
Definition: port.h:100
#define mbedtls_pk_get_bitlen
int mbedtls_ctr_drbg_seed(mbedtls_ctr_drbg_context *ctx, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len)
This function seeds and sets up the CTR_DRBG entropy source for future reseeds.
#define mbedtls_entropy_func
#define SONAME_LIBMBEDTLS
Definition: config.h:1245
#define mbedtls_ssl_ciphersuite_from_id
#define LOAD_FUNCPTR(f)
#define mbedtls_ctr_drbg_random
#define mbedtls_md_info_from_type
#define mbedtls_cipher_info_from_type
#define mbedtls_ssl_get_peer_cert
#define mbedtls_ssl_get_ciphersuite
#define mbedtls_entropy_free
#define mbedtls_ssl_get_max_frag_len
#define MAKE_FUNCPTR(f)
#define schan_imp_deinit
#define mbedtls_entropy_init
#define mbedtls_ssl_conf_dbg
#define mbedtls_ssl_conf_endpoint
#define mbedtls_ssl_set_hostname
#define mbedtls_ssl_write
#define mbedtls_ssl_conf_min_version
#define mbedtls_ssl_read
int wine_dlclose(void *handle, char *error, size_t errorsize)
Definition: loader.c:58
#define mbedtls_ssl_handshake