mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-10 18:28:10 +09:00
kex: Reformat ssh_send_kex
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
95
src/kex.c
95
src/kex.c
@@ -861,61 +861,66 @@ int ssh_kex_select_methods (ssh_session session)
|
|||||||
/* this function only sends the predefined set of kex methods */
|
/* this function only sends the predefined set of kex methods */
|
||||||
int ssh_send_kex(ssh_session session, int server_kex)
|
int ssh_send_kex(ssh_session session, int server_kex)
|
||||||
{
|
{
|
||||||
struct ssh_kex_struct *kex = (server_kex ? &session->next_crypto->server_kex :
|
struct ssh_kex_struct *kex = (server_kex ?
|
||||||
&session->next_crypto->client_kex);
|
&session->next_crypto->server_kex :
|
||||||
ssh_string str = NULL;
|
&session->next_crypto->client_kex);
|
||||||
int i;
|
ssh_string str = NULL;
|
||||||
int rc;
|
int i;
|
||||||
|
int rc;
|
||||||
|
|
||||||
rc = ssh_buffer_pack(session->out_buffer,
|
rc = ssh_buffer_pack(session->out_buffer,
|
||||||
"bP",
|
"bP",
|
||||||
SSH2_MSG_KEXINIT,
|
SSH2_MSG_KEXINIT,
|
||||||
16,
|
16,
|
||||||
kex->cookie); /* cookie */
|
kex->cookie); /* cookie */
|
||||||
if (rc != SSH_OK)
|
if (rc != SSH_OK)
|
||||||
goto error;
|
goto error;
|
||||||
if (ssh_hashbufout_add_cookie(session) < 0) {
|
if (ssh_hashbufout_add_cookie(session) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
ssh_list_kex(kex);
|
|
||||||
|
|
||||||
for (i = 0; i < SSH_KEX_METHODS; i++) {
|
|
||||||
str = ssh_string_from_char(kex->methods[i]);
|
|
||||||
if (str == NULL) {
|
|
||||||
goto error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ssh_buffer_add_ssh_string(session->out_hashbuf, str) < 0) {
|
ssh_list_kex(kex);
|
||||||
goto error;
|
|
||||||
|
for (i = 0; i < SSH_KEX_METHODS; i++) {
|
||||||
|
str = ssh_string_from_char(kex->methods[i]);
|
||||||
|
if (str == NULL) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = ssh_buffer_add_ssh_string(session->out_hashbuf, str);
|
||||||
|
if (rc < 0) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
rc = ssh_buffer_add_ssh_string(session->out_buffer, str);
|
||||||
|
if (rc < 0) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
SSH_STRING_FREE(str);
|
||||||
|
str = NULL;
|
||||||
}
|
}
|
||||||
if (ssh_buffer_add_ssh_string(session->out_buffer, str) < 0) {
|
|
||||||
goto error;
|
rc = ssh_buffer_pack(session->out_buffer,
|
||||||
|
"bd",
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
if (rc != SSH_OK) {
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
SSH_STRING_FREE(str);
|
|
||||||
str = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = ssh_buffer_pack(session->out_buffer,
|
rc = ssh_packet_send(session);
|
||||||
"bd",
|
if (rc == SSH_ERROR) {
|
||||||
0,
|
return -1;
|
||||||
0);
|
}
|
||||||
if (rc != SSH_OK) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ssh_packet_send(session) == SSH_ERROR) {
|
SSH_LOG(SSH_LOG_PACKET, "SSH_MSG_KEXINIT sent");
|
||||||
return -1;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
SSH_LOG(SSH_LOG_PACKET, "SSH_MSG_KEXINIT sent");
|
|
||||||
return 0;
|
|
||||||
error:
|
error:
|
||||||
ssh_buffer_reinit(session->out_buffer);
|
ssh_buffer_reinit(session->out_buffer);
|
||||||
ssh_buffer_reinit(session->out_hashbuf);
|
ssh_buffer_reinit(session->out_hashbuf);
|
||||||
SSH_STRING_FREE(str);
|
SSH_STRING_FREE(str);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user