version 1.10, 2000/05/08 17:42:25 |
version 1.10.2.1, 2000/06/12 02:37:38 |
|
|
int session_id2_len = 0; |
int session_id2_len = 0; |
|
|
void |
void |
ssh_kex2(char *host, struct sockaddr *hostaddr) |
ssh_kex_dh(Kex *kex, char *host, struct sockaddr *hostaddr, |
|
Buffer *client_kexinit, Buffer *server_kexinit) |
{ |
{ |
Kex *kex; |
int plen, dlen; |
char *cprop[PROPOSAL_MAX]; |
|
char *sprop[PROPOSAL_MAX]; |
|
Buffer *client_kexinit; |
|
Buffer *server_kexinit; |
|
int payload_len, dlen; |
|
unsigned int klen, kout; |
unsigned int klen, kout; |
char *ptr; |
|
char *signature = NULL; |
char *signature = NULL; |
unsigned int slen; |
unsigned int slen; |
char *server_host_key_blob = NULL; |
char *server_host_key_blob = NULL; |
|
|
DH *dh; |
DH *dh; |
BIGNUM *dh_server_pub = 0; |
BIGNUM *dh_server_pub = 0; |
BIGNUM *shared_secret = 0; |
BIGNUM *shared_secret = 0; |
int i; |
|
unsigned char *kbuf; |
unsigned char *kbuf; |
unsigned char *hash; |
unsigned char *hash; |
|
|
/* KEXINIT */ |
|
|
|
debug("Sending KEX init."); |
|
if (options.ciphers != NULL) { |
|
myproposal[PROPOSAL_ENC_ALGS_CTOS] = |
|
myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers; |
|
} else if (options.cipher == SSH_CIPHER_3DES) { |
|
myproposal[PROPOSAL_ENC_ALGS_CTOS] = |
|
myproposal[PROPOSAL_ENC_ALGS_STOC] = |
|
cipher_name(SSH_CIPHER_3DES_CBC); |
|
} else if (options.cipher == SSH_CIPHER_BLOWFISH) { |
|
myproposal[PROPOSAL_ENC_ALGS_CTOS] = |
|
myproposal[PROPOSAL_ENC_ALGS_STOC] = |
|
cipher_name(SSH_CIPHER_BLOWFISH_CBC); |
|
} |
|
if (options.compression) { |
|
myproposal[PROPOSAL_COMP_ALGS_CTOS] = "zlib"; |
|
myproposal[PROPOSAL_COMP_ALGS_STOC] = "zlib"; |
|
} else { |
|
myproposal[PROPOSAL_COMP_ALGS_CTOS] = "none"; |
|
myproposal[PROPOSAL_COMP_ALGS_STOC] = "none"; |
|
} |
|
for (i = 0; i < PROPOSAL_MAX; i++) |
|
cprop[i] = xstrdup(myproposal[i]); |
|
|
|
client_kexinit = kex_init(cprop); |
|
packet_start(SSH2_MSG_KEXINIT); |
|
packet_put_raw(buffer_ptr(client_kexinit), buffer_len(client_kexinit)); |
|
packet_send(); |
|
packet_write_wait(); |
|
|
|
debug("done"); |
|
|
|
packet_read_expect(&payload_len, SSH2_MSG_KEXINIT); |
|
|
|
/* save payload for session_id */ |
|
server_kexinit = xmalloc(sizeof(*server_kexinit)); |
|
buffer_init(server_kexinit); |
|
ptr = packet_get_raw(&payload_len); |
|
buffer_append(server_kexinit, ptr, payload_len); |
|
|
|
/* skip cookie */ |
|
for (i = 0; i < 16; i++) |
|
(void) packet_get_char(); |
|
/* kex init proposal strings */ |
|
for (i = 0; i < PROPOSAL_MAX; i++) { |
|
sprop[i] = packet_get_string(NULL); |
|
debug("got kexinit string: %s", sprop[i]); |
|
} |
|
i = (int) packet_get_char(); |
|
debug("first kex follow == %d", i); |
|
i = packet_get_int(); |
|
debug("reserved == %d", i); |
|
packet_done(); |
|
|
|
debug("done read kexinit"); |
|
kex = kex_choose_conf(cprop, sprop, 0); |
|
|
|
/* KEXDH */ |
|
|
|
debug("Sending SSH2_MSG_KEXDH_INIT."); |
debug("Sending SSH2_MSG_KEXDH_INIT."); |
|
|
/* generate and send 'e', client DH public key */ |
/* generate and send 'e', client DH public key */ |
dh = dh_new_group1(); |
dh = dh_new_group1(); |
packet_start(SSH2_MSG_KEXDH_INIT); |
packet_start(SSH2_MSG_KEXDH_INIT); |
|
|
|
|
debug("Wait SSH2_MSG_KEXDH_REPLY."); |
debug("Wait SSH2_MSG_KEXDH_REPLY."); |
|
|
packet_read_expect(&payload_len, SSH2_MSG_KEXDH_REPLY); |
packet_read_expect(&plen, SSH2_MSG_KEXDH_REPLY); |
|
|
debug("Got SSH2_MSG_KEXDH_REPLY."); |
debug("Got SSH2_MSG_KEXDH_REPLY."); |
|
|
|
|
shared_secret |
shared_secret |
); |
); |
xfree(server_host_key_blob); |
xfree(server_host_key_blob); |
buffer_free(client_kexinit); |
DH_free(dh); |
buffer_free(server_kexinit); |
|
xfree(client_kexinit); |
|
xfree(server_kexinit); |
|
#ifdef DEBUG_KEXDH |
#ifdef DEBUG_KEXDH |
fprintf(stderr, "hash == "); |
fprintf(stderr, "hash == "); |
for (i = 0; i< 20; i++) |
for (i = 0; i< 20; i++) |
|
|
kex_derive_keys(kex, hash, shared_secret); |
kex_derive_keys(kex, hash, shared_secret); |
packet_set_kex(kex); |
packet_set_kex(kex); |
|
|
/* have keys, free DH */ |
|
DH_free(dh); |
|
|
|
/* save session id */ |
/* save session id */ |
session_id2_len = 20; |
session_id2_len = 20; |
session_id2 = xmalloc(session_id2_len); |
session_id2 = xmalloc(session_id2_len); |
memcpy(session_id2, hash, session_id2_len); |
memcpy(session_id2, hash, session_id2_len); |
|
} |
|
|
|
void |
|
ssh_kex2(char *host, struct sockaddr *hostaddr) |
|
{ |
|
int i, plen; |
|
Kex *kex; |
|
Buffer *client_kexinit, *server_kexinit; |
|
char *sprop[PROPOSAL_MAX]; |
|
|
|
if (options.ciphers != NULL) { |
|
myproposal[PROPOSAL_ENC_ALGS_CTOS] = |
|
myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers; |
|
} else if (options.cipher == SSH_CIPHER_3DES) { |
|
myproposal[PROPOSAL_ENC_ALGS_CTOS] = |
|
myproposal[PROPOSAL_ENC_ALGS_STOC] = |
|
(char *) cipher_name(SSH_CIPHER_3DES_CBC); |
|
} else if (options.cipher == SSH_CIPHER_BLOWFISH) { |
|
myproposal[PROPOSAL_ENC_ALGS_CTOS] = |
|
myproposal[PROPOSAL_ENC_ALGS_STOC] = |
|
(char *) cipher_name(SSH_CIPHER_BLOWFISH_CBC); |
|
} |
|
if (options.compression) { |
|
myproposal[PROPOSAL_COMP_ALGS_CTOS] = "zlib"; |
|
myproposal[PROPOSAL_COMP_ALGS_STOC] = "zlib"; |
|
} else { |
|
myproposal[PROPOSAL_COMP_ALGS_CTOS] = "none"; |
|
myproposal[PROPOSAL_COMP_ALGS_STOC] = "none"; |
|
} |
|
|
|
/* buffers with raw kexinit messages */ |
|
server_kexinit = xmalloc(sizeof(*server_kexinit)); |
|
buffer_init(server_kexinit); |
|
client_kexinit = kex_init(myproposal); |
|
|
|
/* algorithm negotiation */ |
|
kex_exchange_kexinit(client_kexinit, server_kexinit, sprop); |
|
kex = kex_choose_conf(myproposal, sprop, 0); |
|
for (i = 0; i < PROPOSAL_MAX; i++) |
|
xfree(sprop[i]); |
|
|
|
/* server authentication and session key agreement */ |
|
ssh_kex_dh(kex, host, hostaddr, client_kexinit, server_kexinit); |
|
|
|
buffer_free(client_kexinit); |
|
buffer_free(server_kexinit); |
|
xfree(client_kexinit); |
|
xfree(server_kexinit); |
|
|
debug("Wait SSH2_MSG_NEWKEYS."); |
debug("Wait SSH2_MSG_NEWKEYS."); |
packet_read_expect(&payload_len, SSH2_MSG_NEWKEYS); |
packet_read_expect(&plen, SSH2_MSG_NEWKEYS); |
packet_done(); |
packet_done(); |
debug("GOT SSH2_MSG_NEWKEYS."); |
debug("GOT SSH2_MSG_NEWKEYS."); |
|
|
|
|
#endif |
#endif |
debug("done: KEX2."); |
debug("done: KEX2."); |
} |
} |
|
|
/* |
/* |
* Authenticate user |
* Authenticate user |
*/ |
*/ |
|
|
char prompt[80]; |
char prompt[80]; |
char *password; |
char *password; |
|
|
if (attempt++ > options.number_of_password_prompts) |
if (attempt++ >= options.number_of_password_prompts) |
return 0; |
return 0; |
|
|
|
if(attempt != 1) |
|
error("Permission denied, please try again."); |
|
|
snprintf(prompt, sizeof(prompt), "%.30s@%.40s's password: ", |
snprintf(prompt, sizeof(prompt), "%.30s@%.40s's password: ", |
server_user, host); |
server_user, host); |