diff options
Diffstat (limited to 'src/protocol/internal/fqterm_ssh1_packet.cpp')
-rw-r--r-- | src/protocol/internal/fqterm_ssh1_packet.cpp | 88 |
1 files changed, 21 insertions, 67 deletions
diff --git a/src/protocol/internal/fqterm_ssh1_packet.cpp b/src/protocol/internal/fqterm_ssh1_packet.cpp index 7510194..eda4fd1 100644 --- a/src/protocol/internal/fqterm_ssh1_packet.cpp +++ b/src/protocol/internal/fqterm_ssh1_packet.cpp @@ -35,73 +35,27 @@ namespace FQTerm { cipher = new_3des_ssh1(0); } -void FQTermSSH1PacketReceiver::parseData(buffer *input) { - u_int mycrc, gotcrc; - u_char *buf = NULL; - u_char *targetData = NULL; - u_char *sourceData = NULL; - - // Get the length of the packet. - while (buffer_len(input) > 0) { - if (buffer_len(input) < 4) { - FQ_TRACE("ssh1packet", 3) << "The packet is too small."; - return ; - } - buf = buffer_data(input); - real_data_len_ = ntohu32(buf); - - if (real_data_len_ > SSH_BUFFER_MAX) { - emit packetError(tr("parseData: The packet is too big")); - return ; - } - - u_int total_len = (real_data_len_ + 8) &~7; - u_int padding_len = total_len - real_data_len_; - - real_data_len_ -= 5; - buffer_clear(&recvbuf); - - // Get the data of the packet. - if (buffer_len(input) - 4 < (long)total_len) { - FQ_TRACE("ssh1packet", 3) << "The packet is too small"; - return ; - } - - real_data_len_ = buffer_get_u32(input) - 5; - targetData = new u_char[total_len]; - sourceData = new u_char[total_len]; - memset(targetData, 0, total_len); - memset(sourceData, 0, total_len); - - buffer_get(input, sourceData, total_len); - if (cipher->started) { - cipher->crypt(cipher, sourceData, targetData, total_len); - } else { - memcpy(targetData, sourceData, total_len); - } - - buffer_append(&recvbuf, targetData, total_len); - - // Check the crc32. - buf = buffer_data(&recvbuf) + total_len - 4; - mycrc = ntohu32(buf); - gotcrc = ssh_crc32(buffer_data(&recvbuf), total_len - 4); - - if (mycrc != gotcrc) { - emit packetError(tr("parseData: bad CRC32")); - break; - } - - // Drop the padding. - buffer_consume(&recvbuf, padding_len); - - packet_type_ = buffer_get_u8(&recvbuf); - - emit packetAvaliable(packet_type_); - - delete [] sourceData; - delete [] targetData; - } +void FQTermSSH1PacketReceiver::parseData(buffer *input) +{ + while (buffer_len(input) > 0) { + int res = parse_ssh1_packet(input, &recvbuf, cipher); + switch (res) { + case -ETOOBIG: + emit packetError("Packet too big!"); + return; + case -ETOOSMALL: + return; + case -ECRC32: + emit packetError("CRC32 error!"); + return; + default: + real_data_len_ = res; + } + + packet_type_ = buffer_get_u8(&recvbuf); + + emit packetAvaliable(packet_type_); + } } } // namespace FQTerm |