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

Merge tag '0.80'.

This involved a trivial merge conflict fix in terminal.c because of
the way the cherry-pick 73b41feba5 differed from its original
bdbd5f429c.

But a more significant rework was needed in windows/console.c, because
the updates to confirm_weak_* conflicted with the changes on main to
abstract out the ConsoleIO system.
This commit is contained in:
Simon Tatham
2023-12-18 14:32:57 +00:00
24 changed files with 803 additions and 283 deletions

View File

@ -337,14 +337,16 @@ static ResponseType parse_and_free_response(char *line)
return toret;
}
SeatPromptResult console_confirm_ssh_host_key(
Seat *seat, const char *host, int port, const char *keytype,
char *keystr, SeatDialogText *text, HelpCtx helpctx,
void (*callback)(void *ctx, SeatPromptResult result), void *ctx)
/*
* Helper function to print the message from a SeatDialogText. Returns
* the final prompt to print on the input line, or NULL if a
* batch-mode abort is needed. In the latter case it will have printed
* the abort text already.
*/
static const char *console_print_seatdialogtext(
ConsoleIO *conio, SeatDialogText *text)
{
ConsoleIO *conio = conio_setup(false);
const char *prompt = NULL;
SeatPromptResult result;
for (SeatDialogTextItem *item = text->items,
*end = item+text->nitems; item < end; item++) {
@ -364,9 +366,7 @@ SeatPromptResult console_confirm_ssh_host_key(
case SDT_BATCH_ABORT:
if (console_batch_mode) {
put_fmt(conio, "%s\n", item->text);
result = SPR_SW_ABORT(
"Cannot confirm a host key in batch mode");
goto out;
return NULL;
}
break;
case SDT_PROMPT:
@ -377,6 +377,20 @@ SeatPromptResult console_confirm_ssh_host_key(
}
}
assert(prompt); /* something in the SeatDialogText should have set this */
return prompt;
}
SeatPromptResult console_confirm_ssh_host_key(
Seat *seat, const char *host, int port, const char *keytype,
char *keystr, SeatDialogText *text, HelpCtx helpctx,
void (*callback)(void *ctx, SeatPromptResult result), void *ctx)
{
ConsoleIO *conio = conio_setup(false);
SeatPromptResult result;
const char *prompt = console_print_seatdialogtext(conio, text);
if (!prompt)
return SPR_SW_ABORT("Cannot confirm a host key in batch mode");
ResponseType response;
@ -416,28 +430,24 @@ SeatPromptResult console_confirm_ssh_host_key(
put_dataz(conio, console_abandoned_msg);
result = SPR_USER_ABORT;
}
out:
conio_free(conio);
return result;
}
SeatPromptResult console_confirm_weak_crypto_primitive(
Seat *seat, const char *algtype, const char *algname,
Seat *seat, SeatDialogText *text,
void (*callback)(void *ctx, SeatPromptResult result), void *ctx)
{
ConsoleIO *conio = conio_setup(false);
SeatPromptResult result;
put_fmt(conio, weakcrypto_msg_common_fmt, algtype, algname);
const char *prompt = console_print_seatdialogtext(conio, text);
if (!prompt)
return SPR_SW_ABORT("Cannot confirm a weak crypto primitive "
"in batch mode");
if (console_batch_mode) {
put_dataz(conio, console_abandoned_msg);
result = SPR_SW_ABORT("Cannot confirm a weak crypto primitive "
"in batch mode");
goto out;
}
put_dataz(conio, console_continue_prompt);
put_fmt(conio, "%s (y/n)", prompt);
ResponseType response = parse_and_free_response(
console_read_line(conio, true));
@ -448,28 +458,24 @@ SeatPromptResult console_confirm_weak_crypto_primitive(
put_dataz(conio, console_abandoned_msg);
result = SPR_USER_ABORT;
}
out:
conio_free(conio);
return result;
}
SeatPromptResult console_confirm_weak_cached_hostkey(
Seat *seat, const char *algname, const char *betteralgs,
Seat *seat, SeatDialogText *text,
void (*callback)(void *ctx, SeatPromptResult result), void *ctx)
{
ConsoleIO *conio = conio_setup(false);
SeatPromptResult result;
put_fmt(conio, weakhk_msg_common_fmt, algname, betteralgs);
const char *prompt = console_print_seatdialogtext(conio, text);
if (!prompt)
return SPR_SW_ABORT("Cannot confirm a weak cached host key "
"in batch mode");
if (console_batch_mode) {
put_dataz(conio, console_abandoned_msg);
result = SPR_SW_ABORT("Cannot confirm a weak cached host key "
"in batch mode");
goto out;
}
put_dataz(conio, console_continue_prompt);
put_fmt(conio, "%s (y/n) ", prompt);
ResponseType response = parse_and_free_response(
console_read_line(conio, true));
@ -480,7 +486,7 @@ SeatPromptResult console_confirm_weak_cached_hostkey(
put_dataz(conio, console_abandoned_msg);
result = SPR_USER_ABORT;
}
out:
conio_free(conio);
return result;
}

View File

@ -949,6 +949,39 @@ static INT_PTR HostKeyMoreInfoProc(HWND hwnd, UINT msg, WPARAM wParam,
return 0;
}
static const char *process_seatdialogtext(
strbuf *dlg_text, const char **scary_heading, SeatDialogText *text)
{
const char *dlg_title = "";
for (SeatDialogTextItem *item = text->items,
*end = item + text->nitems; item < end; item++) {
switch (item->type) {
case SDT_PARA:
put_fmt(dlg_text, "%s\r\n\r\n", item->text);
break;
case SDT_DISPLAY:
put_fmt(dlg_text, "%s\r\n\r\n", item->text);
break;
case SDT_SCARY_HEADING:
assert(scary_heading != NULL && "only expect a scary heading if "
"the dialog has somewhere to put it");
*scary_heading = item->text;
break;
case SDT_TITLE:
dlg_title = item->text;
break;
default:
break;
}
}
/* Trim any trailing newlines */
while (strbuf_chomp(dlg_text, '\r') || strbuf_chomp(dlg_text, '\n'));
return dlg_title;
}
static INT_PTR HostKeyDialogProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam, void *vctx)
{
@ -957,32 +990,15 @@ static INT_PTR HostKeyDialogProc(HWND hwnd, UINT msg,
switch (msg) {
case WM_INITDIALOG: {
strbuf *dlg_text = strbuf_new();
const char *dlg_title = "";
ctx->has_title = false;
LPCTSTR iconid = IDI_QUESTION;
const char *scary_heading = NULL;
const char *dlg_title = process_seatdialogtext(
dlg_text, &scary_heading, ctx->text);
for (SeatDialogTextItem *item = ctx->text->items,
*end = item + ctx->text->nitems; item < end; item++) {
switch (item->type) {
case SDT_PARA:
put_fmt(dlg_text, "%s\r\n\r\n", item->text);
break;
case SDT_DISPLAY:
put_fmt(dlg_text, "%s\r\n\r\n", item->text);
break;
case SDT_SCARY_HEADING:
SetDlgItemText(hwnd, IDC_HK_TITLE, item->text);
iconid = IDI_WARNING;
ctx->has_title = true;
break;
case SDT_TITLE:
dlg_title = item->text;
break;
default:
break;
}
LPCTSTR iconid = IDI_QUESTION;
if (scary_heading) {
SetDlgItemText(hwnd, IDC_HK_TITLE, scary_heading);
iconid = IDI_WARNING;
}
while (strbuf_chomp(dlg_text, '\r') || strbuf_chomp(dlg_text, '\n'));
SetDlgItemText(hwnd, IDC_HK_TEXT, dlg_text->s);
MakeDlgItemBorderless(hwnd, IDC_HK_TEXT);
@ -1121,6 +1137,8 @@ const SeatDialogPromptDescriptions *win_seat_prompt_descriptions(Seat *seat)
.hk_connect_once_action = "press \"Connect Once\"",
.hk_cancel_action = "press \"Cancel\"",
.hk_cancel_action_Participle = "Pressing \"Cancel\"",
.weak_accept_action = "press \"Yes\"",
.weak_cancel_action = "press \"No\"",
};
return &descs;
}
@ -1155,25 +1173,17 @@ SeatPromptResult win_seat_confirm_ssh_host_key(
* below the configured 'warn' threshold).
*/
SeatPromptResult win_seat_confirm_weak_crypto_primitive(
Seat *seat, const char *algtype, const char *algname,
Seat *seat, SeatDialogText *text,
void (*callback)(void *ctx, SeatPromptResult result), void *ctx)
{
static const char mbtitle[] = "%s Security Alert";
static const char msg[] =
"The first %s supported by the server\n"
"is %s, which is below the configured\n"
"warning threshold.\n"
"Do you want to continue with this connection?\n";
char *message, *title;
int mbret;
strbuf *dlg_text = strbuf_new();
const char *dlg_title = process_seatdialogtext(dlg_text, NULL, text);
message = dupprintf(msg, algtype, algname);
title = dupprintf(mbtitle, appname);
mbret = MessageBox(NULL, message, title,
MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2);
int mbret = MessageBox(NULL, dlg_text->s, dlg_title,
MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2);
socket_reselect_all();
sfree(message);
sfree(title);
strbuf_free(dlg_text);
if (mbret == IDYES)
return SPR_OK;
else
@ -1181,27 +1191,17 @@ SeatPromptResult win_seat_confirm_weak_crypto_primitive(
}
SeatPromptResult win_seat_confirm_weak_cached_hostkey(
Seat *seat, const char *algname, const char *betteralgs,
Seat *seat, SeatDialogText *text,
void (*callback)(void *ctx, SeatPromptResult result), void *ctx)
{
static const char mbtitle[] = "%s Security Alert";
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"
"Do you want to continue with this connection?\n";
char *message, *title;
int mbret;
strbuf *dlg_text = strbuf_new();
const char *dlg_title = process_seatdialogtext(dlg_text, NULL, text);
message = dupprintf(msg, algname, betteralgs);
title = dupprintf(mbtitle, appname);
mbret = MessageBox(NULL, message, title,
MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2);
int mbret = MessageBox(NULL, dlg_text->s, dlg_title,
MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2);
socket_reselect_all();
sfree(message);
sfree(title);
strbuf_free(dlg_text);
if (mbret == IDYES)
return SPR_OK;
else

View File

@ -254,10 +254,10 @@ SeatPromptResult win_seat_confirm_ssh_host_key(
char *keystr, SeatDialogText *text, HelpCtx helpctx,
void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
SeatPromptResult win_seat_confirm_weak_crypto_primitive(
Seat *seat, const char *algtype, const char *algname,
Seat *seat, SeatDialogText *text,
void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
SeatPromptResult win_seat_confirm_weak_cached_hostkey(
Seat *seat, const char *algname, const char *betteralgs,
Seat *seat, SeatDialogText *text,
void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
const SeatDialogPromptDescriptions *win_seat_prompt_descriptions(Seat *seat);