2017-01-23 05:38:16 +05:30
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Denys Vlasenko
|
|
|
|
*
|
|
|
|
* Licensed under GPLv2, see file LICENSE in this source tree.
|
|
|
|
*/
|
|
|
|
//config:config SSL_CLIENT
|
2017-07-19 01:31:24 +05:30
|
|
|
//config: bool "ssl_client (23 kb)"
|
2017-01-23 05:38:16 +05:30
|
|
|
//config: default y
|
|
|
|
//config: select TLS
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: This tool pipes data to/from a socket, TLS-encrypting it.
|
2017-01-23 05:38:16 +05:30
|
|
|
|
|
|
|
//applet:IF_SSL_CLIENT(APPLET(ssl_client, BB_DIR_USR_BIN, BB_SUID_DROP))
|
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_SSL_CLIENT) += ssl_client.o
|
|
|
|
|
|
|
|
//usage:#define ssl_client_trivial_usage
|
2018-02-06 19:45:08 +05:30
|
|
|
//usage: "[-e] -s FD [-r FD] [-n SNI]"
|
2017-01-23 05:38:16 +05:30
|
|
|
//usage:#define ssl_client_full_usage ""
|
|
|
|
|
|
|
|
#include "libbb.h"
|
|
|
|
|
|
|
|
int ssl_client_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
|
|
int ssl_client_main(int argc UNUSED_PARAM, char **argv)
|
|
|
|
{
|
|
|
|
tls_state_t *tls;
|
|
|
|
const char *sni = NULL;
|
|
|
|
int opt;
|
|
|
|
|
|
|
|
// INIT_G();
|
|
|
|
|
|
|
|
tls = new_tls_state();
|
2018-03-20 16:11:28 +05:30
|
|
|
opt = getopt32(argv, "es:+r:+n:", &tls->ofd, &tls->ifd, &sni);
|
2018-02-06 19:45:08 +05:30
|
|
|
if (!(opt & (1<<2))) {
|
2017-01-23 05:38:16 +05:30
|
|
|
/* -r N defaults to -s N */
|
|
|
|
tls->ifd = tls->ofd;
|
|
|
|
}
|
|
|
|
|
2018-02-06 19:45:08 +05:30
|
|
|
if (!(opt & (3<<1))) {
|
2017-01-23 05:38:16 +05:30
|
|
|
if (!argv[1])
|
|
|
|
bb_show_usage();
|
|
|
|
/* Undocumented debug feature: without -s and -r, takes HOST arg and connects to it */
|
|
|
|
//
|
|
|
|
// Talk to kernel.org:
|
2018-02-06 19:45:08 +05:30
|
|
|
// printf "GET / HTTP/1.1\r\nHost: kernel.org\r\n\r\n" | busybox ssl_client kernel.org
|
2017-01-23 05:38:16 +05:30
|
|
|
if (!sni)
|
|
|
|
sni = argv[1];
|
|
|
|
tls->ifd = tls->ofd = create_and_connect_stream_or_die(argv[1], 443);
|
|
|
|
}
|
|
|
|
|
|
|
|
tls_handshake(tls, sni);
|
2018-02-06 19:45:08 +05:30
|
|
|
|
|
|
|
BUILD_BUG_ON(TLSLOOP_EXIT_ON_LOCAL_EOF != 1);
|
|
|
|
tls_run_copy_loop(tls, /*flags*/ opt & 1);
|
2017-01-23 05:38:16 +05:30
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|