diff options
author | Markus Friedl <markus@cvs.openbsd.org> | 2000-09-05 19:18:49 +0000 |
---|---|---|
committer | Markus Friedl <markus@cvs.openbsd.org> | 2000-09-05 19:18:49 +0000 |
commit | 94afb990a5a380e734bfdc73c614934998b8e97e (patch) | |
tree | f866031dbaa180918005eb79828cd180dd031faf /usr.bin | |
parent | 26f2c634cf644276cd544c193b2a8a6a7b2674fe (diff) |
enable ssh-add -d for DSA keys
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/ssh/authfile.c | 57 | ||||
-rw-r--r-- | usr.bin/ssh/ssh-add.c | 10 |
2 files changed, 63 insertions, 4 deletions
diff --git a/usr.bin/ssh/authfile.c b/usr.bin/ssh/authfile.c index 71c4a5d84ee..9fe37cd58e1 100644 --- a/usr.bin/ssh/authfile.c +++ b/usr.bin/ssh/authfile.c @@ -15,7 +15,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: authfile.c,v 1.17 2000/06/20 01:39:38 markus Exp $"); +RCSID("$OpenBSD: authfile.c,v 1.18 2000/09/05 19:18:47 markus Exp $"); #include <openssl/bn.h> #include <openssl/dsa.h> @@ -262,6 +262,7 @@ load_public_key_rsa(const char *filename, RSA * pub, char **comment_return) return 1; } +/* load public key from private-key file */ int load_public_key(const char *filename, Key * key, char **comment_return) { @@ -491,3 +492,57 @@ load_private_key(const char *filename, const char *passphrase, Key *key, close(fd); return ret; } + +int +do_load_public_key(const char *filename, Key *k, char **commentp) +{ + FILE *f; + unsigned int bits; + char line[1024]; + char *cp; + + f = fopen(filename, "r"); + if (f != NULL) { + while (fgets(line, sizeof(line), f)) { + line[sizeof(line)-1] = '\0'; + cp = line; + switch(*cp){ + case '#': + case '\n': + case '\0': + continue; + } + /* Skip leading whitespace. */ + for (; *cp && (*cp == ' ' || *cp == '\t'); cp++) + ; + if (*cp) { + bits = key_read(k, &cp); + if (bits != 0) { + if (commentp) + *commentp=xstrdup(filename); + fclose(f); + return 1; + } + } + } + fclose(f); + } + return 0; +} + +/* load public key from pubkey file */ +int +try_load_public_key(const char *filename, Key *k, char **commentp) +{ + char pub[MAXPATHLEN]; + + if (do_load_public_key(filename, k, commentp) == 1) + return 1; + if (strlcpy(pub, filename, sizeof pub) >= MAXPATHLEN) + return 0; + if (strlcat(pub, ".pub", sizeof pub) >= MAXPATHLEN) + return 0; + if (do_load_public_key(pub, k, commentp) == 1) + return 1; + return 0; +} diff --git a/usr.bin/ssh/ssh-add.c b/usr.bin/ssh/ssh-add.c index 48053739b66..cebecc21719 100644 --- a/usr.bin/ssh/ssh-add.c +++ b/usr.bin/ssh/ssh-add.c @@ -10,7 +10,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: ssh-add.c,v 1.20 2000/08/28 03:50:54 deraadt Exp $"); +RCSID("$OpenBSD: ssh-add.c,v 1.21 2000/09/05 19:18:48 markus Exp $"); #include <openssl/evp.h> #include <openssl/rsa.h> @@ -31,8 +31,12 @@ delete_file(AuthenticationConnection *ac, const char *filename) public = key_new(KEY_RSA); if (!load_public_key(filename, public, &comment)) { - printf("Bad key file %s: %s\n", filename, strerror(errno)); - return; + key_free(public); + public = key_new(KEY_DSA); + if (!try_load_public_key(filename, public, &comment)) { + printf("Bad key file %s\n", filename); + return; + } } if (ssh_remove_identity(ac, public)) fprintf(stderr, "Identity removed: %s (%s)\n", filename, comment); |