2021-10-28 04:54:18 +02:00
|
|
|
/* $OpenBSD: ssh-sk-helper.c,v 1.12 2021/10/28 02:54:18 djm Exp $ */
|
2019-10-31 22:22:01 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Google LLC
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a tiny program used to isolate the address space used for
|
|
|
|
* security key middleware signing operations from ssh-agent. It is similar
|
2019-12-13 20:11:14 +01:00
|
|
|
* to ssh-pkcs11-helper.c but considerably simpler as the operations for
|
|
|
|
* security keys are stateless.
|
2019-10-31 22:22:01 +01:00
|
|
|
*
|
2019-12-13 20:11:14 +01:00
|
|
|
* Please crank SSH_SK_HELPER_VERSION in sshkey.h for any incompatible
|
|
|
|
* protocol changes.
|
2019-10-31 22:22:01 +01:00
|
|
|
*/
|
2019-12-13 20:11:14 +01:00
|
|
|
|
2019-10-31 22:22:01 +01:00
|
|
|
#include "includes.h"
|
|
|
|
|
2019-12-13 20:11:14 +01:00
|
|
|
#include <limits.h>
|
2019-10-31 22:22:01 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "xmalloc.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "sshkey.h"
|
|
|
|
#include "authfd.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "sshbuf.h"
|
|
|
|
#include "msg.h"
|
|
|
|
#include "uidswap.h"
|
|
|
|
#include "sshkey.h"
|
|
|
|
#include "ssherr.h"
|
|
|
|
#include "ssh-sk.h"
|
|
|
|
|
2019-11-01 03:34:49 +01:00
|
|
|
#ifdef ENABLE_SK
|
2019-10-31 22:22:01 +01:00
|
|
|
extern char *__progname;
|
|
|
|
|
2019-12-30 10:23:28 +01:00
|
|
|
static struct sshbuf *reply_error(int r, char *fmt, ...)
|
|
|
|
__attribute__((__format__ (printf, 2, 3)));
|
|
|
|
|
|
|
|
static struct sshbuf *
|
|
|
|
reply_error(int r, char *fmt, ...)
|
|
|
|
{
|
|
|
|
char *msg;
|
|
|
|
va_list ap;
|
|
|
|
struct sshbuf *resp;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
xvasprintf(&msg, fmt, ap);
|
|
|
|
va_end(ap);
|
2020-01-26 00:13:09 +01:00
|
|
|
debug("%s: %s", __progname, msg);
|
2019-12-30 10:23:28 +01:00
|
|
|
free(msg);
|
|
|
|
|
|
|
|
if (r >= 0)
|
2020-10-18 13:32:01 +02:00
|
|
|
fatal_f("invalid error code %d", r);
|
2019-12-30 10:23:28 +01:00
|
|
|
|
|
|
|
if ((resp = sshbuf_new()) == NULL)
|
|
|
|
fatal("%s: sshbuf_new failed", __progname);
|
|
|
|
if (sshbuf_put_u32(resp, SSH_SK_HELPER_ERROR) != 0 ||
|
|
|
|
sshbuf_put_u32(resp, (u_int)-r) != 0)
|
|
|
|
fatal("%s: buffer error", __progname);
|
|
|
|
return resp;
|
|
|
|
}
|
|
|
|
|
2020-01-06 03:00:46 +01:00
|
|
|
/* If the specified string is zero length, then free it and replace with NULL */
|
|
|
|
static void
|
|
|
|
null_empty(char **s)
|
|
|
|
{
|
|
|
|
if (s == NULL || *s == NULL || **s != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
free(*s);
|
|
|
|
*s = NULL;
|
|
|
|
}
|
|
|
|
|
2019-12-13 20:11:14 +01:00
|
|
|
static struct sshbuf *
|
|
|
|
process_sign(struct sshbuf *req)
|
2019-10-31 22:22:01 +01:00
|
|
|
{
|
2019-12-13 20:11:14 +01:00
|
|
|
int r = SSH_ERR_INTERNAL_ERROR;
|
|
|
|
struct sshbuf *resp, *kbuf;
|
2020-05-26 03:59:46 +02:00
|
|
|
struct sshkey *key = NULL;
|
2019-10-31 22:22:01 +01:00
|
|
|
uint32_t compat;
|
|
|
|
const u_char *message;
|
2020-05-26 03:59:46 +02:00
|
|
|
u_char *sig = NULL;
|
|
|
|
size_t msglen, siglen = 0;
|
|
|
|
char *provider = NULL, *pin = NULL;
|
2019-12-13 20:11:14 +01:00
|
|
|
|
|
|
|
if ((r = sshbuf_froms(req, &kbuf)) != 0 ||
|
|
|
|
(r = sshbuf_get_cstring(req, &provider, NULL)) != 0 ||
|
|
|
|
(r = sshbuf_get_string_direct(req, &message, &msglen)) != 0 ||
|
|
|
|
(r = sshbuf_get_cstring(req, NULL, NULL)) != 0 || /* alg */
|
2019-12-30 10:23:28 +01:00
|
|
|
(r = sshbuf_get_u32(req, &compat)) != 0 ||
|
|
|
|
(r = sshbuf_get_cstring(req, &pin, NULL)) != 0)
|
2020-10-18 13:32:01 +02:00
|
|
|
fatal_r(r, "%s: parse", __progname);
|
2019-12-13 20:11:14 +01:00
|
|
|
if (sshbuf_len(req) != 0)
|
|
|
|
fatal("%s: trailing data in request", __progname);
|
|
|
|
|
|
|
|
if ((r = sshkey_private_deserialize(kbuf, &key)) != 0)
|
2020-10-18 13:32:01 +02:00
|
|
|
fatal_r(r, "%s: Unable to parse private key", __progname);
|
2022-01-21 20:33:17 +01:00
|
|
|
#ifndef WINDOWS
|
2020-10-18 13:32:01 +02:00
|
|
|
if (!sshkey_is_sk(key)) {
|
|
|
|
fatal("%s: Unsupported key type %s",
|
|
|
|
__progname, sshkey_ssh_name(key));
|
|
|
|
}
|
2022-01-21 20:33:17 +01:00
|
|
|
#else
|
|
|
|
if (!sshkey_is_sk(key) || key->sk_application == NULL) {
|
|
|
|
fatal("%s: Unsupported key type %s",
|
|
|
|
__progname, sshkey_ssh_name(key));
|
|
|
|
}
|
|
|
|
if (strncmp(key->sk_application, "ssh:", 4) != 0) {
|
|
|
|
fatal("%s: web-origin key", __progname);
|
|
|
|
}
|
|
|
|
#endif
|
2019-12-13 20:11:14 +01:00
|
|
|
|
2020-10-18 13:32:01 +02:00
|
|
|
debug_f("ready to sign with key %s, provider %s: "
|
|
|
|
"msg len %zu, compat 0x%lx", sshkey_type(key),
|
2019-12-13 20:11:14 +01:00
|
|
|
provider, msglen, (u_long)compat);
|
|
|
|
|
2020-01-06 03:00:46 +01:00
|
|
|
null_empty(&pin);
|
2019-12-30 10:23:28 +01:00
|
|
|
|
2019-12-13 20:11:14 +01:00
|
|
|
if ((r = sshsk_sign(provider, key, &sig, &siglen,
|
2019-12-30 10:23:28 +01:00
|
|
|
message, msglen, compat, pin)) != 0) {
|
|
|
|
resp = reply_error(r, "Signing failed: %s", ssh_err(r));
|
|
|
|
goto out;
|
|
|
|
}
|
2019-12-13 20:11:14 +01:00
|
|
|
|
|
|
|
if ((resp = sshbuf_new()) == NULL)
|
|
|
|
fatal("%s: sshbuf_new failed", __progname);
|
|
|
|
|
2019-12-30 10:23:28 +01:00
|
|
|
if ((r = sshbuf_put_u32(resp, SSH_SK_HELPER_SIGN)) != 0 ||
|
|
|
|
(r = sshbuf_put_string(resp, sig, siglen)) != 0)
|
2020-10-18 13:32:01 +02:00
|
|
|
fatal_r(r, "%s: compose", __progname);
|
2019-12-30 10:23:28 +01:00
|
|
|
out:
|
2020-05-26 03:59:46 +02:00
|
|
|
sshkey_free(key);
|
2019-12-13 20:11:14 +01:00
|
|
|
sshbuf_free(kbuf);
|
|
|
|
free(provider);
|
2020-05-26 03:59:46 +02:00
|
|
|
if (sig != NULL)
|
|
|
|
freezero(sig, siglen);
|
2019-12-30 10:23:28 +01:00
|
|
|
if (pin != NULL)
|
|
|
|
freezero(pin, strlen(pin));
|
2019-12-13 20:11:14 +01:00
|
|
|
return resp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sshbuf *
|
|
|
|
process_enroll(struct sshbuf *req)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
u_int type;
|
2020-01-06 03:00:46 +01:00
|
|
|
char *provider, *application, *pin, *device, *userid;
|
2019-12-13 20:11:14 +01:00
|
|
|
uint8_t flags;
|
|
|
|
struct sshbuf *challenge, *attest, *kbuf, *resp;
|
|
|
|
struct sshkey *key;
|
|
|
|
|
2019-12-30 10:23:28 +01:00
|
|
|
if ((attest = sshbuf_new()) == NULL ||
|
2019-12-13 20:11:14 +01:00
|
|
|
(kbuf = sshbuf_new()) == NULL)
|
|
|
|
fatal("%s: sshbuf_new failed", __progname);
|
|
|
|
|
|
|
|
if ((r = sshbuf_get_u32(req, &type)) != 0 ||
|
|
|
|
(r = sshbuf_get_cstring(req, &provider, NULL)) != 0 ||
|
2020-01-06 03:00:46 +01:00
|
|
|
(r = sshbuf_get_cstring(req, &device, NULL)) != 0 ||
|
2019-12-13 20:11:14 +01:00
|
|
|
(r = sshbuf_get_cstring(req, &application, NULL)) != 0 ||
|
2020-01-06 03:00:46 +01:00
|
|
|
(r = sshbuf_get_cstring(req, &userid, NULL)) != 0 ||
|
2019-12-13 20:11:14 +01:00
|
|
|
(r = sshbuf_get_u8(req, &flags)) != 0 ||
|
2019-12-30 10:23:28 +01:00
|
|
|
(r = sshbuf_get_cstring(req, &pin, NULL)) != 0 ||
|
2019-12-13 20:11:14 +01:00
|
|
|
(r = sshbuf_froms(req, &challenge)) != 0)
|
2020-10-18 13:32:01 +02:00
|
|
|
fatal_r(r, "%s: parse", __progname);
|
2019-12-13 20:11:14 +01:00
|
|
|
if (sshbuf_len(req) != 0)
|
|
|
|
fatal("%s: trailing data in request", __progname);
|
|
|
|
|
|
|
|
if (type > INT_MAX)
|
|
|
|
fatal("%s: bad type %u", __progname, type);
|
2022-01-21 20:33:17 +01:00
|
|
|
#ifdef WINDOWS
|
|
|
|
if (application == NULL || strncmp(application, "ssh:", 4) != 0)
|
|
|
|
fatal("%s: bogus application", __progname);
|
|
|
|
#endif
|
2019-12-13 20:11:14 +01:00
|
|
|
if (sshbuf_len(challenge) == 0) {
|
|
|
|
sshbuf_free(challenge);
|
|
|
|
challenge = NULL;
|
|
|
|
}
|
2020-01-06 03:00:46 +01:00
|
|
|
null_empty(&device);
|
|
|
|
null_empty(&userid);
|
|
|
|
null_empty(&pin);
|
2019-12-13 20:11:14 +01:00
|
|
|
|
2020-01-06 03:00:46 +01:00
|
|
|
if ((r = sshsk_enroll((int)type, provider, device, application, userid,
|
|
|
|
flags, pin, challenge, &key, attest)) != 0) {
|
2019-12-30 10:23:28 +01:00
|
|
|
resp = reply_error(r, "Enrollment failed: %s", ssh_err(r));
|
|
|
|
goto out;
|
|
|
|
}
|
2019-12-13 20:11:14 +01:00
|
|
|
|
2019-12-30 10:23:28 +01:00
|
|
|
if ((resp = sshbuf_new()) == NULL)
|
|
|
|
fatal("%s: sshbuf_new failed", __progname);
|
2019-12-13 20:11:14 +01:00
|
|
|
if ((r = sshkey_private_serialize(key, kbuf)) != 0)
|
2020-10-18 13:32:01 +02:00
|
|
|
fatal_r(r, "%s: encode key", __progname);
|
2019-12-30 10:23:28 +01:00
|
|
|
if ((r = sshbuf_put_u32(resp, SSH_SK_HELPER_ENROLL)) != 0 ||
|
|
|
|
(r = sshbuf_put_stringb(resp, kbuf)) != 0 ||
|
2019-12-13 20:11:14 +01:00
|
|
|
(r = sshbuf_put_stringb(resp, attest)) != 0)
|
2020-10-18 13:32:01 +02:00
|
|
|
fatal_r(r, "%s: compose", __progname);
|
2019-12-13 20:11:14 +01:00
|
|
|
|
2019-12-30 10:23:28 +01:00
|
|
|
out:
|
2019-12-13 20:11:14 +01:00
|
|
|
sshkey_free(key);
|
|
|
|
sshbuf_free(kbuf);
|
|
|
|
sshbuf_free(attest);
|
|
|
|
sshbuf_free(challenge);
|
|
|
|
free(provider);
|
|
|
|
free(application);
|
2019-12-30 10:23:28 +01:00
|
|
|
if (pin != NULL)
|
|
|
|
freezero(pin, strlen(pin));
|
2019-12-13 20:11:14 +01:00
|
|
|
|
|
|
|
return resp;
|
|
|
|
}
|
|
|
|
|
2019-12-30 10:21:59 +01:00
|
|
|
static struct sshbuf *
|
|
|
|
process_load_resident(struct sshbuf *req)
|
|
|
|
{
|
|
|
|
int r;
|
2020-01-06 03:00:46 +01:00
|
|
|
char *provider, *pin, *device;
|
2019-12-30 10:21:59 +01:00
|
|
|
struct sshbuf *kbuf, *resp;
|
2021-10-28 04:54:18 +02:00
|
|
|
struct sshsk_resident_key **srks = NULL;
|
|
|
|
size_t nsrks = 0, i;
|
|
|
|
u_int flags;
|
2019-12-30 10:21:59 +01:00
|
|
|
|
2019-12-30 10:23:28 +01:00
|
|
|
if ((kbuf = sshbuf_new()) == NULL)
|
2019-12-30 10:21:59 +01:00
|
|
|
fatal("%s: sshbuf_new failed", __progname);
|
|
|
|
|
|
|
|
if ((r = sshbuf_get_cstring(req, &provider, NULL)) != 0 ||
|
2020-01-06 03:00:46 +01:00
|
|
|
(r = sshbuf_get_cstring(req, &device, NULL)) != 0 ||
|
2021-10-28 04:54:18 +02:00
|
|
|
(r = sshbuf_get_cstring(req, &pin, NULL)) != 0 ||
|
|
|
|
(r = sshbuf_get_u32(req, &flags)) != 0)
|
2020-10-18 13:32:01 +02:00
|
|
|
fatal_r(r, "%s: parse", __progname);
|
2019-12-30 10:21:59 +01:00
|
|
|
if (sshbuf_len(req) != 0)
|
|
|
|
fatal("%s: trailing data in request", __progname);
|
|
|
|
|
2020-01-06 03:00:46 +01:00
|
|
|
null_empty(&device);
|
|
|
|
null_empty(&pin);
|
2019-12-30 10:23:28 +01:00
|
|
|
|
2021-10-28 04:54:18 +02:00
|
|
|
if ((r = sshsk_load_resident(provider, device, pin, flags,
|
|
|
|
&srks, &nsrks)) != 0) {
|
|
|
|
resp = reply_error(r, "sshsk_load_resident failed: %s",
|
2019-12-30 10:23:28 +01:00
|
|
|
ssh_err(r));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((resp = sshbuf_new()) == NULL)
|
|
|
|
fatal("%s: sshbuf_new failed", __progname);
|
|
|
|
|
|
|
|
if ((r = sshbuf_put_u32(resp, SSH_SK_HELPER_LOAD_RESIDENT)) != 0)
|
2020-10-18 13:32:01 +02:00
|
|
|
fatal_r(r, "%s: compose", __progname);
|
2019-12-30 10:21:59 +01:00
|
|
|
|
2021-10-28 04:54:18 +02:00
|
|
|
for (i = 0; i < nsrks; i++) {
|
2022-01-21 20:33:17 +01:00
|
|
|
#ifdef WINDOWS
|
|
|
|
if (keys[i]->sk_application == NULL ||
|
|
|
|
strncmp(keys[i]->sk_application, "ssh:", 4) != 0)
|
|
|
|
fatal("%s: non-ssh application", __progname);
|
|
|
|
#endif
|
2021-10-28 04:54:18 +02:00
|
|
|
debug_f("key %zu %s %s uidlen %zu", i,
|
|
|
|
sshkey_type(srks[i]->key), srks[i]->key->sk_application,
|
|
|
|
srks[i]->user_id_len);
|
2019-12-30 10:21:59 +01:00
|
|
|
sshbuf_reset(kbuf);
|
2021-10-28 04:54:18 +02:00
|
|
|
if ((r = sshkey_private_serialize(srks[i]->key, kbuf)) != 0)
|
2020-10-18 13:32:01 +02:00
|
|
|
fatal_r(r, "%s: encode key", __progname);
|
2019-12-30 10:21:59 +01:00
|
|
|
if ((r = sshbuf_put_stringb(resp, kbuf)) != 0 ||
|
2021-10-28 04:54:18 +02:00
|
|
|
(r = sshbuf_put_cstring(resp, "")) != 0 || /* comment */
|
|
|
|
(r = sshbuf_put_string(resp, srks[i]->user_id,
|
|
|
|
srks[i]->user_id_len)) != 0)
|
2020-10-18 13:32:01 +02:00
|
|
|
fatal_r(r, "%s: compose key", __progname);
|
2019-12-30 10:21:59 +01:00
|
|
|
}
|
|
|
|
|
2019-12-30 10:23:28 +01:00
|
|
|
out:
|
2021-10-28 04:54:18 +02:00
|
|
|
sshsk_free_resident_keys(srks, nsrks);
|
2019-12-30 10:21:59 +01:00
|
|
|
sshbuf_free(kbuf);
|
|
|
|
free(provider);
|
2019-12-30 10:23:28 +01:00
|
|
|
if (pin != NULL)
|
|
|
|
freezero(pin, strlen(pin));
|
2019-12-30 10:21:59 +01:00
|
|
|
return resp;
|
|
|
|
}
|
|
|
|
|
2019-12-13 20:11:14 +01:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
SyslogFacility log_facility = SYSLOG_FACILITY_AUTH;
|
|
|
|
LogLevel log_level = SYSLOG_LEVEL_ERROR;
|
2019-12-13 21:53:11 +01:00
|
|
|
struct sshbuf *req, *resp;
|
2020-01-11 00:43:26 +01:00
|
|
|
int in, out, ch, r, vflag = 0;
|
|
|
|
u_int rtype, ll = 0;
|
|
|
|
uint8_t version, log_stderr = 0;
|
2019-10-31 22:22:01 +01:00
|
|
|
|
|
|
|
sanitise_stdfd();
|
|
|
|
log_init(__progname, log_level, log_facility, log_stderr);
|
|
|
|
|
|
|
|
while ((ch = getopt(argc, argv, "v")) != -1) {
|
|
|
|
switch (ch) {
|
|
|
|
case 'v':
|
2020-01-11 00:43:26 +01:00
|
|
|
vflag = 1;
|
2019-10-31 22:22:01 +01:00
|
|
|
if (log_level == SYSLOG_LEVEL_ERROR)
|
|
|
|
log_level = SYSLOG_LEVEL_DEBUG1;
|
|
|
|
else if (log_level < SYSLOG_LEVEL_DEBUG3)
|
|
|
|
log_level++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "usage: %s [-v]\n", __progname);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2020-01-11 00:43:26 +01:00
|
|
|
log_init(__progname, log_level, log_facility, vflag);
|
2019-10-31 22:22:01 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Rearrange our file descriptors a little; we don't trust the
|
|
|
|
* providers not to fiddle with stdin/out.
|
|
|
|
*/
|
|
|
|
closefrom(STDERR_FILENO + 1);
|
|
|
|
if ((in = dup(STDIN_FILENO)) == -1 || (out = dup(STDOUT_FILENO)) == -1)
|
|
|
|
fatal("%s: dup: %s", __progname, strerror(errno));
|
|
|
|
close(STDIN_FILENO);
|
|
|
|
close(STDOUT_FILENO);
|
|
|
|
sanitise_stdfd(); /* resets to /dev/null */
|
|
|
|
|
2019-12-13 20:11:14 +01:00
|
|
|
if ((req = sshbuf_new()) == NULL)
|
2019-10-31 22:22:01 +01:00
|
|
|
fatal("%s: sshbuf_new failed", __progname);
|
|
|
|
if (ssh_msg_recv(in, req) < 0)
|
|
|
|
fatal("ssh_msg_recv failed");
|
|
|
|
close(in);
|
2020-10-18 13:32:01 +02:00
|
|
|
debug_f("received message len %zu", sshbuf_len(req));
|
2019-10-31 22:22:01 +01:00
|
|
|
|
|
|
|
if ((r = sshbuf_get_u8(req, &version)) != 0)
|
2020-10-18 13:32:01 +02:00
|
|
|
fatal_r(r, "%s: parse version", __progname);
|
2019-10-31 22:22:01 +01:00
|
|
|
if (version != SSH_SK_HELPER_VERSION) {
|
|
|
|
fatal("unsupported version: received %d, expected %d",
|
|
|
|
version, SSH_SK_HELPER_VERSION);
|
|
|
|
}
|
|
|
|
|
2020-01-11 00:43:26 +01:00
|
|
|
if ((r = sshbuf_get_u32(req, &rtype)) != 0 ||
|
|
|
|
(r = sshbuf_get_u8(req, &log_stderr)) != 0 ||
|
|
|
|
(r = sshbuf_get_u32(req, &ll)) != 0)
|
2020-10-18 13:32:01 +02:00
|
|
|
fatal_r(r, "%s: parse", __progname);
|
2019-10-31 22:22:01 +01:00
|
|
|
|
2020-01-11 00:43:26 +01:00
|
|
|
if (!vflag && log_level_name((LogLevel)ll) != NULL)
|
|
|
|
log_init(__progname, (LogLevel)ll, log_facility, log_stderr);
|
|
|
|
|
2019-12-13 20:11:14 +01:00
|
|
|
switch (rtype) {
|
|
|
|
case SSH_SK_HELPER_SIGN:
|
|
|
|
resp = process_sign(req);
|
|
|
|
break;
|
|
|
|
case SSH_SK_HELPER_ENROLL:
|
|
|
|
resp = process_enroll(req);
|
|
|
|
break;
|
2019-12-30 10:21:59 +01:00
|
|
|
case SSH_SK_HELPER_LOAD_RESIDENT:
|
|
|
|
resp = process_load_resident(req);
|
|
|
|
break;
|
2019-12-13 20:11:14 +01:00
|
|
|
default:
|
|
|
|
fatal("%s: unsupported request type %u", __progname, rtype);
|
|
|
|
}
|
|
|
|
sshbuf_free(req);
|
2020-10-18 13:32:01 +02:00
|
|
|
debug_f("reply len %zu", sshbuf_len(resp));
|
2019-12-13 20:11:14 +01:00
|
|
|
|
2019-10-31 22:22:01 +01:00
|
|
|
if (ssh_msg_send(out, SSH_SK_HELPER_VERSION, resp) == -1)
|
|
|
|
fatal("ssh_msg_send failed");
|
2019-12-13 20:11:14 +01:00
|
|
|
sshbuf_free(resp);
|
2019-10-31 22:22:01 +01:00
|
|
|
close(out);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2019-11-01 03:34:49 +01:00
|
|
|
#else /* ENABLE_SK */
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ssh-sk-helper: disabled at compile time\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif /* ENABLE_SK */
|