1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Special host key warning when a better key exists.

If you're connecting to a new server and it _only_ provides host key
types you've configured to be below the warning threshold, it's OK to
give the standard askalg() message. But if you've newly demoted a host
key type and now reconnect to some server for which that type was the
best key you had cached, the askalg() wording isn't really appropriate
(it's not that the key we've settled on is the first type _supported
by the server_, it's that it's the first type _cached by us_), and
also it's potentially helpful to list the better algorithms so that
the user can pick one to cross-certify.
This commit is contained in:
Simon Tatham
2016-03-27 18:08:49 +01:00
parent 909a7af07c
commit 940a82fd37
6 changed files with 212 additions and 4 deletions

View File

@ -3562,6 +3562,37 @@ int askalg(void *frontend, const char *algtype, const char *algname,
}
}
int askhk(void *frontend, 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?";
char *text;
int ret;
text = dupprintf(msg, algname, betteralgs);
ret = messagebox(GTK_WIDGET(get_window(frontend)),
"PuTTY Security Alert", text,
string_width("is ecdsa-nistp521, which is"
" below the configured warning threshold."),
FALSE,
"Yes", 'y', 0, 1,
"No", 'n', 0, 0,
NULL);
sfree(text);
if (ret) {
return 1;
} else {
return 0;
}
}
void old_keyfile_warning(void)
{
/*

View File

@ -264,6 +264,59 @@ int askalg(void *frontend, const char *algtype, const char *algname,
}
}
int askhk(void *frontend, 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);
if (console_batch_mode) {
fprintf(stderr, msg_batch, algname, betteralgs);
return 0;
}
fprintf(stderr, msg, algname, betteralgs);
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] == 'y' || line[0] == 'Y') {
postmsg(&cf);
return 1;
} else {
fprintf(stderr, abandoned);
postmsg(&cf);
return 0;
}
}
/*
* Ask whether to wipe a session log file before writing to it.
* Returns 2 for wipe, 1 for append, 0 for cancel (don't log).