2019-01-21 06:57:45 +08:00
|
|
|
/* $OpenBSD: ssh-pkcs11-client.c,v 1.14 2019/01/20 22:57:45 djm Exp $ */
|
2010-02-12 06:21:02 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010 Markus Friedl. All rights reserved.
|
2019-01-21 06:51:37 +08:00
|
|
|
* Copyright (c) 2014 Pedro Martelletto. All rights reserved.
|
2010-02-12 06:21:02 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2010-02-12 06:49:06 +08:00
|
|
|
#include "includes.h"
|
|
|
|
|
2010-02-12 07:06:28 +08:00
|
|
|
#ifdef ENABLE_PKCS11
|
|
|
|
|
2010-02-12 06:21:02 +08:00
|
|
|
#include <sys/types.h>
|
2010-02-12 06:49:06 +08:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
#endif
|
2010-02-12 06:21:02 +08:00
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2019-01-21 06:51:37 +08:00
|
|
|
#include <openssl/ecdsa.h>
|
2014-07-02 13:28:02 +08:00
|
|
|
#include <openssl/rsa.h>
|
|
|
|
|
2018-09-13 10:13:50 +08:00
|
|
|
#include "openbsd-compat/openssl-compat.h"
|
|
|
|
|
2010-02-12 06:21:02 +08:00
|
|
|
#include "pathnames.h"
|
|
|
|
#include "xmalloc.h"
|
2018-07-10 04:39:28 +08:00
|
|
|
#include "sshbuf.h"
|
2010-02-12 06:21:02 +08:00
|
|
|
#include "log.h"
|
|
|
|
#include "misc.h"
|
2018-07-10 04:39:28 +08:00
|
|
|
#include "sshkey.h"
|
2010-02-12 06:21:02 +08:00
|
|
|
#include "authfd.h"
|
|
|
|
#include "atomicio.h"
|
|
|
|
#include "ssh-pkcs11.h"
|
2018-07-10 04:39:28 +08:00
|
|
|
#include "ssherr.h"
|
2010-02-12 06:21:02 +08:00
|
|
|
|
|
|
|
/* borrows code from sftp-server and ssh-agent */
|
|
|
|
|
|
|
|
int fd = -1;
|
|
|
|
pid_t pid = -1;
|
|
|
|
|
|
|
|
static void
|
2018-07-10 04:39:28 +08:00
|
|
|
send_msg(struct sshbuf *m)
|
2010-02-12 06:21:02 +08:00
|
|
|
{
|
|
|
|
u_char buf[4];
|
2018-07-10 04:39:28 +08:00
|
|
|
size_t mlen = sshbuf_len(m);
|
|
|
|
int r;
|
2010-02-12 06:21:02 +08:00
|
|
|
|
2018-07-10 04:39:28 +08:00
|
|
|
POKE_U32(buf, mlen);
|
2010-02-12 06:21:02 +08:00
|
|
|
if (atomicio(vwrite, fd, buf, 4) != 4 ||
|
2018-07-10 05:59:10 +08:00
|
|
|
atomicio(vwrite, fd, sshbuf_mutable_ptr(m),
|
2018-07-10 04:39:28 +08:00
|
|
|
sshbuf_len(m)) != sshbuf_len(m))
|
2010-02-12 06:21:02 +08:00
|
|
|
error("write to helper failed");
|
2018-07-10 04:39:28 +08:00
|
|
|
if ((r = sshbuf_consume(m, mlen)) != 0)
|
|
|
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
2010-02-12 06:21:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2018-07-10 04:39:28 +08:00
|
|
|
recv_msg(struct sshbuf *m)
|
2010-02-12 06:21:02 +08:00
|
|
|
{
|
|
|
|
u_int l, len;
|
2018-07-10 04:39:28 +08:00
|
|
|
u_char c, buf[1024];
|
|
|
|
int r;
|
2010-02-12 06:21:02 +08:00
|
|
|
|
|
|
|
if ((len = atomicio(read, fd, buf, 4)) != 4) {
|
|
|
|
error("read from helper failed: %u", len);
|
|
|
|
return (0); /* XXX */
|
|
|
|
}
|
2018-07-10 04:39:28 +08:00
|
|
|
len = PEEK_U32(buf);
|
2010-02-12 06:21:02 +08:00
|
|
|
if (len > 256 * 1024)
|
|
|
|
fatal("response too long: %u", len);
|
|
|
|
/* read len bytes into m */
|
2018-07-10 04:39:28 +08:00
|
|
|
sshbuf_reset(m);
|
2010-02-12 06:21:02 +08:00
|
|
|
while (len > 0) {
|
|
|
|
l = len;
|
|
|
|
if (l > sizeof(buf))
|
|
|
|
l = sizeof(buf);
|
|
|
|
if (atomicio(read, fd, buf, l) != l) {
|
|
|
|
error("response from helper failed.");
|
|
|
|
return (0); /* XXX */
|
|
|
|
}
|
2018-07-10 04:39:28 +08:00
|
|
|
if ((r = sshbuf_put(m, buf, l)) != 0)
|
|
|
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
2010-02-12 06:21:02 +08:00
|
|
|
len -= l;
|
|
|
|
}
|
2018-07-10 04:39:28 +08:00
|
|
|
if ((r = sshbuf_get_u8(m, &c)) != 0)
|
|
|
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
|
return c;
|
2010-02-12 06:21:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pkcs11_init(int interactive)
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pkcs11_terminate(void)
|
|
|
|
{
|
2018-02-05 13:37:46 +08:00
|
|
|
if (fd >= 0)
|
|
|
|
close(fd);
|
2010-02-12 06:21:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2019-01-21 06:51:37 +08:00
|
|
|
rsa_encrypt(int flen, const u_char *from, u_char *to, RSA *rsa, int padding)
|
2010-02-12 06:21:02 +08:00
|
|
|
{
|
2019-01-21 06:57:45 +08:00
|
|
|
struct sshkey *key = NULL;
|
|
|
|
struct sshbuf *msg = NULL;
|
|
|
|
u_char *blob = NULL, *signature = NULL;
|
2018-07-10 04:39:28 +08:00
|
|
|
size_t blen, slen = 0;
|
|
|
|
int r, ret = -1;
|
2010-02-12 06:21:02 +08:00
|
|
|
|
|
|
|
if (padding != RSA_PKCS1_PADDING)
|
2019-01-21 06:57:45 +08:00
|
|
|
goto fail;
|
|
|
|
key = sshkey_new(KEY_UNSPEC);
|
|
|
|
if (key == NULL) {
|
|
|
|
error("%s: sshkey_new failed", __func__);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
key->type = KEY_RSA;
|
|
|
|
RSA_up_ref(rsa);
|
|
|
|
key->rsa = rsa;
|
|
|
|
if ((r = sshkey_to_blob(key, &blob, &blen)) != 0) {
|
2018-07-10 04:39:28 +08:00
|
|
|
error("%s: sshkey_to_blob: %s", __func__, ssh_err(r));
|
2019-01-21 06:57:45 +08:00
|
|
|
goto fail;
|
2018-07-10 04:39:28 +08:00
|
|
|
}
|
|
|
|
if ((msg = sshbuf_new()) == NULL)
|
|
|
|
fatal("%s: sshbuf_new failed", __func__);
|
|
|
|
if ((r = sshbuf_put_u8(msg, SSH2_AGENTC_SIGN_REQUEST)) != 0 ||
|
|
|
|
(r = sshbuf_put_string(msg, blob, blen)) != 0 ||
|
|
|
|
(r = sshbuf_put_string(msg, from, flen)) != 0 ||
|
|
|
|
(r = sshbuf_put_u32(msg, 0)) != 0)
|
|
|
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
|
send_msg(msg);
|
|
|
|
sshbuf_reset(msg);
|
2010-02-12 06:21:02 +08:00
|
|
|
|
2018-07-10 04:39:28 +08:00
|
|
|
if (recv_msg(msg) == SSH2_AGENT_SIGN_RESPONSE) {
|
|
|
|
if ((r = sshbuf_get_string(msg, &signature, &slen)) != 0)
|
|
|
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
|
if (slen <= (size_t)RSA_size(rsa)) {
|
2010-02-12 06:21:02 +08:00
|
|
|
memcpy(to, signature, slen);
|
|
|
|
ret = slen;
|
|
|
|
}
|
2013-06-02 05:31:17 +08:00
|
|
|
free(signature);
|
2010-02-12 06:21:02 +08:00
|
|
|
}
|
2019-01-21 06:57:45 +08:00
|
|
|
fail:
|
|
|
|
free(blob);
|
|
|
|
sshkey_free(key);
|
2018-07-10 04:39:28 +08:00
|
|
|
sshbuf_free(msg);
|
2010-02-12 06:21:02 +08:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2019-01-21 08:32:28 +08:00
|
|
|
#ifdef HAVE_EC_KEY_METHOD_NEW
|
2019-01-21 06:51:37 +08:00
|
|
|
static ECDSA_SIG *
|
|
|
|
ecdsa_do_sign(const unsigned char *dgst, int dgst_len, const BIGNUM *inv,
|
|
|
|
const BIGNUM *rp, EC_KEY *ec)
|
|
|
|
{
|
2019-01-21 06:57:45 +08:00
|
|
|
struct sshkey *key = NULL;
|
|
|
|
struct sshbuf *msg = NULL;
|
|
|
|
ECDSA_SIG *ret = NULL;
|
2019-01-21 06:51:37 +08:00
|
|
|
const u_char *cp;
|
2019-01-21 06:57:45 +08:00
|
|
|
u_char *blob = NULL, *signature = NULL;
|
2019-01-21 06:51:37 +08:00
|
|
|
size_t blen, slen = 0;
|
2019-01-21 06:57:45 +08:00
|
|
|
int r, nid;
|
2019-01-21 06:51:37 +08:00
|
|
|
|
2019-01-21 06:57:45 +08:00
|
|
|
nid = sshkey_ecdsa_key_to_nid(ec);
|
|
|
|
if (nid < 0) {
|
2019-01-21 06:51:37 +08:00
|
|
|
error("%s: couldn't get curve nid", __func__);
|
2019-01-21 06:57:45 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
key = sshkey_new(KEY_UNSPEC);
|
|
|
|
if (key == NULL) {
|
|
|
|
error("%s: sshkey_new failed", __func__);
|
|
|
|
goto fail;
|
2019-01-21 06:51:37 +08:00
|
|
|
}
|
2019-01-21 06:57:45 +08:00
|
|
|
key->ecdsa = ec;
|
|
|
|
key->ecdsa_nid = nid;
|
|
|
|
key->type = KEY_ECDSA;
|
|
|
|
EC_KEY_up_ref(ec);
|
|
|
|
|
|
|
|
if ((r = sshkey_to_blob(key, &blob, &blen)) != 0) {
|
2019-01-21 06:51:37 +08:00
|
|
|
error("%s: sshkey_to_blob: %s", __func__, ssh_err(r));
|
2019-01-21 06:57:45 +08:00
|
|
|
goto fail;
|
2019-01-21 06:51:37 +08:00
|
|
|
}
|
|
|
|
if ((msg = sshbuf_new()) == NULL)
|
|
|
|
fatal("%s: sshbuf_new failed", __func__);
|
|
|
|
if ((r = sshbuf_put_u8(msg, SSH2_AGENTC_SIGN_REQUEST)) != 0 ||
|
|
|
|
(r = sshbuf_put_string(msg, blob, blen)) != 0 ||
|
|
|
|
(r = sshbuf_put_string(msg, dgst, dgst_len)) != 0 ||
|
|
|
|
(r = sshbuf_put_u32(msg, 0)) != 0)
|
|
|
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
|
send_msg(msg);
|
|
|
|
sshbuf_reset(msg);
|
|
|
|
|
|
|
|
if (recv_msg(msg) == SSH2_AGENT_SIGN_RESPONSE) {
|
|
|
|
if ((r = sshbuf_get_string(msg, &signature, &slen)) != 0)
|
|
|
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
|
cp = signature;
|
|
|
|
ret = d2i_ECDSA_SIG(NULL, &cp, slen);
|
|
|
|
free(signature);
|
|
|
|
}
|
|
|
|
|
2019-01-21 06:57:45 +08:00
|
|
|
fail:
|
|
|
|
free(blob);
|
|
|
|
sshkey_free(key);
|
2019-01-21 06:51:37 +08:00
|
|
|
sshbuf_free(msg);
|
|
|
|
return (ret);
|
|
|
|
}
|
2019-01-21 08:32:28 +08:00
|
|
|
#endif /* HAVE_EC_KEY_METHOD_NEW */
|
2019-01-21 06:51:37 +08:00
|
|
|
|
|
|
|
static RSA_METHOD *helper_rsa;
|
2019-01-21 08:32:28 +08:00
|
|
|
#ifdef HAVE_EC_KEY_METHOD_NEW
|
2019-01-21 06:51:37 +08:00
|
|
|
static EC_KEY_METHOD *helper_ecdsa;
|
2019-01-21 08:32:28 +08:00
|
|
|
#endif /* HAVE_EC_KEY_METHOD_NEW */
|
2019-01-21 06:51:37 +08:00
|
|
|
|
|
|
|
/* redirect private key crypto operations to the ssh-pkcs11-helper */
|
|
|
|
static void
|
|
|
|
wrap_key(struct sshkey *k)
|
|
|
|
{
|
|
|
|
if (k->type == KEY_RSA)
|
|
|
|
RSA_set_method(k->rsa, helper_rsa);
|
2019-01-21 08:32:28 +08:00
|
|
|
#ifdef HAVE_EC_KEY_METHOD_NEW
|
2019-01-21 06:51:37 +08:00
|
|
|
else if (k->type == KEY_ECDSA)
|
|
|
|
EC_KEY_set_method(k->ecdsa, helper_ecdsa);
|
2019-01-21 08:32:28 +08:00
|
|
|
#endif /* HAVE_EC_KEY_METHOD_NEW */
|
2019-01-21 06:51:37 +08:00
|
|
|
else
|
|
|
|
fatal("%s: unknown key type", __func__);
|
|
|
|
}
|
|
|
|
|
2010-02-12 06:21:02 +08:00
|
|
|
static int
|
2019-01-21 06:51:37 +08:00
|
|
|
pkcs11_start_helper_methods(void)
|
2010-02-12 06:21:02 +08:00
|
|
|
{
|
2019-01-21 08:32:28 +08:00
|
|
|
if (helper_rsa != NULL)
|
2019-01-21 06:51:37 +08:00
|
|
|
return (0);
|
|
|
|
|
2019-01-21 08:32:28 +08:00
|
|
|
#ifdef HAVE_EC_KEY_METHOD_NEW
|
2019-01-21 06:51:37 +08:00
|
|
|
int (*orig_sign)(int, const unsigned char *, int, unsigned char *,
|
|
|
|
unsigned int *, const BIGNUM *, const BIGNUM *, EC_KEY *) = NULL;
|
|
|
|
if (helper_ecdsa != NULL)
|
|
|
|
return (0);
|
|
|
|
helper_ecdsa = EC_KEY_METHOD_new(EC_KEY_OpenSSL());
|
|
|
|
if (helper_ecdsa == NULL)
|
|
|
|
return (-1);
|
|
|
|
EC_KEY_METHOD_get_sign(helper_ecdsa, &orig_sign, NULL, NULL);
|
|
|
|
EC_KEY_METHOD_set_sign(helper_ecdsa, orig_sign, NULL, ecdsa_do_sign);
|
2019-01-21 08:32:28 +08:00
|
|
|
#endif /* HAVE_EC_KEY_METHOD_NEW */
|
2018-09-13 10:08:33 +08:00
|
|
|
|
|
|
|
if ((helper_rsa = RSA_meth_dup(RSA_get_default_method())) == NULL)
|
|
|
|
fatal("%s: RSA_meth_dup failed", __func__);
|
|
|
|
if (!RSA_meth_set1_name(helper_rsa, "ssh-pkcs11-helper") ||
|
2019-01-21 06:51:37 +08:00
|
|
|
!RSA_meth_set_priv_enc(helper_rsa, rsa_encrypt))
|
2018-09-13 10:08:33 +08:00
|
|
|
fatal("%s: failed to prepare method", __func__);
|
2019-01-21 06:51:37 +08:00
|
|
|
|
2010-02-12 06:21:02 +08:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pkcs11_start_helper(void)
|
|
|
|
{
|
|
|
|
int pair[2];
|
2019-01-21 06:54:30 +08:00
|
|
|
char *helper;
|
2010-02-12 06:21:02 +08:00
|
|
|
|
2019-01-21 06:51:37 +08:00
|
|
|
if (pkcs11_start_helper_methods() == -1) {
|
|
|
|
error("pkcs11_start_helper_methods failed");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2010-02-12 06:21:02 +08:00
|
|
|
if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
|
|
|
|
error("socketpair: %s", strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if ((pid = fork()) == -1) {
|
|
|
|
error("fork: %s", strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
} else if (pid == 0) {
|
|
|
|
if ((dup2(pair[1], STDIN_FILENO) == -1) ||
|
|
|
|
(dup2(pair[1], STDOUT_FILENO) == -1)) {
|
|
|
|
fprintf(stderr, "dup2: %s\n", strerror(errno));
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
close(pair[0]);
|
|
|
|
close(pair[1]);
|
2019-01-21 06:54:30 +08:00
|
|
|
helper = getenv("SSH_PKCS11_HELPER");
|
|
|
|
if (helper == NULL || strlen(helper) == 0)
|
|
|
|
helper = _PATH_SSH_PKCS11_HELPER;
|
|
|
|
execlp(helper, helper, (char *)NULL);
|
|
|
|
fprintf(stderr, "exec: %s: %s\n", helper, strerror(errno));
|
2010-02-12 06:21:02 +08:00
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
close(pair[1]);
|
|
|
|
fd = pair[0];
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2018-07-10 04:39:28 +08:00
|
|
|
pkcs11_add_provider(char *name, char *pin, struct sshkey ***keysp)
|
2010-02-12 06:21:02 +08:00
|
|
|
{
|
2017-05-30 16:52:19 +08:00
|
|
|
struct sshkey *k;
|
2019-01-21 06:51:37 +08:00
|
|
|
int r, type;
|
2010-02-12 06:21:02 +08:00
|
|
|
u_char *blob;
|
2018-07-10 04:39:28 +08:00
|
|
|
size_t blen;
|
|
|
|
u_int nkeys, i;
|
|
|
|
struct sshbuf *msg;
|
2010-02-12 06:21:02 +08:00
|
|
|
|
|
|
|
if (fd < 0 && pkcs11_start_helper() < 0)
|
|
|
|
return (-1);
|
|
|
|
|
2018-07-10 04:39:28 +08:00
|
|
|
if ((msg = sshbuf_new()) == NULL)
|
|
|
|
fatal("%s: sshbuf_new failed", __func__);
|
|
|
|
if ((r = sshbuf_put_u8(msg, SSH_AGENTC_ADD_SMARTCARD_KEY)) != 0 ||
|
|
|
|
(r = sshbuf_put_cstring(msg, name)) != 0 ||
|
|
|
|
(r = sshbuf_put_cstring(msg, pin)) != 0)
|
|
|
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
|
send_msg(msg);
|
|
|
|
sshbuf_reset(msg);
|
2010-02-12 06:21:02 +08:00
|
|
|
|
2019-01-21 06:51:37 +08:00
|
|
|
type = recv_msg(msg);
|
|
|
|
if (type == SSH2_AGENT_IDENTITIES_ANSWER) {
|
2018-07-10 04:39:28 +08:00
|
|
|
if ((r = sshbuf_get_u32(msg, &nkeys)) != 0)
|
|
|
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
|
*keysp = xcalloc(nkeys, sizeof(struct sshkey *));
|
2010-02-12 06:21:02 +08:00
|
|
|
for (i = 0; i < nkeys; i++) {
|
2018-07-10 04:39:28 +08:00
|
|
|
/* XXX clean up properly instead of fatal() */
|
|
|
|
if ((r = sshbuf_get_string(msg, &blob, &blen)) != 0 ||
|
|
|
|
(r = sshbuf_skip_string(msg)) != 0)
|
|
|
|
fatal("%s: buffer error: %s",
|
|
|
|
__func__, ssh_err(r));
|
|
|
|
if ((r = sshkey_from_blob(blob, blen, &k)) != 0)
|
|
|
|
fatal("%s: bad key: %s", __func__, ssh_err(r));
|
2019-01-21 06:51:37 +08:00
|
|
|
wrap_key(k);
|
2010-02-12 06:21:02 +08:00
|
|
|
(*keysp)[i] = k;
|
2013-06-02 05:31:17 +08:00
|
|
|
free(blob);
|
2010-02-12 06:21:02 +08:00
|
|
|
}
|
2019-01-21 06:51:37 +08:00
|
|
|
} else if (type == SSH2_AGENT_FAILURE) {
|
|
|
|
if ((r = sshbuf_get_u32(msg, &nkeys)) != 0)
|
|
|
|
nkeys = -1;
|
2010-02-12 06:21:02 +08:00
|
|
|
} else {
|
|
|
|
nkeys = -1;
|
|
|
|
}
|
2018-07-10 04:39:28 +08:00
|
|
|
sshbuf_free(msg);
|
2010-02-12 06:21:02 +08:00
|
|
|
return (nkeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pkcs11_del_provider(char *name)
|
|
|
|
{
|
2018-07-10 04:39:28 +08:00
|
|
|
int r, ret = -1;
|
|
|
|
struct sshbuf *msg;
|
2010-02-12 06:21:02 +08:00
|
|
|
|
2018-07-10 04:39:28 +08:00
|
|
|
if ((msg = sshbuf_new()) == NULL)
|
|
|
|
fatal("%s: sshbuf_new failed", __func__);
|
|
|
|
if ((r = sshbuf_put_u8(msg, SSH_AGENTC_REMOVE_SMARTCARD_KEY)) != 0 ||
|
|
|
|
(r = sshbuf_put_cstring(msg, name)) != 0 ||
|
|
|
|
(r = sshbuf_put_cstring(msg, "")) != 0)
|
|
|
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
|
send_msg(msg);
|
|
|
|
sshbuf_reset(msg);
|
2010-02-12 06:21:02 +08:00
|
|
|
|
2018-07-10 04:39:28 +08:00
|
|
|
if (recv_msg(msg) == SSH_AGENT_SUCCESS)
|
2010-02-12 06:21:02 +08:00
|
|
|
ret = 0;
|
2018-07-10 04:39:28 +08:00
|
|
|
sshbuf_free(msg);
|
2010-02-12 06:21:02 +08:00
|
|
|
return (ret);
|
|
|
|
}
|
2010-02-12 07:06:28 +08:00
|
|
|
|
|
|
|
#endif /* ENABLE_PKCS11 */
|