From: Pekka Riikonen Date: Thu, 30 Nov 2006 14:55:37 +0000 (+0000) Subject: Handle special packet processing correctly. X-Git-Tag: silc.client.1.1.beta1~155 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=7ada165ecc5e25429cd4fc9511f31794cd86d540 Handle special packet processing correctly. --- diff --git a/lib/silccore/silcmessage.c b/lib/silccore/silcmessage.c index 19fb22f3..e7f06c0e 100644 --- a/lib/silccore/silcmessage.c +++ b/lib/silccore/silcmessage.c @@ -281,7 +281,7 @@ SilcBool silc_message_payload_decrypt(unsigned char *data, if (!private_message || (private_message && static_key)) iv_len = block_len; - if (data_len <= (mac_len + iv_len + block_len)) + if (data_len < (mac_len + iv_len + block_len)) return FALSE; if (check_mac) { @@ -306,8 +306,10 @@ SilcBool silc_message_payload_decrypt(unsigned char *data, silc_cipher_get_iv(cipher)); /* Decrypt block */ - if (!silc_cipher_decrypt(cipher, data, data, block_len, ivp)) + if (!silc_cipher_decrypt(cipher, data, data, block_len, ivp)) { + SILC_ASSERT(FALSE); return FALSE; + } /* Get the payload length and decrypt rest */ totlen = 2; @@ -319,8 +321,10 @@ SilcBool silc_message_payload_decrypt(unsigned char *data, if (totlen >= block_len) if (!silc_cipher_decrypt(cipher, data + block_len, data + block_len, (totlen - block_len) + SILC_MESSAGE_PAD(totlen), - ivp)) + ivp)) { + SILC_ASSERT(FALSE); return FALSE; + } return TRUE; } @@ -648,9 +652,9 @@ unsigned char *silc_message_get_mac(SilcMessagePayload payload) /* Verify the signature in SILC_MESSAGE_FLAG_SIGNED Payload */ -int silc_message_signed_verify(SilcMessagePayload message, - SilcPublicKey remote_public_key, - SilcHash hash) +SilcAuthResult silc_message_signed_verify(SilcMessagePayload message, + SilcPublicKey remote_public_key, + SilcHash hash) { int ret = SILC_AUTH_FAILED; SilcBuffer sign, tmp; diff --git a/lib/silccore/silcmessage.h b/lib/silccore/silcmessage.h index 09ca21aa..e51c3009 100644 --- a/lib/silccore/silcmessage.h +++ b/lib/silccore/silcmessage.h @@ -329,9 +329,10 @@ unsigned char *silc_message_get_mac(SilcMessagePayload payload); * * SYNOPSIS * - * int silc_message_signed_verify(SilcMessagePayload message, - * SilcPublicKey remote_public_key, - * SilcHash hash); + * SilcAuthResult + * silc_message_signed_verify(SilcMessagePayload message, + * SilcPublicKey remote_public_key, + * SilcHash hash); * * DESCRIPTION * @@ -341,9 +342,9 @@ unsigned char *silc_message_get_mac(SilcMessagePayload payload); * returns SILC_AUTH_OK if the signature verification was successful. * ***/ -int silc_message_signed_verify(SilcMessagePayload message, - SilcPublicKey remote_public_key, - SilcHash hash); +SilcAuthResult silc_message_signed_verify(SilcMessagePayload message, + SilcPublicKey remote_public_key, + SilcHash hash); /****f* silccore/SilcMessageAPI/silc_message_signed_get_public_key * diff --git a/lib/silccore/silcpacket.c b/lib/silccore/silcpacket.c index 2a2b9af1..39ca67c4 100644 --- a/lib/silccore/silcpacket.c +++ b/lib/silccore/silcpacket.c @@ -1434,7 +1434,7 @@ static void silc_packet_read_process(SilcPacketStream stream) SilcUInt32 paddedlen, mac_len, block_len, ivlen, psnlen; unsigned char tmp[SILC_PACKET_MIN_HEADER_LEN], *header; unsigned char iv[SILC_CIPHER_MAX_IV_SIZE], *packet_seq = NULL; - SilcBool normal = TRUE; + SilcBool normal; int ret; /* Parse the packets from the data */ @@ -1442,6 +1442,7 @@ static void silc_packet_read_process(SilcPacketStream stream) ivlen = psnlen = 0; cipher = stream->receive_key[0]; hmac = stream->receive_hmac[0]; + normal = FALSE; if (silc_buffer_len(&stream->inbuf) < (stream->iv_included ? SILC_PACKET_MIN_HEADER_LEN_IV : @@ -1547,6 +1548,7 @@ static void silc_packet_read_process(SilcPacketStream stream) silc_buffer_reset(&stream->inbuf); return; } + packet->stream = stream; /* Allocate more space to packet buffer, if needed */ if (silc_buffer_truelen(&packet->buffer) < paddedlen) { @@ -1616,7 +1618,6 @@ static void silc_packet_read_process(SilcPacketStream stream) silc_buffer_pull(&stream->inbuf, paddedlen + mac_len); /* Dispatch the packet to application */ - packet->stream = stream; silc_packet_dispatch(packet); } diff --git a/lib/silccore/silcpacket.h b/lib/silccore/silcpacket.h index d926bcb3..89d0da9b 100644 --- a/lib/silccore/silcpacket.h +++ b/lib/silccore/silcpacket.h @@ -415,7 +415,7 @@ SilcPacketStream silc_packet_stream_create(SilcPacketEngine engine, * DESCRIPTION * * Destroy packet stream and the underlaying stream. This will also - * send end of stream to the underlaying stream. + * close and destroy the underlaying stream. * ***/ void silc_packet_stream_destroy(SilcPacketStream stream);