summaryrefslogtreecommitdiff
path: root/ssh-add.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh-add.c')
-rw-r--r--ssh-add.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/ssh-add.c b/ssh-add.c
index 738644d27..008084704 100644
--- a/ssh-add.c
+++ b/ssh-add.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-add.c,v 1.103 2011/10/18 23:37:42 djm Exp $ */ 1/* $OpenBSD: ssh-add.c,v 1.105 2012/12/05 15:42:52 markus Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -96,10 +96,10 @@ clear_pass(void)
96} 96}
97 97
98static int 98static int
99delete_file(AuthenticationConnection *ac, const char *filename) 99delete_file(AuthenticationConnection *ac, const char *filename, int key_only)
100{ 100{
101 Key *public; 101 Key *public = NULL, *cert = NULL;
102 char *comment = NULL; 102 char *certpath = NULL, *comment = NULL;
103 int ret = -1; 103 int ret = -1;
104 104
105 public = key_load_public(filename, &comment); 105 public = key_load_public(filename, &comment);
@@ -113,8 +113,33 @@ delete_file(AuthenticationConnection *ac, const char *filename)
113 } else 113 } else
114 fprintf(stderr, "Could not remove identity: %s\n", filename); 114 fprintf(stderr, "Could not remove identity: %s\n", filename);
115 115
116 key_free(public); 116 if (key_only)
117 xfree(comment); 117 goto out;
118
119 /* Now try to delete the corresponding certificate too */
120 free(comment);
121 comment = NULL;
122 xasprintf(&certpath, "%s-cert.pub", filename);
123 if ((cert = key_load_public(certpath, &comment)) == NULL)
124 goto out;
125 if (!key_equal_public(cert, public))
126 fatal("Certificate %s does not match private key %s",
127 certpath, filename);
128
129 if (ssh_remove_identity(ac, cert)) {
130 fprintf(stderr, "Identity removed: %s (%s)\n", certpath,
131 comment);
132 ret = 0;
133 } else
134 fprintf(stderr, "Could not remove identity: %s\n", certpath);
135
136 out:
137 if (cert != NULL)
138 key_free(cert);
139 if (public != NULL)
140 key_free(public);
141 free(certpath);
142 free(comment);
118 143
119 return ret; 144 return ret;
120} 145}
@@ -354,7 +379,7 @@ static int
354do_file(AuthenticationConnection *ac, int deleting, int key_only, char *file) 379do_file(AuthenticationConnection *ac, int deleting, int key_only, char *file)
355{ 380{
356 if (deleting) { 381 if (deleting) {
357 if (delete_file(ac, file) == -1) 382 if (delete_file(ac, file, key_only) == -1)
358 return -1; 383 return -1;
359 } else { 384 } else {
360 if (add_file(ac, file, key_only) == -1) 385 if (add_file(ac, file, key_only) == -1)