version 1.27, 2000/10/19 16:45:16 |
version 1.28, 2000/11/12 19:50:38 |
|
|
#include "kex.h" |
#include "kex.h" |
#include "myproposal.h" |
#include "myproposal.h" |
#include "key.h" |
#include "key.h" |
#include "dsa.h" |
|
#include "sshconnect.h" |
#include "sshconnect.h" |
#include "authfile.h" |
#include "authfile.h" |
#include "cli.h" |
#include "cli.h" |
|
|
|
|
/* key, cert */ |
/* key, cert */ |
server_host_key_blob = packet_get_string(&sbloblen); |
server_host_key_blob = packet_get_string(&sbloblen); |
server_host_key = dsa_key_from_blob(server_host_key_blob, sbloblen); |
server_host_key = key_from_blob(server_host_key_blob, sbloblen); |
if (server_host_key == NULL) |
if (server_host_key == NULL) |
fatal("cannot decode server_host_key_blob"); |
fatal("cannot decode server_host_key_blob"); |
|
|
|
|
fprintf(stderr, "%02x", (hash[i])&0xff); |
fprintf(stderr, "%02x", (hash[i])&0xff); |
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
#endif |
#endif |
if (dsa_verify(server_host_key, (unsigned char *)signature, slen, hash, 20) != 1) |
if (key_verify(server_host_key, (unsigned char *)signature, slen, hash, 20) != 1) |
fatal("dsa_verify failed for server_host_key"); |
fatal("key_verify failed for server_host_key"); |
key_free(server_host_key); |
key_free(server_host_key); |
|
|
kex_derive_keys(kex, hash, shared_secret); |
kex_derive_keys(kex, hash, shared_secret); |
|
|
|
|
/* key, cert */ |
/* key, cert */ |
server_host_key_blob = packet_get_string(&sbloblen); |
server_host_key_blob = packet_get_string(&sbloblen); |
server_host_key = dsa_key_from_blob(server_host_key_blob, sbloblen); |
server_host_key = key_from_blob(server_host_key_blob, sbloblen); |
if (server_host_key == NULL) |
if (server_host_key == NULL) |
fatal("cannot decode server_host_key_blob"); |
fatal("cannot decode server_host_key_blob"); |
|
|
|
|
fprintf(stderr, "%02x", (hash[i])&0xff); |
fprintf(stderr, "%02x", (hash[i])&0xff); |
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
#endif |
#endif |
if (dsa_verify(server_host_key, (unsigned char *)signature, slen, hash, 20) != 1) |
if (key_verify(server_host_key, (unsigned char *)signature, slen, hash, 20) != 1) |
fatal("dsa_verify failed for server_host_key"); |
fatal("key_verify failed for server_host_key"); |
key_free(server_host_key); |
key_free(server_host_key); |
|
|
kex_derive_keys(kex, hash, shared_secret); |
kex_derive_keys(kex, hash, shared_secret); |
|
|
Authmethod authmethods[] = { |
Authmethod authmethods[] = { |
{"publickey", |
{"publickey", |
userauth_pubkey, |
userauth_pubkey, |
&options.dsa_authentication, |
&options.pubkey_authentication, |
NULL}, |
NULL}, |
{"password", |
{"password", |
userauth_passwd, |
userauth_passwd, |
|
|
int ret = -1; |
int ret = -1; |
int have_sig = 1; |
int have_sig = 1; |
|
|
dsa_make_key_blob(k, &blob, &bloblen); |
if (key_to_blob(k, &blob, &bloblen) == 0) { |
|
/* we cannot handle this key */ |
|
return 0; |
|
} |
/* data to be signed */ |
/* data to be signed */ |
buffer_init(&b); |
buffer_init(&b); |
if (datafellows & SSH_OLD_SESSIONID) { |
if (datafellows & SSH_OLD_SESSIONID) { |
|
|
authctxt->service); |
authctxt->service); |
buffer_put_cstring(&b, authctxt->method->name); |
buffer_put_cstring(&b, authctxt->method->name); |
buffer_put_char(&b, have_sig); |
buffer_put_char(&b, have_sig); |
buffer_put_cstring(&b, KEX_DSS); |
buffer_put_cstring(&b, key_ssh_name(k)); |
buffer_put_string(&b, blob, bloblen); |
buffer_put_string(&b, blob, bloblen); |
|
|
/* generate signature */ |
/* generate signature */ |
|
|
buffer_free(&b); |
buffer_free(&b); |
return 0; |
return 0; |
} |
} |
#ifdef DEBUG_DSS |
#ifdef DEBUG_PK |
buffer_dump(&b); |
buffer_dump(&b); |
#endif |
#endif |
if (datafellows & SSH_BUG_PUBKEYAUTH) { |
if (datafellows & SSH_BUG_PUBKEYAUTH) { |
|
|
buffer_put_cstring(&b, authctxt->service); |
buffer_put_cstring(&b, authctxt->service); |
buffer_put_cstring(&b, authctxt->method->name); |
buffer_put_cstring(&b, authctxt->method->name); |
buffer_put_char(&b, have_sig); |
buffer_put_char(&b, have_sig); |
buffer_put_cstring(&b, KEX_DSS); |
buffer_put_cstring(&b, key_ssh_name(k)); |
buffer_put_string(&b, blob, bloblen); |
buffer_put_string(&b, blob, bloblen); |
} |
} |
xfree(blob); |
xfree(blob); |
|
|
} |
} |
|
|
/* sign callback */ |
/* sign callback */ |
int dsa_sign_cb(Authctxt *authctxt, Key *key, unsigned char **sigp, int *lenp, |
int key_sign_cb(Authctxt *authctxt, Key *key, unsigned char **sigp, int *lenp, |
unsigned char *data, int datalen) |
unsigned char *data, int datalen) |
{ |
{ |
return dsa_sign(key, sigp, lenp, data, datalen); |
return key_sign(key, sigp, lenp, data, datalen); |
} |
} |
|
|
int |
int |
|
|
} |
} |
debug("try pubkey: %s", filename); |
debug("try pubkey: %s", filename); |
|
|
k = key_new(KEY_DSA); |
k = key_new(KEY_UNSPEC); |
if (!load_private_key(filename, "", k, NULL)) { |
if (!load_private_key(filename, "", k, NULL)) { |
int success = 0; |
int success = 0; |
char *passphrase; |
char *passphrase; |
char prompt[300]; |
char prompt[300]; |
snprintf(prompt, sizeof prompt, |
snprintf(prompt, sizeof prompt, |
"Enter passphrase for %s key '%.100s': ", |
"Enter passphrase for key '%.100s': ", filename); |
key_type(k), filename); |
|
for (i = 0; i < options.number_of_password_prompts; i++) { |
for (i = 0; i < options.number_of_password_prompts; i++) { |
passphrase = read_passphrase(prompt, 0); |
passphrase = read_passphrase(prompt, 0); |
if (strcmp(passphrase, "") != 0) { |
if (strcmp(passphrase, "") != 0) { |
|
|
return 0; |
return 0; |
} |
} |
} |
} |
ret = sign_and_send_pubkey(authctxt, k, dsa_sign_cb); |
ret = sign_and_send_pubkey(authctxt, k, key_sign_cb); |
key_free(k); |
key_free(k); |
return ret; |
return ret; |
} |
} |
|
|
userauth_pubkey_agent(Authctxt *authctxt) |
userauth_pubkey_agent(Authctxt *authctxt) |
{ |
{ |
static int called = 0; |
static int called = 0; |
|
int ret = 0; |
char *comment; |
char *comment; |
Key *k; |
Key *k; |
int ret; |
|
|
|
if (called == 0) { |
if (called == 0) { |
k = ssh_get_first_identity(authctxt->agent, &comment, 2); |
if (ssh_get_num_identities(authctxt->agent, 2) == 0) |
|
debug2("userauth_pubkey_agent: no keys at all"); |
called = 1; |
called = 1; |
} else { |
|
k = ssh_get_next_identity(authctxt->agent, &comment, 2); |
|
} |
} |
|
k = ssh_get_next_identity(authctxt->agent, &comment, 2); |
if (k == NULL) { |
if (k == NULL) { |
debug2("no more DSA keys from agent"); |
debug2("userauth_pubkey_agent: no more keys"); |
return 0; |
} else { |
|
debug("userauth_pubkey_agent: trying agent key %s", comment); |
|
xfree(comment); |
|
ret = sign_and_send_pubkey(authctxt, k, agent_sign_cb); |
|
key_free(k); |
} |
} |
debug("trying DSA agent key %s", comment); |
if (ret == 0) |
xfree(comment); |
debug2("userauth_pubkey_agent: no message sent"); |
ret = sign_and_send_pubkey(authctxt, k, agent_sign_cb); |
|
key_free(k); |
|
return ret; |
return ret; |
} |
} |
|
|
|
|
static int idx = 0; |
static int idx = 0; |
int sent = 0; |
int sent = 0; |
|
|
if (authctxt->agent != NULL) |
if (authctxt->agent != NULL) { |
sent = userauth_pubkey_agent(authctxt); |
do { |
while (sent == 0 && idx < options.num_identity_files2) |
sent = userauth_pubkey_agent(authctxt); |
sent = userauth_pubkey_identity(authctxt, options.identity_files2[idx++]); |
} while(!sent && authctxt->agent->howmany > 0); |
|
} |
|
while (!sent && idx < options.num_identity_files) { |
|
if (options.identity_files_type[idx] != KEY_RSA1) |
|
sent = userauth_pubkey_identity(authctxt, |
|
options.identity_files[idx]); |
|
idx++; |
|
} |
return sent; |
return sent; |
} |
} |
|
|