summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander M Pickering <alex@cogarr.net>2024-11-20 16:11:39 -0600
committerAlexander M Pickering <alex@cogarr.net>2024-11-20 16:11:39 -0600
commit224a19520d5112aaa44274ac5ab343c685fe6e69 (patch)
treee064af6a70dbc03cc264c961a7a1bb8868904412
parent685f6c76a07ab25d766d0a4b4494e2b7464b8c51 (diff)
downloadbusybox-w32-packaging-224a19520d5112aaa44274ac5ab343c685fe6e69.tar.gz
busybox-w32-packaging-224a19520d5112aaa44274ac5ab343c685fe6e69.tar.bz2
busybox-w32-packaging-224a19520d5112aaa44274ac5ab343c685fe6e69.zip
More debugging messages
-rw-r--r--libressl.patch40
1 files changed, 28 insertions, 12 deletions
diff --git a/libressl.patch b/libressl.patch
index 28d46a3..0406099 100644
--- a/libressl.patch
+++ b/libressl.patch
@@ -102,7 +102,7 @@ index 9f1dd67ec..60e1afe99 100644
102 static void tls_xwrite(tls_state_t *tls, int len) 102 static void tls_xwrite(tls_state_t *tls, int len)
103 { 103 {
104diff --git a/networking/wget.c b/networking/wget.c 104diff --git a/networking/wget.c b/networking/wget.c
105index 6a64836fb..490daf001 100644 105index 6a64836fb..e09c4bc7d 100644
106--- a/networking/wget.c 106--- a/networking/wget.c
107+++ b/networking/wget.c 107+++ b/networking/wget.c
108@@ -1,4 +1,3 @@ 108@@ -1,4 +1,3 @@
@@ -110,7 +110,7 @@ index 6a64836fb..490daf001 100644
110 /* 110 /*
111 * wget - retrieve a file using HTTP or FTP 111 * wget - retrieve a file using HTTP or FTP
112 * 112 *
113@@ -460,6 +459,49 @@ static FILE *open_socket(len_and_sockaddr *lsa) 113@@ -460,6 +459,59 @@ static FILE *open_socket(len_and_sockaddr *lsa)
114 return fp; 114 return fp;
115 } 115 }
116 116
@@ -119,12 +119,19 @@ index 6a64836fb..490daf001 100644
119+#include <openssl/ssl.h> 119+#include <openssl/ssl.h>
120+#include <openssl/x509.h> 120+#include <openssl/x509.h>
121+#include <wincrypt.h> 121+#include <wincrypt.h>
122+#include <tls.h>
123+#include <winsock2.h>
124+#include <windows.h>
122+char* gather_certificates(struct tls_config *cfg) 125+char* gather_certificates(struct tls_config *cfg)
123+{ 126+{
124+ FILE *pemfile; 127+ FILE *pemfile;
125+ pemfile = tmpfile(); 128+ pemfile = tmpfile();
129+ if(pemfile == NULL)
130+ bb_error_msg_and_die("Failed to open pem tempfile: %s", strerror(errno));
126+ HCERTSTORE dstore; 131+ HCERTSTORE dstore;
127+ dstore = CertOpenSystemStore(0,"ROOT"); 132+ dstore = CertOpenSystemStore(0,"ROOT");
133+ if(dstore == NULL)
134+ bb_error_msg_and_die("Failed to open system store: %s", GetLastError());
128+ size_t numcerts; 135+ size_t numcerts;
129+ if(!dstore) 136+ if(!dstore)
130+ bb_error_msg_and_die("Error opening 'CA' cert store"); 137+ bb_error_msg_and_die("Error opening 'CA' cert store");
@@ -140,6 +147,8 @@ index 6a64836fb..490daf001 100644
140+ X509 *x509cert; 147+ X509 *x509cert;
141+ x509cert = d2i_X509(NULL,&dcert,dcert_len); 148+ x509cert = d2i_X509(NULL,&dcert,dcert_len);
142+ if(x509cert == NULL) 149+ if(x509cert == NULL)
150+ bb_error_msg_and_die("Failed to convert dcert to x509");
151+ if(x509cert == NULL)
143+ bb_error_msg_and_die("Failed to convert cert"); 152+ bb_error_msg_and_die("Failed to convert cert");
144+ if(!PEM_write_X509(pemfile, x509cert)) 153+ if(!PEM_write_X509(pemfile, x509cert))
145+ bb_error_msg_and_die("Failed to write cert"); 154+ bb_error_msg_and_die("Failed to write cert");
@@ -154,23 +163,22 @@ index 6a64836fb..490daf001 100644
154+ if(fread(pemmem, sizeof(char), pemsize, pemfile) != pemsize) 163+ if(fread(pemmem, sizeof(char), pemsize, pemfile) != pemsize)
155+ bb_error_msg_and_die("Failed to read temp ca pem file"); 164+ bb_error_msg_and_die("Failed to read temp ca pem file");
156+ tls_config_set_ca_mem(cfg, pemmem, pemsize); 165+ tls_config_set_ca_mem(cfg, pemmem, pemsize);
166+ fclose(pemfile);
157+} 167+}
158+#endif 168+#endif
159+ 169+
160 /* We balk at any control chars in other side's messages. 170 /* We balk at any control chars in other side's messages.
161 * This prevents nasty surprises (e.g. ESC sequences) in "Location:" URLs 171 * This prevents nasty surprises (e.g. ESC sequences) in "Location:" URLs
162 * and error messages. 172 * and error messages.
163@@ -689,6 +731,9 @@ static void reset_beg_range_to_zero(void) 173@@ -689,6 +741,7 @@ static void reset_beg_range_to_zero(void)
164 } 174 }
165 175
166 #if ENABLE_FEATURE_WGET_OPENSSL 176 #if ENABLE_FEATURE_WGET_OPENSSL
167+#include <tls.h>
168+#include <winsock2.h>
169+/* 177+/*
170 static int spawn_https_helper_openssl(const char *host, unsigned port) 178 static int spawn_https_helper_openssl(const char *host, unsigned port)
171 { 179 {
172 char *allocated = NULL; 180 char *allocated = NULL;
173@@ -698,7 +743,7 @@ static int spawn_https_helper_openssl(const char *host, unsigned port) 181@@ -698,7 +751,7 @@ static int spawn_https_helper_openssl(const char *host, unsigned port)
174 IF_FEATURE_WGET_HTTPS(volatile int child_failed = 0;) 182 IF_FEATURE_WGET_HTTPS(volatile int child_failed = 0;)
175 183
176 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) != 0) 184 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) != 0)
@@ -179,7 +187,7 @@ index 6a64836fb..490daf001 100644
179 bb_simple_perror_msg_and_die("socketpair"); 187 bb_simple_perror_msg_and_die("socketpair");
180 188
181 if (!strchr(host, ':')) 189 if (!strchr(host, ':'))
182@@ -709,18 +754,18 @@ static int spawn_https_helper_openssl(const char *host, unsigned port) 190@@ -709,18 +762,18 @@ static int spawn_https_helper_openssl(const char *host, unsigned port)
183 fflush_all(); 191 fflush_all();
184 pid = xvfork(); 192 pid = xvfork();
185 if (pid == 0) { 193 if (pid == 0) {
@@ -204,7 +212,7 @@ index 6a64836fb..490daf001 100644
204 xmove_fd(2, 3); 212 xmove_fd(2, 3);
205 xopen("/dev/null", O_RDWR); 213 xopen("/dev/null", O_RDWR);
206 memset(&argv, 0, sizeof(argv)); 214 memset(&argv, 0, sizeof(argv));
207@@ -729,18 +774,18 @@ static int spawn_https_helper_openssl(const char *host, unsigned port) 215@@ -729,18 +782,18 @@ static int spawn_https_helper_openssl(const char *host, unsigned port)
208 argv[2] = (char*)"-quiet"; 216 argv[2] = (char*)"-quiet";
209 argv[3] = (char*)"-connect"; 217 argv[3] = (char*)"-connect";
210 argv[4] = (char*)host; 218 argv[4] = (char*)host;
@@ -229,7 +237,7 @@ index 6a64836fb..490daf001 100644
229 *argp++ = (char*)"-verify"; //[7] 237 *argp++ = (char*)"-verify"; //[7]
230 *argp++ = (char*)"100"; //[8] 238 *argp++ = (char*)"100"; //[8]
231 *argp++ = (char*)"-verify_return_error"; //[9] 239 *argp++ = (char*)"-verify_return_error"; //[9]
232@@ -762,10 +807,10 @@ static int spawn_https_helper_openssl(const char *host, unsigned port) 240@@ -762,10 +815,10 @@ static int spawn_https_helper_openssl(const char *host, unsigned port)
233 # else 241 # else
234 bb_perror_msg_and_die("can't execute '%s'", argv[0]); 242 bb_perror_msg_and_die("can't execute '%s'", argv[0]);
235 # endif 243 # endif
@@ -242,7 +250,7 @@ index 6a64836fb..490daf001 100644
242 free(servername); 250 free(servername);
243 free(allocated); 251 free(allocated);
244 close(sp[1]); 252 close(sp[1]);
245@@ -777,6 +822,7 @@ static int spawn_https_helper_openssl(const char *host, unsigned port) 253@@ -777,6 +830,7 @@ static int spawn_https_helper_openssl(const char *host, unsigned port)
246 # endif 254 # endif
247 return sp[0]; 255 return sp[0];
248 } 256 }
@@ -250,7 +258,7 @@ index 6a64836fb..490daf001 100644
250 #endif 258 #endif
251 259
252 #if ENABLE_FEATURE_WGET_HTTPS 260 #if ENABLE_FEATURE_WGET_HTTPS
253@@ -1230,26 +1276,47 @@ static void download_one_url(const char *url) 261@@ -1230,26 +1284,51 @@ static void download_one_url(const char *url)
254 /* Open socket to http(s) server */ 262 /* Open socket to http(s) server */
255 #if ENABLE_FEATURE_WGET_OPENSSL 263 #if ENABLE_FEATURE_WGET_OPENSSL
256 /* openssl (and maybe internal TLS) support is configured */ 264 /* openssl (and maybe internal TLS) support is configured */
@@ -282,7 +290,11 @@ index 6a64836fb..490daf001 100644
282+ if(tls_configure(ctx,config) != 0) 290+ if(tls_configure(ctx,config) != 0)
283+ bb_error_msg_and_die("Failed to configure client"); 291+ bb_error_msg_and_die("Failed to configure client");
284+ sfp = tmpfile(); 292+ sfp = tmpfile();
293+ if(sfp == NULL)
294+ bb_error_msg_and_die("Failed to open source tempfile %d: %s", errno, strerror(errno));
285+ dfp = tmpfile(); 295+ dfp = tmpfile();
296+ if(dfp == NULL)
297+ bb_error_msg_and_die("Failed to open source tempfile %d: %s", errno, strerror(errno));
286+ if(tls_connect(ctx, servername, NULL) != 0) 298+ if(tls_connect(ctx, servername, NULL) != 0)
287+ bb_error_msg_and_die("Failed to connect: %s", tls_error(ctx)); 299+ bb_error_msg_and_die("Failed to connect: %s", tls_error(ctx));
288+ free(pemmem); 300+ free(pemmem);
@@ -308,7 +320,7 @@ index 6a64836fb..490daf001 100644
308 socket_opened: 320 socket_opened:
309 #elif ENABLE_FEATURE_WGET_HTTPS 321 #elif ENABLE_FEATURE_WGET_HTTPS
310 /* Only internal TLS support is configured */ 322 /* Only internal TLS support is configured */
311@@ -1353,7 +1420,35 @@ static void download_one_url(const char *url) 323@@ -1353,7 +1432,39 @@ static void download_one_url(const char *url)
312 shutdown(fileno(sfp), SHUT_WR); 324 shutdown(fileno(sfp), SHUT_WR);
313 } 325 }
314 #endif 326 #endif
@@ -316,10 +328,14 @@ index 6a64836fb..490daf001 100644
316+ //How much data did we actually get? 328+ //How much data did we actually get?
317+ size_t wlen, bufsize; 329+ size_t wlen, bufsize;
318+ wlen = ftell(sfp); 330+ wlen = ftell(sfp);
331+ if(wlen < 0)
332+ bb_error_msg_and_die("Failed to get source len %d:%s",errno,strerror(errno));
319+ bufsize = 4096; 333+ bufsize = 4096;
320+ char buf[bufsize]; 334+ char buf[bufsize];
321+ char *outbuf; 335+ char *outbuf;
322+ outbuf = (char*)malloc(sizeof(char) * wlen); 336+ outbuf = (char*)malloc(sizeof(char) * wlen);
337+ if(outbuf == NULL)
338+ bb_error_msg_and_die("Out of memory");
323+ rewind(sfp); 339+ rewind(sfp);
324+ rewind(dfp); 340+ rewind(dfp);
325+ if(fread(outbuf, sizeof(char), wlen, sfp) < wlen) 341+ if(fread(outbuf, sizeof(char), wlen, sfp) < wlen)