aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-10-07 01:39:40 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2015-10-07 01:39:40 +0200
commit1c6c670ed44a77ab4784ea0d4ac5411d7b0648d8 (patch)
tree477c1daf40605269b4ee5912c5402d3f9e60aabc
parent3b650c1e7b0bcbb4dfebab6fd87449e6b1e0b788 (diff)
downloadbusybox-w32-1c6c670ed44a77ab4784ea0d4ac5411d7b0648d8.tar.gz
busybox-w32-1c6c670ed44a77ab4784ea0d4ac5411d7b0648d8.tar.bz2
busybox-w32-1c6c670ed44a77ab4784ea0d4ac5411d7b0648d8.zip
wget: make openssl/ssl_helper choice configurable
I got sick of not being able to wget a https file... Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/applets.src.h1
-rw-r--r--networking/Config.src42
-rw-r--r--networking/Kbuild.src1
-rwxr-xr-xnetworking/ssl_helper-wolfssl/00cfg-wolfssl-3.6.822
-rw-r--r--networking/ssl_helper-wolfssl/README15
-rw-r--r--networking/ssl_helper-wolfssl/ssl_helper.c480
-rwxr-xr-xnetworking/ssl_helper-wolfssl/ssl_helper.sh11
-rw-r--r--networking/wget.c105
8 files changed, 623 insertions, 54 deletions
diff --git a/include/applets.src.h b/include/applets.src.h
index 9f3ac78cb..dac83e7fb 100644
--- a/include/applets.src.h
+++ b/include/applets.src.h
@@ -382,7 +382,6 @@ IF_VOLNAME(APPLET(volname, BB_DIR_USR_BIN, BB_SUID_DROP))
382IF_WATCH(APPLET(watch, BB_DIR_BIN, BB_SUID_DROP)) 382IF_WATCH(APPLET(watch, BB_DIR_BIN, BB_SUID_DROP))
383IF_WATCHDOG(APPLET(watchdog, BB_DIR_SBIN, BB_SUID_DROP)) 383IF_WATCHDOG(APPLET(watchdog, BB_DIR_SBIN, BB_SUID_DROP))
384IF_WC(APPLET(wc, BB_DIR_USR_BIN, BB_SUID_DROP)) 384IF_WC(APPLET(wc, BB_DIR_USR_BIN, BB_SUID_DROP))
385IF_WGET(APPLET(wget, BB_DIR_USR_BIN, BB_SUID_DROP))
386IF_WHICH(APPLET(which, BB_DIR_USR_BIN, BB_SUID_DROP)) 385IF_WHICH(APPLET(which, BB_DIR_USR_BIN, BB_SUID_DROP))
387IF_WHOAMI(APPLET_NOFORK(whoami, whoami, BB_DIR_USR_BIN, BB_SUID_DROP, whoami)) 386IF_WHOAMI(APPLET_NOFORK(whoami, whoami, BB_DIR_USR_BIN, BB_SUID_DROP, whoami))
388IF_YES(APPLET_NOFORK(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes)) 387IF_YES(APPLET_NOFORK(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes))
diff --git a/networking/Config.src b/networking/Config.src
index da36e8627..76cbccf4a 100644
--- a/networking/Config.src
+++ b/networking/Config.src
@@ -947,48 +947,6 @@ config VCONFIG
947 help 947 help
948 Creates, removes, and configures VLAN interfaces 948 Creates, removes, and configures VLAN interfaces
949 949
950config WGET
951 bool "wget"
952 default y
953 help
954 wget is a utility for non-interactive download of files from HTTP
955 and FTP servers.
956
957config FEATURE_WGET_STATUSBAR
958 bool "Enable a nifty process meter (+2k)"
959 default y
960 depends on WGET
961 help
962 Enable the transfer progress bar for wget transfers.
963
964config FEATURE_WGET_AUTHENTICATION
965 bool "Enable HTTP authentication"
966 default y
967 depends on WGET
968 help
969 Support authenticated HTTP transfers.
970
971config FEATURE_WGET_LONG_OPTIONS
972 bool "Enable long options"
973 default y
974 depends on WGET && LONG_OPTS
975 help
976 Support long options for the wget applet.
977
978config FEATURE_WGET_TIMEOUT
979 bool "Enable timeout option -T SEC"
980 default y
981 depends on WGET
982 help
983 Supports network read and connect timeouts for wget,
984 so that wget will give up and timeout, through the -T
985 command line option.
986
987 Currently only connect and network data read timeout are
988 supported (i.e., timeout is not applied to the DNS query). When
989 FEATURE_WGET_LONG_OPTIONS is also enabled, the --timeout option
990 will work in addition to -T.
991
992config ZCIP 950config ZCIP
993 bool "zcip" 951 bool "zcip"
994 default y 952 default y
diff --git a/networking/Kbuild.src b/networking/Kbuild.src
index 944f27be1..79f54824b 100644
--- a/networking/Kbuild.src
+++ b/networking/Kbuild.src
@@ -41,7 +41,6 @@ lib-$(CONFIG_TFTPD) += tftp.o
41lib-$(CONFIG_TRACEROUTE) += traceroute.o 41lib-$(CONFIG_TRACEROUTE) += traceroute.o
42lib-$(CONFIG_TUNCTL) += tunctl.o 42lib-$(CONFIG_TUNCTL) += tunctl.o
43lib-$(CONFIG_VCONFIG) += vconfig.o 43lib-$(CONFIG_VCONFIG) += vconfig.o
44lib-$(CONFIG_WGET) += wget.o
45lib-$(CONFIG_ZCIP) += zcip.o 44lib-$(CONFIG_ZCIP) += zcip.o
46 45
47lib-$(CONFIG_TCPSVD) += tcpudp.o tcpudp_perhost.o 46lib-$(CONFIG_TCPSVD) += tcpudp.o tcpudp_perhost.o
diff --git a/networking/ssl_helper-wolfssl/00cfg-wolfssl-3.6.8 b/networking/ssl_helper-wolfssl/00cfg-wolfssl-3.6.8
new file mode 100755
index 000000000..27d0c41ee
--- /dev/null
+++ b/networking/ssl_helper-wolfssl/00cfg-wolfssl-3.6.8
@@ -0,0 +1,22 @@
1#!/bin/sh
2
3# How to configure & build a static wolfssl-3.6.8 library
4# suitable for static build of ssl_helper.
5
6export CC="x86_64-gcc"
7export CFLAGS="\
8-Os \
9-static \
10-fomit-frame-pointer \
11-falign-functions=1 -falign-labels=1 -falign-loops=1 -falign-jumps=1 \
12-ffunction-sections -fdata-sections \
13"
14
15./configure \
16 --enable-static \
17 --enable-singlethreaded \
18 --disable-shared \
19|| exit $?
20
21make
22exit $?
diff --git a/networking/ssl_helper-wolfssl/README b/networking/ssl_helper-wolfssl/README
new file mode 100644
index 000000000..17437606d
--- /dev/null
+++ b/networking/ssl_helper-wolfssl/README
@@ -0,0 +1,15 @@
1Build instructions:
2
3* Unpack wolfssl-3.6.8.zip
4* Build it:
5 ./configure --enable-static --disable-shared && make
6* Drop this directory into wolfssl-3.6.8/ssl_helper
7* Run ssl_helper.sh to compile and link the helper
8
9Usage: "ssl_helper -d FILE_DESCRIPTOR" where FILE_DESCRIPTOR is open to the peer.
10
11In bash, you can do it this way:
12$ ssl_helper -d3 3<>/dev/tcp/HOST/PORT
13
14Stdin will be SSL-encrypted and sent to FILE_DESCRIPTOR.
15Data from FILE_DESCRIPTOR will be decrypted and sent to stdout.
diff --git a/networking/ssl_helper-wolfssl/ssl_helper.c b/networking/ssl_helper-wolfssl/ssl_helper.c
new file mode 100644
index 000000000..38b7b56c6
--- /dev/null
+++ b/networking/ssl_helper-wolfssl/ssl_helper.c
@@ -0,0 +1,480 @@
1/*
2 * Adapted from:
3 *
4 * client.c
5 *
6 * Copyright (C) 2006-2015 wolfSSL Inc.
7 *
8 * This file is part of wolfSSL. (formerly known as CyaSSL)
9 *
10 * wolfSSL is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * wolfSSL is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24#include <stdlib.h>
25#include <unistd.h>
26#include <stdarg.h>
27#include <string.h>
28#include <errno.h>
29#include <fcntl.h>
30#include <stdio.h>
31#include <time.h>
32#include <poll.h>
33#include <sys/socket.h>
34
35#include <wolfssl/wolfcrypt/types.h>
36#include <wolfssl/ssl.h>
37
38#if 0
39# define dbg(...) say(__VA_ARGS__)
40#else
41# define dbg(...) ((void)0)
42#endif
43
44static ssize_t safe_write(int fd, const void *buf, size_t count)
45{
46 ssize_t n;
47
48 do {
49 n = write(fd, buf, count);
50 } while (n < 0 && errno == EINTR);
51
52 return n;
53}
54
55static ssize_t full_write(int fd, const void *buf, size_t len)
56{
57 ssize_t cc;
58 ssize_t total;
59
60 total = 0;
61
62 while (len) {
63 cc = safe_write(fd, buf, len);
64
65 if (cc < 0) {
66 if (total) {
67 /* we already wrote some! */
68 /* user can do another write to know the error code */
69 return total;
70 }
71 return cc; /* write() returns -1 on failure. */
72 }
73
74 total += cc;
75 buf = ((const char *)buf) + cc;
76 len -= cc;
77 }
78
79 return total;
80}
81
82static void say(const char *s, ...)
83{
84 char buf[256];
85 va_list p;
86 int sz;
87
88 va_start(p, s);
89 sz = vsnprintf(buf, sizeof(buf), s, p);
90 full_write(STDERR_FILENO, buf, sz >= 0 && sz < sizeof(buf) ? sz : strlen(buf));
91 va_end(p);
92}
93
94static void die(const char *s, ...)
95{
96 char buf[256];
97 va_list p;
98 int sz;
99
100 va_start(p, s);
101 sz = vsnprintf(buf, sizeof(buf), s, p);
102 full_write(STDERR_FILENO, buf, sz >= 0 && sz < sizeof(buf) ? sz : strlen(buf));
103 exit(1);
104 va_end(p);
105}
106
107static void err_sys(const char *msg)
108{
109 die("%s\n", msg);
110}
111
112/* ==== */
113
114#if 0
115static void showPeer(WOLFSSL* ssl)
116{
117 WOLFSSL_CIPHER* cipher;
118 WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl);
119 if (peer)
120 ShowX509(peer, "peer's cert info:");
121 else
122 say("peer has no cert!\n");
123 say("SSL version is %s\n", wolfSSL_get_version(ssl));
124
125 cipher = wolfSSL_get_current_cipher(ssl);
126 say("SSL cipher suite is %s\n", wolfSSL_CIPHER_get_name(cipher));
127
128 {
129 WOLFSSL_X509_CHAIN* chain = wolfSSL_get_peer_chain(ssl);
130 int count = wolfSSL_get_chain_count(chain);
131 int i;
132
133 for (i = 0; i < count; i++) {
134 int length;
135 unsigned char buffer[3072];
136 WOLFSSL_X509* chainX509;
137
138 wolfSSL_get_chain_cert_pem(chain, i, buffer, sizeof(buffer), &length);
139 buffer[length] = 0;
140 say("cert %d has length %d data = \n%s\n", i, length, buffer);
141
142 chainX509 = wolfSSL_get_chain_X509(chain, i);
143 if (chainX509)
144 ShowX509(chainX509, "session cert info:");
145 else
146 say("get_chain_X509 failed\n");
147 wolfSSL_FreeX509(chainX509);
148 }
149 }
150}
151#endif
152
153WOLFSSL *prepare(int sockfd)
154{
155 WOLFSSL_METHOD* method;
156 WOLFSSL_CTX* ctx;
157 WOLFSSL* ssl;
158
159 wolfSSL_Init();
160
161 method = wolfTLSv1_1_client_method();
162 if (method == NULL)
163 err_sys("out of memory");
164 ctx = wolfSSL_CTX_new(method);
165 if (ctx == NULL)
166 err_sys("out of memory");
167// if (cipherList)
168// if (wolfSSL_CTX_set_cipher_list(ctx, cipherList) != SSL_SUCCESS)
169// err_sys("client can't set cipher list 1");
170
171// if (fewerPackets)
172// wolfSSL_CTX_set_group_messages(ctx);
173
174//#ifndef NO_DH
175// wolfSSL_CTX_SetMinDhKey_Sz(ctx, (word16)minDhKeyBits);
176//#endif
177
178// if (usePsk) {
179// wolfSSL_CTX_set_psk_client_callback(ctx, my_psk_client_cb);
180// if (cipherList == NULL) {
181// const char *defaultCipherList;
182//#if defined(HAVE_AESGCM) && !defined(NO_DH)
183// defaultCipherList = "DHE-PSK-AES128-GCM-SHA256";
184//#elif defined(HAVE_NULL_CIPHER)
185// defaultCipherList = "PSK-NULL-SHA256";
186//#else
187// defaultCipherList = "PSK-AES128-CBC-SHA256";
188//#endif
189// if (wolfSSL_CTX_set_cipher_list(ctx,defaultCipherList) != SSL_SUCCESS)
190// err_sys("client can't set cipher list 2");
191// }
192// useClientCert = 0;
193// }
194
195// if (useAnon) {
196// if (cipherList == NULL) {
197// wolfSSL_CTX_allow_anon_cipher(ctx);
198// if (wolfSSL_CTX_set_cipher_list(ctx,"ADH-AES128-SHA") != SSL_SUCCESS)
199// err_sys("client can't set cipher list 4");
200// }
201// useClientCert = 0;
202// }
203
204//#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
205// wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
206//#endif
207
208// if (useOcsp) {
209// if (ocspUrl != NULL) {
210// wolfSSL_CTX_SetOCSP_OverrideURL(ctx, ocspUrl);
211// wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_NO_NONCE
212// | WOLFSSL_OCSP_URL_OVERRIDE);
213// }
214// else
215// wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_NO_NONCE);
216// }
217//
218//#ifdef USER_CA_CB
219// wolfSSL_CTX_SetCACb(ctx, CaCb);
220//#endif
221//
222//#ifdef VERIFY_CALLBACK
223// wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
224//#endif
225//#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
226// if (useClientCert) {
227// if (wolfSSL_CTX_use_certificate_chain_file(ctx, ourCert) != SSL_SUCCESS)
228// err_sys("can't load client cert file, check file and run from"
229// " wolfSSL home dir");
230// if (wolfSSL_CTX_use_PrivateKey_file(ctx, ourKey, SSL_FILETYPE_PEM) != SSL_SUCCESS)
231// err_sys("can't load client private key file, check file and run "
232// "from wolfSSL home dir");
233// }
234//
235// if (!usePsk && !useAnon) {
236// if (wolfSSL_CTX_load_verify_locations(ctx, verifyCert,0) != SSL_SUCCESS)
237// err_sys("can't load ca file, Please run from wolfSSL home dir");
238//#ifdef HAVE_ECC
239// /* load ecc verify too, echoserver uses it by default w/ ecc */
240// if (wolfSSL_CTX_load_verify_locations(ctx, eccCert, 0) != SSL_SUCCESS)
241// err_sys("can't load ecc ca file, Please run from wolfSSL home dir");
242//#endif
243// }
244//#endif /* !NO_FILESYSTEM && !NO_CERTS */
245
246//#if !defined(NO_CERTS)
247// if (!usePsk && !useAnon && doPeerCheck == 0)
248// wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
249// if (!usePsk && !useAnon && overrideDateErrors == 1)
250// wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myDateCb);
251//#endif
252
253 wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
254
255//#ifdef HAVE_SNI
256// if (sniHostName)
257// if (wolfSSL_CTX_UseSNI(ctx, 0, sniHostName, XSTRLEN(sniHostName)) != SSL_SUCCESS)
258// err_sys("UseSNI failed");
259//#endif
260
261//#ifdef HAVE_MAX_FRAGMENT
262// if (maxFragment)
263// if (wolfSSL_CTX_UseMaxFragment(ctx, maxFragment) != SSL_SUCCESS)
264// err_sys("UseMaxFragment failed");
265//#endif
266//#ifdef HAVE_TRUNCATED_HMAC
267// if (truncatedHMAC)
268// if (wolfSSL_CTX_UseTruncatedHMAC(ctx) != SSL_SUCCESS)
269// err_sys("UseTruncatedHMAC failed");
270//#endif
271//#ifdef HAVE_SESSION_TICKET
272// if (wolfSSL_CTX_UseSessionTicket(ctx) != SSL_SUCCESS)
273// err_sys("UseSessionTicket failed");
274//#endif
275
276//#if defined(WOLFSSL_MDK_ARM)
277// wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
278//#endif
279
280 ssl = wolfSSL_new(ctx);
281 if (ssl == NULL)
282 err_sys("out of memory");
283
284//#ifdef HAVE_SESSION_TICKET
285// wolfSSL_set_SessionTicket_cb(ssl, sessionTicketCB, (void*)"initial session");
286//#endif
287
288// if (doDTLS) {
289// SOCKADDR_IN_T addr;
290// build_addr(&addr, host, port, 1);
291// wolfSSL_dtls_set_peer(ssl, &addr, sizeof(addr));
292// tcp_socket(&sockfd, 1);
293// } wlse {
294// tcp_connect(&sockfd, host, port, 0);
295// }
296
297//#ifdef HAVE_POLY1305
298// /* use old poly to connect with google server */
299// if (!XSTRNCMP(domain, "www.google.com", 14)) {
300// if (wolfSSL_use_old_poly(ssl, 1) != 0)
301// err_sys("unable to set to old poly");
302// }
303//#endif
304
305 wolfSSL_set_fd(ssl, sockfd);
306
307//#ifdef HAVE_CRL
308// if (disableCRL == 0) {
309// if (wolfSSL_EnableCRL(ssl, WOLFSSL_CRL_CHECKALL) != SSL_SUCCESS)
310// err_sys("can't enable crl check");
311// if (wolfSSL_LoadCRL(ssl, crlPemDir, SSL_FILETYPE_PEM, 0) != SSL_SUCCESS)
312// err_sys("can't load crl, check crlfile and date validity");
313// if (wolfSSL_SetCRL_Cb(ssl, CRL_CallBack) != SSL_SUCCESS)
314// err_sys("can't set crl callback");
315// }
316//#endif
317//#ifdef HAVE_SECURE_RENEGOTIATION
318// if (scr) {
319// if (wolfSSL_UseSecureRenegotiation(ssl) != SSL_SUCCESS)
320// err_sys("can't enable secure renegotiation");
321// }
322//#endif
323//#ifdef ATOMIC_USER
324// if (atomicUser)
325// SetupAtomicUser(ctx, ssl);
326//#endif
327//#ifdef HAVE_PK_CALLBACKS
328// if (pkCallbacks)
329// SetupPkCallbacks(ctx, ssl);
330//#endif
331// if (matchName && doPeerCheck)
332// wolfSSL_check_domain_name(ssl, domain);
333
334 if (wolfSSL_connect(ssl) != SSL_SUCCESS) {
335// /* see note at top of README */
336// int err = wolfSSL_get_error(ssl, 0);
337// char buffer[WOLFSSL_MAX_ERROR_SZ];
338// say("err = %d, %s\n", err,
339// wolfSSL_ERR_error_string(err, buffer));
340 err_sys("SSL_connect failed");
341 }
342// showPeer(ssl);
343
344//#ifdef HAVE_SECURE_RENEGOTIATION
345// if (scr && forceScr) {
346// if (wolfSSL_Rehandshake(ssl) != SSL_SUCCESS) {
347// int err = wolfSSL_get_error(ssl, 0);
348// char buffer[WOLFSSL_MAX_ERROR_SZ];
349// say("err = %d, %s\n", err,
350// wolfSSL_ERR_error_string(err, buffer));
351// err_sys("wolfSSL_Rehandshake failed");
352// }
353// }
354//#endif
355
356 return ssl;
357}
358
359static struct pollfd pfd[2] = {
360 { -1, POLLIN|POLLERR|POLLHUP, 0 },
361 { -1, POLLIN|POLLERR|POLLHUP, 0 },
362};
363#define STDIN pfd[0]
364#define NETWORK pfd[1]
365#define STDIN_READY() (pfd[0].revents & (POLLIN|POLLERR|POLLHUP))
366#define NETWORK_READY() (pfd[1].revents & (POLLIN|POLLERR|POLLHUP))
367
368static void wait_for_input(void)
369{
370 if (STDIN.fd == NETWORK.fd) /* means both are -1 */
371 exit(0);
372 dbg("polling\n");
373 STDIN.revents = NETWORK.revents = 0;
374 while (poll(pfd, 2, -1) < 0 && errno == EINTR)
375 continue;
376}
377
378static void do_io_until_eof_and_exit(WOLFSSL *ssl, int fd)
379{
380 int len;
381 char ibuf[4 * 1024];
382
383 NETWORK.fd = fd;
384 STDIN.fd = 0;
385
386 len = 0; /* only to suppress compiler warning */
387 for (;;) {
388 wait_for_input();
389
390 if (STDIN_READY()) {
391 dbg("reading stdin\n");
392 len = read(STDIN_FILENO, ibuf, sizeof(ibuf));
393 if (len < 0)
394 die("read error on stdin\n");
395 if (len == 0) {
396 dbg("read len = 0, stdin not polled anymore\n");
397 STDIN.fd = -1;
398 } else {
399 int n = wolfSSL_write(ssl, ibuf, len);
400 if (n != len)
401 die("SSL_write(%d) failed (returned %d)\n", len, n);
402 }
403 }
404
405 if (NETWORK_READY()) {
406 dbg("%s%s%s\n",
407 (pfd[1].revents & POLLIN) ? "POLLIN" : "",
408 (pfd[1].revents & POLLERR) ? "|POLLERR" : "",
409 (pfd[1].revents & POLLHUP) ? "|POLLHUP" : ""
410 );
411/* We are using blocking socket here.
412 * (Nonblocking socket would complicate writing to it).
413 * Therefore, SSL_read _can block_ here.
414 * This is not what wget expects (it wants to see short reads).
415 * Therefore, we use smallish buffer here, to approximate that.
416 */
417 len = wolfSSL_read(ssl, ibuf,
418 sizeof(ibuf) < 1024 ? sizeof(ibuf) : 1024
419 );
420 if (len < 0)
421 die("SSL_read error on network (%d)\n", len);
422 if (len > 0) {
423 int n;
424 n = full_write(STDOUT_FILENO, ibuf, len);
425 if (n != len)
426 die("write(%d) to stdout returned %d\n", len, n);
427 continue;
428 }
429/* Blocking reads are easier wtr EOF detection (no EAGAIN error to check for) */
430 dbg("read len = 0, network not polled anymore\n");
431 NETWORK.fd = -1;
432 /* saw EOF on network, and we processed
433 * and wrote out all ssl data. Signal it:
434 */
435 close(STDOUT_FILENO);
436 }
437 }
438}
439
440int main(int argc, char **argv)
441{
442 WOLFSSL *ssl;
443 int fd;
444 char *fd_str;
445
446 if (!argv[1])
447 die("Syntax error\n");
448 if (argv[1][0] != '-')
449 die("Syntax error\n");
450 if (argv[1][1] != 'd')
451 die("Syntax error\n");
452 fd_str = argv[1] + 2;
453 if (!fd_str[0])
454 fd_str = argv[2];
455 if (!fd_str || fd_str[0] < '0' || fd_str[0] > '9')
456 die("Syntax error\n");
457
458 fd = atoi(fd_str);
459 if (fd < 3)
460 die("Syntax error\n");
461
462 ssl = prepare(fd);
463 do_io_until_eof_and_exit(ssl, fd);
464 /* does not return */
465
466// if (doDTLS == 0) { /* don't send alert after "break" command */
467// ret = wolfSSL_shutdown(ssl);
468// if (wc_shutdown && ret == SSL_SHUTDOWN_NOT_DONE)
469// wolfSSL_shutdown(ssl); /* bidirectional shutdown */
470// }
471//#ifdef ATOMIC_USER
472// if (atomicUser)
473// FreeAtomicUser(ssl);
474//#endif
475// wolfSSL_free(ssl);
476// CloseSocket(sockfd);
477// wolfSSL_CTX_free(ctx);
478
479 return 0;
480}
diff --git a/networking/ssl_helper-wolfssl/ssl_helper.sh b/networking/ssl_helper-wolfssl/ssl_helper.sh
new file mode 100755
index 000000000..ddb4536c7
--- /dev/null
+++ b/networking/ssl_helper-wolfssl/ssl_helper.sh
@@ -0,0 +1,11 @@
1#!/bin/sh
2
3# I use this to build static uclibc based binary using Aboriginal Linux toolchain:
4PREFIX=x86_64-
5STATIC=-static
6# Standard build:
7#PREFIX=""
8#STATIC=""
9
10${PREFIX}gcc -Os -Wall -I.. -c ssl_helper.c -o ssl_helper.o
11${PREFIX}gcc $STATIC --start-group ssl_helper.o -lm ../src/.libs/libwolfssl.a --end-group -o ssl_helper
diff --git a/networking/wget.c b/networking/wget.c
index f744ea2de..baa7e0e78 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -9,6 +9,89 @@
9 * Kuhn's copyrights are licensed GPLv2-or-later. File as a whole remains GPLv2. 9 * Kuhn's copyrights are licensed GPLv2-or-later. File as a whole remains GPLv2.
10 */ 10 */
11 11
12//config:config WGET
13//config: bool "wget"
14//config: default y
15//config: help
16//config: wget is a utility for non-interactive download of files from HTTP
17//config: and FTP servers.
18//config:
19//config:config FEATURE_WGET_STATUSBAR
20//config: bool "Enable a nifty process meter (+2k)"
21//config: default y
22//config: depends on WGET
23//config: help
24//config: Enable the transfer progress bar for wget transfers.
25//config:
26//config:config FEATURE_WGET_AUTHENTICATION
27//config: bool "Enable HTTP authentication"
28//config: default y
29//config: depends on WGET
30//config: help
31//config: Support authenticated HTTP transfers.
32//config:
33//config:config FEATURE_WGET_LONG_OPTIONS
34//config: bool "Enable long options"
35//config: default y
36//config: depends on WGET && LONG_OPTS
37//config: help
38//config: Support long options for the wget applet.
39//config:
40//config:config FEATURE_WGET_TIMEOUT
41//config: bool "Enable timeout option -T SEC"
42//config: default y
43//config: depends on WGET
44//config: help
45//config: Supports network read and connect timeouts for wget,
46//config: so that wget will give up and timeout, through the -T
47//config: command line option.
48//config:
49//config: Currently only connect and network data read timeout are
50//config: supported (i.e., timeout is not applied to the DNS query). When
51//config: FEATURE_WGET_LONG_OPTIONS is also enabled, the --timeout option
52//config: will work in addition to -T.
53//config:
54//config:choice
55//config: prompt "Choose how to handle https:// URLs"
56//config: depends on WGET
57//config: default FEATURE_WGET_OPENSSL
58//config: help
59//config: Choose how wget establishes SSL connection for https:// URLs.
60//config:
61//config: Busybox itself contains no SSL code. wget will spawn
62//config: a helper program to talk over HTTPS.
63//config:
64//config: OpenSSL has a simple SSL client for debug purposes.
65//config: If you select "openssl" helper, wget will effectively call
66//config: "openssl s_client -quiet -connect IP:443 2>/dev/null"
67//config: and pipe its data through it.
68//config: Note inconvenient API: host resolution is done twice,
69//config: and there is no guarantee openssl's idea of IPv6 address
70//config: format is the same as ours.
71//config: Another problem is that s_client prints debug information
72//config: to stderr, and it needs to be suppressed. This means
73//config: all error messages get suppressed too.
74//config: openssl is also a big binary, often dynamically linked
75//config: against ~15 libraries.
76//config:
77//config: ssl_helper is a tool which can be built statically
78//config: from busybox sources against a small embedded SSL library.
79//config: Please see networking/ssl_helper/README.
80//config: It does not require double host resolution and emits
81//config: error messages to stderr.
82//config:
83//config:config FEATURE_WGET_OPENSSL
84//config: bool "openssl"
85//config:
86//config:config FEATURE_WGET_SSL_HELPER
87//config: bool "ssl_helper"
88//config:
89//config:endchoice
90
91//applet:IF_WGET(APPLET(wget, BB_DIR_USR_BIN, BB_SUID_DROP))
92
93//kbuild:lib-$(CONFIG_WGET) += wget.o
94
12//usage:#define wget_trivial_usage 95//usage:#define wget_trivial_usage
13//usage: IF_FEATURE_WGET_LONG_OPTIONS( 96//usage: IF_FEATURE_WGET_LONG_OPTIONS(
14//usage: "[-c|--continue] [-s|--spider] [-q|--quiet] [-O|--output-document FILE]\n" 97//usage: "[-c|--continue] [-s|--spider] [-q|--quiet] [-O|--output-document FILE]\n"
@@ -520,6 +603,7 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_
520 return sfp; 603 return sfp;
521} 604}
522 605
606#if ENABLE_FEATURE_WGET_OPENSSL
523static int spawn_https_helper(const char *host, unsigned port) 607static int spawn_https_helper(const char *host, unsigned port)
524{ 608{
525 char *allocated = NULL; 609 char *allocated = NULL;
@@ -569,12 +653,11 @@ static int spawn_https_helper(const char *host, unsigned port)
569 close(sp[1]); 653 close(sp[1]);
570 return sp[0]; 654 return sp[0];
571} 655}
656#endif
572 657
573/* See networking/ssl_helper/README */ 658/* See networking/ssl_helper/README how to build one */
574#define SSL_HELPER 0 659#if ENABLE_FEATURE_WGET_SSL_HELPER
575 660static void spawn_https_helper(int network_fd)
576#if SSL_HELPER
577static void spawn_https_helper1(int network_fd)
578{ 661{
579 int sp[2]; 662 int sp[2];
580 int pid; 663 int pid;
@@ -851,19 +934,21 @@ static void download_one_url(const char *url)
851 int status; 934 int status;
852 935
853 /* Open socket to http(s) server */ 936 /* Open socket to http(s) server */
937#if ENABLE_FEATURE_WGET_OPENSSL
854 if (target.protocol == P_HTTPS) { 938 if (target.protocol == P_HTTPS) {
855/* openssl-based helper 939 /* openssl-based helper
856 * Inconvenient API since we can't give it an open fd 940 * Inconvenient API since we can't give it an open fd
857 */ 941 */
858 int fd = spawn_https_helper(server.host, server.port); 942 int fd = spawn_https_helper(server.host, server.port);
859 sfp = fdopen(fd, "r+"); 943 sfp = fdopen(fd, "r+");
860 if (!sfp) 944 if (!sfp)
861 bb_perror_msg_and_die(bb_msg_memory_exhausted); 945 bb_perror_msg_and_die(bb_msg_memory_exhausted);
862 } else 946 } else
947#endif
863 sfp = open_socket(lsa); 948 sfp = open_socket(lsa);
864#if SSL_HELPER 949#if ENABLE_FEATURE_WGET_SSL_HELPER
865 if (target.protocol == P_HTTPS) 950 if (target.protocol == P_HTTPS)
866 spawn_https_helper1(fileno(sfp)); 951 spawn_https_helper(fileno(sfp));
867#endif 952#endif
868 /* Send HTTP request */ 953 /* Send HTTP request */
869 if (use_proxy) { 954 if (use_proxy) {