This repository has been archived by the owner on Jun 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
wolfssl-3.13.0-mysql-8.0.diff
384 lines (367 loc) · 13.5 KB
/
wolfssl-3.13.0-mysql-8.0.diff
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
diff -ur -N -d -x CMakeLists.txt wolfssl-3.13.0-pristine/src/internal.c wolfssl-3.13.0/src/internal.c
--- wolfssl-3.13.0-pristine/src/internal.c 2017-12-21 19:23:03.000000000 +0200
+++ wolfssl-3.13.0/src/internal.c 2018-01-03 17:13:10.889281600 +0200
@@ -3992,6 +3992,17 @@
ssl->devId = ctx->devId;
#endif
+ /* downgrade the version according to the flags */
+ if (ssl->options.downgrade)
+ {
+ if ((ssl->options.mask & (SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1)) == SSL_OP_NO_TLSv1)
+ wolfSSL_SetVersion(ssl, WOLFSSL_SSLV3);
+ else if ((ssl->options.mask & (SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1)) == SSL_OP_NO_TLSv1_1)
+ wolfSSL_SetVersion(ssl, WOLFSSL_TLSV1);
+ else if ((ssl->options.mask & (SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2)) == SSL_OP_NO_TLSv1_2)
+ wolfSSL_SetVersion(ssl, WOLFSSL_TLSV1_1);
+ }
+
if (writeDup == 0) {
int keySz = 0;
#ifndef NO_CERTS
@@ -4722,7 +4733,7 @@
XFREE(ssl->buffers.serverDH_Priv.buffer, ssl->heap, DYNAMIC_TYPE_PRIVATE_KEY);
XFREE(ssl->buffers.serverDH_Pub.buffer, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY);
/* parameters (p,g) may be owned by ctx */
- if (ssl->buffers.weOwnDH || ssl->options.side == WOLFSSL_CLIENT_END) {
+ if (ssl->buffers.weOwnDH /*|| ssl->options.side == WOLFSSL_CLIENT_END*/) {
XFREE(ssl->buffers.serverDH_G.buffer, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY);
XFREE(ssl->buffers.serverDH_P.buffer, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY);
}
@@ -4971,7 +4982,7 @@
XFREE(ssl->buffers.serverDH_Pub.buffer, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY);
ssl->buffers.serverDH_Pub.buffer = NULL;
/* parameters (p,g) may be owned by ctx */
- if (ssl->buffers.weOwnDH || ssl->options.side == WOLFSSL_CLIENT_END) {
+ if (ssl->buffers.weOwnDH /*|| ssl->options.side == WOLFSSL_CLIENT_END*/) {
XFREE(ssl->buffers.serverDH_G.buffer, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY);
ssl->buffers.serverDH_G.buffer = NULL;
XFREE(ssl->buffers.serverDH_P.buffer, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY);
@@ -16805,6 +16816,7 @@
}
else
#endif
+#ifndef WOLFSSL_MYSQL_COMPATIBLE
if (ssl->ctx->method->version.major == SSLv3_MAJOR &&
ssl->ctx->method->version.minor == TLSv1_2_MINOR) {
/* TLS v1.2 capable client not allowed to downgrade when connecting
@@ -16817,6 +16829,7 @@
return VERSION_ERROR;
}
}
+#endif
/* session id */
ssl->arrays->sessionIDSz = input[i++];
@@ -17375,6 +17388,8 @@
length);
args->idx += length;
+ ssl->buffers.weOwnDH= 1;
+
/* pub */
if ((args->idx - args->begin) + OPAQUE16_LEN > size) {
ERROR_OUT(BUFFER_ERROR, exit_dske);
@@ -17566,6 +17581,8 @@
length);
args->idx += length;
+ ssl->buffers.weOwnDH= 1;
+
/* pub */
if ((args->idx - args->begin) + OPAQUE16_LEN > size) {
ERROR_OUT(BUFFER_ERROR, exit_dske);
diff -ur -N -d -x CMakeLists.txt wolfssl-3.13.0-pristine/src/ssl.c wolfssl-3.13.0/src/ssl.c
--- wolfssl-3.13.0-pristine/src/ssl.c 2017-12-21 19:23:03.000000000 +0200
+++ wolfssl-3.13.0/src/ssl.c 2018-01-03 17:13:10.889281600 +0200
@@ -23442,6 +23442,230 @@
return WOLFSSL_SUCCESS;
}
+
+
+/* return WOLFSSL_SUCCESS if success, WOLFSSL_FATAL_ERROR if error */
+static int wolfSSL_RSA_PubLoadDer(WOLFSSL_RSA* rsa, const unsigned char* derBuf, int derSz)
+{
+ word32 idx = 0;
+ int ret;
+
+ WOLFSSL_ENTER("wolfSSL_RSA_LoadDer");
+
+ if (rsa == NULL || rsa->internal == NULL || derBuf == NULL || derSz <= 0) {
+ WOLFSSL_MSG("Bad function arguments");
+ return WOLFSSL_FATAL_ERROR;
+ }
+
+ ret = wc_RsaPublicKeyDecode(derBuf, &idx, (RsaKey*)rsa->internal, derSz);
+ if (ret < 0) {
+ WOLFSSL_MSG("RsaPublicKeyDecode failed");
+ return WOLFSSL_FATAL_ERROR;
+ }
+
+ if (SetRsaExternal(rsa) != WOLFSSL_SUCCESS) {
+ WOLFSSL_MSG("SetRsaExternal failed");
+ return WOLFSSL_FATAL_ERROR;
+ }
+
+ rsa->inSet = 1;
+
+ return WOLFSSL_SUCCESS;
+}
+
+/* returns WOLFSSL_RSA object on success, NULL on failure */
+static RSA * wolfssl_PEM_read_mem_RSA_PUBKEY(void * buffer, int buffer_size)
+{
+ byte *der_buff = NULL;
+ int der_buff_size = 0;
+ int load_result = 0;
+ WOLFSSL_RSA *pub_rsa = NULL;
+
+ if (!buffer || !buffer_size)
+ return NULL;
+
+ if(!(der_buff = (byte *)XMALLOC(buffer_size, NULL, DYNAMIC_TYPE_DER)))
+ return NULL;
+
+ /* Convert public key from PEM format to DER format */
+ der_buff_size = wolfSSL_PubKeyPemToDer((unsigned char *)buffer, buffer_size,
+ der_buff, buffer_size);
+
+ if (der_buff_size <= 0)
+ {
+ ForceZero(der_buff, (word32)buffer_size);
+ XFREE(der_buff, NULL, DYNAMIC_TYPE_DER);
+ return NULL;
+ }
+
+ if (!(pub_rsa = wolfSSL_RSA_new()))
+ {
+ ForceZero(der_buff, (word32)buffer_size);
+ XFREE(der_buff, NULL, DYNAMIC_TYPE_DER);
+ return NULL;
+ }
+
+ /* Create RSA structure from public key in DER format */
+ load_result = wolfSSL_RSA_PubLoadDer(pub_rsa, der_buff, der_buff_size);
+ if (load_result == WOLFSSL_FATAL_ERROR)
+ {
+ ForceZero(der_buff, (word32)buffer_size);
+ XFREE(der_buff, NULL, DYNAMIC_TYPE_DER);
+ wolfSSL_RSA_free(pub_rsa);
+ return NULL;
+ }
+
+ return pub_rsa;
+}
+
+WOLFSSL_RSA *wolfssl_PEM_read_bio_RSA_PUBKEY(WOLFSSL_BIO *bp, WOLFSSL_RSA **x,
+ pem_password_cb *cb, void *u)
+{
+ byte *pem_buf;
+ int pem_buf_size;
+
+ if (bp == NULL) {
+ WOLFSSL_MSG("NULL argument passed in");
+ return NULL;
+ }
+ if (bp->type != BIO_MEMORY) {
+ WOLFSSL_MSG("currently only works with memory BIOs");
+ return NULL;
+ }
+ pem_buf_size = wolfSSL_BIO_get_mem_data(bp, &pem_buf);
+ /* Create RSA structure from DER buffer */
+ return wolfssl_PEM_read_mem_RSA_PUBKEY(pem_buf, pem_buf_size);
+}
+
+WOLFSSL_RSA *wolfssl_PEM_read_RSA_PUBKEY(FILE * fp,
+ WOLFSSL_RSA ** x,
+ pem_password_cb * cb,
+ void * u)
+{
+ int file_size = 0;
+ int pem_buff_size = 0;
+ byte *pem_buff = NULL;
+ XFILE file = (XFILE) fp;
+ WOLFSSL_RSA *pub_rsa = NULL;
+
+ (void)x;
+ (void)cb;
+ (void)u;
+ /* Get file size */
+ if (!file)
+ return NULL;
+ XFSEEK(file, 0, XSEEK_END);
+ file_size = XFTELL(file);
+ XREWIND(file);
+
+ if (!file_size ||
+ !(pem_buff = (byte *)XMALLOC(file_size, NULL, DYNAMIC_TYPE_PEM)))
+ return NULL;
+
+ /* Read file content */
+ pem_buff_size = (int) XFREAD(pem_buff, 1, file_size, file);
+ if (pem_buff_size != file_size)
+ {
+ ForceZero(pem_buff, (word32)file_size);
+ XFREE(pem_buff, NULL, DYNAMIC_TYPE_PEM);
+ return NULL;
+ }
+
+ /* Create RSA structure from DER buffer */
+ if (!(pub_rsa = wolfssl_PEM_read_mem_RSA_PUBKEY(pem_buff, pem_buff_size)))
+ {
+ ForceZero(pem_buff, (word32)file_size);
+ XFREE(pem_buff, NULL, DYNAMIC_TYPE_PEM);
+ return NULL;
+ }
+
+ return pub_rsa;
+}
+
+WOLFSSL_RSA *wolfssl_PEM_read_RSAPrivateKey(FILE *fp,
+ WOLFSSL_RSA ** x,
+ pem_password_cb * cb,
+ void * u)
+{
+ int file_size = 0;
+ int pem_buff_size = 0;
+ int der_buff_size = 0;
+ int load_result = 0;
+ byte *pem_buff = NULL;
+ byte *der_buff = NULL;
+ WOLFSSL_RSA *priv_rsa = NULL;
+ XFILE file = (XFILE) fp;
+
+ (void)x;
+ (void)cb;
+ (void)u;
+ /* Get file size */
+ if (!file)
+ return NULL;
+ XFSEEK(file, 0, XSEEK_END);
+ file_size = XFTELL(file);
+ XREWIND(file);
+
+ if (!file_size ||
+ !(pem_buff = (byte *)XMALLOC(file_size, NULL, DYNAMIC_TYPE_PEM)))
+ {
+ return NULL;
+ }
+
+ /* Read file content */
+ pem_buff_size = (int) XFREAD(pem_buff, 1, file_size, file);
+ if (pem_buff_size != file_size)
+ {
+ ForceZero(pem_buff, (word32)file_size);
+ XFREE(pem_buff, NULL, DYNAMIC_TYPE_PEM);
+ return NULL;
+ }
+
+ if (!(der_buff = (byte *)XMALLOC(pem_buff_size, NULL, DYNAMIC_TYPE_DER)))
+ {
+
+ ForceZero(pem_buff, (word32)file_size);
+ XFREE(pem_buff, NULL, DYNAMIC_TYPE_PEM);
+ return NULL;
+ }
+
+ /* Convert private key from PEM format to DER format */
+ der_buff_size = wolfSSL_KeyPemToDer(pem_buff, pem_buff_size,
+ der_buff, pem_buff_size,
+ NULL);
+
+ if (der_buff_size <= 0)
+ {
+ ForceZero(pem_buff, (word32)file_size);
+ XFREE(pem_buff, NULL, DYNAMIC_TYPE_PEM);
+ ForceZero(der_buff, (word32)pem_buff_size);
+ XFREE(der_buff, NULL, DYNAMIC_TYPE_DER);
+ return NULL;
+ }
+
+ if (!(priv_rsa = wolfSSL_RSA_new()))
+ {
+ ForceZero(pem_buff, (word32)file_size);
+ XFREE(pem_buff, NULL, DYNAMIC_TYPE_PEM);
+ ForceZero(der_buff, (word32)pem_buff_size);
+ XFREE(der_buff, NULL, DYNAMIC_TYPE_DER);
+ return NULL;
+ }
+
+ /* Create RSA structure from private key in DER format */
+ load_result = wolfSSL_RSA_LoadDer(priv_rsa, der_buff, der_buff_size);
+ if (load_result == WOLFSSL_FATAL_ERROR)
+ {
+ ForceZero(pem_buff, (word32)file_size);
+ XFREE(pem_buff, NULL, DYNAMIC_TYPE_PEM);
+ ForceZero(der_buff, (word32)pem_buff_size);
+ XFREE(der_buff, NULL, DYNAMIC_TYPE_DER);
+ wolfSSL_RSA_free(priv_rsa);
+ return NULL;
+ }
+
+ return priv_rsa;
+}
#endif /* NO_RSA */
diff -ur -N -d -x CMakeLists.txt wolfssl-3.13.0-pristine/wolfssl/openssl/md5.h wolfssl-3.13.0/wolfssl/openssl/md5.h
--- wolfssl-3.13.0-pristine/wolfssl/openssl/md5.h 2017-12-21 19:23:03.000000000 +0200
+++ wolfssl-3.13.0/wolfssl/openssl/md5.h 2018-01-04 10:59:15.905576800 +0200
@@ -20,7 +20,7 @@
typedef struct WOLFSSL_MD5_CTX {
- int holder[28 + (WC_ASYNC_DEV_SIZE / sizeof(int))]; /* big enough to hold wolfcrypt md5, but check on init */
+ void *holder[28 + (WC_ASYNC_DEV_SIZE / sizeof(void *))]; /* big enough to hold wolfcrypt md5, but check on init */
} WOLFSSL_MD5_CTX;
WOLFSSL_API int wolfSSL_MD5_Init(WOLFSSL_MD5_CTX*);
diff -ur -N -d -x CMakeLists.txt wolfssl-3.13.0-pristine/wolfssl/openssl/pem.h wolfssl-3.13.0/wolfssl/openssl/pem.h
--- wolfssl-3.13.0-pristine/wolfssl/openssl/pem.h 2017-12-21 19:23:03.000000000 +0200
+++ wolfssl-3.13.0/wolfssl/openssl/pem.h 2018-01-03 17:13:10.904907100 +0200
@@ -35,10 +35,19 @@
WOLFSSL_RSA *wolfSSL_PEM_read_RSAPublicKey(FILE *fp, WOLFSSL_RSA **x,
pem_password_cb *cb, void *u);
WOLFSSL_API
+WOLFSSL_RSA *wolfssl_PEM_read_RSAPrivateKey(FILE *, WOLFSSL_RSA **, pem_password_cb *, void *);
+
+WOLFSSL_API
+WOLFSSL_RSA *wolfssl_PEM_read_bio_RSA_PUBKEY(WOLFSSL_BIO *bp, WOLFSSL_RSA **x,
+ pem_password_cb *cb, void *u);
+WOLFSSL_API
int wolfSSL_PEM_write_RSAPublicKey(FILE *fp, WOLFSSL_RSA *x);
WOLFSSL_API
int wolfSSL_PEM_write_RSA_PUBKEY(FILE *fp, WOLFSSL_RSA *x);
+
+WOLFSSL_API
+WOLFSSL_RSA * wolfssl_PEM_read_RSA_PUBKEY(FILE *, WOLFSSL_RSA **, pem_password_cb *, void *);
#endif /* NO_FILESYSTEM */
/* DSA */
@@ -123,6 +132,7 @@
#define PEM_write_RSA_PUBKEY wolfSSL_PEM_write_RSA_PUBKEY
#define PEM_write_RSAPublicKey wolfSSL_PEM_write_RSAPublicKey
#define PEM_read_RSAPublicKey wolfSSL_PEM_read_RSAPublicKey
+#define PEM_read_bio_RSA_PUBKEY wolfssl_PEM_read_bio_RSA_PUBKEY
/* DSA */
#define PEM_write_bio_DSAPrivateKey wolfSSL_PEM_write_bio_DSAPrivateKey
#define PEM_write_DSAPrivateKey wolfSSL_PEM_write_DSAPrivateKey
@@ -136,6 +146,9 @@
#define PEM_read_PUBKEY wolfSSL_PEM_read_PUBKEY
#define EVP_PKEY_type wolfSSL_EVP_PKEY_type
+#define PEM_read_RSAPrivateKey wolfssl_PEM_read_RSAPrivateKey
+#define PEM_read_RSA_PUBKEY wolfssl_PEM_read_RSA_PUBKEY
+
#ifdef __cplusplus
} /* extern "C" */
#endif
diff -ur -N -d -x CMakeLists.txt wolfssl-3.13.0-pristine/wolfssl/openssl/sha.h wolfssl-3.13.0/wolfssl/openssl/sha.h
--- wolfssl-3.13.0-pristine/wolfssl/openssl/sha.h 2017-12-21 19:23:03.000000000 +0200
+++ wolfssl-3.13.0/wolfssl/openssl/sha.h 2018-01-03 17:55:41.094027800 +0200
@@ -18,7 +18,7 @@
typedef struct WOLFSSL_SHA_CTX {
/* big enough to hold wolfcrypt Sha, but check on init */
- int holder[28 + (WC_ASYNC_DEV_SIZE / sizeof(int))];
+ void* holder[28 + (WC_ASYNC_DEV_SIZE / sizeof(void *))];
} WOLFSSL_SHA_CTX;
WOLFSSL_API int wolfSSL_SHA_Init(WOLFSSL_SHA_CTX*);
diff -ur -N -d -x CMakeLists.txt wolfssl-3.13.0-pristine/wolfssl/ssl.h wolfssl-3.13.0/wolfssl/ssl.h
--- wolfssl-3.13.0-pristine/wolfssl/ssl.h 2017-12-21 19:23:03.000000000 +0200
+++ wolfssl-3.13.0/wolfssl/ssl.h 2018-01-03 17:13:10.904907100 +0200
@@ -506,7 +506,7 @@
#endif /* SESSION_INDEX && SESSION_CERTS */
typedef int (*VerifyCallback)(int, WOLFSSL_X509_STORE_CTX*);
-typedef int (pem_password_cb)(char*, int, int, void*);
+typedef int pem_password_cb(char*, int, int, void*);
WOLFSSL_API void wolfSSL_CTX_set_verify(WOLFSSL_CTX*, int,
VerifyCallback verify_callback);