version 1.58, 2001/06/26 05:07:43 |
version 1.59, 2001/06/26 05:33:34 |
|
|
#include "compat.h" |
#include "compat.h" |
#include "log.h" |
#include "log.h" |
|
|
|
#ifdef SMARTCARD |
|
#include <openssl/engine.h> |
|
#include "scard.h" |
|
#endif |
|
|
typedef struct { |
typedef struct { |
int fd; |
int fd; |
enum { |
enum { |
|
|
success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE); |
success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE); |
} |
} |
|
|
|
|
|
#ifdef SMARTCARD |
|
static void |
|
process_add_smartcard_key (SocketEntry *e) |
|
{ |
|
Idtab *tab; |
|
Key *n = NULL, *k = NULL; |
|
int success = 0; |
|
int sc_reader_num = 0; |
|
|
|
sc_reader_num = buffer_get_int(&e->input); |
|
|
|
k = sc_get_key(sc_reader_num); |
|
if (k == NULL) { |
|
error("sc_get_pubkey failed"); |
|
goto send; |
|
} |
|
success = 1; |
|
|
|
tab = idtab_lookup(1); |
|
if (lookup_private_key(k, NULL, 1) == NULL) { |
|
if (tab->nentries == 0) |
|
tab->identities = xmalloc(sizeof(Identity)); |
|
else |
|
tab->identities = xrealloc(tab->identities, |
|
(tab->nentries + 1) * sizeof(Identity)); |
|
n = key_new(KEY_RSA1); |
|
BN_copy(n->rsa->n, k->rsa->n); |
|
BN_copy(n->rsa->e, k->rsa->e); |
|
RSA_set_method(n->rsa, sc_get_engine()); |
|
tab->identities[tab->nentries].key = n; |
|
tab->identities[tab->nentries].comment = |
|
xstrdup("rsa1 smartcard"); |
|
tab->nentries++; |
|
} |
|
tab = idtab_lookup(2); |
|
if (lookup_private_key(k, NULL, 2) == NULL) { |
|
if (tab->nentries == 0) |
|
tab->identities = xmalloc(sizeof(Identity)); |
|
else |
|
tab->identities = xrealloc(tab->identities, |
|
(tab->nentries + 1) * sizeof(Identity)); |
|
n = key_new(KEY_RSA); |
|
BN_copy(n->rsa->n, k->rsa->n); |
|
BN_copy(n->rsa->e, k->rsa->e); |
|
RSA_set_method(n->rsa, sc_get_engine()); |
|
tab->identities[tab->nentries].key = n; |
|
tab->identities[tab->nentries].comment = |
|
xstrdup("rsa smartcard"); |
|
tab->nentries++; |
|
} |
|
key_free(k); |
|
send: |
|
buffer_put_int(&e->output, 1); |
|
buffer_put_char(&e->output, |
|
success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE); |
|
} |
|
|
|
static void |
|
process_remove_smartcard_key(SocketEntry *e) |
|
{ |
|
Key *k = NULL, *private; |
|
int idx; |
|
int success = 0; |
|
int sc_reader_num = 0; |
|
|
|
sc_reader_num = buffer_get_int(&e->input); |
|
|
|
if ((k = sc_get_key(sc_reader_num)) == NULL) { |
|
error("sc_get_pubkey failed"); |
|
} else { |
|
private = lookup_private_key(k, &idx, 1); |
|
if (private != NULL) { |
|
Idtab *tab = idtab_lookup(1); |
|
key_free(tab->identities[idx].key); |
|
xfree(tab->identities[idx].comment); |
|
if (idx != tab->nentries) |
|
tab->identities[idx] = tab->identities[tab->nentries]; |
|
tab->nentries--; |
|
success = 1; |
|
} |
|
private = lookup_private_key(k, &idx, 2); |
|
if (private != NULL) { |
|
Idtab *tab = idtab_lookup(2); |
|
key_free(tab->identities[idx].key); |
|
xfree(tab->identities[idx].comment); |
|
if (idx != tab->nentries) |
|
tab->identities[idx] = tab->identities[tab->nentries]; |
|
tab->nentries--; |
|
success = 1; |
|
} |
|
key_free(k); |
|
} |
|
|
|
buffer_put_int(&e->output, 1); |
|
buffer_put_char(&e->output, |
|
success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE); |
|
} |
|
#endif |
|
|
/* dispatch incoming messages */ |
/* dispatch incoming messages */ |
|
|
static void |
static void |
|
|
buffer_consume(&e->input, 4); |
buffer_consume(&e->input, 4); |
type = buffer_get_char(&e->input); |
type = buffer_get_char(&e->input); |
|
|
|
debug("type %d", type); |
switch (type) { |
switch (type) { |
/* ssh1 */ |
/* ssh1 */ |
case SSH_AGENTC_RSA_CHALLENGE: |
case SSH_AGENTC_RSA_CHALLENGE: |
|
|
case SSH2_AGENTC_REMOVE_ALL_IDENTITIES: |
case SSH2_AGENTC_REMOVE_ALL_IDENTITIES: |
process_remove_all_identities(e, 2); |
process_remove_all_identities(e, 2); |
break; |
break; |
|
#ifdef SMARTCARD |
|
case SSH_AGENTC_ADD_SMARTCARD_KEY: |
|
process_add_smartcard_key(e); |
|
break; |
|
case SSH_AGENTC_REMOVE_SMARTCARD_KEY: |
|
process_remove_smartcard_key(e); |
|
break; |
|
#endif |
default: |
default: |
/* Unknown message. Respond with failure. */ |
/* Unknown message. Respond with failure. */ |
error("Unknown message %d", type); |
error("Unknown message %d", type); |