summaryrefslogtreecommitdiff
path: root/usr.bin/ssh
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2020-08-27 01:06:20 +0000
committerDamien Miller <djm@cvs.openbsd.org>2020-08-27 01:06:20 +0000
commitc6033e8945d214efd07c42b188f773dd96c8ca2e (patch)
treed3e4acabc6e5889f835bd94eeb46afbdf009f513 /usr.bin/ssh
parentcd21b93ed81739c03a33699c7f21be17cf524043 (diff)
support for user-verified FIDO keys
FIDO2 supports a notion of "user verification" where the user is required to demonstrate their identity to the token before particular operations (e.g. signing). Typically this is done by authenticating themselves using a PIN that has been set on the token. This adds support for generating and using user verified keys where the verification happens via PIN (other options might be added in the future, but none are in common use now). Practically, this adds another key generation option "verify-required" that yields a key that requires a PIN before each authentication. feedback markus@ and Pedro Martelletto; ok markus@
Diffstat (limited to 'usr.bin/ssh')
-rw-r--r--usr.bin/ssh/krl.c7
-rw-r--r--usr.bin/ssh/monitor.c4
-rw-r--r--usr.bin/ssh/monitor_wrap.c4
-rw-r--r--usr.bin/ssh/monitor_wrap.h5
-rw-r--r--usr.bin/ssh/sk-usbhid.c38
-rw-r--r--usr.bin/ssh/ssh-agent.c5
-rw-r--r--usr.bin/ssh/ssh-keygen.122
-rw-r--r--usr.bin/ssh/ssh-keygen.c55
-rw-r--r--usr.bin/ssh/ssh-keysign.c4
-rw-r--r--usr.bin/ssh/ssh_api.c10
-rw-r--r--usr.bin/ssh/sshconnect2.c37
-rw-r--r--usr.bin/ssh/sshd.c8
-rw-r--r--usr.bin/ssh/sshkey.c20
-rw-r--r--usr.bin/ssh/sshkey.h11
-rw-r--r--usr.bin/ssh/sshsig.c16
-rw-r--r--usr.bin/ssh/sshsig.h8
16 files changed, 164 insertions, 90 deletions
diff --git a/usr.bin/ssh/krl.c b/usr.bin/ssh/krl.c
index 9a0f6981137..156a4397c65 100644
--- a/usr.bin/ssh/krl.c
+++ b/usr.bin/ssh/krl.c
@@ -14,7 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $OpenBSD: krl.c,v 1.50 2020/04/03 05:48:57 djm Exp $ */
+/* $OpenBSD: krl.c,v 1.51 2020/08/27 01:06:18 djm Exp $ */
#include <sys/types.h>
#include <sys/tree.h>
@@ -810,9 +810,10 @@ ssh_krl_to_blob(struct ssh_krl *krl, struct sshbuf *buf,
if ((r = sshbuf_put_u8(buf, KRL_SECTION_SIGNATURE)) != 0 ||
(r = sshkey_puts(sign_keys[i], buf)) != 0)
goto out;
-
+ /* XXX support sk-* keys */
if ((r = sshkey_sign(sign_keys[i], &sblob, &slen,
- sshbuf_ptr(buf), sshbuf_len(buf), NULL, NULL, 0)) != 0)
+ sshbuf_ptr(buf), sshbuf_len(buf), NULL, NULL,
+ NULL, 0)) != 0)
goto out;
KRL_DBG(("%s: signature sig len %zu", __func__, slen));
if ((r = sshbuf_put_string(buf, sblob, slen)) != 0)
diff --git a/usr.bin/ssh/monitor.c b/usr.bin/ssh/monitor.c
index 2a091b3f2dd..a98b66ffc2e 100644
--- a/usr.bin/ssh/monitor.c
+++ b/usr.bin/ssh/monitor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: monitor.c,v 1.212 2020/07/07 02:47:21 deraadt Exp $ */
+/* $OpenBSD: monitor.c,v 1.213 2020/08/27 01:06:18 djm Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* Copyright 2002 Markus Friedl <markus@openbsd.org>
@@ -613,7 +613,7 @@ mm_answer_sign(struct ssh *ssh, int sock, struct sshbuf *m)
if ((key = get_hostkey_by_index(keyid)) != NULL) {
if ((r = sshkey_sign(key, &signature, &siglen, p, datlen, alg,
- options.sk_provider, compat)) != 0)
+ options.sk_provider, NULL, compat)) != 0)
fatal("%s: sshkey_sign failed: %s",
__func__, ssh_err(r));
} else if ((key = get_hostkey_public_by_index(keyid, ssh)) != NULL &&
diff --git a/usr.bin/ssh/monitor_wrap.c b/usr.bin/ssh/monitor_wrap.c
index 81c066a93c5..a25efe9d61b 100644
--- a/usr.bin/ssh/monitor_wrap.c
+++ b/usr.bin/ssh/monitor_wrap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: monitor_wrap.c,v 1.117 2019/12/15 18:57:30 djm Exp $ */
+/* $OpenBSD: monitor_wrap.c,v 1.118 2020/08/27 01:06:18 djm Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* Copyright 2002 Markus Friedl <markus@openbsd.org>
@@ -212,7 +212,7 @@ mm_choose_dh(int min, int nbits, int max)
int
mm_sshkey_sign(struct ssh *ssh, struct sshkey *key, u_char **sigp, size_t *lenp,
const u_char *data, size_t datalen, const char *hostkey_alg,
- const char *sk_provider, u_int compat)
+ const char *sk_provider, const char *sk_pin, u_int compat)
{
struct kex *kex = *pmonitor->m_pkex;
struct sshbuf *m;
diff --git a/usr.bin/ssh/monitor_wrap.h b/usr.bin/ssh/monitor_wrap.h
index b2c64adfbf6..b6e99e34ff3 100644
--- a/usr.bin/ssh/monitor_wrap.h
+++ b/usr.bin/ssh/monitor_wrap.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: monitor_wrap.h,v 1.44 2019/11/25 00:51:37 djm Exp $ */
+/* $OpenBSD: monitor_wrap.h,v 1.45 2020/08/27 01:06:18 djm Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
@@ -46,7 +46,8 @@ int mm_is_monitor(void);
DH *mm_choose_dh(int, int, int);
#endif
int mm_sshkey_sign(struct ssh *, struct sshkey *, u_char **, size_t *,
- const u_char *, size_t, const char *, const char *, u_int compat);
+ const u_char *, size_t, const char *, const char *,
+ const char *, u_int compat);
void mm_inform_authserv(char *, char *);
struct passwd *mm_getpwnamallow(struct ssh *, const char *);
char *mm_auth2_read_banner(void);
diff --git a/usr.bin/ssh/sk-usbhid.c b/usr.bin/ssh/sk-usbhid.c
index 329323e2c5a..5c99a815787 100644
--- a/usr.bin/ssh/sk-usbhid.c
+++ b/usr.bin/ssh/sk-usbhid.c
@@ -157,7 +157,8 @@ pick_first_device(void)
/* Check if the specified key handle exists on a given device. */
static int
try_device(fido_dev_t *dev, const uint8_t *message, size_t message_len,
- const char *application, const uint8_t *key_handle, size_t key_handle_len)
+ const char *application, const uint8_t *key_handle, size_t key_handle_len,
+ uint8_t flags, const char *pin)
{
fido_assert_t *assert = NULL;
int r = FIDO_ERR_INTERNAL;
@@ -185,7 +186,7 @@ try_device(fido_dev_t *dev, const uint8_t *message, size_t message_len,
skdebug(__func__, "fido_assert_up: %s", fido_strerr(r));
goto out;
}
- r = fido_dev_get_assert(dev, assert, NULL);
+ r = fido_dev_get_assert(dev, assert, pin);
skdebug(__func__, "fido_dev_get_assert: %s", fido_strerr(r));
if (r == FIDO_ERR_USER_PRESENCE_REQUIRED) {
/* U2F tokens may return this */
@@ -200,7 +201,8 @@ try_device(fido_dev_t *dev, const uint8_t *message, size_t message_len,
/* Iterate over configured devices looking for a specific key handle */
static fido_dev_t *
find_device(const char *path, const uint8_t *message, size_t message_len,
- const char *application, const uint8_t *key_handle, size_t key_handle_len)
+ const char *application, const uint8_t *key_handle, size_t key_handle_len,
+ uint8_t flags, const char *pin)
{
fido_dev_info_t *devlist = NULL;
fido_dev_t *dev = NULL;
@@ -254,7 +256,7 @@ find_device(const char *path, const uint8_t *message, size_t message_len,
continue;
}
if (try_device(dev, message, message_len, application,
- key_handle, key_handle_len) == 0) {
+ key_handle, key_handle_len, flags, pin) == 0) {
skdebug(__func__, "found key");
break;
}
@@ -564,19 +566,23 @@ sk_enroll(uint32_t alg, const uint8_t *challenge, size_t challenge_len,
skdebug(__func__, "fido_dev_open: %s", fido_strerr(r));
goto out;
}
- if ((flags & SSH_SK_RESIDENT_KEY) != 0) {
+ if ((flags & (SSH_SK_RESIDENT_KEY|SSH_SK_USER_VERIFICATION_REQD)) != 0) {
if (check_sk_extensions(dev, "credProtect", &credprot) < 0) {
skdebug(__func__, "check_sk_extensions failed");
goto out;
}
if (credprot == 0) {
skdebug(__func__, "refusing to create unprotected "
- "resident key");
+ "resident/verify-required key");
ret = SSH_SK_ERR_UNSUPPORTED;
goto out;
}
- if ((r = fido_cred_set_prot(cred,
- FIDO_CRED_PROT_UV_OPTIONAL_WITH_ID)) != FIDO_OK) {
+ if ((flags & SSH_SK_USER_VERIFICATION_REQD))
+ credprot = FIDO_CRED_PROT_UV_REQUIRED;
+ else
+ credprot = FIDO_CRED_PROT_UV_OPTIONAL_WITH_ID;
+
+ if ((r = fido_cred_set_prot(cred, credprot)) != FIDO_OK) {
skdebug(__func__, "fido_cred_set_prot: %s",
fido_strerr(r));
ret = fidoerr_to_skerr(r);
@@ -820,7 +826,7 @@ sk_sign(uint32_t alg, const uint8_t *data, size_t datalen,
goto out;
}
if ((dev = find_device(device, message, sizeof(message),
- application, key_handle, key_handle_len)) == NULL) {
+ application, key_handle, key_handle_len, flags, pin)) == NULL) {
skdebug(__func__, "couldn't find device for key handle");
goto out;
}
@@ -849,8 +855,15 @@ sk_sign(uint32_t alg, const uint8_t *data, size_t datalen,
skdebug(__func__, "fido_assert_set_up: %s", fido_strerr(r));
goto out;
}
- if ((r = fido_dev_get_assert(dev, assert, NULL)) != FIDO_OK) {
+ if (pin == NULL && (flags & SSH_SK_USER_VERIFICATION_REQD) &&
+ (r = fido_assert_set_uv(assert, FIDO_OPT_TRUE)) != FIDO_OK) {
+ skdebug(__func__, "fido_assert_set_uv: %s", fido_strerr(r));
+ ret = FIDO_ERR_PIN_REQUIRED;
+ goto out;
+ }
+ if ((r = fido_dev_get_assert(dev, assert, pin)) != FIDO_OK) {
skdebug(__func__, "fido_dev_get_assert: %s", fido_strerr(r));
+ ret = fidoerr_to_skerr(r);
goto out;
}
if ((response = calloc(1, sizeof(*response))) == NULL) {
@@ -972,8 +985,9 @@ read_rks(const char *devpath, const char *pin,
continue;
}
skdebug(__func__, "Device %s RP \"%s\" slot %zu: "
- "type %d", devpath, fido_credman_rp_id(rp, i), j,
- fido_cred_type(cred));
+ "type %d flags 0x%02x prot 0x%02x", devpath,
+ fido_credman_rp_id(rp, i), j, fido_cred_type(cred),
+ fido_cred_flags(cred), fido_cred_prot(cred));
/* build response entry */
if ((srk = calloc(1, sizeof(*srk))) == NULL ||
diff --git a/usr.bin/ssh/ssh-agent.c b/usr.bin/ssh/ssh-agent.c
index 0b312350d57..8572fa09df2 100644
--- a/usr.bin/ssh/ssh-agent.c
+++ b/usr.bin/ssh/ssh-agent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-agent.c,v 1.262 2020/07/05 23:59:45 djm Exp $ */
+/* $OpenBSD: ssh-agent.c,v 1.263 2020/08/27 01:06:18 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -393,9 +393,10 @@ process_sign_request2(SocketEntry *e)
sshkey_type(id->key), fp);
}
}
+ /* XXX support PIN required FIDO keys */
if ((r = sshkey_sign(id->key, &signature, &slen,
data, dlen, agent_decode_alg(key, flags),
- id->sk_provider, compat)) != 0) {
+ id->sk_provider, NULL, compat)) != 0) {
error("%s: sshkey_sign: %s", __func__, ssh_err(r));
goto send;
}
diff --git a/usr.bin/ssh/ssh-keygen.1 b/usr.bin/ssh/ssh-keygen.1
index 9198a511fb7..7e0558fe194 100644
--- a/usr.bin/ssh/ssh-keygen.1
+++ b/usr.bin/ssh/ssh-keygen.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ssh-keygen.1,v 1.205 2020/07/15 07:50:46 solene Exp $
+.\" $OpenBSD: ssh-keygen.1,v 1.206 2020/08/27 01:06:18 djm Exp $
.\"
.\" Author: Tatu Ylonen <ylo@cs.hut.fi>
.\" Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -35,7 +35,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: July 15 2020 $
+.Dd $Mdocdate: August 27 2020 $
.Dt SSH-KEYGEN 1
.Os
.Sh NAME
@@ -511,6 +511,12 @@ A username to be associated with a resident key,
overriding the empty default username.
Specifying a username may be useful when generating multiple resident keys
for the same application name.
+.It Cm verify-required
+Indicate that this private key should require user verification for
+each signature.
+Not all FIDO tokens support support this option.
+Currently PIN authentication is the only supported verification method,
+but other methods may be supported in the future.
.It Cm write-attestation Ns = Ns Ar path
May be used at key generation time to record the attestation certificate
returned from FIDO tokens during key generation.
@@ -961,7 +967,7 @@ by
Allows X11 forwarding.
.Pp
.It Ic no-touch-required
-Do not require signatures made using this key require demonstration
+Do not require signatures made using this key include demonstration
of user presence (e.g. by having the user touch the authenticator).
This option only makes sense for the FIDO authenticator algorithms
.Cm ecdsa-sk
@@ -974,6 +980,16 @@ The
.Ar address_list
is a comma-separated list of one or more address/netmask pairs in CIDR
format.
+.Pp
+.It Ic verify-required
+Require signatures made using this key indicate that the user was first
+verified.
+This option only makes sense for the FIDO authenticator algorithms
+.Cm ecdsa-sk
+and
+.Cm ed25519-sk .
+Currently PIN authentication is the only supported verification method,
+but other methods may be supported in the future.
.El
.Pp
At present, no standard options are valid for host keys.
diff --git a/usr.bin/ssh/ssh-keygen.c b/usr.bin/ssh/ssh-keygen.c
index e418cff56dd..6610b6a49ce 100644
--- a/usr.bin/ssh/ssh-keygen.c
+++ b/usr.bin/ssh/ssh-keygen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keygen.c,v 1.415 2020/08/03 02:53:51 djm Exp $ */
+/* $OpenBSD: ssh-keygen.c,v 1.416 2020/08/27 01:06:18 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -573,7 +573,7 @@ do_convert_private_ssh2(struct sshbuf *b)
/* try the key */
if (sshkey_sign(key, &sig, &slen, data, sizeof(data),
- NULL, NULL, 0) != 0 ||
+ NULL, NULL, NULL, 0) != 0 ||
sshkey_verify(key, sig, slen, data, sizeof(data),
NULL, 0, NULL) != 0) {
sshkey_free(key);
@@ -1705,7 +1705,8 @@ load_pkcs11_key(char *path)
static int
agent_signer(struct sshkey *key, u_char **sigp, size_t *lenp,
const u_char *data, size_t datalen,
- const char *alg, const char *provider, u_int compat, void *ctx)
+ const char *alg, const char *provider, const char *pin,
+ u_int compat, void *ctx)
{
int *agent_fdp = (int *)ctx;
@@ -1722,7 +1723,7 @@ do_ca_sign(struct passwd *pw, const char *ca_key_path, int prefer_agent,
u_int n;
struct sshkey *ca, *public;
char valid[64], *otmp, *tmp, *cp, *out, *comment;
- char *ca_fp = NULL, **plist = NULL;
+ char *ca_fp = NULL, **plist = NULL, *pin = NULL;
struct ssh_identitylist *agent_ids;
size_t j;
struct notifier_ctx *notifier = NULL;
@@ -1763,6 +1764,12 @@ do_ca_sign(struct passwd *pw, const char *ca_key_path, int prefer_agent,
} else {
/* CA key is assumed to be a private key on the filesystem */
ca = load_identity(tmp, NULL);
+ if (sshkey_is_sk(ca) &&
+ (ca->sk_flags & SSH_SK_USER_VERIFICATION_REQD)) {
+ if ((pin = read_passphrase("Enter PIN for CA key: ",
+ RP_ALLOW_STDIN)) == NULL)
+ fatal("%s: couldn't read PIN", __func__);
+ }
}
free(tmp);
@@ -1822,7 +1829,7 @@ do_ca_sign(struct passwd *pw, const char *ca_key_path, int prefer_agent,
if (agent_fd != -1 && (ca->flags & SSHKEY_FLAG_EXT) != 0) {
if ((r = sshkey_certify_custom(public, ca,
- key_type_name, sk_provider, agent_signer,
+ key_type_name, sk_provider, NULL, agent_signer,
&agent_fd)) != 0)
fatal("Couldn't certify key %s via agent: %s",
tmp, ssh_err(r));
@@ -1834,7 +1841,7 @@ do_ca_sign(struct passwd *pw, const char *ca_key_path, int prefer_agent,
sshkey_type(ca), ca_fp);
}
r = sshkey_certify(public, ca, key_type_name,
- sk_provider);
+ sk_provider, pin);
notify_complete(notifier);
if (r != 0)
fatal("Couldn't certify key %s: %s",
@@ -1868,6 +1875,8 @@ do_ca_sign(struct passwd *pw, const char *ca_key_path, int prefer_agent,
if (cert_serial_autoinc)
cert_serial++;
}
+ if (pin != NULL)
+ freezero(pin, strlen(pin));
free(ca_fp);
#ifdef ENABLE_PKCS11
pkcs11_terminate();
@@ -2504,6 +2513,7 @@ sign_one(struct sshkey *signkey, const char *filename, int fd,
struct sshbuf *sigbuf = NULL, *abuf = NULL;
int r = SSH_ERR_INTERNAL_ERROR, wfd = -1, oerrno;
char *wfile = NULL, *asig = NULL, *fp = NULL;
+ char *pin = NULL, *prompt = NULL;
if (!quiet) {
if (fd == STDIN_FILENO)
@@ -2511,17 +2521,25 @@ sign_one(struct sshkey *signkey, const char *filename, int fd,
else
fprintf(stderr, "Signing file %s\n", filename);
}
- if (signer == NULL && sshkey_is_sk(signkey) &&
- (signkey->sk_flags & SSH_SK_USER_PRESENCE_REQD)) {
- if ((fp = sshkey_fingerprint(signkey, fingerprint_hash,
- SSH_FP_DEFAULT)) == NULL)
- fatal("%s: sshkey_fingerprint failed", __func__);
- fprintf(stderr, "Confirm user presence for key %s %s\n",
- sshkey_type(signkey), fp);
- free(fp);
+ if (signer == NULL && sshkey_is_sk(signkey)) {
+ if ((signkey->sk_flags & SSH_SK_USER_VERIFICATION_REQD)) {
+ xasprintf(&prompt, "Enter PIN for %s key: ",
+ sshkey_type(signkey));
+ if ((pin = read_passphrase(prompt,
+ RP_ALLOW_STDIN)) == NULL)
+ fatal("%s: couldn't read PIN", __func__);
+ }
+ if ((signkey->sk_flags & SSH_SK_USER_PRESENCE_REQD)) {
+ if ((fp = sshkey_fingerprint(signkey, fingerprint_hash,
+ SSH_FP_DEFAULT)) == NULL)
+ fatal("%s: fingerprint failed", __func__);
+ fprintf(stderr, "Confirm user presence for key %s %s\n",
+ sshkey_type(signkey), fp);
+ free(fp);
+ }
}
- if ((r = sshsig_sign_fd(signkey, NULL, sk_provider, fd, sig_namespace,
- &sigbuf, signer, signer_ctx)) != 0) {
+ if ((r = sshsig_sign_fd(signkey, NULL, sk_provider, pin,
+ fd, sig_namespace, &sigbuf, signer, signer_ctx)) != 0) {
error("Signing %s failed: %s", filename, ssh_err(r));
goto out;
}
@@ -2569,7 +2587,10 @@ sign_one(struct sshkey *signkey, const char *filename, int fd,
r = 0;
out:
free(wfile);
+ free(prompt);
free(asig);
+ if (pin != NULL)
+ freezero(pin, strlen(pin));
sshbuf_free(abuf);
sshbuf_free(sigbuf);
if (wfd != -1)
@@ -3529,6 +3550,8 @@ main(int argc, char **argv)
for (i = 0; i < nopts; i++) {
if (strcasecmp(opts[i], "no-touch-required") == 0) {
sk_flags &= ~SSH_SK_USER_PRESENCE_REQD;
+ } else if (strcasecmp(opts[i], "verify-required") == 0) {
+ sk_flags |= SSH_SK_USER_VERIFICATION_REQD;
} else if (strcasecmp(opts[i], "resident") == 0) {
sk_flags |= SSH_SK_RESIDENT_KEY;
} else if (strncasecmp(opts[i], "device=", 7) == 0) {
diff --git a/usr.bin/ssh/ssh-keysign.c b/usr.bin/ssh/ssh-keysign.c
index 16e087baa9d..68ef420426c 100644
--- a/usr.bin/ssh/ssh-keysign.c
+++ b/usr.bin/ssh/ssh-keysign.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keysign.c,v 1.63 2019/11/18 16:10:05 naddy Exp $ */
+/* $OpenBSD: ssh-keysign.c,v 1.64 2020/08/27 01:06:18 djm Exp $ */
/*
* Copyright (c) 2002 Markus Friedl. All rights reserved.
*
@@ -274,7 +274,7 @@ main(int argc, char **argv)
}
if ((r = sshkey_sign(keys[i], &signature, &slen, data, dlen,
- NULL, NULL, 0)) != 0)
+ NULL, NULL, NULL, 0)) != 0)
fatal("sshkey_sign failed: %s", ssh_err(r));
free(data);
diff --git a/usr.bin/ssh/ssh_api.c b/usr.bin/ssh/ssh_api.c
index 68b2c14391e..ef10460d0e1 100644
--- a/usr.bin/ssh/ssh_api.c
+++ b/usr.bin/ssh/ssh_api.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh_api.c,v 1.20 2020/07/01 16:28:31 markus Exp $ */
+/* $OpenBSD: ssh_api.c,v 1.21 2020/08/27 01:06:18 djm Exp $ */
/*
* Copyright (c) 2012 Markus Friedl. All rights reserved.
*
@@ -50,7 +50,7 @@ int _ssh_host_key_sign(struct ssh *, struct sshkey *, struct sshkey *,
*/
int use_privsep = 0;
int mm_sshkey_sign(struct sshkey *, u_char **, u_int *,
- const u_char *, u_int, const char *, const char *, u_int);
+ const u_char *, u_int, const char *, const char *, const char *, u_int);
#ifdef WITH_OPENSSL
DH *mm_choose_dh(int, int, int);
@@ -62,8 +62,8 @@ u_int session_id2_len = 0;
int
mm_sshkey_sign(struct sshkey *key, u_char **sigp, u_int *lenp,
- const u_char *data, u_int datalen, const char *alg, const char *sk_provider,
- u_int compat)
+ const u_char *data, u_int datalen, const char *alg,
+ const char *sk_provider, const char *sk_pin, u_int compat)
{
return (-1);
}
@@ -561,5 +561,5 @@ _ssh_host_key_sign(struct ssh *ssh, struct sshkey *privkey,
const u_char *data, size_t dlen, const char *alg)
{
return sshkey_sign(privkey, signature, slen, data, dlen,
- alg, NULL, ssh->compat);
+ alg, NULL, NULL, ssh->compat);
}
diff --git a/usr.bin/ssh/sshconnect2.c b/usr.bin/ssh/sshconnect2.c
index 3a263ded2a4..de5b862713b 100644
--- a/usr.bin/ssh/sshconnect2.c
+++ b/usr.bin/ssh/sshconnect2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshconnect2.c,v 1.324 2020/06/27 13:39:09 bket Exp $ */
+/* $OpenBSD: sshconnect2.c,v 1.325 2020/08/27 01:06:18 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2008 Damien Miller. All rights reserved.
@@ -1168,7 +1168,7 @@ identity_sign(struct identity *id, u_char **sigp, size_t *lenp,
struct sshkey *sign_key = NULL, *prv = NULL;
int r = SSH_ERR_INTERNAL_ERROR;
struct notifier_ctx *notifier = NULL;
- char *fp = NULL;
+ char *fp = NULL, *pin = NULL, *prompt = NULL;
*sigp = NULL;
*lenp = 0;
@@ -1197,20 +1197,28 @@ identity_sign(struct identity *id, u_char **sigp, size_t *lenp,
goto out;
}
sign_key = prv;
- if (sshkey_is_sk(sign_key) &&
- (sign_key->sk_flags & SSH_SK_USER_PRESENCE_REQD)) {
- /* XXX match batch mode should just skip these keys? */
- if ((fp = sshkey_fingerprint(sign_key,
- options.fingerprint_hash, SSH_FP_DEFAULT)) == NULL)
- fatal("%s: sshkey_fingerprint", __func__);
- notifier = notify_start(options.batch_mode,
- "Confirm user presence for key %s %s",
- sshkey_type(sign_key), fp);
- free(fp);
+ if (sshkey_is_sk(sign_key)) {
+ if ((sign_key->sk_flags &
+ SSH_SK_USER_VERIFICATION_REQD)) {
+ xasprintf(&prompt, "Enter PIN for %s key %s: ",
+ sshkey_type(sign_key), id->filename);
+ pin = read_passphrase(prompt, 0);
+ }
+ if ((sign_key->sk_flags & SSH_SK_USER_PRESENCE_REQD)) {
+ /* XXX should batch mode just skip these? */
+ if ((fp = sshkey_fingerprint(sign_key,
+ options.fingerprint_hash,
+ SSH_FP_DEFAULT)) == NULL)
+ fatal("%s: fingerprint", __func__);
+ notifier = notify_start(options.batch_mode,
+ "Confirm user presence for key %s %s",
+ sshkey_type(sign_key), fp);
+ free(fp);
+ }
}
}
if ((r = sshkey_sign(sign_key, sigp, lenp, data, datalen,
- alg, options.sk_provider, compat)) != 0) {
+ alg, options.sk_provider, pin, compat)) != 0) {
debug("%s: sshkey_sign: %s", __func__, ssh_err(r));
goto out;
}
@@ -1225,6 +1233,9 @@ identity_sign(struct identity *id, u_char **sigp, size_t *lenp,
/* success */
r = 0;
out:
+ free(prompt);
+ if (pin != NULL)
+ freezero(pin, strlen(pin));
notify_complete(notifier);
sshkey_free(prv);
return r;
diff --git a/usr.bin/ssh/sshd.c b/usr.bin/ssh/sshd.c
index 34c13df9858..d50d1633fb2 100644
--- a/usr.bin/ssh/sshd.c
+++ b/usr.bin/ssh/sshd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshd.c,v 1.560 2020/07/03 10:12:26 markus Exp $ */
+/* $OpenBSD: sshd.c,v 1.561 2020/08/27 01:06:19 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -2159,19 +2159,19 @@ sshd_hostkey_sign(struct ssh *ssh, struct sshkey *privkey,
if (use_privsep) {
if (privkey) {
if (mm_sshkey_sign(ssh, privkey, signature, slenp,
- data, dlen, alg, options.sk_provider,
+ data, dlen, alg, options.sk_provider, NULL,
ssh->compat) < 0)
fatal("%s: privkey sign failed", __func__);
} else {
if (mm_sshkey_sign(ssh, pubkey, signature, slenp,
- data, dlen, alg, options.sk_provider,
+ data, dlen, alg, options.sk_provider, NULL,
ssh->compat) < 0)
fatal("%s: pubkey sign failed", __func__);
}
} else {
if (privkey) {
if (sshkey_sign(privkey, signature, slenp, data, dlen,
- alg, options.sk_provider, ssh->compat) < 0)
+ alg, options.sk_provider, NULL, ssh->compat) < 0)
fatal("%s: privkey sign failed", __func__);
} else {
if ((r = ssh_agent_sign(auth_sock, pubkey,
diff --git a/usr.bin/ssh/sshkey.c b/usr.bin/ssh/sshkey.c
index 3b8e81c16f4..c795e3901ab 100644
--- a/usr.bin/ssh/sshkey.c
+++ b/usr.bin/ssh/sshkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshkey.c,v 1.110 2020/06/24 15:07:33 markus Exp $ */
+/* $OpenBSD: sshkey.c,v 1.111 2020/08/27 01:06:19 djm Exp $ */
/*
* Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
* Copyright (c) 2008 Alexander von Gernler. All rights reserved.
@@ -2682,7 +2682,7 @@ int
sshkey_sign(struct sshkey *key,
u_char **sigp, size_t *lenp,
const u_char *data, size_t datalen,
- const char *alg, const char *sk_provider, u_int compat)
+ const char *alg, const char *sk_provider, const char *sk_pin, u_int compat)
{
int was_shielded = sshkey_is_shielded(key);
int r2, r = SSH_ERR_INTERNAL_ERROR;
@@ -2719,7 +2719,7 @@ sshkey_sign(struct sshkey *key,
case KEY_ECDSA_SK_CERT:
case KEY_ECDSA_SK:
r = sshsk_sign(sk_provider, key, sigp, lenp, data,
- datalen, compat, /* XXX PIN */ NULL);
+ datalen, compat, sk_pin);
break;
#ifdef WITH_XMSS
case KEY_XMSS:
@@ -2839,7 +2839,8 @@ sshkey_drop_cert(struct sshkey *k)
/* Sign a certified key, (re-)generating the signed certblob. */
int
sshkey_certify_custom(struct sshkey *k, struct sshkey *ca, const char *alg,
- const char *sk_provider, sshkey_certify_signer *signer, void *signer_ctx)
+ const char *sk_provider, const char *sk_pin,
+ sshkey_certify_signer *signer, void *signer_ctx)
{
struct sshbuf *principals = NULL;
u_char *ca_blob = NULL, *sig_blob = NULL, nonce[32];
@@ -2975,7 +2976,7 @@ sshkey_certify_custom(struct sshkey *k, struct sshkey *ca, const char *alg,
/* Sign the whole mess */
if ((ret = signer(ca, &sig_blob, &sig_len, sshbuf_ptr(cert),
- sshbuf_len(cert), alg, sk_provider, 0, signer_ctx)) != 0)
+ sshbuf_len(cert), alg, sk_provider, sk_pin, 0, signer_ctx)) != 0)
goto out;
/* Check and update signature_type against what was actually used */
if ((ret = sshkey_get_sigtype(sig_blob, sig_len, &sigtype)) != 0)
@@ -3005,19 +3006,20 @@ sshkey_certify_custom(struct sshkey *k, struct sshkey *ca, const char *alg,
static int
default_key_sign(struct sshkey *key, u_char **sigp, size_t *lenp,
const u_char *data, size_t datalen,
- const char *alg, const char *sk_provider, u_int compat, void *ctx)
+ const char *alg, const char *sk_provider, const char *sk_pin,
+ u_int compat, void *ctx)
{
if (ctx != NULL)
return SSH_ERR_INVALID_ARGUMENT;
return sshkey_sign(key, sigp, lenp, data, datalen, alg,
- sk_provider, compat);
+ sk_provider, sk_pin, compat);
}
int
sshkey_certify(struct sshkey *k, struct sshkey *ca, const char *alg,
- const char *sk_provider)
+ const char *sk_provider, const char *sk_pin)
{
- return sshkey_certify_custom(k, ca, alg, sk_provider,
+ return sshkey_certify_custom(k, ca, alg, sk_provider, sk_pin,
default_key_sign, NULL);
}
diff --git a/usr.bin/ssh/sshkey.h b/usr.bin/ssh/sshkey.h
index 01deea7126d..dc79c086dfb 100644
--- a/usr.bin/ssh/sshkey.h
+++ b/usr.bin/ssh/sshkey.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshkey.h,v 1.45 2020/04/08 00:08:46 djm Exp $ */
+/* $OpenBSD: sshkey.h,v 1.46 2020/08/27 01:06:19 djm Exp $ */
/*
* Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
@@ -194,12 +194,13 @@ size_t sshkey_format_cert_validity(const struct sshkey_cert *,
int sshkey_check_cert_sigtype(const struct sshkey *, const char *);
int sshkey_certify(struct sshkey *, struct sshkey *,
- const char *, const char *);
+ const char *, const char *, const char *);
/* Variant allowing use of a custom signature function (e.g. for ssh-agent) */
typedef int sshkey_certify_signer(struct sshkey *, u_char **, size_t *,
- const u_char *, size_t, const char *, const char *, u_int, void *);
+ const u_char *, size_t, const char *, const char *, const char *,
+ u_int, void *);
int sshkey_certify_custom(struct sshkey *, struct sshkey *, const char *,
- const char *, sshkey_certify_signer *, void *);
+ const char *, const char *, sshkey_certify_signer *, void *);
int sshkey_ecdsa_nid_from_name(const char *);
int sshkey_curve_name_to_nid(const char *);
@@ -228,7 +229,7 @@ int sshkey_plain_to_blob(const struct sshkey *, u_char **, size_t *);
int sshkey_putb_plain(const struct sshkey *, struct sshbuf *);
int sshkey_sign(struct sshkey *, u_char **, size_t *,
- const u_char *, size_t, const char *, const char *, u_int);
+ const u_char *, size_t, const char *, const char *, const char *, u_int);
int sshkey_verify(const struct sshkey *, const u_char *, size_t,
const u_char *, size_t, const char *, u_int, struct sshkey_sig_details **);
int sshkey_check_sigtype(const u_char *, size_t, const char *);
diff --git a/usr.bin/ssh/sshsig.c b/usr.bin/ssh/sshsig.c
index 8e6b19f3e2a..c0994ccd431 100644
--- a/usr.bin/ssh/sshsig.c
+++ b/usr.bin/ssh/sshsig.c
@@ -149,7 +149,7 @@ done:
static int
sshsig_wrap_sign(struct sshkey *key, const char *hashalg,
- const char *sk_provider, const struct sshbuf *h_message,
+ const char *sk_provider, const char *sk_pin, const struct sshbuf *h_message,
const char *sig_namespace, struct sshbuf **out,
sshsig_signer *signer, void *signer_ctx)
{
@@ -183,14 +183,14 @@ sshsig_wrap_sign(struct sshkey *key, const char *hashalg,
if (signer != NULL) {
if ((r = signer(key, &sig, &slen,
sshbuf_ptr(tosign), sshbuf_len(tosign),
- sign_alg, sk_provider, 0, signer_ctx)) != 0) {
+ sign_alg, sk_provider, sk_pin, 0, signer_ctx)) != 0) {
error("Couldn't sign message: %s", ssh_err(r));
goto done;
}
} else {
if ((r = sshkey_sign(key, &sig, &slen,
sshbuf_ptr(tosign), sshbuf_len(tosign),
- sign_alg, sk_provider, 0)) != 0) {
+ sign_alg, sk_provider, sk_pin, 0)) != 0) {
error("Couldn't sign message: %s", ssh_err(r));
goto done;
}
@@ -428,7 +428,8 @@ hash_buffer(const struct sshbuf *m, const char *hashalg, struct sshbuf **bp)
}
int
-sshsig_signb(struct sshkey *key, const char *hashalg, const char *sk_provider,
+sshsig_signb(struct sshkey *key, const char *hashalg,
+ const char *sk_provider, const char *sk_pin,
const struct sshbuf *message, const char *sig_namespace,
struct sshbuf **out, sshsig_signer *signer, void *signer_ctx)
{
@@ -443,7 +444,7 @@ sshsig_signb(struct sshkey *key, const char *hashalg, const char *sk_provider,
error("%s: hash_buffer failed: %s", __func__, ssh_err(r));
goto out;
}
- if ((r = sshsig_wrap_sign(key, hashalg, sk_provider, b,
+ if ((r = sshsig_wrap_sign(key, hashalg, sk_provider, sk_pin, b,
sig_namespace, out, signer, signer_ctx)) != 0)
goto out;
/* success */
@@ -556,7 +557,8 @@ hash_file(int fd, const char *hashalg, struct sshbuf **bp)
}
int
-sshsig_sign_fd(struct sshkey *key, const char *hashalg, const char *sk_provider,
+sshsig_sign_fd(struct sshkey *key, const char *hashalg,
+ const char *sk_provider, const char *sk_pin,
int fd, const char *sig_namespace, struct sshbuf **out,
sshsig_signer *signer, void *signer_ctx)
{
@@ -571,7 +573,7 @@ sshsig_sign_fd(struct sshkey *key, const char *hashalg, const char *sk_provider,
error("%s: hash_file failed: %s", __func__, ssh_err(r));
return r;
}
- if ((r = sshsig_wrap_sign(key, hashalg, sk_provider, b,
+ if ((r = sshsig_wrap_sign(key, hashalg, sk_provider, sk_pin, b,
sig_namespace, out, signer, signer_ctx)) != 0)
goto out;
/* success */
diff --git a/usr.bin/ssh/sshsig.h b/usr.bin/ssh/sshsig.h
index 63cc1ad1a20..44157bc2ace 100644
--- a/usr.bin/ssh/sshsig.h
+++ b/usr.bin/ssh/sshsig.h
@@ -23,7 +23,8 @@ struct sshsigopt;
struct sshkey_sig_details;
typedef int sshsig_signer(struct sshkey *, u_char **, size_t *,
- const u_char *, size_t, const char *, const char *, u_int, void *);
+ const u_char *, size_t, const char *, const char *, const char *,
+ u_int, void *);
/* Buffer-oriented API */
@@ -33,7 +34,7 @@ typedef int sshsig_signer(struct sshkey *, u_char **, size_t *,
* out is populated with the detached signature, or NULL on failure.
*/
int sshsig_signb(struct sshkey *key, const char *hashalg,
- const char *sk_provider, const struct sshbuf *message,
+ const char *sk_provider, const char *sk_pin, const struct sshbuf *message,
const char *sig_namespace, struct sshbuf **out,
sshsig_signer *signer, void *signer_ctx);
@@ -54,7 +55,8 @@ int sshsig_verifyb(struct sshbuf *signature,
* out is populated with the detached signature, or NULL on failure.
*/
int sshsig_sign_fd(struct sshkey *key, const char *hashalg,
- const char *sk_provider, int fd, const char *sig_namespace,
+ const char *sk_provider, const char *sk_pin,
+ int fd, const char *sig_namespace,
struct sshbuf **out, sshsig_signer *signer, void *signer_ctx);
/*