aboutsummaryrefslogtreecommitdiff
path: root/networking/tls.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-01-20 14:27:58 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-01-20 14:27:58 +0100
commit19e695ebadda206d1e0fbefa59ed8fabee0d0f64 (patch)
treeb1d2a94da61cc4bb41513bef067f738195938b1f /networking/tls.c
parenta0aae9f71442366ec429657c437fd7dd815978fd (diff)
downloadbusybox-w32-19e695ebadda206d1e0fbefa59ed8fabee0d0f64.tar.gz
busybox-w32-19e695ebadda206d1e0fbefa59ed8fabee0d0f64.tar.bz2
busybox-w32-19e695ebadda206d1e0fbefa59ed8fabee0d0f64.zip
tls: do not use common_bufsiz
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/tls.c')
-rw-r--r--networking/tls.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/networking/tls.c b/networking/tls.c
index e037eba69..2674997ff 100644
--- a/networking/tls.c
+++ b/networking/tls.c
@@ -23,7 +23,7 @@
23//usage:#define tls_full_usage "\n\n" 23//usage:#define tls_full_usage "\n\n"
24 24
25#include "tls.h" 25#include "tls.h"
26#include "common_bufsiz.h" 26//#include "common_bufsiz.h"
27 27
28#define TLS_DEBUG 1 28#define TLS_DEBUG 1
29#define TLS_DEBUG_HASH 1 29#define TLS_DEBUG_HASH 1
@@ -677,7 +677,8 @@ static int xread_tls_block(tls_state_t *tls)
677 677
678 again: 678 again:
679 dbg("insize:%u tail:%u\n", tls->insize, tls->tail); 679 dbg("insize:%u tail:%u\n", tls->insize, tls->tail);
680 memmove(tls->inbuf, tls->inbuf + tls->insize, tls->tail); 680 if (tls->tail != 0)
681 memmove(tls->inbuf, tls->inbuf + tls->insize, tls->tail);
681 errno = 0; 682 errno = 0;
682 total = tls->tail; 683 total = tls->tail;
683 target = sizeof(tls->inbuf); 684 target = sizeof(tls->inbuf);
@@ -702,7 +703,6 @@ static int xread_tls_block(tls_state_t *tls)
702 /* "Abrupt" EOF, no TLS shutdown (seen from kernel.org) */ 703 /* "Abrupt" EOF, no TLS shutdown (seen from kernel.org) */
703 dbg("EOF (without TLS shutdown) from peer\n"); 704 dbg("EOF (without TLS shutdown) from peer\n");
704 tls->tail = 0; 705 tls->tail = 0;
705 tls->insize = 0;
706 goto end; 706 goto end;
707 } 707 }
708 bb_perror_msg_and_die("short read, have only %d", total); 708 bb_perror_msg_and_die("short read, have only %d", total);
@@ -1062,6 +1062,8 @@ static void send_client_hello(tls_state_t *tls)
1062 record->comprtypes_len = 1; 1062 record->comprtypes_len = 1;
1063 record->comprtypes[0] = 0; 1063 record->comprtypes[0] = 0;
1064 1064
1065//TODO: send options, at least SNI.
1066
1065 dbg(">> CLIENT_HELLO\n"); 1067 dbg(">> CLIENT_HELLO\n");
1066 xwrite_and_update_handshake_hash(tls, sizeof(*record)); 1068 xwrite_and_update_handshake_hash(tls, sizeof(*record));
1067} 1069}
@@ -1453,6 +1455,9 @@ static void tls_xwrite(tls_state_t *tls, int len)
1453// openssl req -x509 -newkey rsa:$((4096/4*3)) -keyout key.pem -out server.pem -nodes -days 99999 -subj '/CN=localhost' 1455// openssl req -x509 -newkey rsa:$((4096/4*3)) -keyout key.pem -out server.pem -nodes -days 99999 -subj '/CN=localhost'
1454// openssl s_server -key key.pem -cert server.pem -debug -tls1_2 -no_tls1 -no_tls1_1 -cipher NULL 1456// openssl s_server -key key.pem -cert server.pem -debug -tls1_2 -no_tls1 -no_tls1_1 -cipher NULL
1455// openssl s_client -connect 127.0.0.1:4433 -debug -tls1_2 -no_tls1 -no_tls1_1 -cipher NULL-SHA256 1457// openssl s_client -connect 127.0.0.1:4433 -debug -tls1_2 -no_tls1 -no_tls1_1 -cipher NULL-SHA256
1458//
1459// Talk to kernel.org:
1460// printf "GET / HTTP/1.1\r\nHost: kernel.org\r\n\r\n" | ./busybox tls kernel.org
1456 1461
1457int tls_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1462int tls_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1458int tls_main(int argc UNUSED_PARAM, char **argv) 1463int tls_main(int argc UNUSED_PARAM, char **argv)
@@ -1478,8 +1483,8 @@ int tls_main(int argc UNUSED_PARAM, char **argv)
1478 FD_SET(cfd, &readfds); 1483 FD_SET(cfd, &readfds);
1479 FD_SET(STDIN_FILENO, &readfds); 1484 FD_SET(STDIN_FILENO, &readfds);
1480 1485
1481#define iobuf bb_common_bufsiz1 1486//#define iobuf bb_common_bufsiz1
1482 setup_common_bufsiz(); 1487// setup_common_bufsiz();
1483 for (;;) { 1488 for (;;) {
1484 int nread; 1489 int nread;
1485 1490
@@ -1492,12 +1497,14 @@ int tls_main(int argc UNUSED_PARAM, char **argv)
1492 void *buf; 1497 void *buf;
1493 1498
1494 dbg("STDIN HAS DATA\n"); 1499 dbg("STDIN HAS DATA\n");
1495 buf = tls_get_outbuf(tls, COMMON_BUFSIZE); 1500//TODO: growable buffer
1496 nread = safe_read(STDIN_FILENO, buf, COMMON_BUFSIZE); 1501 buf = tls_get_outbuf(tls, 4 * 1024);
1502 nread = safe_read(STDIN_FILENO, buf, 4 * 1024);
1497 if (nread < 1) { 1503 if (nread < 1) {
1498//&& errno != EAGAIN 1504//&& errno != EAGAIN
1499 /* Close outgoing half-connection so they get EOF, 1505 /* Close outgoing half-connection so they get EOF,
1500 * but leave incoming alone so we can see response */ 1506 * but leave incoming alone so we can see response */
1507//TLS has no way to encode this, doubt it's ok to do it "raw"
1501// shutdown(cfd, SHUT_WR); 1508// shutdown(cfd, SHUT_WR);
1502 FD_CLR(STDIN_FILENO, &readfds); 1509 FD_CLR(STDIN_FILENO, &readfds);
1503 } 1510 }
@@ -1507,7 +1514,7 @@ int tls_main(int argc UNUSED_PARAM, char **argv)
1507 dbg("NETWORK HAS DATA\n"); 1514 dbg("NETWORK HAS DATA\n");
1508 nread = xread_tls_block(tls); 1515 nread = xread_tls_block(tls);
1509 if (nread < 1) 1516 if (nread < 1)
1510//if eof, just close stdout, but not exit! 1517//TODO: if eof, just close stdout, but not exit!
1511 return EXIT_SUCCESS; 1518 return EXIT_SUCCESS;
1512 xwrite(STDOUT_FILENO, tls->inbuf + RECHDR_LEN, nread); 1519 xwrite(STDOUT_FILENO, tls->inbuf + RECHDR_LEN, nread);
1513 } 1520 }