diff options
author | djm@openbsd.org <djm@openbsd.org> | 2019-10-31 22:19:56 +0100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2019-10-31 23:46:09 +0100 |
commit | 486164d060314a7f8bca2a00f53be9e900c5e74d (patch) | |
tree | fd88518f7ef5c9e8b8ea168f670e929b1a81c4a1 /ssh-add.c | |
parent | upstream: add new agent key constraint for U2F/FIDO provider (diff) | |
download | openssh-486164d060314a7f8bca2a00f53be9e900c5e74d.tar.xz openssh-486164d060314a7f8bca2a00f53be9e900c5e74d.zip |
upstream: ssh-add support for U2F/FIDO keys
OpenBSD-Commit-ID: 7f88a5181c982687afedf3130c6ab2bba60f7644
Diffstat (limited to 'ssh-add.c')
-rw-r--r-- | ssh-add.c | 37 |
1 files changed, 27 insertions, 10 deletions
@@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-add.c,v 1.142 2019/10/31 21:19:15 djm Exp $ */ +/* $OpenBSD: ssh-add.c,v 1.143 2019/10/31 21:19:56 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -77,6 +77,7 @@ static char *default_files[] = { _PATH_SSH_CLIENT_ID_DSA, #ifdef OPENSSL_HAS_ECC _PATH_SSH_CLIENT_ID_ECDSA, + _PATH_SSH_CLIENT_ID_ECDSA_SK, #endif #endif /* WITH_OPENSSL */ _PATH_SSH_CLIENT_ID_ED25519, @@ -191,7 +192,8 @@ delete_all(int agent_fd, int qflag) } static int -add_file(int agent_fd, const char *filename, int key_only, int qflag) +add_file(int agent_fd, const char *filename, int key_only, int qflag, + const char *skprovider) { struct sshkey *private, *cert; char *comment = NULL; @@ -310,8 +312,16 @@ add_file(int agent_fd, const char *filename, int key_only, int qflag) ssh_free_identitylist(idlist); } + if (sshkey_type_plain(private->type) != KEY_ECDSA_SK) + skprovider = NULL; /* Don't send constraint for other keys */ + else if (skprovider == NULL) { + fprintf(stderr, "Cannot load security key %s without " + "provider\n", filename); + goto out; + } + if ((r = ssh_add_identity_constrained(agent_fd, private, comment, - lifetime, confirm, maxsign, NULL)) == 0) { + lifetime, confirm, maxsign, skprovider)) == 0) { ret = 0; if (!qflag) { fprintf(stderr, "Identity added: %s (%s)\n", @@ -364,7 +374,7 @@ add_file(int agent_fd, const char *filename, int key_only, int qflag) sshkey_free(cert); if ((r = ssh_add_identity_constrained(agent_fd, private, comment, - lifetime, confirm, maxsign, NULL)) != 0) { + lifetime, confirm, maxsign, skprovider)) != 0) { error("Certificate %s (%s) add failed: %s", certpath, private->cert->key_id, ssh_err(r)); goto out; @@ -529,13 +539,14 @@ lock_agent(int agent_fd, int lock) } static int -do_file(int agent_fd, int deleting, int key_only, char *file, int qflag) +do_file(int agent_fd, int deleting, int key_only, char *file, int qflag, + const char *skprovider) { if (deleting) { if (delete_file(agent_fd, file, key_only, qflag) == -1) return -1; } else { - if (add_file(agent_fd, file, key_only, qflag) == -1) + if (add_file(agent_fd, file, key_only, qflag, skprovider) == -1) return -1; } return 0; @@ -561,6 +572,7 @@ usage(void) fprintf(stderr, " -s pkcs11 Add keys from PKCS#11 provider.\n"); fprintf(stderr, " -e pkcs11 Remove keys provided by PKCS#11 provider.\n"); fprintf(stderr, " -T pubkey Test if ssh-agent can access matching private key.\n"); + fprintf(stderr, " -S provider Specify security key provider.\n"); fprintf(stderr, " -q Be quiet after a successful operation.\n"); fprintf(stderr, " -v Be more verbose.\n"); } @@ -571,7 +583,7 @@ main(int argc, char **argv) extern char *optarg; extern int optind; int agent_fd; - char *pkcs11provider = NULL; + char *pkcs11provider = NULL, *skprovider = NULL; int r, i, ch, deleting = 0, ret = 0, key_only = 0; int xflag = 0, lflag = 0, Dflag = 0, qflag = 0, Tflag = 0; SyslogFacility log_facility = SYSLOG_FACILITY_AUTH; @@ -600,7 +612,9 @@ main(int argc, char **argv) exit(2); } - while ((ch = getopt(argc, argv, "vklLcdDTxXE:e:M:m:qs:t:")) != -1) { + skprovider = getenv("SSH_SK_PROVIDER"); + + while ((ch = getopt(argc, argv, "vklLcdDTxXE:e:M:m:qs:S:t:")) != -1) { switch (ch) { case 'v': if (log_level == SYSLOG_LEVEL_INFO) @@ -656,6 +670,9 @@ main(int argc, char **argv) case 's': pkcs11provider = optarg; break; + case 'S': + skprovider = optarg; + break; case 'e': deleting = 1; pkcs11provider = optarg; @@ -732,7 +749,7 @@ main(int argc, char **argv) if (stat(buf, &st) == -1) continue; if (do_file(agent_fd, deleting, key_only, buf, - qflag) == -1) + qflag, skprovider) == -1) ret = 1; else count++; @@ -742,7 +759,7 @@ main(int argc, char **argv) } else { for (i = 0; i < argc; i++) { if (do_file(agent_fd, deleting, key_only, - argv[i], qflag) == -1) + argv[i], qflag, skprovider) == -1) ret = 1; } } |