Skip to content

Commit

Permalink
sshconnect2: Write kbd-interactive service, info and instructions as …
Browse files Browse the repository at this point in the history
…utf-8

As per the previous server change now the keyboard-interactive service
and instruction values could be reported as soon as they are available
and so they're not prompts anymore and not parsed like them.

While this was already supported by the SSH client, these messages were
not properly written as the escaped sequences they contained were not
correctly reported.

So for example a message containing "\" was represented as "\\" and
similarly for all the other C escape sequences.

This was leading to more problems when it come to utf-8 chars, as they
were only represented by their octal representation.

This was easily testable by adding a line like the one below to the
sshd PAM service:
  auth    requisite pam_echo.so Hello SSHD! Want some 🍕?

Which was causing this to be written instead:
  Hello SSHD! Want some \360\237\215\225?

To handle this, instead of simply using fmprintf, we're using the notifier
in a way can be exposed to users in the proper format and UI.
  • Loading branch information
3v1n0 committed Jan 11, 2024
1 parent 598ee34 commit cc14301
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions sshconnect2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ input_userauth_passwd_changereq(int type, u_int32_t seqnr, struct ssh *ssh)
char *info = NULL, *lang = NULL, *password = NULL, *retype = NULL;
char prompt[256];
const char *host;
size_t info_len;
int r;

debug2("input_userauth_passwd_changereq");
Expand All @@ -1100,11 +1101,15 @@ input_userauth_passwd_changereq(int type, u_int32_t seqnr, struct ssh *ssh)
"no authentication context");
host = options.host_key_alias ? options.host_key_alias : authctxt->host;

if ((r = sshpkt_get_cstring(ssh, &info, NULL)) != 0 ||
if ((r = sshpkt_get_cstring(ssh, &info, &info_len)) != 0 ||
(r = sshpkt_get_cstring(ssh, &lang, NULL)) != 0)
goto out;
if (strlen(info) > 0)
logit("%s", info);
if (info_len > 0) {
struct notifier_ctx *notifier = NULL;
debug_f("input_userauth_passwd_changereq info: %s", info);
notifier = notify_start(0, "%s", info);
notify_complete(notifier, NULL);
}
if ((r = sshpkt_start(ssh, SSH2_MSG_USERAUTH_REQUEST)) != 0 ||
(r = sshpkt_put_cstring(ssh, authctxt->server_user)) != 0 ||
(r = sshpkt_put_cstring(ssh, authctxt->service)) != 0 ||
Expand Down Expand Up @@ -1938,8 +1943,10 @@ input_userauth_info_req(int type, u_int32_t seq, struct ssh *ssh)
Authctxt *authctxt = ssh->authctxt;
char *name = NULL, *inst = NULL, *lang = NULL, *prompt = NULL;
char *display_prompt = NULL, *response = NULL;
struct notifier_ctx *notifier = NULL;
u_char echo = 0;
u_int num_prompts, i;
size_t name_len, inst_len;
int r;

debug2_f("entering");
Expand All @@ -1949,14 +1956,22 @@ input_userauth_info_req(int type, u_int32_t seq, struct ssh *ssh)

authctxt->info_req_seen = 1;

if ((r = sshpkt_get_cstring(ssh, &name, NULL)) != 0 ||
(r = sshpkt_get_cstring(ssh, &inst, NULL)) != 0 ||
if ((r = sshpkt_get_cstring(ssh, &name, &name_len)) != 0 ||
(r = sshpkt_get_cstring(ssh, &inst, &inst_len)) != 0 ||
(r = sshpkt_get_cstring(ssh, &lang, NULL)) != 0)
goto out;
if (strlen(name) > 0)
logit("%s", name);
if (strlen(inst) > 0)
logit("%s", inst);
if (name_len > 0) {
debug_f("kbd int name: %s", name);
notifier = notify_start(0, "%s", name);
notify_complete(notifier, NULL);
notifier = NULL;
}
if (inst_len > 0) {
debug_f("kbd int inst: %s", inst);
notifier = notify_start(0, "%s", inst);
notify_complete(notifier, NULL);
notifier = NULL;
}

if ((r = sshpkt_get_u32(ssh, &num_prompts)) != 0)
goto out;
Expand Down

0 comments on commit cc14301

Please sign in to comment.