summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2020-01-10 23:43:26 +0000
committerDamien Miller <djm@mindrot.org>2020-01-21 18:09:09 +1100
commit57b181eaf2d34fd0a1b51ab30cb6983df784de5a (patch)
tree5f5f8b134a5ffdfb6bddce720d49a44d09b18b56
parenta8bd5fdbdb7581afc7123a042a7cd6ca25357388 (diff)
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
-rw-r--r--ssh-sk-client.c40
-rw-r--r--ssh-sk-helper.c19
-rw-r--r--ssh-sk.h4
3 files changed, 37 insertions, 26 deletions
diff --git a/ssh-sk-client.c b/ssh-sk-client.c
index d3d37f792..9121570dc 100644
--- a/ssh-sk-client.c
+++ b/ssh-sk-client.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-sk-client.c,v 1.4 2020/01/06 02:00:46 djm Exp $ */ 1/* $OpenBSD: ssh-sk-client.c,v 1.5 2020/01/10 23:43:26 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2019 Google LLC 3 * Copyright (c) 2019 Google LLC
4 * 4 *
@@ -129,24 +129,32 @@ reap_helper(pid_t pid)
129} 129}
130 130
131static int 131static int
132client_converse(struct sshbuf *req, struct sshbuf **respp, u_int msg) 132client_converse(struct sshbuf *msg, struct sshbuf **respp, u_int type)
133{ 133{
134 int oerrno, fd, r2, r = SSH_ERR_INTERNAL_ERROR; 134 int oerrno, fd, r2, ll, r = SSH_ERR_INTERNAL_ERROR;
135 u_int rmsg, rerr; 135 u_int rtype, rerr;
136 pid_t pid; 136 pid_t pid;
137 u_char version; 137 u_char version;
138 void (*osigchld)(int); 138 void (*osigchld)(int);
139 struct sshbuf *resp = NULL; 139 struct sshbuf *req = NULL, *resp = NULL;
140 *respp = NULL; 140 *respp = NULL;
141 141
142 if ((r = start_helper(&fd, &pid, &osigchld)) != 0) 142 if ((r = start_helper(&fd, &pid, &osigchld)) != 0)
143 return r; 143 return r;
144 144
145 if ((resp = sshbuf_new()) == NULL) { 145 if ((req = sshbuf_new()) == NULL || (resp = sshbuf_new()) == NULL) {
146 r = SSH_ERR_ALLOC_FAIL; 146 r = SSH_ERR_ALLOC_FAIL;
147 goto out; 147 goto out;
148 } 148 }
149 149 /* Request preamble: type, log_on_stderr, log_level */
150 ll = log_level_get();
151 if ((r = sshbuf_put_u32(req, type)) != 0 ||
152 (r = sshbuf_put_u8(req, log_is_on_stderr() != 0)) != 0 ||
153 (r = sshbuf_put_u32(req, ll < 0 ? 0 : ll)) != 0 ||
154 (r = sshbuf_putb(req, msg)) != 0) {
155 error("%s: build: %s", __func__, ssh_err(r));
156 goto out;
157 }
150 if ((r = ssh_msg_send(fd, SSH_SK_HELPER_VERSION, req)) != 0) { 158 if ((r = ssh_msg_send(fd, SSH_SK_HELPER_VERSION, req)) != 0) {
151 error("%s: send: %s", __func__, ssh_err(r)); 159 error("%s: send: %s", __func__, ssh_err(r));
152 goto out; 160 goto out;
@@ -165,11 +173,11 @@ client_converse(struct sshbuf *req, struct sshbuf **respp, u_int msg)
165 r = SSH_ERR_INVALID_FORMAT; 173 r = SSH_ERR_INVALID_FORMAT;
166 goto out; 174 goto out;
167 } 175 }
168 if ((r = sshbuf_get_u32(resp, &rmsg)) != 0) { 176 if ((r = sshbuf_get_u32(resp, &rtype)) != 0) {
169 error("%s: parse message type: %s", __func__, ssh_err(r)); 177 error("%s: parse message type: %s", __func__, ssh_err(r));
170 goto out; 178 goto out;
171 } 179 }
172 if (rmsg == SSH_SK_HELPER_ERROR) { 180 if (rtype == SSH_SK_HELPER_ERROR) {
173 if ((r = sshbuf_get_u32(resp, &rerr)) != 0) { 181 if ((r = sshbuf_get_u32(resp, &rerr)) != 0) {
174 error("%s: parse error: %s", __func__, ssh_err(r)); 182 error("%s: parse error: %s", __func__, ssh_err(r));
175 goto out; 183 goto out;
@@ -181,9 +189,9 @@ client_converse(struct sshbuf *req, struct sshbuf **respp, u_int msg)
181 else 189 else
182 r = -(int)rerr; 190 r = -(int)rerr;
183 goto out; 191 goto out;
184 } else if (rmsg != msg) { 192 } else if (rtype != type) {
185 error("%s: helper returned incorrect message type %u, " 193 error("%s: helper returned incorrect message type %u, "
186 "expecting %u", __func__, rmsg, msg); 194 "expecting %u", __func__, rtype, type);
187 r = SSH_ERR_INTERNAL_ERROR; 195 r = SSH_ERR_INTERNAL_ERROR;
188 goto out; 196 goto out;
189 } 197 }
@@ -202,6 +210,7 @@ client_converse(struct sshbuf *req, struct sshbuf **respp, u_int msg)
202 *respp = resp; 210 *respp = resp;
203 resp = NULL; 211 resp = NULL;
204 } 212 }
213 sshbuf_free(req);
205 sshbuf_free(resp); 214 sshbuf_free(resp);
206 signal(SIGCHLD, osigchld); 215 signal(SIGCHLD, osigchld);
207 errno = oerrno; 216 errno = oerrno;
@@ -235,8 +244,7 @@ sshsk_sign(const char *provider, struct sshkey *key,
235 error("%s: serialize private key: %s", __func__, ssh_err(r)); 244 error("%s: serialize private key: %s", __func__, ssh_err(r));
236 goto out; 245 goto out;
237 } 246 }
238 if ((r = sshbuf_put_u32(req, SSH_SK_HELPER_SIGN)) != 0 || 247 if ((r = sshbuf_put_stringb(req, kbuf)) != 0 ||
239 (r = sshbuf_put_stringb(req, kbuf)) != 0 ||
240 (r = sshbuf_put_cstring(req, provider)) != 0 || 248 (r = sshbuf_put_cstring(req, provider)) != 0 ||
241 (r = sshbuf_put_string(req, data, datalen)) != 0 || 249 (r = sshbuf_put_string(req, data, datalen)) != 0 ||
242 (r = sshbuf_put_cstring(req, NULL)) != 0 || /* alg */ 250 (r = sshbuf_put_cstring(req, NULL)) != 0 || /* alg */
@@ -309,8 +317,7 @@ sshsk_enroll(int type, const char *provider_path, const char *device,
309 goto out; 317 goto out;
310 } 318 }
311 319
312 if ((r = sshbuf_put_u32(req, SSH_SK_HELPER_ENROLL)) != 0 || 320 if ((r = sshbuf_put_u32(req, (u_int)type)) != 0 ||
313 (r = sshbuf_put_u32(req, (u_int)type)) != 0 ||
314 (r = sshbuf_put_cstring(req, provider_path)) != 0 || 321 (r = sshbuf_put_cstring(req, provider_path)) != 0 ||
315 (r = sshbuf_put_cstring(req, device)) != 0 || 322 (r = sshbuf_put_cstring(req, device)) != 0 ||
316 (r = sshbuf_put_cstring(req, application)) != 0 || 323 (r = sshbuf_put_cstring(req, application)) != 0 ||
@@ -379,8 +386,7 @@ sshsk_load_resident(const char *provider_path, const char *device,
379 goto out; 386 goto out;
380 } 387 }
381 388
382 if ((r = sshbuf_put_u32(req, SSH_SK_HELPER_LOAD_RESIDENT)) != 0 || 389 if ((r = sshbuf_put_cstring(req, provider_path)) != 0 ||
383 (r = sshbuf_put_cstring(req, provider_path)) != 0 ||
384 (r = sshbuf_put_cstring(req, device)) != 0 || 390 (r = sshbuf_put_cstring(req, device)) != 0 ||
385 (r = sshbuf_put_cstring(req, pin)) != 0) { 391 (r = sshbuf_put_cstring(req, pin)) != 0) {
386 error("%s: compose: %s", __func__, ssh_err(r)); 392 error("%s: compose: %s", __func__, ssh_err(r));
diff --git a/ssh-sk-helper.c b/ssh-sk-helper.c
index 85a461d53..a4be9d369 100644
--- a/ssh-sk-helper.c
+++ b/ssh-sk-helper.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-sk-helper.c,v 1.7 2020/01/06 02:00:46 djm Exp $ */ 1/* $OpenBSD: ssh-sk-helper.c,v 1.8 2020/01/10 23:43:26 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2019 Google LLC 3 * Copyright (c) 2019 Google LLC
4 * 4 *
@@ -269,9 +269,9 @@ main(int argc, char **argv)
269 SyslogFacility log_facility = SYSLOG_FACILITY_AUTH; 269 SyslogFacility log_facility = SYSLOG_FACILITY_AUTH;
270 LogLevel log_level = SYSLOG_LEVEL_ERROR; 270 LogLevel log_level = SYSLOG_LEVEL_ERROR;
271 struct sshbuf *req, *resp; 271 struct sshbuf *req, *resp;
272 int in, out, ch, r, log_stderr = 0; 272 int in, out, ch, r, vflag = 0;
273 u_int rtype; 273 u_int rtype, ll = 0;
274 uint8_t version; 274 uint8_t version, log_stderr = 0;
275 275
276 sanitise_stdfd(); 276 sanitise_stdfd();
277 log_init(__progname, log_level, log_facility, log_stderr); 277 log_init(__progname, log_level, log_facility, log_stderr);
@@ -279,7 +279,7 @@ main(int argc, char **argv)
279 while ((ch = getopt(argc, argv, "v")) != -1) { 279 while ((ch = getopt(argc, argv, "v")) != -1) {
280 switch (ch) { 280 switch (ch) {
281 case 'v': 281 case 'v':
282 log_stderr = 1; 282 vflag = 1;
283 if (log_level == SYSLOG_LEVEL_ERROR) 283 if (log_level == SYSLOG_LEVEL_ERROR)
284 log_level = SYSLOG_LEVEL_DEBUG1; 284 log_level = SYSLOG_LEVEL_DEBUG1;
285 else if (log_level < SYSLOG_LEVEL_DEBUG3) 285 else if (log_level < SYSLOG_LEVEL_DEBUG3)
@@ -290,7 +290,7 @@ main(int argc, char **argv)
290 exit(1); 290 exit(1);
291 } 291 }
292 } 292 }
293 log_init(__progname, log_level, log_facility, log_stderr); 293 log_init(__progname, log_level, log_facility, vflag);
294 294
295 /* 295 /*
296 * Rearrange our file descriptors a little; we don't trust the 296 * Rearrange our file descriptors a little; we don't trust the
@@ -317,9 +317,14 @@ main(int argc, char **argv)
317 version, SSH_SK_HELPER_VERSION); 317 version, SSH_SK_HELPER_VERSION);
318 } 318 }
319 319
320 if ((r = sshbuf_get_u32(req, &rtype)) != 0) 320 if ((r = sshbuf_get_u32(req, &rtype)) != 0 ||
321 (r = sshbuf_get_u8(req, &log_stderr)) != 0 ||
322 (r = sshbuf_get_u32(req, &ll)) != 0)
321 fatal("%s: buffer error: %s", __progname, ssh_err(r)); 323 fatal("%s: buffer error: %s", __progname, ssh_err(r));
322 324
325 if (!vflag && log_level_name((LogLevel)ll) != NULL)
326 log_init(__progname, (LogLevel)ll, log_facility, log_stderr);
327
323 switch (rtype) { 328 switch (rtype) {
324 case SSH_SK_HELPER_SIGN: 329 case SSH_SK_HELPER_SIGN:
325 resp = process_sign(req); 330 resp = process_sign(req);
diff --git a/ssh-sk.h b/ssh-sk.h
index ea9ff6e1a..0f566bbc3 100644
--- a/ssh-sk.h
+++ b/ssh-sk.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-sk.h,v 1.9 2020/01/06 02:00:47 djm Exp $ */ 1/* $OpenBSD: ssh-sk.h,v 1.10 2020/01/10 23:43:26 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2019 Google LLC 3 * Copyright (c) 2019 Google LLC
4 * 4 *
@@ -23,7 +23,7 @@ struct sshkey;
23struct sk_option; 23struct sk_option;
24 24
25/* Version of protocol expected from ssh-sk-helper */ 25/* Version of protocol expected from ssh-sk-helper */
26#define SSH_SK_HELPER_VERSION 4 26#define SSH_SK_HELPER_VERSION 5
27 27
28/* ssh-sk-helper messages */ 28/* ssh-sk-helper messages */
29#define SSH_SK_HELPER_ERROR 0 /* Only valid H->C */ 29#define SSH_SK_HELPER_ERROR 0 /* Only valid H->C */