version 1.16, 2000/04/26 20:56:29 |
version 1.16.2.1, 2000/09/01 18:23:23 |
|
|
* All rights reserved |
* All rights reserved |
* Created: Thu Apr 6 00:52:24 1995 ylo |
* Created: Thu Apr 6 00:52:24 1995 ylo |
* Adds an identity to the authentication server, or removes an identity. |
* Adds an identity to the authentication server, or removes an identity. |
|
* |
|
* SSH2 implementation, |
|
* Copyright (c) 2000 Markus Friedl. All rights reserved. |
*/ |
*/ |
|
|
#include "includes.h" |
#include "includes.h" |
RCSID("$Id$"); |
RCSID("$OpenBSD$"); |
|
|
|
#include <openssl/evp.h> |
#include <openssl/rsa.h> |
#include <openssl/rsa.h> |
#include <openssl/dsa.h> |
#include <openssl/dsa.h> |
|
|
#include "rsa.h" |
#include "rsa.h" |
#include "ssh.h" |
#include "ssh.h" |
#include "xmalloc.h" |
#include "xmalloc.h" |
#include "authfd.h" |
|
#include "fingerprint.h" |
|
#include "key.h" |
#include "key.h" |
|
#include "authfd.h" |
#include "authfile.h" |
#include "authfile.h" |
|
|
void |
void |
|
|
printf("Bad key file %s: %s\n", filename, strerror(errno)); |
printf("Bad key file %s: %s\n", filename, strerror(errno)); |
return; |
return; |
} |
} |
if (ssh_remove_identity(ac, public->rsa)) |
if (ssh_remove_identity(ac, public)) |
fprintf(stderr, "Identity removed: %s (%s)\n", filename, comment); |
fprintf(stderr, "Identity removed: %s (%s)\n", filename, comment); |
else |
else |
fprintf(stderr, "Could not remove identity: %s\n", filename); |
fprintf(stderr, "Could not remove identity: %s\n", filename); |
|
|
xfree(comment); |
xfree(comment); |
} |
} |
|
|
|
/* Send a request to remove all identities. */ |
void |
void |
delete_all(AuthenticationConnection *ac) |
delete_all(AuthenticationConnection *ac) |
{ |
{ |
/* Send a request to remove all identities. */ |
int success = 1; |
if (ssh_remove_all_identities(ac)) |
|
|
if (!ssh_remove_all_identities(ac, 1)) |
|
success = 0; |
|
/* ignore error-code for ssh2 */ |
|
ssh_remove_all_identities(ac, 2); |
|
|
|
if (success) |
fprintf(stderr, "All identities removed.\n"); |
fprintf(stderr, "All identities removed.\n"); |
else |
else |
fprintf(stderr, "Failed to remove all identitities.\n"); |
fprintf(stderr, "Failed to remove all identitities.\n"); |
|
|
void |
void |
add_file(AuthenticationConnection *ac, const char *filename) |
add_file(AuthenticationConnection *ac, const char *filename) |
{ |
{ |
|
struct stat st; |
Key *public; |
Key *public; |
Key *private; |
Key *private; |
char *saved_comment, *comment, *askpass = NULL; |
char *saved_comment, *comment, *askpass = NULL; |
char buf[1024], msg[1024]; |
char buf[1024], msg[1024]; |
int success; |
int success; |
int interactive = isatty(STDIN_FILENO); |
int interactive = isatty(STDIN_FILENO); |
|
int type = KEY_RSA; |
|
|
|
if (stat(filename, &st) < 0) { |
|
perror(filename); |
|
exit(1); |
|
} |
|
/* |
|
* try to load the public key. right now this only works for RSA, |
|
* since DSA keys are fully encrypted |
|
*/ |
public = key_new(KEY_RSA); |
public = key_new(KEY_RSA); |
if (!load_public_key(filename, public, &saved_comment)) { |
if (!load_public_key(filename, public, &saved_comment)) { |
printf("Bad key file %s: %s\n", filename, strerror(errno)); |
/* ok, so we will asume this is a DSA key */ |
return; |
type = KEY_DSA; |
|
saved_comment = xstrdup(filename); |
} |
} |
key_free(public); |
key_free(public); |
|
|
|
|
} |
} |
|
|
/* At first, try empty passphrase */ |
/* At first, try empty passphrase */ |
private = key_new(KEY_RSA); |
private = key_new(type); |
success = load_private_key(filename, "", private, &comment); |
success = load_private_key(filename, "", private, &comment); |
if (!success) { |
if (!success) { |
printf("Need passphrase for %.200s\n", filename); |
printf("Need passphrase for %.200s\n", filename); |
|
|
strlcpy(msg, "Bad passphrase, try again", sizeof msg); |
strlcpy(msg, "Bad passphrase, try again", sizeof msg); |
} |
} |
} |
} |
xfree(saved_comment); |
xfree(comment); |
|
if (ssh_add_identity(ac, private, saved_comment)) |
if (ssh_add_identity(ac, private->rsa, comment)) |
fprintf(stderr, "Identity added: %s (%s)\n", filename, saved_comment); |
fprintf(stderr, "Identity added: %s (%s)\n", filename, comment); |
|
else |
else |
fprintf(stderr, "Could not add identity: %s\n", filename); |
fprintf(stderr, "Could not add identity: %s\n", filename); |
key_free(private); |
key_free(private); |
xfree(comment); |
xfree(saved_comment); |
} |
} |
|
|
void |
void |
list_identities(AuthenticationConnection *ac, int fp) |
list_identities(AuthenticationConnection *ac, int fp) |
{ |
{ |
BIGNUM *e, *n; |
Key *key; |
int status; |
|
char *comment; |
char *comment; |
int had_identities; |
int had_identities = 0; |
|
int version; |
|
|
e = BN_new(); |
for (version = 1; version <= 2; version++) { |
n = BN_new(); |
for (key = ssh_get_first_identity(ac, &comment, version); |
had_identities = 0; |
key != NULL; |
for (status = ssh_get_first_identity(ac, e, n, &comment); |
key = ssh_get_next_identity(ac, &comment, version)) { |
status; |
had_identities = 1; |
status = ssh_get_next_identity(ac, e, n, &comment)) { |
if (fp) { |
unsigned int bits = BN_num_bits(n); |
printf("%d %s %s\n", |
had_identities = 1; |
key_size(key), key_fingerprint(key), comment); |
if (fp) { |
|
printf("%d %s %s\n", bits, fingerprint(e, n), comment); |
|
} else { |
|
char *ebuf, *nbuf; |
|
ebuf = BN_bn2dec(e); |
|
if (ebuf == NULL) { |
|
error("list_identities: BN_bn2dec(e) failed."); |
|
} else { |
} else { |
nbuf = BN_bn2dec(n); |
if (!key_write(key, stdout)) |
if (nbuf == NULL) { |
fprintf(stderr, "key_write failed"); |
error("list_identities: BN_bn2dec(n) failed."); |
fprintf(stdout, " %s\n", comment); |
} else { |
|
printf("%d %s %s %s\n", bits, ebuf, nbuf, comment); |
|
free(nbuf); |
|
} |
|
free(ebuf); |
|
} |
} |
|
key_free(key); |
|
xfree(comment); |
} |
} |
xfree(comment); |
|
} |
} |
BN_clear_free(e); |
|
BN_clear_free(n); |
|
if (!had_identities) |
if (!had_identities) |
printf("The agent has no identities.\n"); |
printf("The agent has no identities.\n"); |
} |
} |
|
|
__progname); |
__progname); |
exit(1); |
exit(1); |
} |
} |
|
SSLeay_add_all_algorithms(); |
|
|
/* At first, get a connection to the authentication agent. */ |
/* At first, get a connection to the authentication agent. */ |
ac = ssh_get_authentication_connection(); |
ac = ssh_get_authentication_connection(); |
if (ac == NULL) { |
if (ac == NULL) { |
|
|
if (no_files) { |
if (no_files) { |
pw = getpwuid(getuid()); |
pw = getpwuid(getuid()); |
if (!pw) { |
if (!pw) { |
fprintf(stderr, "No user found with uid %d\n", (int) getuid()); |
fprintf(stderr, "No user found with uid %u\n", |
|
(u_int)getuid()); |
ssh_close_authentication_connection(ac); |
ssh_close_authentication_connection(ac); |
exit(1); |
exit(1); |
} |
} |