From 637cd92d14f463b594ee89949146aa6f5f320d25 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Wed, 11 Dec 2013 21:19:04 +0400 Subject: [PATCH] openssl: fix keypress requirement in apps on win32 Original source: http://openssl.6102.n7.nabble.com/PATCH-s-client-Fix-keypress-requirement-with-redirected-input-on-Windows-td46787.html Reviewed-By: Fedor Indutny --- deps/openssl/openssl/apps/s_client.c | 45 ++++++++++++++++------------ 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/deps/openssl/openssl/apps/s_client.c b/deps/openssl/openssl/apps/s_client.c index 28737b6d1e6b..5e9862afb919 100644 --- a/deps/openssl/openssl/apps/s_client.c +++ b/deps/openssl/openssl/apps/s_client.c @@ -180,6 +180,13 @@ typedef unsigned int u_int; # include #endif +/* Use Windows API with STD_INPUT_HANDLE when checking for input? + Don't look at OPENSSL_SYS_MSDOS for this, since it is always defined if + OPENSSL_SYS_WINDOWS is defined */ +#if defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_WINCE) && defined(STD_INPUT_HANDLE) +#define OPENSSL_USE_STD_INPUT_HANDLE +#endif + #undef PROG #define PROG s_client_main @@ -226,6 +233,7 @@ static int ocsp_resp_cb(SSL *s, void *arg); static BIO *bio_c_out = NULL; static int c_quiet = 0; static int c_ign_eof = 0; +static int c_no_rand_screen = 0; #ifndef OPENSSL_NO_PSK /* Default PSK identity and key */ @@ -428,6 +436,10 @@ static void sc_usage(void) " -keymatexport label - Export keying material using label\n"); BIO_printf(bio_err, " -keymatexportlen len - Export len bytes of keying material (default 20)\n"); +#ifdef OPENSSL_SYS_WINDOWS + BIO_printf(bio_err, + " -no_rand_screen - Do not use RAND_screen() to initialize random state\n"); +#endif } #ifndef OPENSSL_NO_TLSEXT @@ -1004,6 +1016,10 @@ int MAIN(int argc, char **argv) keymatexportlen = atoi(*(++argv)); if (keymatexportlen == 0) goto bad; +#ifdef OPENSSL_SYS_WINDOWS + } else if (strcmp(*argv, "-no_rand_screen") == 0) { + c_no_rand_screen = 1; +#endif } else { BIO_printf(bio_err, "unknown option %s\n", *argv); badop = 1; @@ -1087,7 +1103,7 @@ int MAIN(int argc, char **argv) } } - if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL + if (!app_RAND_load_file(NULL, bio_err, ++c_no_rand_screen) && inrand == NULL && !RAND_status()) { BIO_printf(bio_err, "warning, not much extra random data, consider using the -rand option\n"); @@ -1584,18 +1600,11 @@ int MAIN(int argc, char **argv) tv.tv_usec = 0; i = select(width, (void *)&readfds, (void *)&writefds, NULL, &tv); -# if defined(OPENSSL_SYS_WINCE) || defined(OPENSSL_SYS_MSDOS) - if (!i && (!_kbhit() || !read_tty)) - continue; -# else - if (!i && (!((_kbhit()) - || (WAIT_OBJECT_0 == - WaitForSingleObject(GetStdHandle - (STD_INPUT_HANDLE), - 0))) - || !read_tty)) - continue; -# endif +#if defined(OPENSSL_USE_STD_INPUT_HANDLE) + if(!i && (!((_kbhit()) || (WAIT_OBJECT_0 == WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0))) || !read_tty) ) continue; +#else + if(!i && (!_kbhit() || !read_tty) ) continue; +#endif } else i = select(width, (void *)&readfds, (void *)&writefds, NULL, timeoutp); @@ -1793,13 +1802,11 @@ int MAIN(int argc, char **argv) } } #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) -# if defined(OPENSSL_SYS_WINCE) || defined(OPENSSL_SYS_MSDOS) +#if defined(OPENSSL_USE_STD_INPUT_HANDLE) + else if ((_kbhit()) || (WAIT_OBJECT_0 == WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0))) +#else else if (_kbhit()) -# else - else if ((_kbhit()) - || (WAIT_OBJECT_0 == - WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0))) -# endif +#endif #elif defined (OPENSSL_SYS_NETWARE) else if (_kbhit()) #elif defined(OPENSSL_SYS_BEOS_R5)