-
Notifications
You must be signed in to change notification settings - Fork 125
/
ocaml-ssl_0001-fixed-stubs-for-windows-compilation.patch.windows
294 lines (260 loc) · 8.3 KB
/
ocaml-ssl_0001-fixed-stubs-for-windows-compilation.patch.windows
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
From 676db4a493a3ced98fbce8a89143db633be8ffa6 Mon Sep 17 00:00:00 2001
From: Louis Gesbert <louis.gesbert@mlstate.com>
Date: Thu, 16 Jun 2011 16:59:19 +0200
Subject: [PATCH] fixed stubs for windows compilation
---
src/ssl_stubs.c | 124 +++++++++++++++++++++++++-----------------------------
1 files changed, 57 insertions(+), 67 deletions(-)
diff --git a/src/ssl_stubs.c b/src/ssl_stubs.c
index afc1e7f..5073d68 100644
--- a/src/ssl_stubs.c
+++ b/src/ssl_stubs.c
@@ -24,14 +24,16 @@
* @author Samuel Mimram
*/
-/* $Id: ssl_stubs.c 7933 2010-11-09 17:38:05Z smimram $ */
+/* $Id: ssl_stubs.c 6920 2009-11-10 08:48:26Z smimram $ */
/*
* WARNING: because of thread callbacks, all ssl functions should be in
* blocking sections.
*/
-#include <unistd.h>
+#include <io.h>
+#include <process.h>
+
#include <string.h>
#include <assert.h>
@@ -48,8 +50,6 @@
#include <openssl/err.h>
#include <openssl/crypto.h>
-#include <pthread.h>
-
static int client_verify_callback(int, X509_STORE_CTX *);
/*******************
@@ -101,70 +101,40 @@ static struct custom_operations socket_ops =
* Initialization *
******************/
-struct CRYPTO_dynlock_value
-{
- pthread_mutex_t mutex;
-};
-
-static pthread_mutex_t *mutex_buf = NULL;
-
-static void locking_function(int mode, int n, const char *file, int line)
-{
- if (mode & CRYPTO_LOCK)
- pthread_mutex_lock(&mutex_buf[n]);
- else
- pthread_mutex_unlock(&mutex_buf[n]);
-}
-
-static unsigned long id_function(void)
+CAMLprim value ocaml_ssl_crypto_num_locks(value unit)
{
- return ((unsigned long) pthread_self());
+ return Val_int(CRYPTO_num_locks());
}
-static struct CRYPTO_dynlock_value *dyn_create_function(const char *file, int line)
+void locking_function(int mode, int n, const char *file, int line)
{
- struct CRYPTO_dynlock_value *value;
-
- value = malloc(sizeof(struct CRYPTO_dynlock_value));
- if (!value)
- return NULL;
- pthread_mutex_init(&value->mutex, NULL);
+ value lf;
- return value;
-}
+ caml_leave_blocking_section();
-static void dyn_lock_function(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line)
-{
+ lf = Field(Field(*caml_named_value("caml_ssl_thread_locking_function"), 0), 0);
if (mode & CRYPTO_LOCK)
- pthread_mutex_lock(&l->mutex);
+ caml_callback2(lf, Val_int(n), Val_int(1));
else
- pthread_mutex_unlock(&l->mutex);
+ caml_callback2(lf, Val_int(n), Val_int(0));
+
+ caml_enter_blocking_section();
}
-static void dyn_destroy_function(struct CRYPTO_dynlock_value *l, const char *file, int line)
+unsigned long id_function(void)
{
- pthread_mutex_destroy(&l->mutex);
- free(l);
+ return Int_val(caml_callback(Field(Field(*caml_named_value("caml_ssl_thread_id_function"), 0), 0), Val_unit));
}
CAMLprim value ocaml_ssl_init(value use_threads)
{
- int i;
-
SSL_library_init();
SSL_load_error_strings();
if(Int_val(use_threads))
{
- mutex_buf = malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
- assert(mutex_buf);
- for (i = 0; i < CRYPTO_num_locks(); i++)
- pthread_mutex_init(&mutex_buf[i], NULL);
- CRYPTO_set_locking_callback(locking_function);
CRYPTO_set_id_callback(id_function);
- CRYPTO_set_dynlock_create_callback(dyn_create_function);
- CRYPTO_set_dynlock_lock_callback(dyn_lock_function);
- CRYPTO_set_dynlock_destroy_callback(dyn_destroy_function);
+ CRYPTO_set_locking_callback(locking_function);
}
return Val_unit;
@@ -193,15 +163,15 @@ static SSL_METHOD *get_method(int protocol, int type)
switch (type)
{
case 0:
- method = SSLv23_client_method();
+ method = (SSL_METHOD*) SSLv2_client_method();
break;
case 1:
- method = SSLv23_server_method();
+ method = (SSL_METHOD*) SSLv2_server_method();
break;
case 2:
- method = SSLv23_method();
+ method = (SSL_METHOD*) SSLv2_method();
break;
}
break;
@@ -210,15 +180,15 @@ static SSL_METHOD *get_method(int protocol, int type)
switch (type)
{
case 0:
- method = SSLv3_client_method();
+ method = (SSL_METHOD*) SSLv23_client_method();
break;
case 1:
- method = SSLv3_server_method();
+ method = (SSL_METHOD*) SSLv23_server_method();
break;
case 2:
- method = SSLv3_method();
+ method = (SSL_METHOD*) SSLv23_method();
break;
}
break;
@@ -227,15 +197,32 @@ static SSL_METHOD *get_method(int protocol, int type)
switch (type)
{
case 0:
- method = TLSv1_client_method();
+ method = (SSL_METHOD*) SSLv3_client_method();
break;
case 1:
- method = TLSv1_server_method();
+ method = (SSL_METHOD*)SSLv3_server_method();
break;
case 2:
- method = TLSv1_method();
+ method = (SSL_METHOD*)SSLv3_method();
+ break;
+ }
+ break;
+
+ case 3:
+ switch (type)
+ {
+ case 0:
+ method = (SSL_METHOD*)TLSv1_client_method();
+ break;
+
+ case 1:
+ method = (SSL_METHOD*)TLSv1_server_method();
+ break;
+
+ case 2:
+ method = (SSL_METHOD*)TLSv1_method();
break;
}
break;
@@ -425,7 +412,7 @@ CAMLprim value ocaml_ssl_ctx_set_default_passwd_cb(value context, value cb)
value *pcb;
/* TODO: this never gets freed or even unregistered */
- pcb = malloc(sizeof(value));
+ pcb = (value*)malloc(sizeof(value));
*pcb = cb;
caml_register_global_root(pcb);
@@ -465,9 +452,10 @@ CAMLprim value ocaml_ssl_get_current_cipher(value socket)
{
CAMLparam1(socket);
SSL *ssl = SSL_val(socket);
+ SSL_CIPHER *cipher;
caml_enter_blocking_section();
- SSL_CIPHER *cipher = (SSL_CIPHER*)SSL_get_current_cipher(ssl);
+ cipher = (SSL_CIPHER*)SSL_get_current_cipher(ssl);
caml_leave_blocking_section();
if (!cipher)
caml_raise_constant(*caml_named_value("ssl_exn_cipher_error"));
@@ -535,7 +523,7 @@ static struct custom_operations cert_ops =
CAMLprim value ocaml_ssl_read_certificate(value vfilename)
{
- value block;
+ CAMLlocal1(block);
char *filename = String_val(vfilename);
X509 *cert = NULL;
FILE *fh = NULL;
@@ -562,15 +550,17 @@ CAMLprim value ocaml_ssl_get_certificate(value socket)
{
CAMLparam1(socket);
SSL *ssl = SSL_val(socket);
+ X509 *cert ;
+ CAMLlocal1(block);
caml_enter_blocking_section();
- X509 *cert = SSL_get_peer_certificate(ssl);
+ cert = SSL_get_peer_certificate(ssl);
caml_leave_blocking_section();
if (!cert)
caml_raise_constant(*caml_named_value("ssl_exn_certificate_error"));
- CAMLlocal1(block);
+
block = caml_alloc_final(2, finalize_cert, 0, 1);
(*((X509 **) Data_custom_val(block))) = cert;
CAMLreturn(block);
@@ -580,9 +570,9 @@ CAMLprim value ocaml_ssl_get_issuer(value certificate)
{
CAMLparam1(certificate);
X509 *cert = Cert_val(certificate);
-
+ char *issuer ;
caml_enter_blocking_section();
- char *issuer = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0);
+ issuer = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0);
caml_leave_blocking_section();
if (!issuer) caml_raise_not_found ();
@@ -593,9 +583,9 @@ CAMLprim value ocaml_ssl_get_subject(value certificate)
{
CAMLparam1(certificate);
X509 *cert = Cert_val(certificate);
-
+ char *subject ;
caml_enter_blocking_section();
- char *subject = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0);
+ subject = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0);
caml_leave_blocking_section();
if (subject == NULL) caml_raise_not_found ();
@@ -716,7 +706,7 @@ CAMLprim value ocaml_ssl_write(value socket, value buffer, value start, value le
CAMLparam2(socket, buffer);
int ret, err;
int buflen = Int_val(length);
- char *buf = malloc(buflen);
+ char *buf = (char*)malloc(buflen);
SSL *ssl = SSL_val(socket);
if (Int_val(start) + Int_val(length) > caml_string_length(buffer))
@@ -740,7 +730,7 @@ CAMLprim value ocaml_ssl_read(value socket, value buffer, value start, value len
CAMLparam2(socket, buffer);
int ret, err;
int buflen = Int_val(length);
- char *buf = malloc(buflen);
+ char *buf = (char*)malloc(buflen);
SSL *ssl = SSL_val(socket);
if (Int_val(start) + Int_val(length) > caml_string_length(buffer))
--
1.7.1