Added Twrch support.

This commit is contained in:
Thomas Pornin 2017-07-30 23:11:26 +02:00
parent ce1c57909a
commit 93681c2830
7 changed files with 1100 additions and 11 deletions

File diff suppressed because one or more lines are too long

View file

@ -290,6 +290,7 @@ toolssrc=" \
tools/skey.c \ tools/skey.c \
tools/sslio.c \ tools/sslio.c \
tools/ta.c \ tools/ta.c \
tools/twrch.c \
tools/vector.c \ tools/vector.c \
tools/verify.c \ tools/verify.c \
tools/xmem.c" tools/xmem.c"

View file

@ -50,6 +50,7 @@ usage(void)
fprintf(stderr, " skey decode private key\n"); fprintf(stderr, " skey decode private key\n");
fprintf(stderr, " ta decode trust anchors\n"); fprintf(stderr, " ta decode trust anchors\n");
fprintf(stderr, " chain make C code for certificate chains\n"); fprintf(stderr, " chain make C code for certificate chains\n");
fprintf(stderr, " twrch run the Twrch protocol\n");
} }
int int
@ -98,6 +99,15 @@ main(int argc, char *argv[])
if (do_chain(argc - 2, argv + 2) < 0) { if (do_chain(argc - 2, argv + 2) < 0) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} else if (eqstr(cmd, "twrch")) {
int ret;
ret = do_twrch(argc - 2, argv + 2);
if (ret < 0) {
return EXIT_FAILURE;
} else {
return ret;
}
} else { } else {
fprintf(stderr, "unknown command: '%s'\n", cmd); fprintf(stderr, "unknown command: '%s'\n", cmd);
usage(); usage();

View file

@ -485,7 +485,8 @@ const char *get_algo_name(const void *algo, int long_name);
/* /*
* Run a SSL engine, with a socket connected to the peer, and using * Run a SSL engine, with a socket connected to the peer, and using
* stdin/stdout to exchange application data. * stdin/stdout to exchange application data. The socket must be a
* non-blocking descriptor.
* *
* To help with Win32 compatibility, the socket descriptor is provided * To help with Win32 compatibility, the socket descriptor is provided
* as an "unsigned long" value. * as an "unsigned long" value.
@ -538,4 +539,11 @@ int do_ta(int argc, char *argv[]);
*/ */
int do_chain(int argc, char *argv[]); int do_chain(int argc, char *argv[]);
/*
* Do the "twrch" command. Returned value is 0 on success, -1 on failure
* (processing or arguments), or a non-zero exit code. Command-line
* arguments start _after_ the command name.
*/
int do_twrch(int argc, char *argv[]);
#endif #endif

View file

@ -764,7 +764,7 @@ do_client(int argc, char *argv[])
} }
arg = argv[i]; arg = argv[i];
if (minhello_len != (size_t)-1) { if (minhello_len != (size_t)-1) {
fprintf(stderr, "ERROR: duplicate minium" fprintf(stderr, "ERROR: duplicate minimum"
" ClientHello length\n"); " ClientHello length\n");
usage_client(); usage_client();
goto client_exit_error; goto client_exit_error;

View file

@ -166,7 +166,7 @@ host_bind(const char *host, const char *port, int verbose)
} }
static SOCKET static SOCKET
accept_client(SOCKET server_fd, int verbose) accept_client(SOCKET server_fd, int verbose, int nonblock)
{ {
int fd; int fd;
SOCKADDR_STORAGE sa; SOCKADDR_STORAGE sa;
@ -209,16 +209,16 @@ accept_client(SOCKET server_fd, int verbose)
* We make the socket non-blocking, since we are going to use * We make the socket non-blocking, since we are going to use
* poll() or select() to organise I/O. * poll() or select() to organise I/O.
*/ */
if (nonblock) {
#ifdef _WIN32 #ifdef _WIN32
{
u_long arg; u_long arg;
arg = 1; arg = 1;
ioctlsocket(fd, FIONBIO, &arg); ioctlsocket(fd, FIONBIO, &arg);
}
#else #else
fcntl(fd, F_SETFL, O_NONBLOCK); fcntl(fd, F_SETFL, O_NONBLOCK);
#endif #endif
}
return fd; return fd;
} }
@ -1177,15 +1177,16 @@ do_server(int argc, char *argv[])
*/ */
for (;;) { for (;;) {
int x; int x;
unsigned run_flags;
fd = accept_client(server_fd, verbose); fd = accept_client(server_fd, verbose, 1);
if (fd == INVALID_SOCKET) { if (fd == INVALID_SOCKET) {
goto server_exit_error; goto server_exit_error;
} }
br_ssl_server_reset(&cc); br_ssl_server_reset(&cc);
x = run_ssl_engine(&cc.eng, fd, run_flags = (verbose ? RUN_ENGINE_VERBOSE : 0)
(verbose ? RUN_ENGINE_VERBOSE : 0) | (trace ? RUN_ENGINE_TRACE : 0);
| (trace ? RUN_ENGINE_TRACE : 0)); x = run_ssl_engine(&cc.eng, fd, run_flags);
#ifdef _WIN32 #ifdef _WIN32
closesocket(fd); closesocket(fd);
#else #else

1066
tools/twrch.c Normal file

File diff suppressed because it is too large Load diff