upstream: pass the log-on-stderr flag and log level through to

ssh-sk-helper, making debugging a bit easier. ok markus@

OpenBSD-Commit-ID: 2e7aea6bf5770d3f38b7c7bba891069256c5a49a
This commit is contained in:
djm@openbsd.org 2020-01-10 23:43:26 +00:00 committed by Damien Miller
parent a8bd5fdbdb
commit 57b181eaf2
3 changed files with 37 additions and 26 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ssh-sk-client.c,v 1.4 2020/01/06 02:00:46 djm Exp $ */ /* $OpenBSD: ssh-sk-client.c,v 1.5 2020/01/10 23:43:26 djm Exp $ */
/* /*
* Copyright (c) 2019 Google LLC * Copyright (c) 2019 Google LLC
* *
@ -129,24 +129,32 @@ reap_helper(pid_t pid)
} }
static int static int
client_converse(struct sshbuf *req, struct sshbuf **respp, u_int msg) client_converse(struct sshbuf *msg, struct sshbuf **respp, u_int type)
{ {
int oerrno, fd, r2, r = SSH_ERR_INTERNAL_ERROR; int oerrno, fd, r2, ll, r = SSH_ERR_INTERNAL_ERROR;
u_int rmsg, rerr; u_int rtype, rerr;
pid_t pid; pid_t pid;
u_char version; u_char version;
void (*osigchld)(int); void (*osigchld)(int);
struct sshbuf *resp = NULL; struct sshbuf *req = NULL, *resp = NULL;
*respp = NULL; *respp = NULL;
if ((r = start_helper(&fd, &pid, &osigchld)) != 0) if ((r = start_helper(&fd, &pid, &osigchld)) != 0)
return r; return r;
if ((resp = sshbuf_new()) == NULL) { if ((req = sshbuf_new()) == NULL || (resp = sshbuf_new()) == NULL) {
r = SSH_ERR_ALLOC_FAIL; r = SSH_ERR_ALLOC_FAIL;
goto out; goto out;
} }
/* Request preamble: type, log_on_stderr, log_level */
ll = log_level_get();
if ((r = sshbuf_put_u32(req, type)) != 0 ||
(r = sshbuf_put_u8(req, log_is_on_stderr() != 0)) != 0 ||
(r = sshbuf_put_u32(req, ll < 0 ? 0 : ll)) != 0 ||
(r = sshbuf_putb(req, msg)) != 0) {
error("%s: build: %s", __func__, ssh_err(r));
goto out;
}
if ((r = ssh_msg_send(fd, SSH_SK_HELPER_VERSION, req)) != 0) { if ((r = ssh_msg_send(fd, SSH_SK_HELPER_VERSION, req)) != 0) {
error("%s: send: %s", __func__, ssh_err(r)); error("%s: send: %s", __func__, ssh_err(r));
goto out; goto out;
@ -165,11 +173,11 @@ client_converse(struct sshbuf *req, struct sshbuf **respp, u_int msg)
r = SSH_ERR_INVALID_FORMAT; r = SSH_ERR_INVALID_FORMAT;
goto out; goto out;
} }
if ((r = sshbuf_get_u32(resp, &rmsg)) != 0) { if ((r = sshbuf_get_u32(resp, &rtype)) != 0) {
error("%s: parse message type: %s", __func__, ssh_err(r)); error("%s: parse message type: %s", __func__, ssh_err(r));
goto out; goto out;
} }
if (rmsg == SSH_SK_HELPER_ERROR) { if (rtype == SSH_SK_HELPER_ERROR) {
if ((r = sshbuf_get_u32(resp, &rerr)) != 0) { if ((r = sshbuf_get_u32(resp, &rerr)) != 0) {
error("%s: parse error: %s", __func__, ssh_err(r)); error("%s: parse error: %s", __func__, ssh_err(r));
goto out; goto out;
@ -181,9 +189,9 @@ client_converse(struct sshbuf *req, struct sshbuf **respp, u_int msg)
else else
r = -(int)rerr; r = -(int)rerr;
goto out; goto out;
} else if (rmsg != msg) { } else if (rtype != type) {
error("%s: helper returned incorrect message type %u, " error("%s: helper returned incorrect message type %u, "
"expecting %u", __func__, rmsg, msg); "expecting %u", __func__, rtype, type);
r = SSH_ERR_INTERNAL_ERROR; r = SSH_ERR_INTERNAL_ERROR;
goto out; goto out;
} }
@ -202,6 +210,7 @@ client_converse(struct sshbuf *req, struct sshbuf **respp, u_int msg)
*respp = resp; *respp = resp;
resp = NULL; resp = NULL;
} }
sshbuf_free(req);
sshbuf_free(resp); sshbuf_free(resp);
signal(SIGCHLD, osigchld); signal(SIGCHLD, osigchld);
errno = oerrno; errno = oerrno;
@ -235,8 +244,7 @@ sshsk_sign(const char *provider, struct sshkey *key,
error("%s: serialize private key: %s", __func__, ssh_err(r)); error("%s: serialize private key: %s", __func__, ssh_err(r));
goto out; goto out;
} }
if ((r = sshbuf_put_u32(req, SSH_SK_HELPER_SIGN)) != 0 || if ((r = sshbuf_put_stringb(req, kbuf)) != 0 ||
(r = sshbuf_put_stringb(req, kbuf)) != 0 ||
(r = sshbuf_put_cstring(req, provider)) != 0 || (r = sshbuf_put_cstring(req, provider)) != 0 ||
(r = sshbuf_put_string(req, data, datalen)) != 0 || (r = sshbuf_put_string(req, data, datalen)) != 0 ||
(r = sshbuf_put_cstring(req, NULL)) != 0 || /* alg */ (r = sshbuf_put_cstring(req, NULL)) != 0 || /* alg */
@ -309,8 +317,7 @@ sshsk_enroll(int type, const char *provider_path, const char *device,
goto out; goto out;
} }
if ((r = sshbuf_put_u32(req, SSH_SK_HELPER_ENROLL)) != 0 || if ((r = sshbuf_put_u32(req, (u_int)type)) != 0 ||
(r = sshbuf_put_u32(req, (u_int)type)) != 0 ||
(r = sshbuf_put_cstring(req, provider_path)) != 0 || (r = sshbuf_put_cstring(req, provider_path)) != 0 ||
(r = sshbuf_put_cstring(req, device)) != 0 || (r = sshbuf_put_cstring(req, device)) != 0 ||
(r = sshbuf_put_cstring(req, application)) != 0 || (r = sshbuf_put_cstring(req, application)) != 0 ||
@ -379,8 +386,7 @@ sshsk_load_resident(const char *provider_path, const char *device,
goto out; goto out;
} }
if ((r = sshbuf_put_u32(req, SSH_SK_HELPER_LOAD_RESIDENT)) != 0 || if ((r = sshbuf_put_cstring(req, provider_path)) != 0 ||
(r = sshbuf_put_cstring(req, provider_path)) != 0 ||
(r = sshbuf_put_cstring(req, device)) != 0 || (r = sshbuf_put_cstring(req, device)) != 0 ||
(r = sshbuf_put_cstring(req, pin)) != 0) { (r = sshbuf_put_cstring(req, pin)) != 0) {
error("%s: compose: %s", __func__, ssh_err(r)); error("%s: compose: %s", __func__, ssh_err(r));

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ssh-sk-helper.c,v 1.7 2020/01/06 02:00:46 djm Exp $ */ /* $OpenBSD: ssh-sk-helper.c,v 1.8 2020/01/10 23:43:26 djm Exp $ */
/* /*
* Copyright (c) 2019 Google LLC * Copyright (c) 2019 Google LLC
* *
@ -269,9 +269,9 @@ main(int argc, char **argv)
SyslogFacility log_facility = SYSLOG_FACILITY_AUTH; SyslogFacility log_facility = SYSLOG_FACILITY_AUTH;
LogLevel log_level = SYSLOG_LEVEL_ERROR; LogLevel log_level = SYSLOG_LEVEL_ERROR;
struct sshbuf *req, *resp; struct sshbuf *req, *resp;
int in, out, ch, r, log_stderr = 0; int in, out, ch, r, vflag = 0;
u_int rtype; u_int rtype, ll = 0;
uint8_t version; uint8_t version, log_stderr = 0;
sanitise_stdfd(); sanitise_stdfd();
log_init(__progname, log_level, log_facility, log_stderr); log_init(__progname, log_level, log_facility, log_stderr);
@ -279,7 +279,7 @@ main(int argc, char **argv)
while ((ch = getopt(argc, argv, "v")) != -1) { while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) { switch (ch) {
case 'v': case 'v':
log_stderr = 1; vflag = 1;
if (log_level == SYSLOG_LEVEL_ERROR) if (log_level == SYSLOG_LEVEL_ERROR)
log_level = SYSLOG_LEVEL_DEBUG1; log_level = SYSLOG_LEVEL_DEBUG1;
else if (log_level < SYSLOG_LEVEL_DEBUG3) else if (log_level < SYSLOG_LEVEL_DEBUG3)
@ -290,7 +290,7 @@ main(int argc, char **argv)
exit(1); exit(1);
} }
} }
log_init(__progname, log_level, log_facility, log_stderr); log_init(__progname, log_level, log_facility, vflag);
/* /*
* Rearrange our file descriptors a little; we don't trust the * Rearrange our file descriptors a little; we don't trust the
@ -317,9 +317,14 @@ main(int argc, char **argv)
version, SSH_SK_HELPER_VERSION); version, SSH_SK_HELPER_VERSION);
} }
if ((r = sshbuf_get_u32(req, &rtype)) != 0) if ((r = sshbuf_get_u32(req, &rtype)) != 0 ||
(r = sshbuf_get_u8(req, &log_stderr)) != 0 ||
(r = sshbuf_get_u32(req, &ll)) != 0)
fatal("%s: buffer error: %s", __progname, ssh_err(r)); fatal("%s: buffer error: %s", __progname, ssh_err(r));
if (!vflag && log_level_name((LogLevel)ll) != NULL)
log_init(__progname, (LogLevel)ll, log_facility, log_stderr);
switch (rtype) { switch (rtype) {
case SSH_SK_HELPER_SIGN: case SSH_SK_HELPER_SIGN:
resp = process_sign(req); resp = process_sign(req);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ssh-sk.h,v 1.9 2020/01/06 02:00:47 djm Exp $ */ /* $OpenBSD: ssh-sk.h,v 1.10 2020/01/10 23:43:26 djm Exp $ */
/* /*
* Copyright (c) 2019 Google LLC * Copyright (c) 2019 Google LLC
* *
@ -23,7 +23,7 @@ struct sshkey;
struct sk_option; struct sk_option;
/* Version of protocol expected from ssh-sk-helper */ /* Version of protocol expected from ssh-sk-helper */
#define SSH_SK_HELPER_VERSION 4 #define SSH_SK_HELPER_VERSION 5
/* ssh-sk-helper messages */ /* ssh-sk-helper messages */
#define SSH_SK_HELPER_ERROR 0 /* Only valid H->C */ #define SSH_SK_HELPER_ERROR 0 /* Only valid H->C */