summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander M Pickering <alex@cogarr.net>2024-11-14 21:02:14 -0600
committerAlexander M Pickering <alex@cogarr.net>2024-11-14 21:02:14 -0600
commitdc3a97e1cc8b6bd011158b8e609f71fce55e7a43 (patch)
tree17d3921489313f5026e193f5bdd7798c835dc8f7
parentd305666110dfc0ac1aff6804511bff0adf53fed2 (diff)
downloadbusybox-w32-packaging-dc3a97e1cc8b6bd011158b8e609f71fce55e7a43.tar.gz
busybox-w32-packaging-dc3a97e1cc8b6bd011158b8e609f71fce55e7a43.tar.bz2
busybox-w32-packaging-dc3a97e1cc8b6bd011158b8e609f71fce55e7a43.zip
try a different way of patching
-rwxr-xr-xinit2
-rw-r--r--libressl2.patch105
2 files changed, 106 insertions, 1 deletions
diff --git a/init b/init
index 348c86b..b7ba829 100755
--- a/init
+++ b/init
@@ -13,7 +13,7 @@ mv libcrypto.a /usr/x86_64-w64-mingw32/lib
13 13
14cd busybox-w32 14cd busybox-w32
15cp /root/busybox-w32-packaging/config .config 15cp /root/busybox-w32-packaging/config .config
16git apply /root/busybox-w32-packaging/libressl.patch 16git apply /root/busybox-w32-packaging/libressl2.patch
17# For some reason this code only causes errors on -O0 17# For some reason this code only causes errors on -O0
18if [ -n "$ZERO_PATCH" ]; then 18if [ -n "$ZERO_PATCH" ]; then
19 git apply /root/busybox-w32-packaging/zero.patch 19 git apply /root/busybox-w32-packaging/zero.patch
diff --git a/libressl2.patch b/libressl2.patch
new file mode 100644
index 0000000..ccf7121
--- /dev/null
+++ b/libressl2.patch
@@ -0,0 +1,105 @@
1diff --git a/networking/wget.c b/networking/wget.c
2index 6a64836fb..9da1274ac 100644
3--- a/networking/wget.c
4+++ b/networking/wget.c
5@@ -689,6 +689,8 @@ static void reset_beg_range_to_zero(void)
6 }
7
8 #if ENABLE_FEATURE_WGET_OPENSSL
9+#include <tls.h>
10+#include <winsock2.h>
11 static int spawn_https_helper_openssl(const char *host, unsigned port)
12 {
13 char *allocated = NULL;
14@@ -1230,26 +1232,52 @@ static void download_one_url(const char *url)
15 /* Open socket to http(s) server */
16 #if ENABLE_FEATURE_WGET_OPENSSL
17 /* openssl (and maybe internal TLS) support is configured */
18+ struct tls *ctx;
19 if (server.protocol == P_HTTPS) {
20 /* openssl-based helper
21 * Inconvenient API since we can't give it an open fd
22 */
23- int fd = spawn_https_helper_openssl(server.host, server.port);
24+ //int fd = spawn_https_helper_openssl(server.host, server.port);
25 # if ENABLE_FEATURE_WGET_HTTPS
26- if (fd < 0) { /* no openssl? try internal */
27- sfp = open_socket(lsa);
28- spawn_ssl_client(server.host, fileno(sfp), /*flags*/ 0);
29- goto socket_opened;
30- }
31+ char *allocated, *servername, *p, *host;
32+ if(!strchr(server.host, ":"))
33+ host = allocated = xasprintf("%s:%u", server.host, server.port);
34+ servername = xstrdup(host);
35+ ctx = tls_client();
36+ if(ctx == NULL)
37+ bb_error_msg_and_die("Out of memory 1");
38+ struct tls_config *config;
39+ config = tls_config_new();
40+ if(config == NULL)
41+ bb_error_msg_and_die("Out of memory 2");
42+ if(tls_config_set_ca_path(config, "certs") != 0)
43+ bb_error_msg_and_die("Failed to set ca path");
44+ if(tls_config_set_ca_file(config, "cert.pem") != 0)
45+ bb_error_msg_and_die("Failed to set ca file");
46+ if(tls_configure(ctx,config) != 0)
47+ bb_error_msg_and_die("Failed to configure client");
48+ sfp = tmpfile();
49+ dfp = tmpfile();
50+ printf("TLS connection to %s\n", server.host);
51+ if(tls_connect(ctx, servername, NULL) != 0)
52+ bb_error_msg_and_die("Failed to connect: %s", tls_error(ctx));
53+ tls_config_free(config);
54+ free(allocated);
55+ free(servername);
56+ printf("wget download_one_url 10\n");
57+ printf("wget download_one_url 13\n");
58+ //sfp = fdopen(fd, "r+");
59+ if (!sfp){
60+ bb_error_msg_and_die("Error opening fd: %s",strerror(errno));
61 # else
62 /* We don't check for exec("openssl") failure in this case */
63 # endif
64- sfp = fdopen(fd, "r+");
65- if (!sfp)
66- bb_die_memory_exhausted();
67+ //sfp = fdopen(fd, "r+");
68+ //if (!sfp)
69+ // bb_die_memory_exhausted();
70 goto socket_opened;
71 }
72- sfp = open_socket(lsa);
73+ //sfp = open_socket(lsa);
74 socket_opened:
75 #elif ENABLE_FEATURE_WGET_HTTPS
76 /* Only internal TLS support is configured */
77@@ -1353,7 +1381,27 @@ static void download_one_url(const char *url)
78 shutdown(fileno(sfp), SHUT_WR);
79 }
80 #endif
81-
82+ //How much data did we actually get?
83+ size_t wlen = ftell(sfp);
84+ char *outbuf = (char*)malloc(sizeof(char) * wlen);
85+ rewind(sfp);
86+ rewind(dfp);
87+ if(fread(outbuf, sizeof(char), wlen, sfp) < wlen)
88+ bb_error_msg_and_die("Failed to read tmpfile: %s", strerror(errno));
89+ if(tls_write(ctx, outbuf, wlen) < wlen)
90+ bb_error_msg_and_die("Failed to write:%s",tls_error(ctx));
91+ ssize_t len = TLS_WANT_POLLIN;
92+ size_t bufsize = 4096;
93+ char *buf[bufsize];
94+ while(len == TLS_WANT_POLLIN || len > 0){
95+ len = tls_read(ctx, buf, bufsize);
96+ if(fputs(buf, dfp) == EOF)
97+ bb_error_msg_and_die("Failed to copy buffer to tmpfile");
98+ }
99+ if(len == -1)
100+ bb_error_msg_and_die("tls read error: %s", tls_error(ctx));
101+ rewind(dfp);
102+ sfp = dfp;
103 /*
104 * Retrieve HTTP response line and check for "200" status code.
105 */