1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 11:32:48 -05:00

Revamp interface to verify_ssh_host_key() and askalg(). Each of them

now returns an integer: 0 means cancel the SSH connection and 1
means continue with it. Additionally, they can return -1, which
means `front end has set an asynchronous alert box in motion, please
wait to be called back with the result', and each one is passed a
callback function pointer and context for this purpose.

I have not yet done the same to askappend() yet, because it will
take a certain amount of reorganisation of logging.c.

Importantly, this checkin means the host key dialog box now works on
OS X.

[originally from svn r5330]
This commit is contained in:
Simon Tatham
2005-02-17 18:34:24 +00:00
parent 92ccb964a2
commit 8574822b9b
11 changed files with 456 additions and 140 deletions

View File

@ -45,8 +45,9 @@ void timer_change_notify(long next)
{
}
void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
char *keystr, char *fingerprint)
int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
char *keystr, char *fingerprint,
void (*callback)(void *ctx, int result), void *ctx)
{
int ret;
HANDLE hin;
@ -111,12 +112,12 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
ret = verify_host_key(host, port, keytype, keystr);
if (ret == 0) /* success - key matched OK */
return;
return 1;
if (ret == 2) { /* key was different */
if (console_batch_mode) {
fprintf(stderr, wrongmsg_batch, keytype, fingerprint);
cleanup_exit(1);
return 0;
}
fprintf(stderr, wrongmsg, keytype, fingerprint);
fflush(stderr);
@ -124,7 +125,7 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
if (ret == 1) { /* key was absent */
if (console_batch_mode) {
fprintf(stderr, absentmsg_batch, keytype, fingerprint);
cleanup_exit(1);
return 0;
}
fprintf(stderr, absentmsg, keytype, fingerprint);
fflush(stderr);
@ -140,9 +141,10 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
if (line[0] != '\0' && line[0] != '\r' && line[0] != '\n') {
if (line[0] == 'y' || line[0] == 'Y')
store_host_key(host, port, keytype, keystr);
return 1;
} else {
fprintf(stderr, abandoned);
cleanup_exit(0);
return 0;
}
}
@ -154,7 +156,8 @@ void update_specials_menu(void *frontend)
* Ask whether the selected algorithm is acceptable (since it was
* below the configured 'warn' threshold).
*/
void askalg(void *frontend, const char *algtype, const char *algname)
int askalg(void *frontend, const char *algtype, const char *algname,
void (*callback)(void *ctx, int result), void *ctx)
{
HANDLE hin;
DWORD savemode, i;
@ -173,7 +176,7 @@ void askalg(void *frontend, const char *algtype, const char *algname)
if (console_batch_mode) {
fprintf(stderr, msg_batch, algtype, algname);
cleanup_exit(1);
return 0;
}
fprintf(stderr, msg, algtype, algname);
@ -187,10 +190,10 @@ void askalg(void *frontend, const char *algtype, const char *algname)
SetConsoleMode(hin, savemode);
if (line[0] == 'y' || line[0] == 'Y') {
return;
return 1;
} else {
fprintf(stderr, abandoned);
cleanup_exit(0);
return 0;
}
}

View File

@ -723,8 +723,9 @@ static VOID CALLBACK verify_ssh_host_key_help(LPHELPINFO lpHelpInfo)
}
}
void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
char *keystr, char *fingerprint)
int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
char *keystr, char *fingerprint,
void (*callback)(void *ctx, int result), void *ctx)
{
int ret;
@ -782,7 +783,7 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
ret = verify_host_key(host, port, keytype, keystr);
if (ret == 0) /* success - key matched OK */
return;
return 1;
if (ret == 2) { /* key was different */
int mbret;
mbox.lpszText = dupprintf(wrongmsg, appname, keytype, fingerprint,
@ -797,7 +798,8 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
if (mbret == IDYES)
store_host_key(host, port, keytype, keystr);
if (mbret == IDCANCEL)
cleanup_exit(0);
return 0;
return 1;
}
if (ret == 1) { /* key was absent */
int mbret;
@ -812,7 +814,8 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
if (mbret == IDYES)
store_host_key(host, port, keytype, keystr);
if (mbret == IDCANCEL)
cleanup_exit(0);
return 0;
return 1;
}
}
@ -820,7 +823,8 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
* Ask whether the selected algorithm is acceptable (since it was
* below the configured 'warn' threshold).
*/
void askalg(void *frontend, const char *algtype, const char *algname)
int askalg(void *frontend, const char *algtype, const char *algname,
void (*callback)(void *ctx, int result), void *ctx)
{
static const char mbtitle[] = "%s Security Alert";
static const char msg[] =
@ -838,9 +842,9 @@ void askalg(void *frontend, const char *algtype, const char *algname)
sfree(message);
sfree(title);
if (mbret == IDYES)
return;
return 1;
else
cleanup_exit(0);
return 0;
}
/*