diff --git a/Recipe b/Recipe index a84c646a..4b3387ad 100644 --- a/Recipe +++ b/Recipe @@ -331,13 +331,15 @@ KEYGEN = sshrsag sshdssg sshecdsag putty : [G] GUITERM NONSSH WINSSH W_BE_ALL WINMISC winx11 putty.res LIBS puttytel : [G] GUITERM NONSSH W_BE_NOSSH WINMISC puttytel.res nogss LIBS -plink : [C] winplink wincons NONSSH WINSSH W_BE_ALL logging WINMISC +plink : [C] winplink wincons console NONSSH WINSSH W_BE_ALL logging WINMISC + winx11 plink.res winnojmp sessprep noterm winnohlp winselcli - + clicons wincliloop LIBS + + clicons wincliloop console LIBS pscp : [C] pscp winsftp wincons WINSSH BE_SSH SFTP wildcard WINMISC - + pscp.res winnojmp winnohlp winselcli clicons wincliloop LIBS + + pscp.res winnojmp winnohlp winselcli clicons wincliloop + + console LIBS psftp : [C] psftp winsftp wincons WINSSH BE_SSH SFTP wildcard WINMISC - + psftp.res winnojmp winnohlp winselcli clicons wincliloop LIBS + + psftp.res winnojmp winnohlp winselcli clicons wincliloop + + console LIBS pageant : [G] winpgnt pageant sshrsa sshpubk sshdes ARITH sshmd5 version + tree234 MISC sshaes sshsha winsecur winpgntc aqsync sshdss sshsh256 @@ -363,27 +365,27 @@ puttytel : [X] GTKTERM uxmisc misc ldisc settings uxsel U_BE_NOSSH + nogss utils memory GTKMAIN plink : [U] uxplink uxcons NONSSH UXSSH U_BE_ALL logging UXMISC uxsignal - + ux_x11 noterm uxnogtk sessprep cmdline clicons uxcliloop + + ux_x11 noterm uxnogtk sessprep cmdline clicons uxcliloop console PUTTYGEN_UNIX = KEYGEN SSHPRIME sshdes ARITH sshmd5 version sshprng + sshrand uxnoise sshsha MISC sshrsa sshdss uxcons uxstore uxmisc + sshpubk sshaes sshsh256 sshsh512 IMPORT puttygen.res time tree234 + uxgen notiming CONF sshecc sshsha3 uxnogtk sshauxcrypt sshhmac - + uxpoll uxutils sshblake2 sshargon2 + + uxpoll uxutils sshblake2 sshargon2 console puttygen : [U] cmdgen PUTTYGEN_UNIX cgtest : [UT] cgtest PUTTYGEN_UNIX pscp : [U] pscp uxsftp uxcons UXSSH BE_SSH SFTP wildcard UXMISC uxnogtk - + clicons uxcliloop + + clicons uxcliloop console psftp : [U] psftp uxsftp uxcons UXSSH BE_SSH SFTP wildcard UXMISC uxnogtk - + clicons uxcliloop + + clicons uxcliloop console pageant : [X] uxpgnt uxagentc aqsync pageant sshrsa sshpubk sshdes ARITH + sshmd5 version tree234 misc sshaes sshsha sshdss sshsh256 sshsh512 + sshecc CONF uxsignal nocproxy nogss be_none x11fwd ux_x11 uxcons + gtkask gtkmisc nullplug logging UXMISC uxagentsock utils memory + sshauxcrypt sshhmac sshprng uxnoise uxcliloop sshsha3 sshblake2 - + sshargon2 + + sshargon2 console ptermapp : [XT] GTKTERM uxmisc misc ldisc settings uxpty uxsel BE_NONE uxstore + uxsignal CHARSET uxpterm version time xpmpterm xpmptcfg @@ -411,9 +413,9 @@ psusan : [UT] uxpsusan SSHSERVER UXMISC uxsignal uxnoise nogss uxnogtk PSOCKS = psocks portfwd conf sshutils logging proxy nocproxy timing callback + time tree234 version errsock be_misc norand MISC psocks : [C] PSOCKS winsocks wincons winproxy winnet winmisc winselcli - + winhsock winhandl winmiscs winnohlp wincliloop LIBS + + winhsock winhandl winmiscs winnohlp wincliloop console LIBS psocks : [UT] PSOCKS uxsocks uxcons uxproxy uxnet uxmisc uxpoll uxsel uxnogtk - + uxpeer uxfdsock uxcliloop uxsignal + + uxpeer uxfdsock uxcliloop uxsignal console # ---------------------------------------------------------------------- # On Windows, provide a means of removing local test binaries that we diff --git a/console.c b/console.c new file mode 100644 index 00000000..2431bccb --- /dev/null +++ b/console.c @@ -0,0 +1,111 @@ +/* + * Common pieces between the platform console frontend modules. + */ + +#include +#include + +#include "putty.h" +#include "misc.h" +#include "console.h" + +const char hk_absentmsg_common_fmt[] = + "The server's host key is not cached. You have no guarantee\n" + "that the server is the computer you think it is.\n" + "The server's %s key fingerprint is:\n" + "%s\n"; +const char hk_absentmsg_interactive_intro[] = + "If you trust this host, enter \"y\" to add the key to\n" + "PuTTY's cache and carry on connecting.\n" + "If you want to carry on connecting just once, without\n" + "adding the key to the cache, enter \"n\".\n" + "If you do not trust this host, press Return to abandon the\n" + "connection.\n"; +const char hk_absentmsg_interactive_prompt[] = + "Store key in cache? (y/n, Return cancels connection) "; + +const char hk_wrongmsg_common_fmt[] = + "WARNING - POTENTIAL SECURITY BREACH!\n" + "The server's host key does not match the one PuTTY has\n" + "cached. This means that either the server administrator\n" + "has changed the host key, or you have actually connected\n" + "to another computer pretending to be the server.\n" + "The new %s key fingerprint is:\n" + "%s\n"; +const char hk_wrongmsg_interactive_intro[] = + "If you were expecting this change and trust the new key,\n" + "enter \"y\" to update PuTTY's cache and continue connecting.\n" + "If you want to carry on connecting but without updating\n" + "the cache, enter \"n\".\n" + "If you want to abandon the connection completely, press\n" + "Return to cancel. Pressing Return is the ONLY guaranteed\n" + "safe choice.\n"; +const char hk_wrongmsg_interactive_prompt[] = + "Update cached key? (y/n, Return cancels connection) "; + +const char weakcrypto_msg_common_fmt[] = + "The first %s supported by the server is\n" + "%s, which is below the configured warning threshold.\n"; + +const char weakhk_msg_common_fmt[] = + "The first host key type we have stored for this server\n" + "is %s, which is below the configured warning threshold.\n" + "The server also provides the following types of host key\n" + "above the threshold, which we do not have stored:\n" + "%s\n"; + +const char console_continue_prompt[] = "Continue with connection? (y/n) "; +const char console_abandoned_msg[] = "Connection abandoned.\n"; + +bool console_batch_mode = false; + +/* + * Error message and/or fatal exit functions, all based on + * console_print_error_msg which the platform front end provides. + */ +void console_print_error_msg_fmt_v( + const char *prefix, const char *fmt, va_list ap) +{ + char *msg = dupvprintf(fmt, ap); + console_print_error_msg(prefix, msg); + sfree(msg); +} + +void console_print_error_msg_fmt(const char *prefix, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + console_print_error_msg_fmt_v(prefix, fmt, ap); + va_end(ap); +} + +void modalfatalbox(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + console_print_error_msg_fmt_v("FATAL ERROR", fmt, ap); + va_end(ap); + cleanup_exit(1); +} + +void nonfatal(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + console_print_error_msg_fmt_v("ERROR", fmt, ap); + va_end(ap); +} + +void console_connection_fatal(Seat *seat, const char *msg) +{ + console_print_error_msg("FATAL ERROR", msg); + cleanup_exit(1); +} + +/* + * Console front ends redo their select() or equivalent every time, so + * they don't need separate timer handling. + */ +void timer_change_notify(unsigned long next) +{ +} diff --git a/console.h b/console.h new file mode 100644 index 00000000..a8b22466 --- /dev/null +++ b/console.h @@ -0,0 +1,17 @@ +/* + * Common pieces between the platform console frontend modules. + */ + +extern const char hk_absentmsg_common_fmt[]; +extern const char hk_absentmsg_interactive_intro[]; +extern const char hk_absentmsg_interactive_prompt[]; +extern const char hk_wrongmsg_common_fmt[]; +extern const char hk_wrongmsg_interactive_intro[]; +extern const char hk_wrongmsg_interactive_prompt[]; + +extern const char weakcrypto_msg_common_fmt[]; + +extern const char weakhk_msg_common_fmt[]; + +extern const char console_continue_prompt[]; +extern const char console_abandoned_msg[]; diff --git a/unix/uxcons.c b/unix/uxcons.c index 27bd5050..24279d51 100644 --- a/unix/uxcons.c +++ b/unix/uxcons.c @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -17,8 +16,7 @@ #include "putty.h" #include "storage.h" #include "ssh.h" - -bool console_batch_mode = false; +#include "console.h" static struct termios orig_termios_stderr; static bool stderr_is_a_tty; @@ -45,9 +43,6 @@ void postmsg(struct termios *cf) tcsetattr(STDERR_FILENO, TCSADRAIN, cf); } -/* - * Clean up and exit. - */ void cleanup_exit(int code) { /* @@ -58,9 +53,6 @@ void cleanup_exit(int code) exit(code); } -/* - * Various error message and/or fatal exit functions. - */ void console_print_error_msg(const char *prefix, const char *msg) { struct termios cf; @@ -73,49 +65,6 @@ void console_print_error_msg(const char *prefix, const char *msg) postmsg(&cf); } -void console_print_error_msg_fmt_v( - const char *prefix, const char *fmt, va_list ap) -{ - char *msg = dupvprintf(fmt, ap); - console_print_error_msg(prefix, msg); - sfree(msg); -} - -void console_print_error_msg_fmt(const char *prefix, const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - console_print_error_msg_fmt_v(prefix, fmt, ap); - va_end(ap); -} - -void modalfatalbox(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - console_print_error_msg_fmt_v("FATAL ERROR", fmt, ap); - va_end(ap); - cleanup_exit(1); -} - -void nonfatal(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - console_print_error_msg_fmt_v("ERROR", fmt, ap); - va_end(ap); -} - -void console_connection_fatal(Seat *seat, const char *msg) -{ - console_print_error_msg("FATAL ERROR", msg); - cleanup_exit(1); -} - -void timer_change_notify(unsigned long next) -{ -} - /* * Wrapper around Unix read(2), suitable for use on a file descriptor * that's been set into nonblocking mode. Handles EAGAIN/EWOULDBLOCK @@ -160,55 +109,9 @@ int console_verify_ssh_host_key( { int ret; - static const char absentmsg_batch[] = - "The server's host key is not cached. You have no guarantee\n" - "that the server is the computer you think it is.\n" - "The server's %s key fingerprint is:\n" - "%s\n" - "Connection abandoned.\n"; - static const char absentmsg[] = - "The server's host key is not cached. You have no guarantee\n" - "that the server is the computer you think it is.\n" - "The server's %s key fingerprint is:\n" - "%s\n" - "If you trust this host, enter \"y\" to add the key to\n" - "PuTTY's cache and carry on connecting.\n" - "If you want to carry on connecting just once, without\n" - "adding the key to the cache, enter \"n\".\n" - "If you do not trust this host, press Return to abandon the\n" - "connection.\n" - "Store key in cache? (y/n) "; - - static const char wrongmsg_batch[] = - "WARNING - POTENTIAL SECURITY BREACH!\n" - "The server's host key does not match the one PuTTY has\n" - "cached. This means that either the server administrator\n" - "has changed the host key, or you have actually connected\n" - "to another computer pretending to be the server.\n" - "The new %s key fingerprint is:\n" - "%s\n" - "Connection abandoned.\n"; - static const char wrongmsg[] = - "WARNING - POTENTIAL SECURITY BREACH!\n" - "The server's host key does not match the one PuTTY has\n" - "cached. This means that either the server administrator\n" - "has changed the host key, or you have actually connected\n" - "to another computer pretending to be the server.\n" - "The new %s key fingerprint is:\n" - "%s\n" - "If you were expecting this change and trust the new key,\n" - "enter \"y\" to update PuTTY's cache and continue connecting.\n" - "If you want to carry on connecting but without updating\n" - "the cache, enter \"n\".\n" - "If you want to abandon the connection completely, press\n" - "Return to cancel. Pressing Return is the ONLY guaranteed\n" - "safe choice.\n" - "Update cached key? (y/n, Return cancels connection) "; - - static const char abandoned[] = "Connection abandoned.\n"; - char line[32]; struct termios cf; + const char *common_fmt, *intro, *prompt; /* * Verify the key. @@ -220,41 +123,44 @@ int console_verify_ssh_host_key( premsg(&cf); if (ret == 2) { /* key was different */ - if (console_batch_mode) { - fprintf(stderr, wrongmsg_batch, keytype, fingerprint); - return 0; - } - fprintf(stderr, wrongmsg, keytype, fingerprint); - fflush(stderr); - } - if (ret == 1) { /* key was absent */ - if (console_batch_mode) { - fprintf(stderr, absentmsg_batch, keytype, fingerprint); - return 0; - } - fprintf(stderr, absentmsg, keytype, fingerprint); - fflush(stderr); + common_fmt = hk_wrongmsg_common_fmt; + intro = hk_wrongmsg_interactive_intro; + prompt = hk_wrongmsg_interactive_prompt; + } else { /* key was absent */ + common_fmt = hk_absentmsg_common_fmt; + intro = hk_absentmsg_interactive_intro; + prompt = hk_absentmsg_interactive_prompt; } - { - struct termios oldmode, newmode; - tcgetattr(0, &oldmode); - newmode = oldmode; - newmode.c_lflag |= ECHO | ISIG | ICANON; - tcsetattr(0, TCSANOW, &newmode); - line[0] = '\0'; - if (block_and_read(0, line, sizeof(line) - 1) <= 0) - /* handled below */; - tcsetattr(0, TCSANOW, &oldmode); + fprintf(stderr, common_fmt, keytype, fingerprint); + if (console_batch_mode) { + fputs(console_abandoned_msg, stderr); + return 0; } + fputs(intro, stderr); + fflush(stderr); + + fputs(prompt, stderr); + fflush(stderr); + + struct termios oldmode, newmode; + tcgetattr(0, &oldmode); + newmode = oldmode; + newmode.c_lflag |= ECHO | ISIG | ICANON; + tcsetattr(0, TCSANOW, &newmode); + line[0] = '\0'; + if (block_and_read(0, line, sizeof(line) - 1) <= 0) + /* handled below */; + tcsetattr(0, TCSANOW, &oldmode); + if (line[0] != '\0' && line[0] != '\r' && line[0] != '\n') { if (line[0] == 'y' || line[0] == 'Y') store_host_key(host, port, keytype, keystr); postmsg(&cf); return 1; } else { - fprintf(stderr, abandoned); + fputs(console_abandoned_msg, stderr); postmsg(&cf); return 0; } @@ -264,26 +170,18 @@ int console_confirm_weak_crypto_primitive( Seat *seat, const char *algtype, const char *algname, void (*callback)(void *ctx, int result), void *ctx) { - static const char msg[] = - "The first %s supported by the server is\n" - "%s, which is below the configured warning threshold.\n" - "Continue with connection? (y/n) "; - static const char msg_batch[] = - "The first %s supported by the server is\n" - "%s, which is below the configured warning threshold.\n" - "Connection abandoned.\n"; - static const char abandoned[] = "Connection abandoned.\n"; - char line[32]; struct termios cf; premsg(&cf); + fprintf(stderr, weakcrypto_msg_common_fmt, algtype, algname); + if (console_batch_mode) { - fprintf(stderr, msg_batch, algtype, algname); + fputs(console_abandoned_msg, stderr); return 0; } - fprintf(stderr, msg, algtype, algname); + fputs(console_continue_prompt, stderr); fflush(stderr); { @@ -302,7 +200,7 @@ int console_confirm_weak_crypto_primitive( postmsg(&cf); return 1; } else { - fprintf(stderr, abandoned); + fputs(console_abandoned_msg, stderr); postmsg(&cf); return 0; } @@ -312,32 +210,18 @@ int console_confirm_weak_cached_hostkey( Seat *seat, const char *algname, const char *betteralgs, void (*callback)(void *ctx, int result), void *ctx) { - static const char msg[] = - "The first host key type we have stored for this server\n" - "is %s, which is below the configured warning threshold.\n" - "The server also provides the following types of host key\n" - "above the threshold, which we do not have stored:\n" - "%s\n" - "Continue with connection? (y/n) "; - static const char msg_batch[] = - "The first host key type we have stored for this server\n" - "is %s, which is below the configured warning threshold.\n" - "The server also provides the following types of host key\n" - "above the threshold, which we do not have stored:\n" - "%s\n" - "Connection abandoned.\n"; - static const char abandoned[] = "Connection abandoned.\n"; - char line[32]; struct termios cf; premsg(&cf); + fprintf(stderr, weakhk_msg_common_fmt, algname, betteralgs); + if (console_batch_mode) { - fprintf(stderr, msg_batch, algname, betteralgs); + fputs(console_abandoned_msg, stderr); return 0; } - fprintf(stderr, msg, algname, betteralgs); + fputs(console_continue_prompt, stderr); fflush(stderr); { @@ -356,7 +240,7 @@ int console_confirm_weak_cached_hostkey( postmsg(&cf); return 1; } else { - fprintf(stderr, abandoned); + fputs(console_abandoned_msg, stderr); postmsg(&cf); return 0; } diff --git a/windows/wincons.c b/windows/wincons.c index a965337b..f05d2a84 100644 --- a/windows/wincons.c +++ b/windows/wincons.c @@ -5,17 +5,12 @@ #include #include -#include #include "putty.h" #include "storage.h" #include "ssh.h" +#include "console.h" -bool console_batch_mode = false; - -/* - * Clean up and exit. - */ void cleanup_exit(int code) { /* @@ -28,9 +23,6 @@ void cleanup_exit(int code) exit(code); } -/* - * Various error message and/or fatal exit functions. - */ void console_print_error_msg(const char *prefix, const char *msg) { fputs(prefix, stderr); @@ -40,49 +32,6 @@ void console_print_error_msg(const char *prefix, const char *msg) fflush(stderr); } -void console_print_error_msg_fmt_v( - const char *prefix, const char *fmt, va_list ap) -{ - char *msg = dupvprintf(fmt, ap); - console_print_error_msg(prefix, msg); - sfree(msg); -} - -void console_print_error_msg_fmt(const char *prefix, const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - console_print_error_msg_fmt_v(prefix, fmt, ap); - va_end(ap); -} - -void modalfatalbox(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - console_print_error_msg_fmt_v("FATAL ERROR", fmt, ap); - va_end(ap); - cleanup_exit(1); -} - -void nonfatal(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - console_print_error_msg_fmt_v("ERROR", fmt, ap); - va_end(ap); -} - -void console_connection_fatal(Seat *seat, const char *msg) -{ - console_print_error_msg("FATAL ERROR", msg); - cleanup_exit(1); -} - -void timer_change_notify(unsigned long next) -{ -} - int console_verify_ssh_host_key( Seat *seat, const char *host, int port, const char *keytype, char *keystr, char *fingerprint, @@ -91,57 +40,7 @@ int console_verify_ssh_host_key( int ret; HANDLE hin; DWORD savemode, i; - - static const char absentmsg_batch[] = - "The server's host key is not cached in the registry. You\n" - "have no guarantee that the server is the computer you\n" - "think it is.\n" - "The server's %s key fingerprint is:\n" - "%s\n" - "Connection abandoned.\n"; - static const char absentmsg[] = - "The server's host key is not cached in the registry. You\n" - "have no guarantee that the server is the computer you\n" - "think it is.\n" - "The server's %s key fingerprint is:\n" - "%s\n" - "If you trust this host, enter \"y\" to add the key to\n" - "PuTTY's cache and carry on connecting.\n" - "If you want to carry on connecting just once, without\n" - "adding the key to the cache, enter \"n\".\n" - "If you do not trust this host, press Return to abandon the\n" - "connection.\n" - "Store key in cache? (y/n) "; - - static const char wrongmsg_batch[] = - "WARNING - POTENTIAL SECURITY BREACH!\n" - "The server's host key does not match the one PuTTY has\n" - "cached in the registry. This means that either the\n" - "server administrator has changed the host key, or you\n" - "have actually connected to another computer pretending\n" - "to be the server.\n" - "The new %s key fingerprint is:\n" - "%s\n" - "Connection abandoned.\n"; - static const char wrongmsg[] = - "WARNING - POTENTIAL SECURITY BREACH!\n" - "The server's host key does not match the one PuTTY has\n" - "cached in the registry. This means that either the\n" - "server administrator has changed the host key, or you\n" - "have actually connected to another computer pretending\n" - "to be the server.\n" - "The new %s key fingerprint is:\n" - "%s\n" - "If you were expecting this change and trust the new key,\n" - "enter \"y\" to update PuTTY's cache and continue connecting.\n" - "If you want to carry on connecting but without updating\n" - "the cache, enter \"n\".\n" - "If you want to abandon the connection completely, press\n" - "Return to cancel. Pressing Return is the ONLY guaranteed\n" - "safe choice.\n" - "Update cached key? (y/n, Return cancels connection) "; - - static const char abandoned[] = "Connection abandoned.\n"; + const char *common_fmt, *intro, *prompt; char line[32]; @@ -154,23 +53,28 @@ int console_verify_ssh_host_key( return 1; if (ret == 2) { /* key was different */ - if (console_batch_mode) { - fprintf(stderr, wrongmsg_batch, keytype, fingerprint); - return 0; - } - fprintf(stderr, wrongmsg, keytype, fingerprint); - fflush(stderr); - } - if (ret == 1) { /* key was absent */ - if (console_batch_mode) { - fprintf(stderr, absentmsg_batch, keytype, fingerprint); - return 0; - } - fprintf(stderr, absentmsg, keytype, fingerprint); - fflush(stderr); + common_fmt = hk_wrongmsg_common_fmt; + intro = hk_wrongmsg_interactive_intro; + prompt = hk_wrongmsg_interactive_prompt; + } else { /* key was absent */ + common_fmt = hk_absentmsg_common_fmt; + intro = hk_absentmsg_interactive_intro; + prompt = hk_absentmsg_interactive_prompt; } - line[0] = '\0'; /* fail safe if ReadFile returns no data */ + fprintf(stderr, common_fmt, keytype, fingerprint); + if (console_batch_mode) { + fputs(console_abandoned_msg, stderr); + return 0; + } + + fputs(intro, stderr); + fflush(stderr); + + fputs(prompt, stderr); + fflush(stderr); + + line[0] = '\0'; /* fail safe if ReadFile returns no data */ hin = GetStdHandle(STD_INPUT_HANDLE); GetConsoleMode(hin, &savemode); @@ -184,7 +88,7 @@ int console_verify_ssh_host_key( store_host_key(host, port, keytype, keystr); return 1; } else { - fprintf(stderr, abandoned); + fputs(console_abandoned_msg, stderr); return 0; } } @@ -196,24 +100,16 @@ int console_confirm_weak_crypto_primitive( HANDLE hin; DWORD savemode, i; - static const char msg[] = - "The first %s supported by the server is\n" - "%s, which is below the configured warning threshold.\n" - "Continue with connection? (y/n) "; - static const char msg_batch[] = - "The first %s supported by the server is\n" - "%s, which is below the configured warning threshold.\n" - "Connection abandoned.\n"; - static const char abandoned[] = "Connection abandoned.\n"; - char line[32]; + fprintf(stderr, weakcrypto_msg_common_fmt, algtype, algname); + if (console_batch_mode) { - fprintf(stderr, msg_batch, algtype, algname); + fputs(console_abandoned_msg, stderr); return 0; } - fprintf(stderr, msg, algtype, algname); + fputs(console_continue_prompt, stderr); fflush(stderr); hin = GetStdHandle(STD_INPUT_HANDLE); @@ -226,7 +122,7 @@ int console_confirm_weak_crypto_primitive( if (line[0] == 'y' || line[0] == 'Y') { return 1; } else { - fprintf(stderr, abandoned); + fputs(console_abandoned_msg, stderr); return 0; } } @@ -238,30 +134,16 @@ int console_confirm_weak_cached_hostkey( HANDLE hin; DWORD savemode, i; - static const char msg[] = - "The first host key type we have stored for this server\n" - "is %s, which is below the configured warning threshold.\n" - "The server also provides the following types of host key\n" - "above the threshold, which we do not have stored:\n" - "%s\n" - "Continue with connection? (y/n) "; - static const char msg_batch[] = - "The first host key type we have stored for this server\n" - "is %s, which is below the configured warning threshold.\n" - "The server also provides the following types of host key\n" - "above the threshold, which we do not have stored:\n" - "%s\n" - "Connection abandoned.\n"; - static const char abandoned[] = "Connection abandoned.\n"; - char line[32]; + fprintf(stderr, weakhk_msg_common_fmt, algname, betteralgs); + if (console_batch_mode) { - fprintf(stderr, msg_batch, algname, betteralgs); + fputs(console_abandoned_msg, stderr); return 0; } - fprintf(stderr, msg, algname, betteralgs); + fputs(console_continue_prompt, stderr); fflush(stderr); hin = GetStdHandle(STD_INPUT_HANDLE); @@ -274,7 +156,7 @@ int console_confirm_weak_cached_hostkey( if (line[0] == 'y' || line[0] == 'Y') { return 1; } else { - fprintf(stderr, abandoned); + fputs(console_abandoned_msg, stderr); return 0; } }