diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2011-06-12 20:55:58 +0200 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2011-06-12 20:55:58 +0200 |
commit | 3b72bf08802a058cb663a40359ed0e006a1480ca (patch) | |
tree | 7edbcd4d07215559574592f830071a055250a25b | |
parent | 113de1354322f3fb310b23b412c548d8a9e417bc (diff) | |
download | libssh-3b72bf08802a058cb663a40359ed0e006a1480ca.tar.gz libssh-3b72bf08802a058cb663a40359ed0e006a1480ca.tar.xz libssh-3b72bf08802a058cb663a40359ed0e006a1480ca.zip |
Moved DH specific code to dh.h
-rw-r--r-- | src/client.c | 47 | ||||
-rw-r--r-- | src/dh.c | 44 |
2 files changed, 46 insertions, 45 deletions
diff --git a/src/client.c b/src/client.c index 84a0ad92..7b2e4494 100644 --- a/src/client.c +++ b/src/client.c @@ -318,39 +318,14 @@ error: * completed */ static int dh_handshake(ssh_session session) { - ssh_string e = NULL; - ssh_string f = NULL; - ssh_string signature = NULL; - int rc = SSH_ERROR; + + int rc = SSH_AGAIN; enter_function(); switch (session->dh_handshake_state) { case DH_STATE_INIT: - if (buffer_add_u8(session->out_buffer, SSH2_MSG_KEXDH_INIT) < 0) { - goto error; - } - - if (dh_generate_x(session) < 0) { - goto error; - } - if (dh_generate_e(session) < 0) { - goto error; - } - - e = dh_get_e(session); - if (e == NULL) { - goto error; - } - - if (buffer_add_ssh_string(session->out_buffer, e) < 0) { - goto error; - } - ssh_string_burn(e); - ssh_string_free(e); - e=NULL; - - rc = packet_send(session); + rc = ssh_client_dh_init(session); if (rc == SSH_ERROR) { goto error; } @@ -371,23 +346,7 @@ static int dh_handshake(ssh_session session) { leave_function(); return SSH_ERROR; } - - leave_function(); - return SSH_AGAIN; error: - if(e != NULL){ - ssh_string_burn(e); - ssh_string_free(e); - } - if(f != NULL){ - ssh_string_burn(f); - ssh_string_free(f); - } - if(signature != NULL){ - ssh_string_burn(signature); - ssh_string_free(signature); - } - leave_function(); return rc; } @@ -55,6 +55,7 @@ #include "libssh/session.h" #include "libssh/keys.h" #include "libssh/dh.h" +#include "libssh/ssh2.h" /* todo: remove it */ #include "libssh/string.h" @@ -479,6 +480,47 @@ int dh_build_k(ssh_session session) { return 0; } +/** @internal + * @brief Starts diffie-hellman-group1 key exchange + */ +int ssh_client_dh_init(ssh_session session){ + ssh_string e = NULL; + int rc; + enter_function(); + if (buffer_add_u8(session->out_buffer, SSH2_MSG_KEXDH_INIT) < 0) { + goto error; + } + + if (dh_generate_x(session) < 0) { + goto error; + } + if (dh_generate_e(session) < 0) { + goto error; + } + + e = dh_get_e(session); + if (e == NULL) { + goto error; + } + + if (buffer_add_ssh_string(session->out_buffer, e) < 0) { + goto error; + } + ssh_string_burn(e); + ssh_string_free(e); + e=NULL; + + rc = packet_send(session); + return rc; + error: + if(e != NULL){ + ssh_string_burn(e); + ssh_string_free(e); + } + + leave_function(); + return SSH_ERROR; +} /* static void sha_add(ssh_string str,SHACTX ctx){ sha1_update(ctx,str,string_len(str)+4); @@ -849,7 +891,7 @@ int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash) { return SSH_ERROR; } - h = malloc(sizeof(unsigned char *) * MD5_DIGEST_LEN); + h = malloc(sizeof(unsigned char) * MD5_DIGEST_LEN); if (h == NULL) { return SSH_ERROR; } |