diff options
author | 2012-12-02 20:42:15 +0000 | |
---|---|---|
committer | 2012-12-02 20:42:15 +0000 | |
commit | 1663e249d97adca8f027658af6e1bf437480a1e5 (patch) | |
tree | b1d84d3f84d037ac46c13db9a4157454b9530bfa | |
parent | Fixes logging of partial authentication when privsep is enabled (diff) | |
download | wireguard-openbsd-1663e249d97adca8f027658af6e1bf437480a1e5.tar.xz wireguard-openbsd-1663e249d97adca8f027658af6e1bf437480a1e5.zip |
make deleting explicit keys "ssh-add -d" symmetric with adding keys -
try to delete the corresponding certificate too and respect the -k option
to allow deleting of the key only; feedback and ok markus@
-rw-r--r-- | usr.bin/ssh/ssh-add.1 | 14 | ||||
-rw-r--r-- | usr.bin/ssh/ssh-add.c | 38 |
2 files changed, 38 insertions, 14 deletions
diff --git a/usr.bin/ssh/ssh-add.1 b/usr.bin/ssh/ssh-add.1 index aec620deaf3..af93762ae94 100644 --- a/usr.bin/ssh/ssh-add.1 +++ b/usr.bin/ssh/ssh-add.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ssh-add.1,v 1.56 2011/10/18 05:00:48 djm Exp $ +.\" $OpenBSD: ssh-add.1,v 1.57 2012/12/02 20:42:15 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: October 18 2011 $ +.Dd $Mdocdate: December 2 2012 $ .Dt SSH-ADD 1 .Os .Sh NAME @@ -98,10 +98,10 @@ Deletes all identities from the agent. Instead of adding identities, removes identities from the agent. If .Nm -has been run without arguments, the keys for the default identities will -be removed. +has been run without arguments, the keys for the default identities and +their corresponding certificateswill be removed. Otherwise, the argument list will be interpreted as a list of paths to -public key files and matching keys will be removed from the agent. +public key files to specify keys and certificates to be removed from the agent. If no public key is found at a given path, .Nm will append @@ -111,8 +111,8 @@ and retry. Remove keys provided by the PKCS#11 shared library .Ar pkcs11 . .It Fl k -When loading keys into the agent, load plain private keys only and skip -certificates. +When loading keys into or deleting keys from the agent, process plain private +keys only and skip certificates. .It Fl L Lists public key parameters of all identities currently represented by the agent. diff --git a/usr.bin/ssh/ssh-add.c b/usr.bin/ssh/ssh-add.c index ab6ed511529..4045efc0297 100644 --- a/usr.bin/ssh/ssh-add.c +++ b/usr.bin/ssh/ssh-add.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-add.c,v 1.103 2011/10/18 23:37:42 djm Exp $ */ +/* $OpenBSD: ssh-add.c,v 1.104 2012/12/02 20:42:15 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -90,10 +90,10 @@ clear_pass(void) } static int -delete_file(AuthenticationConnection *ac, const char *filename) +delete_file(AuthenticationConnection *ac, const char *filename, int key_only) { - Key *public; - char *comment = NULL; + Key *public = NULL, *cert = NULL; + char *certpath = NULL, *comment = NULL; int ret = -1; public = key_load_public(filename, &comment); @@ -107,8 +107,32 @@ delete_file(AuthenticationConnection *ac, const char *filename) } else fprintf(stderr, "Could not remove identity: %s\n", filename); - key_free(public); - xfree(comment); + if (key_only) + goto out; + + /* Now try to delete the corresponding certificate too */ + free(comment); + xasprintf(&certpath, "%s-cert.pub", filename); + if ((cert = key_load_public(certpath, &comment)) == NULL) + goto out; + if (!key_equal_public(cert, public)) + fatal("Certificate %s does not match private key %s", + certpath, filename); + + if (ssh_remove_identity(ac, cert)) { + fprintf(stderr, "Identity removed: %s (%s)\n", certpath, + comment); + ret = 0; + } else + fprintf(stderr, "Could not remove identity: %s\n", certpath); + + out: + if (cert != NULL) + key_free(cert); + if (public != NULL) + key_free(public); + free(certpath); + free(comment); return ret; } @@ -348,7 +372,7 @@ static int do_file(AuthenticationConnection *ac, int deleting, int key_only, char *file) { if (deleting) { - if (delete_file(ac, file) == -1) + if (delete_file(ac, file, key_only) == -1) return -1; } else { if (add_file(ac, file, key_only) == -1) |