diff --git a/console.c b/console.c index 7155b9f0..ce70c104 100644 --- a/console.c +++ b/console.c @@ -9,11 +9,15 @@ #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"; +char *hk_absentmsg_common(const char *keytype, const char *fingerprint) +{ + return dupprintf( + "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", keytype, fingerprint); +} + 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" @@ -25,14 +29,18 @@ const char hk_absentmsg_interactive_prompt[] = "Store key in cache? (y/n, Return cancels connection, " "i for more info) "; -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"; +char *hk_wrongmsg_common(const char *keytype, const char *fingerprint) +{ + return dupprintf( + "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", keytype, fingerprint); +} + 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" diff --git a/console.h b/console.h index a8b22466..d28acbdc 100644 --- a/console.h +++ b/console.h @@ -2,10 +2,11 @@ * Common pieces between the platform console frontend modules. */ -extern const char hk_absentmsg_common_fmt[]; +char *hk_absentmsg_common(const char *keytype, const char *fingerprint); extern const char hk_absentmsg_interactive_intro[]; extern const char hk_absentmsg_interactive_prompt[]; -extern const char hk_wrongmsg_common_fmt[]; + +char *hk_wrongmsg_common(const char *keytype, const char *fingerprint); extern const char hk_wrongmsg_interactive_intro[]; extern const char hk_wrongmsg_interactive_prompt[]; diff --git a/unix/console.c b/unix/console.c index e4e372fc..6b6379ed 100644 --- a/unix/console.c +++ b/unix/console.c @@ -111,7 +111,8 @@ int console_verify_ssh_host_key( char line[32]; struct termios cf; - const char *common_fmt, *intro, *prompt; + char *common; + const char *intro, *prompt; /* * Verify the key. @@ -121,21 +122,23 @@ int console_verify_ssh_host_key( if (ret == 0) /* success - key matched OK */ return 1; - premsg(&cf); + FingerprintType fptype_default = + ssh2_pick_default_fingerprint(fingerprints); + if (ret == 2) { /* key was different */ - common_fmt = hk_wrongmsg_common_fmt; + common = hk_wrongmsg_common(keytype, fingerprints[fptype_default]); intro = hk_wrongmsg_interactive_intro; prompt = hk_wrongmsg_interactive_prompt; } else { /* key was absent */ - common_fmt = hk_absentmsg_common_fmt; + common = hk_absentmsg_common(keytype, fingerprints[fptype_default]); intro = hk_absentmsg_interactive_intro; prompt = hk_absentmsg_interactive_prompt; } - FingerprintType fptype_default = - ssh2_pick_default_fingerprint(fingerprints); + premsg(&cf); + fputs(common, stderr); + sfree(common); - fprintf(stderr, common_fmt, keytype, fingerprints[fptype_default]); if (console_batch_mode) { fputs(console_abandoned_msg, stderr); postmsg(&cf); diff --git a/windows/console.c b/windows/console.c index 9bdfb6f4..21d33cd2 100644 --- a/windows/console.c +++ b/windows/console.c @@ -40,7 +40,8 @@ int console_verify_ssh_host_key( int ret; HANDLE hin; DWORD savemode, i; - const char *common_fmt, *intro, *prompt; + char *common; + const char *intro, *prompt; char line[32]; @@ -52,20 +53,22 @@ int console_verify_ssh_host_key( if (ret == 0) /* success - key matched OK */ return 1; + FingerprintType fptype_default = + ssh2_pick_default_fingerprint(fingerprints); + if (ret == 2) { /* key was different */ - common_fmt = hk_wrongmsg_common_fmt; + common = hk_wrongmsg_common(keytype, fingerprints[fptype_default]); intro = hk_wrongmsg_interactive_intro; prompt = hk_wrongmsg_interactive_prompt; } else { /* key was absent */ - common_fmt = hk_absentmsg_common_fmt; + common = hk_absentmsg_common(keytype, fingerprints[fptype_default]); intro = hk_absentmsg_interactive_intro; prompt = hk_absentmsg_interactive_prompt; } - FingerprintType fptype_default = - ssh2_pick_default_fingerprint(fingerprints); + fputs(common, stderr); + sfree(common); - fprintf(stderr, common_fmt, keytype, fingerprints[fptype_default]); if (console_batch_mode) { fputs(console_abandoned_msg, stderr); return 0;