summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander M Pickering <alex@cogarr.net>2024-11-11 13:57:04 -0600
committerAlexander M Pickering <alex@cogarr.net>2024-11-11 13:57:04 -0600
commit11b4644df5de275049210f301c4b791e782fa8a5 (patch)
tree70e24edf751cfb6ff067f8325e45e035a3d781ab
parentc0add6f460d368939558291e5579dfe28b6727fc (diff)
downloadbusybox-w32-packaging-11b4644df5de275049210f301c4b791e782fa8a5.tar.gz
busybox-w32-packaging-11b4644df5de275049210f301c4b791e782fa8a5.tar.bz2
busybox-w32-packaging-11b4644df5de275049210f301c4b791e782fa8a5.zip
work
-rw-r--r--libressl.patch131
1 files changed, 88 insertions, 43 deletions
diff --git a/libressl.patch b/libressl.patch
index 6af3b51..0c7f495 100644
--- a/libressl.patch
+++ b/libressl.patch
@@ -135,20 +135,48 @@ index 9f1dd67ec..7e8da6df2 100644
135 static void tls_xwrite(tls_state_t *tls, int len) 135 static void tls_xwrite(tls_state_t *tls, int len)
136 { 136 {
137diff --git a/networking/wget.c b/networking/wget.c 137diff --git a/networking/wget.c b/networking/wget.c
138index 6a64836fb..3bd573e0a 100644 138index 6a64836fb..8805aae0b 100644
139--- a/networking/wget.c 139--- a/networking/wget.c
140+++ b/networking/wget.c 140+++ b/networking/wget.c
141@@ -169,7 +169,8 @@ 141@@ -169,7 +169,11 @@
142 //usage: "\n -Y on/off Use proxy" 142 //usage: "\n -Y on/off Use proxy"
143 143
144 #include "libbb.h" 144 #include "libbb.h"
145- 145-
146+#include <string.h> 146+#include <string.h>
147+#include <errno.h> 147+#include <errno.h>
148+#include <tls.h>
149+#include <stdarg.h>
150+#include <stdio.h>
148 #if 0 151 #if 0
149 # define log_io(...) bb_error_msg(__VA_ARGS__) 152 # define log_io(...) bb_error_msg(__VA_ARGS__)
150 # define SENDFMT(fp, fmt, ...) \ 153 # define SENDFMT(fp, fmt, ...) \
151@@ -488,26 +489,35 @@ static char fgets_trim_sanitize(FILE *fp, const char *fmt) 154@@ -179,6 +183,24 @@
155 } while (0);
156 #else
157 # define log_io(...) ((void)0)
158+/*
159+void SENDFMT(struct tls *ctx, const char *fmt, ...) {
160+ va_list args, args2;
161+ va_start(args, fmt);
162+ size_t strlen = vsnprintf(NULL, 0, fmt, args);
163+ va_end(args);
164+ char *buf = (char*)malloc(strlen);
165+ va_start(args2, fmt);
166+ vsnprintf(buf, strlen, fmt, args2);
167+ va_end(args2);
168+ ssize_t writelen = tls_write(ctx, buf, strlen);
169+ if(writelen == -1)
170+ bb_error_msg_and_die("tls_write error: %s", tls_error(ctx));
171+ if(writelen != strlen)
172+ bb_error_msg_and_die("tls_write incomplete");
173+ free(buf);
174+}
175+*/
176 # define SENDFMT(fp, fmt, ...) fprintf(fp, fmt, ##__VA_ARGS__)
177 #endif
178
179@@ -488,26 +510,35 @@ static char fgets_trim_sanitize(FILE *fp, const char *fmt)
152 char c; 180 char c;
153 char *buf_ptr; 181 char *buf_ptr;
154 182
@@ -186,7 +214,7 @@ index 6a64836fb..3bd573e0a 100644
186 214
187 return c; 215 return c;
188 } 216 }
189@@ -689,6 +699,7 @@ static void reset_beg_range_to_zero(void) 217@@ -689,6 +720,7 @@ static void reset_beg_range_to_zero(void)
190 } 218 }
191 219
192 #if ENABLE_FEATURE_WGET_OPENSSL 220 #if ENABLE_FEATURE_WGET_OPENSSL
@@ -194,7 +222,7 @@ index 6a64836fb..3bd573e0a 100644
194 static int spawn_https_helper_openssl(const char *host, unsigned port) 222 static int spawn_https_helper_openssl(const char *host, unsigned port)
195 { 223 {
196 char *allocated = NULL; 224 char *allocated = NULL;
197@@ -777,6 +788,38 @@ static int spawn_https_helper_openssl(const char *host, unsigned port) 225@@ -777,6 +809,38 @@ static int spawn_https_helper_openssl(const char *host, unsigned port)
198 # endif 226 # endif
199 return sp[0]; 227 return sp[0];
200 } 228 }
@@ -233,7 +261,7 @@ index 6a64836fb..3bd573e0a 100644
233 #endif 261 #endif
234 262
235 #if ENABLE_FEATURE_WGET_HTTPS 263 #if ENABLE_FEATURE_WGET_HTTPS
236@@ -1151,6 +1194,7 @@ static void download_one_url(const char *url) 264@@ -1151,6 +1215,7 @@ static void download_one_url(const char *url)
237 server.user = NULL; 265 server.user = NULL;
238 target.user = NULL; 266 target.user = NULL;
239 267
@@ -241,7 +269,7 @@ index 6a64836fb..3bd573e0a 100644
241 parse_url(url, &target); 269 parse_url(url, &target);
242 270
243 /* Use the proxy if necessary */ 271 /* Use the proxy if necessary */
244@@ -1172,6 +1216,7 @@ static void download_one_url(const char *url) 272@@ -1172,6 +1237,7 @@ static void download_one_url(const char *url)
245 server.host = target.host; 273 server.host = target.host;
246 } 274 }
247 } 275 }
@@ -249,7 +277,7 @@ index 6a64836fb..3bd573e0a 100644
249 277
250 if (ENABLE_FEATURE_IPV6) 278 if (ENABLE_FEATURE_IPV6)
251 strip_ipv6_scope_id(target.host); 279 strip_ipv6_scope_id(target.host);
252@@ -1191,6 +1236,7 @@ static void download_one_url(const char *url) 280@@ -1191,6 +1257,7 @@ static void download_one_url(const char *url)
253 G.fname_out = fname_out_alloc = xstrdup(G.fname_out); 281 G.fname_out = fname_out_alloc = xstrdup(G.fname_out);
254 } 282 }
255 } 283 }
@@ -257,7 +285,7 @@ index 6a64836fb..3bd573e0a 100644
257 #if ENABLE_FEATURE_WGET_STATUSBAR 285 #if ENABLE_FEATURE_WGET_STATUSBAR
258 G.curfile = bb_get_last_path_component_nostrip(G.fname_out); 286 G.curfile = bb_get_last_path_component_nostrip(G.fname_out);
259 #endif 287 #endif
260@@ -1206,15 +1252,19 @@ static void download_one_url(const char *url) 288@@ -1206,15 +1273,19 @@ static void download_one_url(const char *url)
261 * We are not sure it exists on remote side */ 289 * We are not sure it exists on remote side */
262 } 290 }
263 291
@@ -277,42 +305,58 @@ index 6a64836fb..3bd573e0a 100644
277 /*G.content_len = 0; - redundant, got_clen = 0 is enough */ 305 /*G.content_len = 0; - redundant, got_clen = 0 is enough */
278 G.got_clen = 0; 306 G.got_clen = 0;
279 G.chunked = 0; 307 G.chunked = 0;
280@@ -1229,37 +1279,49 @@ static void download_one_url(const char *url) 308@@ -1229,37 +1300,54 @@ static void download_one_url(const char *url)
281 309
282 /* Open socket to http(s) server */ 310 /* Open socket to http(s) server */
283 #if ENABLE_FEATURE_WGET_OPENSSL 311 #if ENABLE_FEATURE_WGET_OPENSSL
284+ printf("wget download_one_url 8\n"); 312+ printf("wget download_one_url 8\n");
285 /* openssl (and maybe internal TLS) support is configured */ 313 /* openssl (and maybe internal TLS) support is configured */
314+ struct tls *ctx;
286 if (server.protocol == P_HTTPS) { 315 if (server.protocol == P_HTTPS) {
287 /* openssl-based helper 316 /* openssl-based helper
288 * Inconvenient API since we can't give it an open fd 317 * Inconvenient API since we can't give it an open fd
289 */ 318 */
319- int fd = spawn_https_helper_openssl(server.host, server.port);
320-# if ENABLE_FEATURE_WGET_HTTPS
321- if (fd < 0) { /* no openssl? try internal */
322- sfp = open_socket(lsa);
323- spawn_ssl_client(server.host, fileno(sfp), /*flags*/ 0);
324- goto socket_opened;
290+ printf("wget download_one_url 9\n"); 325+ printf("wget download_one_url 9\n");
291 int fd = spawn_https_helper_openssl(server.host, server.port); 326+ //int fd = spawn_https_helper_openssl(server.host, server.port);
327+ ctx = tls_client();
328+ if(ctx == NULL)
329+ bb_error_msg_and_die("Out of memory 1");
330+ struct tls_config *config;
331+ config = tls_config_new();
332+ if(config == NULL)
333+ bb_error_msg_and_die("Out of memory 2");
334+ if(tls_configure(ctx,config) != 0)
335+ bb_error_msg_and_die("Failed to configure client");
336+ sfp = tmpfile();
337+ dfp = tmpfile();
338+ tls_connect_fds(ctx, dfp, sfp, servername);
339+ tls_config_free(config);
340+ free(allocated);
341+ free(servername);
292+ printf("wget download_one_url 10\n"); 342+ printf("wget download_one_url 10\n");
293 # if ENABLE_FEATURE_WGET_HTTPS
294 if (fd < 0) { /* no openssl? try internal */
295+ printf("wget download_one_url 11\n");
296 sfp = open_socket(lsa);
297 spawn_ssl_client(server.host, fileno(sfp), /*flags*/ 0);
298 goto socket_opened;
299+ printf("wget download_one_url 12\n");
300 }
301 # else
302 /* We don't check for exec("openssl") failure in this case */
303 # endif
304+ printf("wget download_one_url 13\n"); 343+ printf("wget download_one_url 13\n");
305 sfp = fdopen(fd, "r+"); 344+ //sfp = fdopen(fd, "r+");
306- if (!sfp)
307- bb_die_memory_exhausted();
308+ if (!sfp){ 345+ if (!sfp){
309+ bb_error_msg_and_die("Error opening fd: %s",strerror(errno)); 346+ bb_error_msg_and_die("Error opening fd: %s",strerror(errno));
310+ } 347 }
348-# else
349- /* We don't check for exec("openssl") failure in this case */
350-# endif
351- sfp = fdopen(fd, "r+");
352- if (!sfp)
353- bb_die_memory_exhausted();
311+ printf("wget download_one_url 14\n"); 354+ printf("wget download_one_url 14\n");
312 goto socket_opened; 355 goto socket_opened;
313 } 356 }
357- sfp = open_socket(lsa);
314+ printf("wget download_one_url 15\n"); 358+ printf("wget download_one_url 15\n");
315 sfp = open_socket(lsa); 359+ //sfp = open_socket(lsa);
316 socket_opened: 360 socket_opened:
317 #elif ENABLE_FEATURE_WGET_HTTPS 361 #elif ENABLE_FEATURE_WGET_HTTPS
318 /* Only internal TLS support is configured */ 362 /* Only internal TLS support is configured */
@@ -329,7 +373,7 @@ index 6a64836fb..3bd573e0a 100644
329 /* Send HTTP request */ 373 /* Send HTTP request */
330 if (use_proxy) { 374 if (use_proxy) {
331 SENDFMT(sfp, "GET %s://%s/%s HTTP/1.1\r\n", 375 SENDFMT(sfp, "GET %s://%s/%s HTTP/1.1\r\n",
332@@ -1270,6 +1332,7 @@ static void download_one_url(const char *url) 376@@ -1270,6 +1358,7 @@ static void download_one_url(const char *url)
333 (option_mask32 & WGET_OPT_POST) ? "POST" : "GET", 377 (option_mask32 & WGET_OPT_POST) ? "POST" : "GET",
334 target.path); 378 target.path);
335 } 379 }
@@ -337,7 +381,7 @@ index 6a64836fb..3bd573e0a 100644
337 if (!USR_HEADER_HOST) 381 if (!USR_HEADER_HOST)
338 SENDFMT(sfp, "Host: %s\r\n", target.host); 382 SENDFMT(sfp, "Host: %s\r\n", target.host);
339 if (!USR_HEADER_USER_AGENT) 383 if (!USR_HEADER_USER_AGENT)
340@@ -1280,6 +1343,7 @@ static void download_one_url(const char *url) 384@@ -1280,6 +1369,7 @@ static void download_one_url(const char *url)
341 */ 385 */
342 SENDFMT(sfp, "Connection: close\r\n"); 386 SENDFMT(sfp, "Connection: close\r\n");
343 387
@@ -345,7 +389,7 @@ index 6a64836fb..3bd573e0a 100644
345 #if ENABLE_FEATURE_WGET_AUTHENTICATION 389 #if ENABLE_FEATURE_WGET_AUTHENTICATION
346 if (target.user && !USR_HEADER_AUTH) { 390 if (target.user && !USR_HEADER_AUTH) {
347 SENDFMT(sfp, "Proxy-Authorization: Basic %s\r\n"+6, 391 SENDFMT(sfp, "Proxy-Authorization: Basic %s\r\n"+6,
348@@ -1291,6 +1355,7 @@ static void download_one_url(const char *url) 392@@ -1291,6 +1381,7 @@ static void download_one_url(const char *url)
349 } 393 }
350 #endif 394 #endif
351 395
@@ -353,7 +397,7 @@ index 6a64836fb..3bd573e0a 100644
353 if (G.beg_range != 0 && !USR_HEADER_RANGE) 397 if (G.beg_range != 0 && !USR_HEADER_RANGE)
354 SENDFMT(sfp, "Range: bytes=%"OFF_FMT"u-\r\n", G.beg_range); 398 SENDFMT(sfp, "Range: bytes=%"OFF_FMT"u-\r\n", G.beg_range);
355 399
356@@ -1300,6 +1365,7 @@ static void download_one_url(const char *url) 400@@ -1300,6 +1391,7 @@ static void download_one_url(const char *url)
357 fputs(G.extra_headers, sfp); 401 fputs(G.extra_headers, sfp);
358 } 402 }
359 403
@@ -361,7 +405,7 @@ index 6a64836fb..3bd573e0a 100644
361 if (option_mask32 & WGET_OPT_POST_FILE) { 405 if (option_mask32 & WGET_OPT_POST_FILE) {
362 int fd = xopen_stdin(G.post_file); 406 int fd = xopen_stdin(G.post_file);
363 G.post_data = xmalloc_read(fd, NULL); 407 G.post_data = xmalloc_read(fd, NULL);
364@@ -1314,15 +1380,18 @@ static void download_one_url(const char *url) 408@@ -1314,15 +1406,18 @@ static void download_one_url(const char *url)
365 ); 409 );
366 } 410 }
367 # if ENABLE_PLATFORM_MINGW32 411 # if ENABLE_PLATFORM_MINGW32
@@ -380,7 +424,7 @@ index 6a64836fb..3bd573e0a 100644
380 } else 424 } else
381 # else 425 # else
382 SENDFMT(sfp, 426 SENDFMT(sfp,
383@@ -1338,6 +1407,7 @@ static void download_one_url(const char *url) 427@@ -1338,6 +1433,7 @@ static void download_one_url(const char *url)
384 SENDFMT(sfp, "\r\n"); 428 SENDFMT(sfp, "\r\n");
385 } 429 }
386 430
@@ -388,10 +432,11 @@ index 6a64836fb..3bd573e0a 100644
388 fflush(sfp); 432 fflush(sfp);
389 433
390 /* Tried doing this unconditionally. 434 /* Tried doing this unconditionally.
391@@ -1358,14 +1428,21 @@ static void download_one_url(const char *url) 435@@ -1358,14 +1454,22 @@ static void download_one_url(const char *url)
392 * Retrieve HTTP response line and check for "200" status code. 436 * Retrieve HTTP response line and check for "200" status code.
393 */ 437 */
394 read_response: 438 read_response:
439+ sfp = dfp;
395+ printf("wget download_one_url 27\n"); 440+ printf("wget download_one_url 27\n");
396 fgets_trim_sanitize(sfp, " %s\n"); 441 fgets_trim_sanitize(sfp, " %s\n");
397+ printf("wget download_one_url 27-1\n"); 442+ printf("wget download_one_url 27-1\n");
@@ -410,7 +455,7 @@ index 6a64836fb..3bd573e0a 100644
410 switch (status) { 455 switch (status) {
411 case 0: 456 case 0:
412 case 100: 457 case 100:
413@@ -1441,6 +1518,7 @@ However, in real world it was observed that some web servers 458@@ -1441,6 +1545,7 @@ However, in real world it was observed that some web servers
414 /* 459 /*
415 * Retrieve HTTP headers. 460 * Retrieve HTTP headers.
416 */ 461 */
@@ -418,7 +463,7 @@ index 6a64836fb..3bd573e0a 100644
418 while ((str = get_sanitized_hdr(sfp)) != NULL) { 463 while ((str = get_sanitized_hdr(sfp)) != NULL) {
419 static const char keywords[] ALIGN1 = 464 static const char keywords[] ALIGN1 =
420 "content-length\0""transfer-encoding\0""location\0"; 465 "content-length\0""transfer-encoding\0""location\0";
421@@ -1497,6 +1575,7 @@ However, in real world it was observed that some web servers 466@@ -1497,6 +1602,7 @@ However, in real world it was observed that some web servers
422 goto establish_session; 467 goto establish_session;
423 } 468 }
424 } 469 }
@@ -426,7 +471,7 @@ index 6a64836fb..3bd573e0a 100644
426 // if (status >= 300) 471 // if (status >= 300)
427 // bb_error_msg_and_die("bad redirection (no Location: header from server)"); 472 // bb_error_msg_and_die("bad redirection (no Location: header from server)");
428 473
429@@ -1514,6 +1593,7 @@ However, in real world it was observed that some web servers 474@@ -1514,6 +1620,7 @@ However, in real world it was observed that some web servers
430 475
431 free(lsa); 476 free(lsa);
432 477
@@ -434,7 +479,7 @@ index 6a64836fb..3bd573e0a 100644
434 if (!(option_mask32 & WGET_OPT_SPIDER)) { 479 if (!(option_mask32 & WGET_OPT_SPIDER)) {
435 if (G.output_fd < 0) 480 if (G.output_fd < 0)
436 G.output_fd = xopen(G.fname_out, G.o_flags); 481 G.output_fd = xopen(G.fname_out, G.o_flags);
437@@ -1536,6 +1616,7 @@ However, in real world it was observed that some web servers 482@@ -1536,6 +1643,7 @@ However, in real world it was observed that some web servers
438 /* ftpcmd("QUIT", NULL, sfp); - why bother? */ 483 /* ftpcmd("QUIT", NULL, sfp); - why bother? */
439 } 484 }
440 #endif 485 #endif
@@ -442,7 +487,7 @@ index 6a64836fb..3bd573e0a 100644
442 fclose(sfp); 487 fclose(sfp);
443 488
444 free(server.allocated); 489 free(server.allocated);
445@@ -1544,11 +1625,13 @@ However, in real world it was observed that some web servers 490@@ -1544,11 +1652,13 @@ However, in real world it was observed that some web servers
446 free(target.user); 491 free(target.user);
447 free(fname_out_alloc); 492 free(fname_out_alloc);
448 free(redirected_path); 493 free(redirected_path);
@@ -456,7 +501,7 @@ index 6a64836fb..3bd573e0a 100644
456 #if ENABLE_FEATURE_WGET_LONG_OPTIONS 501 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
457 static const char wget_longopts[] ALIGN1 = 502 static const char wget_longopts[] ALIGN1 =
458 /* name, has_arg, val */ 503 /* name, has_arg, val */
459@@ -1590,6 +1673,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0") 504@@ -1590,6 +1700,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
460 #endif 505 #endif
461 506
462 INIT_G(); 507 INIT_G();
@@ -464,7 +509,7 @@ index 6a64836fb..3bd573e0a 100644
464 509
465 #if ENABLE_FEATURE_WGET_TIMEOUT 510 #if ENABLE_FEATURE_WGET_TIMEOUT
466 G.timeout_seconds = 900; 511 G.timeout_seconds = 900;
467@@ -1626,6 +1710,8 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0") 512@@ -1626,6 +1737,8 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
468 IF_FEATURE_WGET_LONG_OPTIONS(, &G.post_data) 513 IF_FEATURE_WGET_LONG_OPTIONS(, &G.post_data)
469 IF_FEATURE_WGET_LONG_OPTIONS(, &G.post_file) 514 IF_FEATURE_WGET_LONG_OPTIONS(, &G.post_file)
470 ); 515 );
@@ -473,7 +518,7 @@ index 6a64836fb..3bd573e0a 100644
473 #if 0 /* option bits debug */ 518 #if 0 /* option bits debug */
474 if (option_mask32 & WGET_OPT_RETRIES) bb_error_msg("-t NUM"); 519 if (option_mask32 & WGET_OPT_RETRIES) bb_error_msg("-t NUM");
475 if (option_mask32 & WGET_OPT_nsomething) bb_error_msg("-nsomething"); 520 if (option_mask32 & WGET_OPT_nsomething) bb_error_msg("-nsomething");
476@@ -1670,6 +1756,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0") 521@@ -1670,6 +1783,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
477 } 522 }
478 #endif 523 #endif
479 524
@@ -481,7 +526,7 @@ index 6a64836fb..3bd573e0a 100644
481 G.output_fd = -1; 526 G.output_fd = -1;
482 G.o_flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL; 527 G.o_flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL;
483 if (G.fname_out) { /* -O FILE ? */ 528 if (G.fname_out) { /* -O FILE ? */
484@@ -1691,8 +1778,11 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0") 529@@ -1691,8 +1805,11 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
485 } 530 }
486 } 531 }
487 532