mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 02:38:09 +09:00
packet: Reformat packet_send2()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
47
src/packet.c
47
src/packet.c
@@ -551,27 +551,32 @@ static int ssh_packet_write(ssh_session session) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int packet_send2(ssh_session session) {
|
||||
unsigned int blocksize = (session->current_crypto ?
|
||||
static int packet_send2(ssh_session session)
|
||||
{
|
||||
unsigned int blocksize =
|
||||
(session->current_crypto ?
|
||||
session->current_crypto->out_cipher->blocksize : 8);
|
||||
unsigned int lenfield_blocksize = (session->current_crypto ?
|
||||
unsigned int lenfield_blocksize =
|
||||
(session->current_crypto ?
|
||||
session->current_crypto->out_cipher->lenfield_blocksize : 0);
|
||||
enum ssh_hmac_e hmac_type = (session->current_crypto ?
|
||||
enum ssh_hmac_e hmac_type =
|
||||
(session->current_crypto ?
|
||||
session->current_crypto->out_hmac : session->next_crypto->out_hmac);
|
||||
uint32_t currentlen = ssh_buffer_get_len(session->out_buffer);
|
||||
unsigned char *hmac = NULL;
|
||||
char padstring[32] = { 0 };
|
||||
int rc = SSH_ERROR;
|
||||
uint32_t finallen,payloadsize,compsize;
|
||||
uint8_t padstring[32] = { 0 };
|
||||
uint8_t padding;
|
||||
uint32_t finallen, payloadsize, compsize;
|
||||
ssh_buffer header_buffer = ssh_buffer_new();
|
||||
int rc = SSH_ERROR;
|
||||
|
||||
payloadsize = currentlen;
|
||||
#ifdef WITH_ZLIB
|
||||
if (session->current_crypto
|
||||
&& session->current_crypto->do_compress_out
|
||||
&& ssh_buffer_get_len(session->out_buffer)) {
|
||||
if (compress_buffer(session,session->out_buffer) < 0) {
|
||||
if (session->current_crypto != NULL &&
|
||||
session->current_crypto->do_compress_out &&
|
||||
ssh_buffer_get_len(session->out_buffer) > 0) {
|
||||
rc = compress_buffer(session,session->out_buffer);
|
||||
if (rc < 0) {
|
||||
goto error;
|
||||
}
|
||||
currentlen = ssh_buffer_get_len(session->out_buffer);
|
||||
@@ -599,6 +604,7 @@ static int packet_send2(ssh_session session) {
|
||||
ssh_set_error_oom(session);
|
||||
goto error;
|
||||
}
|
||||
|
||||
finallen = currentlen + padding + 1;
|
||||
rc = ssh_buffer_pack(header_buffer, "db", finallen, padding);
|
||||
if (rc == SSH_ERROR){
|
||||
@@ -611,12 +617,14 @@ static int packet_send2(ssh_session session) {
|
||||
if (rc < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
rc = ssh_buffer_add_data(session->out_buffer, padstring, padding);
|
||||
if (rc < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
#ifdef WITH_PCAP
|
||||
if (session->pcap_ctx) {
|
||||
if (session->pcap_ctx != NULL) {
|
||||
ssh_pcap_context_write(session->pcap_ctx,
|
||||
SSH_PCAP_DIR_OUT,
|
||||
ssh_buffer_get(session->out_buffer),
|
||||
@@ -624,10 +632,14 @@ static int packet_send2(ssh_session session) {
|
||||
ssh_buffer_get_len(session->out_buffer));
|
||||
}
|
||||
#endif
|
||||
hmac = ssh_packet_encrypt(session, ssh_buffer_get(session->out_buffer),
|
||||
|
||||
hmac = ssh_packet_encrypt(session,
|
||||
ssh_buffer_get(session->out_buffer),
|
||||
ssh_buffer_get_len(session->out_buffer));
|
||||
if (hmac) {
|
||||
rc = ssh_buffer_add_data(session->out_buffer, hmac, hmac_digest_len(hmac_type));
|
||||
if (hmac != NULL) {
|
||||
rc = ssh_buffer_add_data(session->out_buffer,
|
||||
hmac,
|
||||
hmac_digest_len(hmac_type));
|
||||
if (rc < 0) {
|
||||
goto error;
|
||||
}
|
||||
@@ -643,9 +655,12 @@ static int packet_send2(ssh_session session) {
|
||||
SSH_LOG(SSH_LOG_PACKET,
|
||||
"packet: wrote [len=%d,padding=%hhd,comp=%d,payload=%d]",
|
||||
finallen, padding, compsize, payloadsize);
|
||||
if (ssh_buffer_reinit(session->out_buffer) < 0) {
|
||||
|
||||
rc = ssh_buffer_reinit(session->out_buffer);
|
||||
if (rc < 0) {
|
||||
rc = SSH_ERROR;
|
||||
}
|
||||
|
||||
error:
|
||||
if (header_buffer != NULL) {
|
||||
ssh_buffer_free(header_buffer);
|
||||
|
||||
Reference in New Issue
Block a user